use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage in project activemq-artemis by apache.
the class ServerPacketDecoder method slowPathDecode.
// separating for performance reasons
private Packet slowPathDecode(ActiveMQBuffer in, byte packetType, CoreRemotingConnection connection) {
Packet packet;
switch(packetType) {
case SESS_SEND_LARGE:
{
packet = new SessionSendLargeMessage(new CoreMessage());
break;
}
case REPLICATION_APPEND:
{
packet = new ReplicationAddMessage();
break;
}
case REPLICATION_APPEND_TX:
{
packet = new ReplicationAddTXMessage();
break;
}
case REPLICATION_DELETE:
{
packet = new ReplicationDeleteMessage();
break;
}
case REPLICATION_DELETE_TX:
{
packet = new ReplicationDeleteTXMessage();
break;
}
case REPLICATION_PREPARE:
{
packet = new ReplicationPrepareMessage();
break;
}
case REPLICATION_COMMIT_ROLLBACK:
{
packet = new ReplicationCommitMessage();
break;
}
case REPLICATION_RESPONSE:
{
packet = new ReplicationResponseMessage();
break;
}
case REPLICATION_RESPONSE_V2:
{
packet = new ReplicationResponseMessageV2();
break;
}
case REPLICATION_PAGE_WRITE:
{
packet = new ReplicationPageWriteMessage();
break;
}
case REPLICATION_PAGE_EVENT:
{
packet = new ReplicationPageEventMessage();
break;
}
case REPLICATION_LARGE_MESSAGE_BEGIN:
{
packet = new ReplicationLargeMessageBeginMessage();
break;
}
case REPLICATION_LARGE_MESSAGE_END:
{
packet = new ReplicationLargeMessageEndMessage();
break;
}
case REPLICATION_LARGE_MESSAGE_WRITE:
{
packet = new ReplicationLargeMessageWriteMessage();
break;
}
case PacketImpl.BACKUP_REGISTRATION:
{
packet = new BackupRegistrationMessage();
break;
}
case PacketImpl.BACKUP_REGISTRATION_FAILED:
{
packet = new BackupReplicationStartFailedMessage();
break;
}
case PacketImpl.REPLICATION_START_FINISH_SYNC:
{
packet = new ReplicationStartSyncMessage();
break;
}
case PacketImpl.REPLICATION_SYNC_FILE:
{
packet = new ReplicationSyncFileMessage();
break;
}
case PacketImpl.REPLICATION_SCHEDULED_FAILOVER:
{
packet = new ReplicationLiveIsStoppingMessage();
break;
}
case CLUSTER_CONNECT:
{
packet = new ClusterConnectMessage();
break;
}
case CLUSTER_CONNECT_REPLY:
{
packet = new ClusterConnectReplyMessage();
break;
}
case NODE_ANNOUNCE:
{
packet = new NodeAnnounceMessage();
break;
}
case BACKUP_REQUEST:
{
packet = new BackupRequestMessage();
break;
}
case BACKUP_REQUEST_RESPONSE:
{
packet = new BackupResponseMessage();
break;
}
case QUORUM_VOTE:
{
packet = new QuorumVoteMessage();
break;
}
case QUORUM_VOTE_REPLY:
{
packet = new QuorumVoteReplyMessage();
break;
}
case SCALEDOWN_ANNOUNCEMENT:
{
packet = new ScaleDownAnnounceMessage();
break;
}
default:
{
packet = super.decode(packetType, connection);
}
}
packet.decode(in);
return packet;
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage in project activemq-artemis by apache.
the class ReplicationManager method sendLargeFile.
/**
* Sends large files in reasonably sized chunks to the backup during replication synchronization.
*
* @param content journal type or {@code null} for large-messages and pages
* @param pageStore page store name for pages, or {@code null} otherwise
* @param id journal file id or (large) message id
* @param file
* @param maxBytesToSend maximum number of bytes to read and send from the file
* @throws Exception
*/
private void sendLargeFile(AbstractJournalStorageManager.JournalContent content, SimpleString pageStore, final long id, SequentialFile file, long maxBytesToSend) throws Exception {
if (!enabled)
return;
if (!file.isOpen()) {
file.open();
}
int size = 32 * 1024;
int flowControlSize = 10;
int packetsSent = 0;
FlushAction action = new FlushAction();
try {
try (FileInputStream fis = new FileInputStream(file.getJavaFile());
FileChannel channel = fis.getChannel()) {
// through ActiveMQBuffer class leaving this buffer free to be reused on the next copy
while (true) {
final ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(size, size);
buffer.clear();
ByteBuffer byteBuffer = buffer.writerIndex(size).readerIndex(0).nioBuffer();
final int bytesRead = channel.read(byteBuffer);
int toSend = bytesRead;
if (bytesRead > 0) {
if (bytesRead >= maxBytesToSend) {
toSend = (int) maxBytesToSend;
maxBytesToSend = 0;
} else {
maxBytesToSend = maxBytesToSend - bytesRead;
}
}
logger.debug("sending " + buffer.writerIndex() + " bytes on file " + file.getFileName());
// sending -1 or 0 bytes will close the file at the backup
// We cannot simply send everything of a file through the executor,
// otherwise we would run out of memory.
// so we don't use the executor here
sendReplicatePacket(new ReplicationSyncFileMessage(content, pageStore, id, toSend, buffer), true);
packetsSent++;
if (packetsSent % flowControlSize == 0) {
flushReplicationStream(action);
}
if (bytesRead == -1 || bytesRead == 0 || maxBytesToSend == 0)
break;
}
}
flushReplicationStream(action);
} finally {
if (file.isOpen())
file.close();
}
}
Aggregations