use of org.apache.activemq.artemis.core.journal.Journal 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.Journal 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.Journal in project activemq-artemis by apache.
the class PagingTest method testMissingTXEverythingAcked.
@Test
public void testMissingTXEverythingAcked() throws Exception {
clearDataRecreateServerDirs();
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
final int numberOfMessages = 5000;
final int numberOfTX = 10;
final int messagesPerTX = numberOfMessages / numberOfTX;
try {
locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, false, false);
session.createQueue(ADDRESS.toString(), "q1", true);
session.createQueue(ADDRESS.toString(), "q2", true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
byte[] body = new byte[MESSAGE_SIZE];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= MESSAGE_SIZE; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
message = session.createMessage(true);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % messagesPerTX == 0) {
session.commit();
}
}
session.commit();
session.close();
ArrayList<RecordInfo> records = new ArrayList<>();
List<PreparedTransactionInfo> list = new ArrayList<>();
server.getStorageManager().getMessageJournal().stop();
Journal jrn = server.getStorageManager().getMessageJournal();
jrn.start();
jrn.load(records, list, null);
// Delete everything from the journal
for (RecordInfo info : records) {
if (!info.isUpdate && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_VALUE && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COUNTER_INC && info.getUserRecordType() != JournalRecordIds.PAGE_CURSOR_COMPLETE) {
jrn.appendDeleteRecord(info.id, false);
}
}
jrn.stop();
} finally {
try {
server.stop();
} catch (Throwable ignored) {
}
}
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession sess = csf.createSession();
sess.start();
ClientConsumer cons = sess.createConsumer("q1");
assertNull(cons.receiveImmediate());
ClientConsumer cons2 = sess.createConsumer("q2");
assertNull(cons2.receiveImmediate());
Queue q1 = server.locateQueue(new SimpleString("q1"));
Queue q2 = server.locateQueue(new SimpleString("q2"));
q1.getPageSubscription().cleanupEntries(false);
q2.getPageSubscription().cleanupEntries(false);
PageCursorProvider provider = q1.getPageSubscription().getPagingStore().getCursorProvider();
provider.cleanup();
waitForNotPaging(q1);
sess.close();
}
use of org.apache.activemq.artemis.core.journal.Journal in project activemq-artemis by apache.
the class XmlDataExporter method getBindings.
/**
* Open the bindings journal and extract all bindings data.
*
* @throws Exception will be thrown if anything goes wrong reading the bindings journal
*/
private void getBindings() throws Exception {
List<RecordInfo> records = new LinkedList<>();
Journal bindingsJournal = storageManager.getBindingsJournal();
bindingsJournal.start();
ActiveMQServerLogger.LOGGER.debug("Reading bindings journal from " + config.getBindingsDirectory());
bindingsJournal.load(records, null, null);
for (RecordInfo info : records) {
if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
PersistentQueueBindingEncoding bindingEncoding = (PersistentQueueBindingEncoding) DescribeJournal.newObjectEncoding(info, null);
queueBindings.put(bindingEncoding.getId(), bindingEncoding);
} else if (info.getUserRecordType() == JournalRecordIds.ADDRESS_BINDING_RECORD) {
PersistentAddressBindingEncoding bindingEncoding = (PersistentAddressBindingEncoding) DescribeJournal.newObjectEncoding(info, null);
addressBindings.put(bindingEncoding.getId(), bindingEncoding);
}
}
bindingsJournal.stop();
}
use of org.apache.activemq.artemis.core.journal.Journal in project activemq-artemis by apache.
the class XmlDataExporter method processMessageJournal.
/**
* Read through the message journal and stuff all the events/data we care about into local data structures. We'll
* use this data later to print all the right information.
*
* @throws Exception will be thrown if anything goes wrong reading the journal
*/
private void processMessageJournal() throws Exception {
ArrayList<RecordInfo> acks = new ArrayList<>();
List<RecordInfo> records = new LinkedList<>();
// We load these, but don't use them.
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
Journal messageJournal = storageManager.getMessageJournal();
ActiveMQServerLogger.LOGGER.debug("Reading journal from " + config.getJournalDirectory());
messageJournal.start();
// Just logging these, no action necessary
TransactionFailureCallback transactionFailureCallback = new TransactionFailureCallback() {
@Override
public void failedTransaction(long transactionID, List<RecordInfo> records1, List<RecordInfo> recordsToDelete) {
StringBuilder message = new StringBuilder();
message.append("Encountered failed journal transaction: ").append(transactionID);
for (int i = 0; i < records1.size(); i++) {
if (i == 0) {
message.append("; Records: ");
}
message.append(records1.get(i));
if (i != (records1.size() - 1)) {
message.append(", ");
}
}
for (int i = 0; i < recordsToDelete.size(); i++) {
if (i == 0) {
message.append("; RecordsToDelete: ");
}
message.append(recordsToDelete.get(i));
if (i != (recordsToDelete.size() - 1)) {
message.append(", ");
}
}
ActiveMQServerLogger.LOGGER.debug(message.toString());
}
};
messageJournal.load(records, preparedTransactions, transactionFailureCallback, false);
// Since we don't use these nullify the reference so that the garbage collector can clean them up
preparedTransactions = null;
for (RecordInfo info : records) {
byte[] data = info.data;
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(data);
Object o = DescribeJournal.newObjectEncoding(info, storageManager);
if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE) {
messages.put(info.id, ((MessageDescribe) o).getMsg().toCore());
} else if (info.getUserRecordType() == JournalRecordIds.ADD_MESSAGE_PROTOCOL) {
messages.put(info.id, ((MessageDescribe) o).getMsg().toCore());
} else if (info.getUserRecordType() == JournalRecordIds.ADD_LARGE_MESSAGE) {
messages.put(info.id, ((MessageDescribe) o).getMsg());
} else if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
ReferenceDescribe ref = (ReferenceDescribe) o;
HashMap<Long, ReferenceDescribe> map = messageRefs.get(info.id);
if (map == null) {
HashMap<Long, ReferenceDescribe> newMap = new HashMap<>();
newMap.put(ref.refEncoding.queueID, ref);
messageRefs.put(info.id, newMap);
} else {
map.put(ref.refEncoding.queueID, ref);
}
} else if (info.getUserRecordType() == JournalRecordIds.ACKNOWLEDGE_REF) {
acks.add(info);
} else if (info.userRecordType == JournalRecordIds.ACKNOWLEDGE_CURSOR) {
CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
encoding.decode(buff);
Set<PagePosition> set = cursorRecords.get(encoding.queueID);
if (set == null) {
set = new HashSet<>();
cursorRecords.put(encoding.queueID, set);
}
set.add(encoding.position);
} else if (info.userRecordType == JournalRecordIds.PAGE_TRANSACTION) {
if (info.isUpdate) {
PageUpdateTXEncoding pageUpdate = new PageUpdateTXEncoding();
pageUpdate.decode(buff);
pgTXs.add(pageUpdate.pageTX);
} else {
PageTransactionInfoImpl pageTransactionInfo = new PageTransactionInfoImpl();
pageTransactionInfo.decode(buff);
pageTransactionInfo.setRecordID(info.id);
pgTXs.add(pageTransactionInfo.getTransactionID());
}
}
}
messageJournal.stop();
removeAcked(acks);
}
Aggregations