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;
}
}
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;
}
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;
}
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;
}
Aggregations