Search in sources :

Example 1 with ReplicationSyncFileMessage

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;
}
Also used : QuorumVoteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.QuorumVoteMessage) ReplicationAddTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddTXMessage) ReplicationLargeMessageWriteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageWriteMessage) ReplicationLargeMessageBeginMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageBeginMessage) BackupRequestMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRequestMessage) ReplicationCommitMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationCommitMessage) ReplicationPageWriteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPageWriteMessage) ReplicationLargeMessageEndMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageEndMessage) ReplicationAddMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddMessage) BackupResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupResponseMessage) ReplicationLiveIsStoppingMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLiveIsStoppingMessage) SessionSendLargeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendLargeMessage) BackupRegistrationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRegistrationMessage) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ClusterConnectReplyMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ClusterConnectReplyMessage) BackupReplicationStartFailedMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupReplicationStartFailedMessage) ReplicationDeleteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteMessage) ScaleDownAnnounceMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ScaleDownAnnounceMessage) QuorumVoteReplyMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.QuorumVoteReplyMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ReplicationPageEventMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPageEventMessage) NodeAnnounceMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.NodeAnnounceMessage) ReplicationSyncFileMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage) ClusterConnectMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ClusterConnectMessage) ReplicationPrepareMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPrepareMessage) ReplicationDeleteTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteTXMessage) ReplicationStartSyncMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationStartSyncMessage) ReplicationResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessage) ReplicationResponseMessageV2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessageV2)

Example 2 with ReplicationSyncFileMessage

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();
    }
}
Also used : ReplicationSyncFileMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage) FileChannel(java.nio.channels.FileChannel) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream)

Aggregations

ReplicationSyncFileMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage)2 ByteBuf (io.netty.buffer.ByteBuf)1 FileInputStream (java.io.FileInputStream)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)1 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)1 BackupRegistrationMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRegistrationMessage)1 BackupReplicationStartFailedMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupReplicationStartFailedMessage)1 BackupRequestMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRequestMessage)1 BackupResponseMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupResponseMessage)1 ClusterConnectMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ClusterConnectMessage)1 ClusterConnectReplyMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ClusterConnectReplyMessage)1 NodeAnnounceMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.NodeAnnounceMessage)1 QuorumVoteMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.QuorumVoteMessage)1 QuorumVoteReplyMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.QuorumVoteReplyMessage)1 ReplicationAddMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddMessage)1 ReplicationAddTXMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddTXMessage)1 ReplicationCommitMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationCommitMessage)1 ReplicationDeleteMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteMessage)1