use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class JournalImplTestUnit method internaltestSpeedNonTransactional.
private void internaltestSpeedNonTransactional() throws Exception {
final long numMessages = 10000;
int numFiles = (int) ((numMessages * 1024 + 512) / (10 * 1024 * 1024) * 1.3);
if (numFiles < 2) {
numFiles = 2;
}
JournalImplTestUnit.log.debug("num Files=" + numFiles);
Journal journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
JournalImplTestUnit.log.debug("Adding data");
SimpleEncoding data = new SimpleEncoding(700, (byte) 'j');
long start = System.currentTimeMillis();
for (int i = 0; i < numMessages; i++) {
journal.appendAddRecord(i, (byte) 0, data, true);
}
long end = System.currentTimeMillis();
double rate = 1000 * (double) numMessages / (end - start);
JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
journal.stop();
journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
journal.stop();
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class JournalImplTestUnit method testSpeedTransactional.
@Test
public void testSpeedTransactional() throws Exception {
Journal journal = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
journal.start();
journal.load(new ArrayList<RecordInfo>(), null, null);
try {
final int numMessages = 50050;
SimpleEncoding data = new SimpleEncoding(1024, (byte) 'j');
long start = System.currentTimeMillis();
int count = 0;
double[] rates = new double[50];
for (int i = 0; i < 50; i++) {
long startTrans = System.currentTimeMillis();
for (int j = 0; j < 1000; j++) {
journal.appendAddRecordTransactional(i, count++, (byte) 0, data);
}
journal.appendCommitRecord(i, true);
long endTrans = System.currentTimeMillis();
rates[i] = 1000 * (double) 1000 / (endTrans - startTrans);
}
long end = System.currentTimeMillis();
for (double rate : rates) {
JournalImplTestUnit.log.info("Transaction Rate = " + rate + " records/sec");
}
double rate = 1000 * (double) numMessages / (end - start);
JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
} finally {
journal.stop();
}
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class ActiveMQTestBase method internalCountJournalLivingRecords.
/**
* This method will load a journal and count the living records
*
* @param config
* @param messageJournal if true -> MessageJournal, false -> BindingsJournal
* @return
* @throws Exception
*/
protected HashMap<Integer, AtomicInteger> internalCountJournalLivingRecords(Configuration config, boolean messageJournal) throws Exception {
final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
SequentialFileFactory ff;
JournalImpl journal;
if (messageJournal) {
ff = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
journal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, ff, "activemq-data", "amq", 1);
} else {
ff = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
journal = new JournalImpl(1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), ff, "activemq-bindings", "bindings", 1);
}
journal.start();
final List<RecordInfo> committedRecords = new LinkedList<>();
final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
journal.load(committedRecords, preparedTransactions, null, false);
for (RecordInfo info : committedRecords) {
Integer ikey = new Integer(info.getUserRecordType());
AtomicInteger value = recordsType.get(ikey);
if (value == null) {
value = new AtomicInteger();
recordsType.put(ikey, value);
}
value.incrementAndGet();
}
journal.stop();
return recordsType;
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class ActiveMQTestBase method countBindingJournal.
protected HashMap<Integer, AtomicInteger> countBindingJournal(Configuration config) throws Exception {
final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
List<JournalFile> filesToRead = messagesJournal.orderFiles();
for (JournalFile file : filesToRead) {
JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType));
}
return recordsType;
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class JournalStorageManager method startReplication.
@Override
public void startReplication(ReplicationManager replicationManager, PagingManager pagingManager, String nodeID, final boolean autoFailBack, long initialReplicationSyncTimeout) throws Exception {
if (!started) {
throw new IllegalStateException("JournalStorageManager must be started...");
}
assert replicationManager != null;
if (!(messageJournal instanceof JournalImpl) || !(bindingsJournal instanceof JournalImpl)) {
throw ActiveMQMessageBundle.BUNDLE.notJournalImpl();
}
// We first do a compact without any locks, to avoid copying unnecessary data over the network.
// We do this without holding the storageManager lock, so the journal stays open while compact is being done
originalMessageJournal.scheduleCompactAndBlock(-1);
originalBindingsJournal.scheduleCompactAndBlock(-1);
JournalFile[] messageFiles = null;
JournalFile[] bindingsFiles = null;
// We get a picture of the current sitaution on the large messages
// and we send the current messages while more state is coming
Map<Long, Pair<String, Long>> pendingLargeMessages = null;
try {
Map<SimpleString, Collection<Integer>> pageFilesToSync;
storageManagerLock.writeLock().lock();
try {
if (isReplicated())
throw new ActiveMQIllegalStateException("already replicating");
replicator = replicationManager;
if (!((JournalImpl) originalMessageJournal).flushAppendExecutor(10, TimeUnit.SECONDS)) {
throw new Exception("Live message journal is busy");
}
if (!((JournalImpl) originalBindingsJournal).flushAppendExecutor(10, TimeUnit.SECONDS)) {
throw new Exception("Live bindings journal is busy");
}
// Establishes lock
originalMessageJournal.synchronizationLock();
originalBindingsJournal.synchronizationLock();
try {
originalBindingsJournal.replicationSyncPreserveOldFiles();
originalMessageJournal.replicationSyncPreserveOldFiles();
pagingManager.lock();
try {
pagingManager.disableCleanup();
messageFiles = prepareJournalForCopy(originalMessageJournal, JournalContent.MESSAGES, nodeID, autoFailBack);
bindingsFiles = prepareJournalForCopy(originalBindingsJournal, JournalContent.BINDINGS, nodeID, autoFailBack);
pageFilesToSync = getPageInformationForSync(pagingManager);
pendingLargeMessages = recoverPendingLargeMessages();
} finally {
pagingManager.unlock();
}
} finally {
originalMessageJournal.synchronizationUnlock();
originalBindingsJournal.synchronizationUnlock();
}
bindingsJournal = new ReplicatedJournal(((byte) 0), originalBindingsJournal, replicator);
messageJournal = new ReplicatedJournal((byte) 1, originalMessageJournal, replicator);
// We need to send the list while locking otherwise part of the body might get sent too soon
// it will send a list of IDs that we are allocating
replicator.sendLargeMessageIdListMessage(pendingLargeMessages);
} finally {
storageManagerLock.writeLock().unlock();
}
sendJournalFile(messageFiles, JournalContent.MESSAGES);
sendJournalFile(bindingsFiles, JournalContent.BINDINGS);
sendLargeMessageFiles(pendingLargeMessages);
sendPagesToBackup(pageFilesToSync, pagingManager);
storageManagerLock.writeLock().lock();
try {
if (replicator != null) {
replicator.sendSynchronizationDone(nodeID, initialReplicationSyncTimeout);
performCachedLargeMessageDeletes();
}
} finally {
storageManagerLock.writeLock().unlock();
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.unableToStartReplication(e);
stopReplication();
throw e;
} finally {
// Re-enable compact and reclaim of journal files
originalBindingsJournal.replicationSyncFinished();
originalMessageJournal.replicationSyncFinished();
pagingManager.resumeCleanup();
}
}
Aggregations