use of org.apache.activemq.artemis.core.journal.LoaderCallback in project activemq-artemis by apache.
the class RedeliveryConsumerTest method internaltestInfiniteDedeliveryMessageOnPersistent.
private void internaltestInfiniteDedeliveryMessageOnPersistent(final boolean strict) throws Exception {
setUp(strict);
ClientSession session = factory.createSession(false, false, false);
RedeliveryConsumerTest.log.info("created");
ClientProducer prod = session.createProducer(ADDRESS);
prod.send(createTextMessage(session, "Hello"));
session.commit();
session.close();
int expectedCount = 1;
for (int i = 0; i < 700; i++) {
session = factory.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
assertEquals(expectedCount, msg.getDeliveryCount());
if (i % 100 == 0) {
expectedCount++;
msg.acknowledge();
session.rollback();
}
session.close();
}
factory.close();
server.stop();
setUp(false);
for (int i = 0; i < 700; i++) {
session = factory.createSession(false, false, false);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
assertEquals(expectedCount, msg.getDeliveryCount());
session.close();
}
server.stop();
JournalImpl journal = new JournalImpl(server.getConfiguration().getJournalFileSize(), 2, 2, 0, 0, new NIOSequentialFileFactory(server.getConfiguration().getJournalLocation(), 1), "activemq-data", "amq", 1);
final AtomicInteger updates = new AtomicInteger();
journal.start();
journal.load(new LoaderCallback() {
@Override
public void failedTransaction(long transactionID, List<RecordInfo> records, List<RecordInfo> recordsToDelete) {
}
@Override
public void updateRecord(RecordInfo info) {
if (info.userRecordType == JournalRecordIds.UPDATE_DELIVERY_COUNT) {
updates.incrementAndGet();
}
}
@Override
public void deleteRecord(long id) {
}
@Override
public void addRecord(RecordInfo info) {
}
@Override
public void addPreparedTransaction(PreparedTransactionInfo preparedTransaction) {
}
});
journal.stop();
assertEquals(7, updates.get());
}
use of org.apache.activemq.artemis.core.journal.LoaderCallback 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.LoaderCallback in project activemq-artemis by apache.
the class ValidateTransactionHealthTest method appendData.
public static JournalImpl appendData(final String journalType, final String journalDir, final long numberOfElements, final int transactionSize, final int numberOfThreads) throws Exception {
final JournalImpl journal = ValidateTransactionHealthTest.createJournal(journalType, journalDir);
journal.start();
journal.load(new LoaderCallback() {
@Override
public void addPreparedTransaction(final PreparedTransactionInfo preparedTransaction) {
}
@Override
public void addRecord(final RecordInfo info) {
}
@Override
public void deleteRecord(final long id) {
}
@Override
public void updateRecord(final RecordInfo info) {
}
@Override
public void failedTransaction(final long transactionID, final List<RecordInfo> records, final List<RecordInfo> recordsToDelete) {
}
});
LocalThread[] threads = new LocalThread[numberOfThreads];
final AtomicLong sequenceTransaction = new AtomicLong();
for (int i = 0; i < numberOfThreads; i++) {
threads[i] = new LocalThread(journal, numberOfElements, transactionSize, sequenceTransaction);
threads[i].start();
}
Exception e = null;
for (LocalThread t : threads) {
t.join();
if (t.e != null) {
e = t.e;
}
}
if (e != null) {
throw e;
}
journal.flush();
return journal;
}
Aggregations