You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2020/07/09 12:31:25 UTC
[activemq-artemis] branch master updated: ARTEMIS-2837 Avoiding
bursts on writes and pending callbacks
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/master by this push:
new 1761f76 ARTEMIS-2837 Avoiding bursts on writes and pending callbacks
new eb54564 This closes #3214
1761f76 is described below
commit 1761f76308010ee2f0862392575185026215223f
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Wed Jul 8 16:33:38 2020 -0400
ARTEMIS-2837 Avoiding bursts on writes and pending callbacks
---
.../core/journal/impl/JournalFilesRepository.java | 10 ++++-----
.../artemis/core/journal/impl/JournalImpl.java | 21 +++++++++++-------
.../core/journal/impl/JournalImplTestUnit.java | 25 ++++++++++++++++++++++
3 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java
index 2c6033b..800d960 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java
@@ -444,11 +444,11 @@ public class JournalFilesRepository {
pushOpen();
nextFile = openedFiles.poll(journalFileOpenTimeout, TimeUnit.SECONDS);
- }
-
- if (openedFiles.isEmpty()) {
- // if empty, push to open one.
- pushOpen();
+ } else {
+ if (openedFiles.isEmpty()) {
+ // if empty, push to open one.
+ pushOpen();
+ }
}
if (nextFile == null) {
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java
index af443c4..8092cd0 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalImpl.java
@@ -47,6 +47,7 @@ import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
import org.apache.activemq.artemis.api.core.ActiveMQShutdownException;
import org.apache.activemq.artemis.api.core.Pair;
+import org.apache.activemq.artemis.core.io.DummyCallback;
import org.apache.activemq.artemis.core.io.IOCallback;
import org.apache.activemq.artemis.core.io.IOCriticalErrorListener;
import org.apache.activemq.artemis.core.io.SequentialFile;
@@ -840,7 +841,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
throw ActiveMQJournalBundle.BUNDLE.recordLargerThanStoreMax(addRecordEncodeSize, maxRecordSize);
}
- final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
+ final SimpleFuture<Boolean> result = newSyncAndCallbackResult(callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
@@ -932,7 +933,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
Object record,
boolean sync,
IOCompletion callback) throws InterruptedException, java.util.concurrent.ExecutionException {
- final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
+ final SimpleFuture<Boolean> result = newSyncAndCallbackResult(callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
@@ -1016,7 +1017,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
private void internalAppendDeleteRecord(long id,
boolean sync,
IOCompletion callback) throws InterruptedException, java.util.concurrent.ExecutionException {
- final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
+ final SimpleFuture<Boolean> result = newSyncAndCallbackResult(callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
@@ -1063,8 +1064,12 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
result.get();
}
- private static SimpleFuture newSyncAndCallbackResult(boolean sync, IOCompletion callback) {
- return (sync && callback == null) ? new SimpleFutureImpl<>() : SimpleFuture.dumb();
+ private static SimpleFuture newSyncAndCallbackResult(IOCompletion callback) {
+ if (callback != null && callback != DummyCallback.getInstance()) {
+ return SimpleFuture.dumb();
+ } else {
+ return new SimpleFutureImpl<>();
+ }
}
@Override
@@ -1290,7 +1295,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
logger.trace("scheduling appendPrepareRecord::txID=" + txID);
}
- final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
+ final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(callback);
appendExecutor.execute(new Runnable() {
@Override
@@ -1376,7 +1381,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
}
- final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
+ final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(callback);
appendExecutor.execute(new Runnable() {
@Override
@@ -1430,7 +1435,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
- final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
+ final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java
index c6e0173..f615c29 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/JournalImplTestUnit.java
@@ -118,6 +118,31 @@ public abstract class JournalImplTestUnit extends JournalImplTestBase {
}
@Test
+ public void testFlushAppendsAndDeletes() throws Exception {
+ setup(10, 10 * 1024, true);
+ createJournal();
+ startJournal();
+ load();
+ byte[] record = new byte[1000];
+ for (int i = 0; i < record.length; i++) {
+ record[i] = (byte) 'a';
+ }
+ // Appending records after restart should be valid (not throwing any
+ // exceptions)
+ for (int i = 0; i < 10_000; i++) {
+ journal.appendAddRecord(i, (byte) 1, new SimpleEncoding(2, (byte) 'a'), false);
+ journal.appendDeleteRecord(i, false);
+ }
+ stopJournal();
+
+ List<String> files = fileFactory.listFiles(fileExtension);
+
+ // I am allowing one extra as a possible race with pushOpenFiles. I have not seen it happening on my test
+ // but it wouldn't be a problem if it happened
+ Assert.assertTrue("Supposed to have up to 10 files", files.size() <= 11);
+ }
+
+ @Test
public void testParams() throws Exception {
try {
new JournalImpl(JournalImpl.MIN_FILE_SIZE - 1, 10, 10, 0, 0, fileFactory, filePrefix, fileExtension, 1);