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/08/17 17:01:55 UTC
[activemq-artemis] branch master updated (093cbe2 -> f6ac058)
This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git.
from 093cbe2 This closes #3243
new 851aef1 Revert "ARTEMIS-2837 Avoiding bursts on writes and pending callbacks"
new a6bf7d0 ARTEMIS-2837 Bursts of open files under high load
new 40f20cf ARTEMIS-2877 Fix journal replication scalability
new f6ac058 This closes #3242
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../core/client/impl/ClientSessionFactoryImpl.java | 21 ++++++
.../artemis/core/protocol/core/Channel.java | 14 ++++
.../artemis/core/protocol/core/ChannelHandler.java | 4 ++
.../core/protocol/core/impl/ChannelImpl.java | 82 ++++++++++++++++++++++
.../protocol/core/impl/RemotingConnectionImpl.java | 9 +++
.../impl/netty/ActiveMQChannelHandler.java | 6 ++
.../core/remoting/impl/netty/NettyConnection.java | 11 +++
.../artemis/spi/core/remoting/BufferHandler.java | 4 ++
.../artemis/spi/core/remoting/Connection.java | 9 +++
.../core/protocol/core/impl/ChannelImplTest.java | 5 ++
.../core/journal/impl/JournalFilesRepository.java | 13 ++--
.../artemis/core/journal/impl/JournalImpl.java | 21 +++---
.../core/remoting/impl/invm/InVMConnection.java | 5 ++
.../core/replication/ReplicationEndpoint.java | 52 ++++++++++++--
.../integration/cluster/util/BackupSyncDelay.java | 10 +++
15 files changed, 243 insertions(+), 23 deletions(-)
[activemq-artemis] 04/04: This closes #3242
Posted by cl...@apache.org.
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
commit f6ac058f7fe1518f3ae68587d15c1e3295ea5677
Merge: 093cbe2 40f20cf
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Mon Aug 17 13:01:42 2020 -0400
This closes #3242
.../core/client/impl/ClientSessionFactoryImpl.java | 21 ++++++
.../artemis/core/protocol/core/Channel.java | 14 ++++
.../artemis/core/protocol/core/ChannelHandler.java | 4 ++
.../core/protocol/core/impl/ChannelImpl.java | 82 ++++++++++++++++++++++
.../protocol/core/impl/RemotingConnectionImpl.java | 9 +++
.../impl/netty/ActiveMQChannelHandler.java | 6 ++
.../core/remoting/impl/netty/NettyConnection.java | 11 +++
.../artemis/spi/core/remoting/BufferHandler.java | 4 ++
.../artemis/spi/core/remoting/Connection.java | 9 +++
.../core/protocol/core/impl/ChannelImplTest.java | 5 ++
.../core/journal/impl/JournalFilesRepository.java | 13 ++--
.../artemis/core/journal/impl/JournalImpl.java | 21 +++---
.../core/remoting/impl/invm/InVMConnection.java | 5 ++
.../core/replication/ReplicationEndpoint.java | 52 ++++++++++++--
.../integration/cluster/util/BackupSyncDelay.java | 10 +++
15 files changed, 243 insertions(+), 23 deletions(-)
[activemq-artemis] 01/04: Revert "ARTEMIS-2837 Avoiding bursts on
writes and pending callbacks"
Posted by cl...@apache.org.
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
commit 851aef11723825f638c288ddd2ddf656cfcdaab2
Author: franz1981 <ni...@gmail.com>
AuthorDate: Fri Aug 7 20:05:15 2020 +0200
Revert "ARTEMIS-2837 Avoiding bursts on writes and pending callbacks"
This reverts commit 1761f763
---
.../core/journal/impl/JournalFilesRepository.java | 10 ++++-----
.../artemis/core/journal/impl/JournalImpl.java | 21 +++++++-----------
.../core/journal/impl/JournalImplTestUnit.java | 25 ----------------------
3 files changed, 13 insertions(+), 43 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 800d960..2c6033b 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);
- } else {
- if (openedFiles.isEmpty()) {
- // if empty, push to open one.
- pushOpen();
- }
+ }
+
+ 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 8092cd0..af443c4 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,7 +47,6 @@ 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;
@@ -841,7 +840,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
throw ActiveMQJournalBundle.BUNDLE.recordLargerThanStoreMax(addRecordEncodeSize, maxRecordSize);
}
- final SimpleFuture<Boolean> result = newSyncAndCallbackResult(callback);
+ final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
@@ -933,7 +932,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(callback);
+ final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
@@ -1017,7 +1016,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(callback);
+ final SimpleFuture<Boolean> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
public void run() {
@@ -1064,12 +1063,8 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
result.get();
}
- private static SimpleFuture newSyncAndCallbackResult(IOCompletion callback) {
- if (callback != null && callback != DummyCallback.getInstance()) {
- return SimpleFuture.dumb();
- } else {
- return new SimpleFutureImpl<>();
- }
+ private static SimpleFuture newSyncAndCallbackResult(boolean sync, IOCompletion callback) {
+ return (sync && callback == null) ? new SimpleFutureImpl<>() : SimpleFuture.dumb();
}
@Override
@@ -1295,7 +1290,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
logger.trace("scheduling appendPrepareRecord::txID=" + txID);
}
- final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(callback);
+ final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
@@ -1381,7 +1376,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
}
- final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(callback);
+ final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, callback);
appendExecutor.execute(new Runnable() {
@Override
@@ -1435,7 +1430,7 @@ public class JournalImpl extends JournalBase implements TestableJournal, Journal
- final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(callback);
+ final SimpleFuture<JournalTransaction> result = newSyncAndCallbackResult(sync, 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 f615c29..c6e0173 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,31 +118,6 @@ 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);
[activemq-artemis] 02/04: ARTEMIS-2837 Bursts of open files under
high load
Posted by cl...@apache.org.
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
commit a6bf7d0e040eadfb5800651277edfe25191490ba
Author: franz1981 <ni...@gmail.com>
AuthorDate: Thu Aug 13 20:31:10 2020 +0200
ARTEMIS-2837 Bursts of open files under high load
This would prevent to push a new opened file if there
is already one available to be consumed
---
.../core/journal/impl/JournalFilesRepository.java | 23 +++++++++++---------
.../core/journal/impl/JournalImplTestUnit.java | 25 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 10 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..0765b7a 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
@@ -88,11 +88,14 @@ public class JournalFilesRepository {
private final Runnable pushOpenRunnable = new Runnable() {
@Override
public void run() {
- try {
- pushOpenedFile();
- } catch (Exception e) {
- ActiveMQJournalLogger.LOGGER.errorPushingFile(e);
- fileFactory.onIOError(e, "unable to open ", null);
+ // if there's already an opened file there is no need to push a new one
+ if (openedFiles.isEmpty()) {
+ try {
+ pushOpenedFile();
+ } catch (Exception e) {
+ ActiveMQJournalLogger.LOGGER.errorPushingFile(e);
+ fileFactory.onIOError(e, "unable to open ", null);
+ }
}
}
};
@@ -444,11 +447,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/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);
[activemq-artemis] 03/04: ARTEMIS-2877 Fix journal replication
scalability
Posted by cl...@apache.org.
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
commit 40f20cfe6a796bdec050b6a149c4fbff3273fdef
Author: franz1981 <ni...@gmail.com>
AuthorDate: Tue Aug 11 17:33:32 2020 +0200
ARTEMIS-2877 Fix journal replication scalability
This is allowing journal appends to happen in burst
during replication, by batching replication response
into the network at the end of the append burst.
---
.../core/client/impl/ClientSessionFactoryImpl.java | 21 ++++++
.../artemis/core/protocol/core/Channel.java | 14 ++++
.../artemis/core/protocol/core/ChannelHandler.java | 4 ++
.../core/protocol/core/impl/ChannelImpl.java | 82 ++++++++++++++++++++++
.../protocol/core/impl/RemotingConnectionImpl.java | 9 +++
.../impl/netty/ActiveMQChannelHandler.java | 6 ++
.../core/remoting/impl/netty/NettyConnection.java | 11 +++
.../artemis/spi/core/remoting/BufferHandler.java | 4 ++
.../artemis/spi/core/remoting/Connection.java | 9 +++
.../core/protocol/core/impl/ChannelImplTest.java | 5 ++
.../core/remoting/impl/invm/InVMConnection.java | 5 ++
.../core/replication/ReplicationEndpoint.java | 52 ++++++++++++--
.../integration/cluster/util/BackupSyncDelay.java | 10 +++
13 files changed, 227 insertions(+), 5 deletions(-)
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl.java
index 75981cf..ba43878 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl.java
@@ -1227,6 +1227,27 @@ public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, C
logger.debug("TheConn == null on ClientSessionFactoryImpl::DelegatingBufferHandler, ignoring packet");
}
}
+
+ @Override
+ public void endOfBatch(final Object connectionID) {
+ RemotingConnection theConn = connection;
+
+ if (theConn != null && connectionID.equals(theConn.getID())) {
+ try {
+ theConn.endOfBatch(connectionID);
+ } catch (final RuntimeException e) {
+ ActiveMQClientLogger.LOGGER.disconnectOnErrorDecoding(e);
+ threadPool.execute(new Runnable() {
+ @Override
+ public void run() {
+ theConn.fail(new ActiveMQException(e.getMessage()));
+ }
+ });
+ }
+ } else {
+ logger.debug("TheConn == null on ClientSessionFactoryImpl::DelegatingBufferHandler, ignoring packet");
+ }
+ }
}
private final class DelegatingFailureListener implements FailureListener {
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/Channel.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/Channel.java
index 56f8259..355e502 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/Channel.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/Channel.java
@@ -85,6 +85,18 @@ public interface Channel {
boolean sendBatched(Packet packet);
/**
+ * Sends a packet on this channel, but request it to be flushed (along with the un-flushed previous ones) only iff
+ * {@code flushConnection} is {@code true}.
+ *
+ * @param packet the packet to send
+ * @param flushConnection if {@code true} requests this {@code packet} and any un-flushed previous sent one to be flushed
+ * to the underlying connection
+ * @return false if the packet was rejected by an outgoing interceptor; true if the send was
+ * successful
+ */
+ boolean send(Packet packet, boolean flushConnection);
+
+ /**
* Sends a packet on this channel and then blocks until it has been written to the connection.
*
* @param packet the packet to send
@@ -131,6 +143,8 @@ public interface Channel {
*/
ChannelHandler getHandler();
+ void endOfBatch();
+
/**
* Closes this channel.
* <p>
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/ChannelHandler.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/ChannelHandler.java
index a44b6d5..4eef181 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/ChannelHandler.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/ChannelHandler.java
@@ -28,4 +28,8 @@ public interface ChannelHandler {
* @param packet the packet received
*/
void handlePacket(Packet packet);
+
+ default void endOfBatch() {
+
+ }
}
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImpl.java
index 84cc135..47fecc8 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImpl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImpl.java
@@ -232,6 +232,79 @@ public final class ChannelImpl implements Channel {
}
@Override
+ public boolean send(Packet packet, boolean flushConnection) {
+ if (invokeInterceptors(packet, interceptors, connection) != null) {
+ return false;
+ }
+
+ final ResponseCache responseAsyncCache = this.responseAsyncCache;
+
+ synchronized (sendLock) {
+ packet.setChannelID(id);
+
+ if (responseAsyncCache != null && packet.isRequiresResponse() && packet.isResponseAsync()) {
+ packet.setCorrelationID(responseAsyncCache.nextCorrelationID());
+ }
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Sending packet nonblocking " + packet + " on channelID=" + id);
+ }
+
+ ActiveMQBuffer buffer = packet.encode(connection);
+
+ lock.lock();
+
+ try {
+ if (failingOver) {
+ waitForFailOver("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " timed-out waiting for fail-over condition on non-blocking send");
+ }
+
+ // Sanity check
+ if (transferring) {
+ throw ActiveMQClientMessageBundle.BUNDLE.cannotSendPacketDuringFailover();
+ }
+
+ if (resendCache != null && packet.isRequiresConfirmations()) {
+ addResendPacket(packet);
+ }
+
+ } finally {
+ lock.unlock();
+ }
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Writing buffer for channelID=" + id);
+ }
+
+ //We do this outside the lock as ResponseCache is threadsafe and allows responses to come in,
+ //As the send could block if the response cache cannot add, preventing responses to be handled.
+ if (responseAsyncCache != null && packet.isRequiresResponse() && packet.isResponseAsync()) {
+ while (!responseAsyncCache.add(packet)) {
+ try {
+ Thread.sleep(1);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+
+ // The actual send must be outside the lock, or with OIO transport, the write can block if the tcp
+ // buffer is full, preventing any incoming buffers being handled and blocking failover
+ try {
+ connection.getTransportConnection().write(buffer, flushConnection);
+ } catch (Throwable t) {
+ //If runtime exception, we must remove from the cache to avoid filling up the cache causing it to be full.
+ //The client would get still know about this as the exception bubbles up the call stack instead.
+ if (responseAsyncCache != null && packet.isRequiresResponse() && packet.isResponseAsync()) {
+ responseAsyncCache.remove(packet.getCorrelationID());
+ }
+ throw t;
+ }
+ return true;
+ }
+ }
+
+ @Override
public boolean sendAndFlush(final Packet packet) {
return send(packet, -1, true, false);
}
@@ -548,6 +621,15 @@ public final class ChannelImpl implements Channel {
}
@Override
+ public void endOfBatch() {
+ ChannelHandler handler = this.handler;
+ if (handler == null) {
+ return;
+ }
+ handler.endOfBatch();
+ }
+
+ @Override
public void close() {
if (closed) {
return;
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/RemotingConnectionImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/RemotingConnectionImpl.java
index 418e3f1..dcc8ecb 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/RemotingConnectionImpl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/RemotingConnectionImpl.java
@@ -392,6 +392,15 @@ public class RemotingConnectionImpl extends AbstractRemotingConnection implement
}
@Override
+ public void endOfBatch(Object connectionID) {
+ super.endOfBatch(connectionID);
+ // TODO we really need a lock here?
+ synchronized (transferLock) {
+ channels.forEach((channelID, channel) -> channel.endOfBatch());
+ }
+ }
+
+ @Override
public String getTransportLocalAddress() {
return getTransportConnection().getLocalAddress();
}
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/ActiveMQChannelHandler.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/ActiveMQChannelHandler.java
index de8b49e..acd314c 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/ActiveMQChannelHandler.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/ActiveMQChannelHandler.java
@@ -77,6 +77,12 @@ public class ActiveMQChannelHandler extends ChannelDuplexHandler {
}
@Override
+ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+ super.channelReadComplete(ctx);
+ handler.endOfBatch(channelId(ctx.channel()));
+ }
+
+ @Override
public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
synchronized (this) {
if (active) {
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
index 51330c7..cde37ae 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
@@ -282,6 +282,17 @@ public class NettyConnection implements Connection {
}
@Override
+ public void write(ActiveMQBuffer buffer, boolean requestFlush) {
+ final Channel channel = this.channel;
+ final ByteBuf bytes = buffer.byteBuf();
+ if (requestFlush) {
+ channel.writeAndFlush(bytes, channel.voidPromise());
+ } else {
+ channel.write(bytes, channel.voidPromise());
+ }
+ }
+
+ @Override
public final void write(ActiveMQBuffer buffer, final boolean flush, final boolean batched) {
write(buffer, flush, batched, null);
}
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/BufferHandler.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/BufferHandler.java
index 5f390a1..f4ddf9d 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/BufferHandler.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/BufferHandler.java
@@ -32,4 +32,8 @@ public interface BufferHandler {
* @param buffer the buffer to decode
*/
void bufferReceived(Object connectionID, ActiveMQBuffer buffer);
+
+ default void endOfBatch(Object connectionID) {
+
+ }
}
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Connection.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Connection.java
index ebde456..0f76354 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Connection.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/Connection.java
@@ -77,6 +77,15 @@ public interface Connection {
Object getID();
/**
+ * writes the buffer to the connection and if flush is true request to flush the buffer
+ * (and any previous un-flushed ones) into the wire.
+ *
+ * @param buffer the buffer to write
+ * @param requestFlush whether to request flush onto the wire
+ */
+ void write(ActiveMQBuffer buffer, boolean requestFlush);
+
+ /**
* writes the buffer to the connection and if flush is true returns only when the buffer has been physically written to the connection.
*
* @param buffer the buffer to write
diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImplTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImplTest.java
index 4863028..d2eccf3 100644
--- a/artemis-core-client/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImplTest.java
+++ b/artemis-core-client/src/test/java/org/apache/activemq/artemis/core/protocol/core/impl/ChannelImplTest.java
@@ -375,6 +375,11 @@ public class ChannelImplTest {
}
@Override
+ public void write(ActiveMQBuffer buffer, boolean requestFlush) {
+
+ }
+
+ @Override
public void write(ActiveMQBuffer buffer, boolean flush, boolean batched) {
}
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnection.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnection.java
index b2fc576..b2d8338 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnection.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/invm/InVMConnection.java
@@ -176,6 +176,11 @@ public class InVMConnection implements Connection {
}
@Override
+ public void write(ActiveMQBuffer buffer, boolean requestFlush) {
+ write(buffer, false, false, null);
+ }
+
+ @Override
public void write(final ActiveMQBuffer buffer) {
write(buffer, false, false, null);
}
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java
index 2a49ec3..1729476 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java
@@ -21,6 +21,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
@@ -51,6 +52,7 @@ import org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournal
import org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageInSync;
import org.apache.activemq.artemis.core.protocol.core.Channel;
import org.apache.activemq.artemis.core.protocol.core.ChannelHandler;
+import org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection;
import org.apache.activemq.artemis.core.protocol.core.Packet;
import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
import org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl;
@@ -73,6 +75,7 @@ import org.apache.activemq.artemis.core.protocol.core.impl.wireformat.Replicatio
import org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationStartSyncMessage;
import org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationStartSyncMessage.SyncDataType;
import org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage;
+import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection;
import org.apache.activemq.artemis.core.replication.ReplicationManager.ADD_OPERATION_TYPE;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
@@ -98,6 +101,7 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon
private final SharedNothingBackupActivation activation;
private final boolean noSync = false;
private Channel channel;
+ private boolean supportResponseBatching;
private Journal[] journals;
private final JournalLoadInformation[] journalLoadInformation = new JournalLoadInformation[2];
@@ -130,6 +134,8 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon
private List<Interceptor> outgoingInterceptors = null;
+ private final ArrayList<Packet> pendingPackets;
+
// Constructors --------------------------------------------------
public ReplicationEndpoint(final ActiveMQServerImpl server,
@@ -140,6 +146,8 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon
this.criticalErrorListener = criticalErrorListener;
this.wantedFailBack = wantedFailBack;
this.activation = activation;
+ this.pendingPackets = new ArrayList<>();
+ this.supportResponseBatching = false;
}
// Public --------------------------------------------------------
@@ -242,15 +250,31 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon
if (logger.isTraceEnabled()) {
logger.trace("Returning " + response);
}
-
- sendResponse(response);
+ if (supportResponseBatching) {
+ pendingPackets.add(response);
+ } else {
+ channel.send(response);
+ }
} else {
logger.trace("Response is null, ignoring response");
}
}
- protected void sendResponse(PacketImpl response) {
- channel.send(response);
+ @Override
+ public void endOfBatch() {
+ final ArrayList<Packet> pendingPackets = this.pendingPackets;
+ if (pendingPackets.isEmpty()) {
+ return;
+ }
+ try {
+ for (int i = 0, size = pendingPackets.size(); i < size; i++) {
+ final Packet packet = pendingPackets.get(i);
+ final boolean isLast = i == (size - 1);
+ channel.send(packet, isLast);
+ }
+ } finally {
+ pendingPackets.clear();
+ }
}
/**
@@ -365,6 +389,21 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon
public void setChannel(final Channel channel) {
this.channel = channel;
+ if (channel == null) {
+ supportResponseBatching = false;
+ } else {
+ try {
+ final CoreRemotingConnection connection = channel.getConnection();
+ if (connection != null) {
+ this.supportResponseBatching = connection.getTransportConnection() instanceof NettyConnection;
+ } else {
+ this.supportResponseBatching = false;
+ }
+ } catch (Throwable t) {
+ logger.warn("Error while checking the channel connection", t);
+ this.supportResponseBatching = false;
+ }
+ }
if (this.channel != null && outgoingInterceptors != null) {
if (channel.getConnection() instanceof RemotingConnectionImpl) {
@@ -551,7 +590,10 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon
registerJournal(journalContent.typeByte, syncJournal);
// We send a response now, to avoid a situation where we handle votes during the deactivation of the live during a failback.
- sendResponse(replicationResponseMessage);
+ if (supportResponseBatching) {
+ endOfBatch();
+ }
+ channel.send(replicationResponseMessage);
replicationResponseMessage = null;
// This needs to be done after the response is sent, to avoid voting shutting it down for any reason.
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java
index c7ed869..c88cb16 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/util/BackupSyncDelay.java
@@ -195,6 +195,11 @@ public class BackupSyncDelay implements Interceptor {
}
@Override
+ public boolean send(Packet packet, boolean flushConnection) {
+ return channel.send(packet, flushConnection);
+ }
+
+ @Override
public String toString() {
return "ChannelWrapper(" + channel + ")";
}
@@ -238,6 +243,11 @@ public class BackupSyncDelay implements Interceptor {
}
@Override
+ public void endOfBatch() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
public void close() {
throw new UnsupportedOperationException();
}