use of org.apache.activemq.artemis.core.journal.impl.JournalImpl 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;
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class NIOJournalCompactTest method testStressDeletesNoSync.
@Test
public void testStressDeletesNoSync() throws Throwable {
Configuration config = createBasicConfig().setJournalFileSize(100 * 1024).setJournalSyncNonTransactional(false).setJournalSyncTransactional(false).setJournalCompactMinFiles(0).setJournalCompactPercentage(0);
final AtomicInteger errors = new AtomicInteger(0);
final AtomicBoolean running = new AtomicBoolean(true);
final AtomicLong seqGenerator = new AtomicLong(1);
final ExecutorService executor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
final ExecutorService ioexecutor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
OrderedExecutorFactory factory = new OrderedExecutorFactory(executor);
OrderedExecutorFactory iofactory = new OrderedExecutorFactory(ioexecutor);
final ExecutorService deleteExecutor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
final JournalStorageManager storage = new JournalStorageManager(config, EmptyCriticalAnalyzer.getInstance(), factory, iofactory);
storage.start();
try {
storage.loadInternalOnly();
((JournalImpl) storage.getMessageJournal()).setAutoReclaim(false);
final LinkedList<Long> survivingMsgs = new LinkedList<>();
Runnable producerRunnable = new Runnable() {
@Override
public void run() {
try {
while (running.get()) {
final long[] values = new long[100];
long tx = seqGenerator.incrementAndGet();
OperationContextImpl ctx = new OperationContextImpl(executor);
storage.setContext(ctx);
for (int i = 0; i < 100; i++) {
long id = seqGenerator.incrementAndGet();
values[i] = id;
CoreMessage message = new CoreMessage(id, 100);
message.getBodyBuffer().writeBytes(new byte[1024]);
storage.storeMessageTransactional(tx, message);
}
CoreMessage message = new CoreMessage(seqGenerator.incrementAndGet(), 100);
survivingMsgs.add(message.getMessageID());
logger.info("Going to store " + message);
// This one will stay here forever
storage.storeMessage(message);
logger.info("message storeed " + message);
logger.info("Going to commit " + tx);
storage.commit(tx);
logger.info("Committed " + tx);
ctx.executeOnCompletion(new IOCallback() {
@Override
public void onError(int errorCode, String errorMessage) {
}
@Override
public void done() {
deleteExecutor.execute(new Runnable() {
@Override
public void run() {
try {
for (long messageID : values) {
storage.deleteMessage(messageID);
}
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
});
}
});
}
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
};
Runnable compressRunnable = new Runnable() {
@Override
public void run() {
try {
while (running.get()) {
Thread.sleep(500);
System.out.println("Compacting");
((JournalImpl) storage.getMessageJournal()).testCompact();
((JournalImpl) storage.getMessageJournal()).checkReclaimStatus();
}
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
};
Thread producerThread = new Thread(producerRunnable);
producerThread.start();
Thread compactorThread = new Thread(compressRunnable);
compactorThread.start();
Thread.sleep(1000);
running.set(false);
producerThread.join();
compactorThread.join();
deleteExecutor.shutdown();
assertTrue("delete executor failted to terminate", deleteExecutor.awaitTermination(30, TimeUnit.SECONDS));
storage.stop();
executor.shutdown();
assertTrue("executor failed to terminate", executor.awaitTermination(30, TimeUnit.SECONDS));
ioexecutor.shutdown();
assertTrue("ioexecutor failed to terminate", ioexecutor.awaitTermination(30, TimeUnit.SECONDS));
Assert.assertEquals(0, errors.get());
} catch (Throwable e) {
e.printStackTrace();
throw e;
} finally {
try {
storage.stop();
} catch (Exception e) {
e.printStackTrace();
}
executor.shutdownNow();
deleteExecutor.shutdownNow();
ioexecutor.shutdownNow();
}
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class NIOJournalCompactTest method testCompactFirstFileReclaimed.
@Test
public void testCompactFirstFileReclaimed() throws Exception {
setup(2, 60 * 1024, false);
final byte recordType = (byte) 0;
journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, fileFactory, filePrefix, fileExtension, maxAIO);
journal.start();
journal.loadInternalOnly();
journal.appendAddRecord(1, recordType, "test".getBytes(), true);
journal.forceMoveNextFile();
journal.appendUpdateRecord(1, recordType, "update".getBytes(), true);
journal.appendDeleteRecord(1, true);
journal.appendAddRecord(2, recordType, "finalRecord".getBytes(), true);
for (int i = 10; i < 100; i++) {
journal.appendAddRecord(i, recordType, ("tst" + i).getBytes(), true);
journal.forceMoveNextFile();
journal.appendUpdateRecord(i, recordType, ("uptst" + i).getBytes(), true);
journal.appendDeleteRecord(i, true);
}
journal.testCompact();
journal.stop();
List<RecordInfo> records1 = new ArrayList<>();
List<PreparedTransactionInfo> preparedRecords = new ArrayList<>();
journal.start();
journal.load(records1, preparedRecords, null);
assertEquals(1, records1.size());
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class CrashOnCompactTest method createJournal.
private static JournalImpl createJournal(File folder, boolean crash) throws Exception {
NIOSequentialFileFactory factory = new NIOSequentialFileFactory(folder, 10);
JournalImpl journal = new JournalImpl(100 * 1024, 2, 2, 0, 0, factory, "jrntest", "jrn", 512) {
@Override
protected SequentialFile writeControlFile(final SequentialFileFactory fileFactory, final List<JournalFile> files, final List<JournalFile> newFiles, final List<Pair<String, String>> renames) throws Exception {
if (crash) {
SequentialFile controlFile = fileFactory.createSequentialFile(AbstractJournalUpdateTask.FILE_COMPACT_CONTROL);
controlFile.open();
controlFile.close();
System.err.println("crashing after creation of control file");
System.exit(OK);
}
return JournalCompactor.writeControlFile(fileFactory, files, newFiles, renames);
}
};
journal.setAutoReclaim(false);
journal.start();
return journal;
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class ActiveMQTestBase method countJournal.
/**
* Reads a journal system and returns a Map<Integer,AtomicInteger> of recordTypes and the number of records per type,
* independent of being deleted or not
*
* @param config
* @return
* @throws Exception
*/
protected HashMap<Integer, AtomicInteger> countJournal(Configuration config) throws Exception {
final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
List<JournalFile> filesToRead = messagesJournal.orderFiles();
for (JournalFile file : filesToRead) {
JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType));
}
return recordsType;
}
Aggregations