Search in sources :

Example 1 with FileWrapperJournal

use of org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal in project activemq-artemis by apache.

the class ReplicationEndpoint method stop.

@Override
public synchronized void stop() throws Exception {
    if (!started) {
        return;
    }
    logger.trace("Stopping endpoint");
    started = false;
    OrderedExecutorFactory.flushExecutor(executor);
    // Channel may be null if there isn't a connection to a live server
    if (channel != null) {
        channel.close();
    }
    for (ReplicatedLargeMessage largeMessage : largeMessages.values()) {
        largeMessage.releaseResources();
    }
    largeMessages.clear();
    for (Entry<JournalContent, Map<Long, JournalSyncFile>> entry : filesReservedForSync.entrySet()) {
        for (JournalSyncFile filesReserved : entry.getValue().values()) {
            filesReserved.close();
        }
    }
    filesReservedForSync.clear();
    if (journals != null) {
        for (Journal j : journals) {
            if (j instanceof FileWrapperJournal)
                j.stop();
        }
    }
    for (ConcurrentMap<Integer, Page> map : pageIndex.values()) {
        for (Page page : map.values()) {
            try {
                page.sync();
                page.close(false);
            } catch (Exception e) {
                ActiveMQServerLogger.LOGGER.errorClosingPageOnReplication(e);
            }
        }
    }
    pageManager.stop();
    pageIndex.clear();
    // Storage needs to be the last to stop
    storageManager.stop();
    started = false;
}
Also used : FileWrapperJournal(org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) FileWrapperJournal(org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal) Page(org.apache.activemq.artemis.core.paging.impl.Page) JournalContent(org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) IOException(java.io.IOException)

Example 2 with FileWrapperJournal

use of org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal in project activemq-artemis by apache.

the class ReplicationEndpoint method handleStartReplicationSynchronization.

/**
 * Reserves files (with the given fileID) in the specified journal, and places a
 * {@link FileWrapperJournal} in place to store messages while synchronization is going on.
 *
 * @param packet
 * @return if the incoming packet indicates the synchronization is finished then return an acknowledgement otherwise
 * return an empty response
 * @throws Exception
 */
private ReplicationResponseMessageV2 handleStartReplicationSynchronization(final ReplicationStartSyncMessage packet) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("handleStartReplicationSynchronization:: nodeID = " + packet);
    }
    ReplicationResponseMessageV2 replicationResponseMessage = new ReplicationResponseMessageV2();
    if (!started)
        return replicationResponseMessage;
    if (packet.isSynchronizationFinished()) {
        finishSynchronization(packet.getNodeID());
        replicationResponseMessage.setSynchronizationIsFinishedAcknowledgement(true);
        return replicationResponseMessage;
    }
    switch(packet.getDataType()) {
        case LargeMessages:
            for (long msgID : packet.getFileIds()) {
                createLargeMessage(msgID, true);
            }
            break;
        case JournalBindings:
        case JournalMessages:
            if (wantedFailBack && !packet.isServerToFailBack()) {
                ActiveMQServerLogger.LOGGER.autoFailBackDenied();
            }
            final JournalContent journalContent = SyncDataType.getJournalContentType(packet.getDataType());
            final Journal journal = journalsHolder.get(journalContent);
            if (packet.getNodeID() != null) {
                // At the start of replication, we still do not know which is the nodeID that the live uses.
                // This is the point where the backup gets this information.
                backupQuorum.liveIDSet(packet.getNodeID());
            }
            Map<Long, JournalSyncFile> mapToFill = filesReservedForSync.get(journalContent);
            for (Entry<Long, JournalFile> entry : journal.createFilesForBackupSync(packet.getFileIds()).entrySet()) {
                mapToFill.put(entry.getKey(), new JournalSyncFile(entry.getValue()));
            }
            FileWrapperJournal syncJournal = new FileWrapperJournal(journal);
            registerJournal(journalContent.typeByte, syncJournal);
            break;
        default:
            throw ActiveMQMessageBundle.BUNDLE.replicationUnhandledDataType();
    }
    return replicationResponseMessage;
}
Also used : JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) FileWrapperJournal(org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) FileWrapperJournal(org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal) JournalContent(org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent) ReplicationResponseMessageV2(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessageV2)

Aggregations

Journal (org.apache.activemq.artemis.core.journal.Journal)2 FileWrapperJournal (org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal)2 JournalContent (org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)1 Page (org.apache.activemq.artemis.core.paging.impl.Page)1 ReplicationResponseMessageV2 (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessageV2)1