use of org.apache.activemq.artemis.core.journal.RecordInfo 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.RecordInfo in project activemq-artemis by apache.
the class JournalPageCountSizeTest method testPageCountRecordSize.
@Test
public void testPageCountRecordSize() throws Exception {
long tx = server.getStorageManager().generateID();
server.getStorageManager().storePageCounter(tx, 1, 1, 100);
server.getStorageManager().commit(tx);
server.getStorageManager().stop();
JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
List<RecordInfo> committedRecords = new LinkedList<>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
try {
journalStorageManager.getMessageJournal().start();
journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
PageCountRecord encoding = new PageCountRecord();
encoding.decode(buff);
Assert.assertEquals(100, encoding.getPersistentSize());
} finally {
journalStorageManager.getMessageJournal().stop();
}
}
use of org.apache.activemq.artemis.core.journal.RecordInfo in project activemq-artemis by apache.
the class JournalPageCountSizeTest method testPageCursorCounterRecordSize.
@Test
public void testPageCursorCounterRecordSize() throws Exception {
server.getStorageManager().storePageCounterInc(1, 1, 1000);
server.getStorageManager().stop();
JournalStorageManager journalStorageManager = (JournalStorageManager) server.getStorageManager();
List<RecordInfo> committedRecords = new LinkedList<>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
try {
journalStorageManager.getMessageJournal().start();
journalStorageManager.getMessageJournal().load(committedRecords, preparedTransactions, transactionFailure);
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(committedRecords.get(0).data);
PageCountRecordInc encoding = new PageCountRecordInc();
encoding.decode(buff);
Assert.assertEquals(1000, encoding.getPersistentSize());
} finally {
journalStorageManager.getMessageJournal().stop();
}
}
use of org.apache.activemq.artemis.core.journal.RecordInfo in project narayana by jbosstm.
the class HornetqJournalStore method start.
public void start() throws Exception {
journal.start();
List<RecordInfo> committedRecords = new LinkedList<RecordInfo>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<PreparedTransactionInfo>();
TransactionFailureCallback failureCallback = new TransactionFailureCallback() {
public void failedTransaction(long l, List<RecordInfo> recordInfos, List<RecordInfo> recordInfos1) {
tsLogger.i18NLogger.warn_journal_load_error();
}
};
JournalLoadInformation journalLoadInformation = journal.load(committedRecords, preparedTransactions, failureCallback);
maxID.set(journalLoadInformation.getMaxID());
if (!preparedTransactions.isEmpty()) {
tsLogger.i18NLogger.warn_journal_load_error();
}
for (RecordInfo record : committedRecords) {
InputBuffer inputBuffer = new InputBuffer(record.data);
Uid uid = UidHelper.unpackFrom(inputBuffer);
String typeName = inputBuffer.unpackString();
getContentForType(typeName).put(uid, record);
// don't unpack the rest yet, we may never need it. read_committed does it on demand.
}
}
use of org.apache.activemq.artemis.core.journal.RecordInfo in project narayana by jbosstm.
the class HornetqJournalStore method write_committed.
/**
* Write a new copy of the object's committed state.
*
* @param uid The object to work on.
* @param typeName The type of the object to work on.
* @param txData The state to write.
* @return <code>true</code> if no errors occurred, <code>false</code>
* otherwise.
* @throws ObjectStoreException if things go wrong.
*/
public boolean write_committed(Uid uid, String typeName, OutputObjectState txData) throws ObjectStoreException {
RecordInfo previousRecord = null;
try {
OutputBuffer outputBuffer = new OutputBuffer();
UidHelper.packInto(uid, outputBuffer);
outputBuffer.packString(typeName);
outputBuffer.packBytes(txData.buffer());
byte[] data = outputBuffer.buffer();
RecordInfo record = new RecordInfo(getId(uid, typeName), RECORD_TYPE, data, false, (short) 0);
previousRecord = getContentForType(typeName).putIfAbsent(uid, record);
if (previousRecord != null) {
// the packed data may have changed so updated the map with the latest data
getContentForType(typeName).replace(uid, record);
journal.appendUpdateRecord(previousRecord.id, RECORD_TYPE, data, syncWrites);
} else {
journal.appendAddRecord(record.id, RECORD_TYPE, data, syncWrites);
}
} catch (Exception e) {
if (previousRecord == null) {
// if appendAddRecord() fails, remove record from map. Leave it there if appendUpdateRecord() fails.
getContentForType(typeName).remove(uid);
}
throw new ObjectStoreException(e);
}
return true;
}
Aggregations