use of org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageInSync in project activemq-artemis by apache.
the class ReplicationEndpoint method handleReplicationSynchronization.
/**
* Receives 'raw' journal/page/large-message data from live server for synchronization of logs.
*
* @param msg
* @throws Exception
*/
private void handleReplicationSynchronization(ReplicationSyncFileMessage msg) throws Exception {
long id = msg.getId();
byte[] data = msg.getData();
SequentialFile channel1;
switch(msg.getFileType()) {
case LARGE_MESSAGE:
{
ReplicatedLargeMessage largeMessage = lookupLargeMessage(id, false, false);
if (!(largeMessage instanceof LargeServerMessageInSync)) {
ActiveMQServerLogger.LOGGER.largeMessageIncompatible();
return;
}
LargeServerMessageInSync largeMessageInSync = (LargeServerMessageInSync) largeMessage;
channel1 = largeMessageInSync.getSyncFile();
break;
}
case PAGE:
{
Page page = getPage(msg.getPageStore(), (int) msg.getId());
channel1 = page.getFile();
break;
}
case JOURNAL:
{
JournalSyncFile journalSyncFile = filesReservedForSync.get(msg.getJournalContent()).get(id);
FileChannel channel2 = journalSyncFile.getChannel();
if (data == null) {
channel2.close();
return;
}
channel2.write(ByteBuffer.wrap(data));
return;
}
default:
throw ActiveMQMessageBundle.BUNDLE.replicationUnhandledFileType(msg.getFileType());
}
if (data == null) {
return;
}
if (!channel1.isOpen()) {
channel1.open();
}
channel1.writeDirect(ByteBuffer.wrap(data), false);
}
use of org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageInSync 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;
}
use of org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageInSync in project activemq-artemis by apache.
the class ReplicationEndpoint method createLargeMessage.
private void createLargeMessage(final long id, boolean liveToBackupSync) {
ReplicatedLargeMessage msg;
if (liveToBackupSync) {
msg = new LargeServerMessageInSync(storageManager);
} else {
msg = storageManager.createLargeMessage();
}
msg.setDurable(true);
msg.setMessageID(id);
largeMessages.put(id, msg);
}
Aggregations