use of org.apache.activemq.artemis.core.journal.EncodingSupport in project activemq-artemis by apache.
the class DescribeJournal method newObjectEncoding.
public static Object newObjectEncoding(RecordInfo info, JournalStorageManager storageManager) {
ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(info.data);
long id = info.id;
int rec = info.getUserRecordType();
switch(rec) {
case ADD_LARGE_MESSAGE_PENDING:
{
PendingLargeMessageEncoding lmEncoding = new PendingLargeMessageEncoding();
lmEncoding.decode(buffer);
return lmEncoding;
}
case ADD_LARGE_MESSAGE:
{
LargeServerMessage largeMessage = new LargeServerMessageImpl(storageManager);
LargeMessagePersister.getInstance().decode(buffer, largeMessage);
return new MessageDescribe(largeMessage);
}
case ADD_MESSAGE:
{
return "ADD-MESSAGE is not supported any longer, use export/import";
}
case ADD_MESSAGE_PROTOCOL:
{
Message message = MessagePersister.getInstance().decode(buffer, null);
return new MessageDescribe(message);
}
case ADD_REF:
{
final RefEncoding encoding = new RefEncoding();
encoding.decode(buffer);
return new ReferenceDescribe(encoding);
}
case ACKNOWLEDGE_REF:
{
final RefEncoding encoding = new RefEncoding();
encoding.decode(buffer);
return new AckDescribe(encoding);
}
case UPDATE_DELIVERY_COUNT:
{
DeliveryCountUpdateEncoding updateDeliveryCount = new DeliveryCountUpdateEncoding();
updateDeliveryCount.decode(buffer);
return updateDeliveryCount;
}
case PAGE_TRANSACTION:
{
if (info.isUpdate) {
PageUpdateTXEncoding pageUpdate = new PageUpdateTXEncoding();
pageUpdate.decode(buffer);
return pageUpdate;
} else {
PageTransactionInfoImpl pageTransactionInfo = new PageTransactionInfoImpl();
pageTransactionInfo.decode(buffer);
pageTransactionInfo.setRecordID(info.id);
return pageTransactionInfo;
}
}
case SET_SCHEDULED_DELIVERY_TIME:
{
ScheduledDeliveryEncoding encoding = new ScheduledDeliveryEncoding();
encoding.decode(buffer);
return encoding;
}
case DUPLICATE_ID:
{
DuplicateIDEncoding encoding = new DuplicateIDEncoding();
encoding.decode(buffer);
return encoding;
}
case HEURISTIC_COMPLETION:
{
HeuristicCompletionEncoding encoding = new HeuristicCompletionEncoding();
encoding.decode(buffer);
return encoding;
}
case ACKNOWLEDGE_CURSOR:
{
CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
encoding.decode(buffer);
return encoding;
}
case PAGE_CURSOR_COUNTER_VALUE:
{
PageCountRecord encoding = new PageCountRecord();
encoding.decode(buffer);
return encoding;
}
case PAGE_CURSOR_COMPLETE:
{
CursorAckRecordEncoding encoding = new PageCompleteCursorAckRecordEncoding();
encoding.decode(buffer);
return encoding;
}
case PAGE_CURSOR_COUNTER_INC:
{
PageCountRecordInc encoding = new PageCountRecordInc();
encoding.decode(buffer);
return encoding;
}
case PAGE_CURSOR_PENDING_COUNTER:
{
PageCountPendingImpl encoding = new PageCountPendingImpl();
encoding.decode(buffer);
encoding.setID(info.id);
return encoding;
}
case QUEUE_STATUS_RECORD:
return AbstractJournalStorageManager.newQueueStatusEncoding(id, buffer);
case QUEUE_BINDING_RECORD:
return AbstractJournalStorageManager.newQueueBindingEncoding(id, buffer);
case ID_COUNTER_RECORD:
EncodingSupport idReturn = new IDCounterEncoding();
idReturn.decode(buffer);
return idReturn;
case JournalRecordIds.GROUP_RECORD:
return AbstractJournalStorageManager.newGroupEncoding(id, buffer);
case ADDRESS_SETTING_RECORD:
return AbstractJournalStorageManager.newAddressEncoding(id, buffer);
case SECURITY_RECORD:
return AbstractJournalStorageManager.newSecurityRecord(id, buffer);
case ADDRESS_BINDING_RECORD:
return AbstractJournalStorageManager.newAddressBindingEncoding(id, buffer);
default:
return null;
}
}
use of org.apache.activemq.artemis.core.journal.EncodingSupport in project activemq-artemis by apache.
the class SequentialFileTptBenchmark method main.
public static void main(String[] args) throws Exception {
final boolean dataSync = false;
final boolean writeSync = true;
final Type type = Type.Mapped;
final int tests = 10;
final int warmup = 20_000;
final int measurements = 100_000;
final int msgSize = 100;
final byte[] msgContent = new byte[msgSize];
Arrays.fill(msgContent, (byte) 1);
final File tmpDirectory = new File("./");
// using the default configuration when the broker starts!
final SequentialFileFactory factory;
switch(type) {
case Mapped:
final int fileSize = Math.max(msgSize * measurements, msgSize * warmup);
factory = new MappedSequentialFileFactory(tmpDirectory, fileSize, true, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO, null).setDatasync(dataSync);
break;
case Nio:
factory = new NIOSequentialFileFactory(tmpDirectory, true, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_NIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_NIO, 1, false, null, null).setDatasync(dataSync);
break;
case Aio:
factory = new AIOSequentialFileFactory(tmpDirectory, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO, 500, false, null, null).setDatasync(dataSync);
// disable it when using directly the same buffer: ((AIOSequentialFileFactory)factory).disableBufferReuse();
if (!LibaioContext.isLoaded()) {
throw new IllegalStateException("lib AIO not loaded!");
}
break;
default:
throw new AssertionError("unsupported case");
}
factory.start();
try {
final EncodingSupport encodingSupport = new EncodingSupport() {
@Override
public int getEncodeSize() {
return msgSize;
}
@Override
public void encode(ActiveMQBuffer buffer) {
final int writerIndex = buffer.writerIndex();
buffer.setBytes(writerIndex, msgContent);
buffer.writerIndex(writerIndex + msgSize);
}
@Override
public void decode(ActiveMQBuffer buffer) {
}
};
final int alignedMessageSize = factory.calculateBlockSize(msgSize);
final long totalFileSize = Math.max(alignedMessageSize * measurements, alignedMessageSize * warmup);
if (totalFileSize > Integer.MAX_VALUE)
throw new IllegalArgumentException("reduce measurements/warmup");
final int fileSize = (int) totalFileSize;
final SequentialFile sequentialFile = factory.createSequentialFile("seq.dat");
sequentialFile.getJavaFile().delete();
sequentialFile.getJavaFile().deleteOnExit();
sequentialFile.open();
final long startZeros = System.nanoTime();
sequentialFile.fill(fileSize);
final long elapsedZeros = System.nanoTime() - startZeros;
System.out.println("Zeroed " + fileSize + " bytes in " + TimeUnit.NANOSECONDS.toMicros(elapsedZeros) + " us");
try {
{
final long elapsed = writeMeasurements(factory, sequentialFile, encodingSupport, warmup, writeSync);
System.out.println("warmup:" + (measurements * 1000_000_000L) / elapsed + " ops/sec");
}
for (int t = 0; t < tests; t++) {
final long elapsed = writeMeasurements(factory, sequentialFile, encodingSupport, measurements, writeSync);
System.out.println((measurements * 1000_000_000L) / elapsed + " ops/sec");
}
} finally {
sequentialFile.close();
}
} finally {
factory.stop();
}
}
use of org.apache.activemq.artemis.core.journal.EncodingSupport in project activemq-artemis by apache.
the class JournalImpl method runDirectJournalBlast.
@Override
public void runDirectJournalBlast() throws Exception {
final int numIts = 100000000;
ActiveMQJournalLogger.LOGGER.runningJournalBlast(numIts);
final CountDownLatch latch = new CountDownLatch(numIts * 2);
class MyAIOCallback implements IOCompletion {
@Override
public void done() {
latch.countDown();
}
@Override
public void onError(final int errorCode, final String errorMessage) {
}
@Override
public void storeLineUp() {
}
}
final MyAIOCallback task = new MyAIOCallback();
final int recordSize = 1024;
final byte[] bytes = new byte[recordSize];
class MyRecord implements EncodingSupport {
@Override
public void decode(final ActiveMQBuffer buffer) {
}
@Override
public void encode(final ActiveMQBuffer buffer) {
buffer.writeBytes(bytes);
}
@Override
public int getEncodeSize() {
return recordSize;
}
}
MyRecord record = new MyRecord();
for (int i = 0; i < numIts; i++) {
appendAddRecord(i, (byte) 1, record, true, task);
appendDeleteRecord(i, true, task);
}
latch.await();
}
use of org.apache.activemq.artemis.core.journal.EncodingSupport in project activemq-artemis by apache.
the class JournalImplTestUnit method testXASimplePrepared.
@Test
public void testXASimplePrepared() throws Exception {
setup(10, 10 * 1024, true);
createJournal();
startJournal();
load();
addTx(1, 1, 2, 3, 4, 5, 6, 7, 8, 9);
updateTx(1, 1, 2, 3, 4, 7, 8);
deleteTx(1, 1, 2, 3, 4, 5);
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
prepare(1, xid);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
use of org.apache.activemq.artemis.core.journal.EncodingSupport in project activemq-artemis by apache.
the class JournalImplTestUnit method testXAChangesNotVisibleRollback.
@Test
public void testXAChangesNotVisibleRollback() throws Exception {
setup(10, 10 * 1024, true);
createJournal();
startJournal();
load();
add(1, 2, 3, 4, 5, 6);
addTx(1, 7, 8, 9, 10);
updateTx(1, 1, 2, 3, 7, 8, 9);
deleteTx(1, 1, 2, 3, 4, 5);
EncodingSupport xid = new SimpleEncoding(10, (byte) 0);
prepare(1, xid);
rollback(1);
stopJournal();
createJournal();
startJournal();
loadAndCheck();
}
Aggregations