use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class JournalImplTestBase method loadAndCheck.
protected void loadAndCheck(final boolean printDebugJournal) throws Exception {
List<RecordInfo> committedRecords = new ArrayList<>();
List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
journal.load(committedRecords, preparedTransactions, null);
checkRecordsEquivalent(records, committedRecords);
if (printDebugJournal) {
printJournalLists(records, committedRecords);
}
// check prepared transactions
List<PreparedTransactionInfo> prepared = new ArrayList<>();
for (Map.Entry<Long, TransactionHolder> entry : transactions.entrySet()) {
if (entry.getValue().prepared) {
PreparedTransactionInfo info = new PreparedTransactionInfo(entry.getKey(), null);
info.getRecords().addAll(entry.getValue().records);
info.getRecordsToDelete().addAll(entry.getValue().deletes);
prepared.add(info);
}
}
checkTransactionsEquivalent(prepared, preparedTransactions);
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class BatchIDGeneratorUnitTest method loadIDs.
protected void loadIDs(final Journal journal, final BatchingIDGenerator batch) throws Exception {
ArrayList<RecordInfo> records = new ArrayList<>();
ArrayList<PreparedTransactionInfo> tx = new ArrayList<>();
journal.start();
journal.load(records, tx, null);
Assert.assertEquals(0, tx.size());
Assert.assertTrue("Contains " + records.size(), records.size() > 0);
for (RecordInfo record : records) {
if (record.userRecordType == JournalRecordIds.ID_COUNTER_RECORD) {
ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
batch.loadState(record.id, buffer);
}
}
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class JournalPageCountSizeTest method testPageCursorCounterRecordSizeTX.
@Test
public void testPageCursorCounterRecordSizeTX() throws Exception {
long tx = server.getStorageManager().generateID();
server.getStorageManager().storePageCounterInc(tx, 1, 1, 1000);
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);
PageCountRecordInc encoding = new PageCountRecordInc();
encoding.decode(buff);
Assert.assertEquals(1000, encoding.getPersistentSize());
} finally {
journalStorageManager.getMessageJournal().stop();
}
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class JournalImpl method load.
/**
* @see JournalImpl#load(LoaderCallback)
*/
@Override
public synchronized JournalLoadInformation load(final List<RecordInfo> committedRecords, final List<PreparedTransactionInfo> preparedTransactions, final TransactionFailureCallback failureCallback, final boolean fixBadTX) throws Exception {
final Set<Long> recordsToDelete = new HashSet<>();
// ArrayList was taking too long to delete elements on checkDeleteSize
final List<RecordInfo> records = new LinkedList<>();
final int DELETE_FLUSH = 20000;
JournalLoadInformation info = load(new LoaderCallback() {
Runtime runtime = Runtime.getRuntime();
private void checkDeleteSize() {
// HORNETQ-482 - Flush deletes only if memory is critical
if (recordsToDelete.size() > DELETE_FLUSH && runtime.freeMemory() < runtime.maxMemory() * 0.2) {
ActiveMQJournalLogger.LOGGER.debug("Flushing deletes during loading, deleteCount = " + recordsToDelete.size());
// Clean up when the list is too large, or it won't be possible to load large sets of files
// Done as part of JBMESSAGING-1678
Iterator<RecordInfo> iter = records.iterator();
while (iter.hasNext()) {
RecordInfo record = iter.next();
if (recordsToDelete.contains(record.id)) {
iter.remove();
}
}
recordsToDelete.clear();
ActiveMQJournalLogger.LOGGER.debug("flush delete done");
}
}
@Override
public void addPreparedTransaction(final PreparedTransactionInfo preparedTransaction) {
preparedTransactions.add(preparedTransaction);
checkDeleteSize();
}
@Override
public void addRecord(final RecordInfo info) {
records.add(info);
checkDeleteSize();
}
@Override
public void updateRecord(final RecordInfo info) {
records.add(info);
checkDeleteSize();
}
@Override
public void deleteRecord(final long id) {
recordsToDelete.add(id);
checkDeleteSize();
}
@Override
public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) {
if (failureCallback != null) {
failureCallback.failedTransaction(transactionID, records, recordsToDelete);
}
}
}, fixBadTX, null);
for (RecordInfo record : records) {
if (!recordsToDelete.contains(record.id)) {
committedRecords.add(record);
}
}
return info;
}
use of org.apache.activemq.artemis.core.journal.PreparedTransactionInfo in project activemq-artemis by apache.
the class BridgeTest method loadQueues.
/**
* It will inspect the journal directly and determine if there are queues on this journal,
*
* @param serverToInvestigate
* @return a Map containing the reference counts per queue
* @throws Exception
*/
protected Map<Long, AtomicInteger> loadQueues(ActiveMQServer serverToInvestigate) throws Exception {
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(serverToInvestigate.getConfiguration().getJournalLocation(), 1);
JournalImpl messagesJournal = new JournalImpl(serverToInvestigate.getConfiguration().getJournalFileSize(), serverToInvestigate.getConfiguration().getJournalMinFiles(), serverToInvestigate.getConfiguration().getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
List<RecordInfo> records = new LinkedList<>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
messagesJournal.start();
messagesJournal.load(records, preparedTransactions, null);
// These are more immutable integers
Map<Long, AtomicInteger> messageRefCounts = new HashMap<>();
for (RecordInfo info : records) {
Object o = DescribeJournal.newObjectEncoding(info);
if (info.getUserRecordType() == JournalRecordIds.ADD_REF) {
DescribeJournal.ReferenceDescribe ref = (DescribeJournal.ReferenceDescribe) o;
AtomicInteger count = messageRefCounts.get(ref.refEncoding.queueID);
if (count == null) {
count = new AtomicInteger(1);
messageRefCounts.put(ref.refEncoding.queueID, count);
} else {
count.incrementAndGet();
}
}
}
messagesJournal.stop();
return messageRefCounts;
}
Aggregations