Search in sources :

Example 1 with JournalContent

use of org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent in project activemq-artemis by apache.

the class ReplicationEndpoint method start.

@Override
public synchronized void start() throws Exception {
    Configuration config = server.getConfiguration();
    try {
        storageManager = server.getStorageManager();
        storageManager.start();
        server.getManagementService().setStorageManager(storageManager);
        journalsHolder.put(JournalContent.BINDINGS, storageManager.getBindingsJournal());
        journalsHolder.put(JournalContent.MESSAGES, storageManager.getMessageJournal());
        for (JournalContent jc : EnumSet.allOf(JournalContent.class)) {
            filesReservedForSync.put(jc, new HashMap<Long, JournalSyncFile>());
            // We only need to load internal structures on the backup...
            journalLoadInformation[jc.typeByte] = journalsHolder.get(jc).loadSyncOnly(JournalState.SYNCING);
        }
        pageManager = new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), config.getJournalBufferTimeout_NIO(), server.getScheduledPool(), server.getIOExecutorFactory(), config.isJournalSyncNonTransactional(), criticalErrorListener), server.getAddressSettingsRepository());
        pageManager.start();
        started = true;
    } catch (Exception e) {
        if (server.isStarted())
            throw e;
    }
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) JournalContent(org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) IOException(java.io.IOException)

Example 2 with JournalContent

use of org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent 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 3 with JournalContent

use of org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent 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)

Example 4 with JournalContent

use of org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent in project activemq-artemis by apache.

the class ReplicationEndpoint method finishSynchronization.

private synchronized void finishSynchronization(String liveID) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("BACKUP-SYNC-START: finishSynchronization::" + liveID);
    }
    for (JournalContent jc : EnumSet.allOf(JournalContent.class)) {
        Journal journal = journalsHolder.remove(jc);
        if (logger.isTraceEnabled()) {
            logger.trace("getting lock on " + jc + ", journal = " + journal);
        }
        registerJournal(jc.typeByte, journal);
        journal.synchronizationLock();
        try {
            if (logger.isTraceEnabled()) {
                logger.trace("lock acquired on " + jc);
            }
            // files should be already in place.
            filesReservedForSync.remove(jc);
            if (logger.isTraceEnabled()) {
                logger.trace("stopping journal for " + jc);
            }
            journal.stop();
            if (logger.isTraceEnabled()) {
                logger.trace("starting journal for " + jc);
            }
            journal.start();
            if (logger.isTraceEnabled()) {
                logger.trace("loadAndSync " + jc);
            }
            journal.loadSyncOnly(JournalState.SYNCING_UP_TO_DATE);
        } finally {
            if (logger.isTraceEnabled()) {
                logger.trace("unlocking " + jc);
            }
            journal.synchronizationUnlock();
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Sync on large messages...");
    }
    ByteBuffer buffer = ByteBuffer.allocate(4 * 1024);
    for (Entry<Long, ReplicatedLargeMessage> entry : largeMessages.entrySet()) {
        ReplicatedLargeMessage lm = entry.getValue();
        if (lm instanceof LargeServerMessageInSync) {
            LargeServerMessageInSync lmSync = (LargeServerMessageInSync) lm;
            if (logger.isTraceEnabled()) {
                logger.trace("lmSync on " + lmSync.toString());
            }
            lmSync.joinSyncedData(buffer);
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("setRemoteBackupUpToDate and liveIDSet for " + liveID);
    }
    journalsHolder = null;
    backupQuorum.liveIDSet(liveID);
    activation.setRemoteBackupUpToDate();
    if (logger.isTraceEnabled()) {
        logger.trace("Backup is synchronized / BACKUP-SYNC-DONE");
    }
    ActiveMQServerLogger.LOGGER.backupServerSynched(server);
    return;
}
Also used : LargeServerMessageInSync(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageInSync) 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) ByteBuffer(java.nio.ByteBuffer)

Aggregations

JournalContent (org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent)4 Journal (org.apache.activemq.artemis.core.journal.Journal)3 FileWrapperJournal (org.apache.activemq.artemis.core.journal.impl.FileWrapperJournal)3 IOException (java.io.IOException)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)1 Page (org.apache.activemq.artemis.core.paging.impl.Page)1 PagingManagerImpl (org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)1 PagingStoreFactoryNIO (org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO)1 LargeServerMessageInSync (org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageInSync)1 ReplicationResponseMessageV2 (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessageV2)1