private Future<RecordInfo> attemptToWriteDocument(final ChronicleQueue queue) throws InterruptedException { final CountDownLatch startedLatch = new CountDownLatch(1); final Future<RecordInfo> future = executorService.submit(() -> { final int counterValue; startedLatch.countDown(); try (final DocumentContext documentContext = queue.acquireAppender().writingDocument()) { counterValue = counter.getAndIncrement(); documentContext.wire().getValueOut().int32(counterValue); } return new RecordInfo(counterValue); }); assertTrue("Task did not start", startedLatch.await(1, TimeUnit.MINUTES)); return future; }
final String debugMessage = "!! Skipped due to recovery of locked header !! By thread " + Thread.currentThread().getName() + ", pid " + OS.getProcessId(); wire.getValueOut().text(debugMessage); final StringWriter stackVisitor = new StringWriter(); new RuntimeException().printStackTrace(new PrintWriter(stackVisitor)); wire.getValueOut().text(stackTrace);
@NotNull private Wire toWire(int key) { final MyData myData = new MyData(); myData.key = key; myData.value = Integer.toString(key); Wire result = WireType.BINARY.apply(Bytes.elasticByteBuffer()); try (final DocumentContext dc = result.writingDocument()) { dc.wire().getValueOut().typedMarshallable(myData); } return result; }
public StartAndMonitor(ChronicleQueue queue, String name, int writePauseMs, int sleepBetweenMillis) { final SlowToSerialiseAndDeserialise object = new SlowToSerialiseAndDeserialise(writePauseMs); Thread thread = new Thread(() -> { try { while (running.get()) { long loopStart = System.nanoTime(); final ExcerptAppender appender = queue.acquireAppender(); // System.out.println("about to open"); try (final DocumentContext ctx = appender.writingDocument()) { // System.out.println("about to write"); ctx.wire().getValueOut().marshallable(object); // System.out.println("about to close"); } // System.out.println("closed"); long timeTaken = System.nanoTime() - loopStart; histo.sampleNanos(timeTaken); Jvm.pause(sleepBetweenMillis); } } catch (Throwable t) { t.printStackTrace(); } }, name); thread.start(); } }
private int write(ExcerptAppender appender) { int value; try (DocumentContext writingDocument = appender.writingDocument()) { final long documentAcquireTimestamp = System.nanoTime(); value = wrote.getAndIncrement(); ValueOut valueOut = writingDocument.wire().getValueOut(); // make the message longer valueOut.int64(documentAcquireTimestamp); for (int i = 0; i < NUMBER_OF_INTS; i++) { valueOut.int32(value); } writingDocument.wire().padToCacheAlign(); } return value; } }
private static long[] writeMessagesStoreIndices(final ExcerptAppender appender, final ExcerptTailer tailer) { final long[] indices = new long[RECORD_COUNT]; for (int i = 0; i < RECORD_COUNT; i++) { try (final DocumentContext ctx = appender.writingDocument()) { ctx.wire().getValueOut().int32(i); } } for (int i = 0; i < RECORD_COUNT; i++) { try (final DocumentContext ctx = tailer.readingDocument()) { assertThat("Expected record at index " + i, ctx.isPresent(), is(true)); indices[i] = tailer.index(); } } return indices; }
final ExcerptAppender excerptAppender = writeQueue.acquireAppender(); try (final DocumentContext ctx = excerptAppender.writingDocument()) { ctx.wire().getValueOut().object("first"); ctx.wire().getValueOut().object("second");
myData.key = i; myData.value = "some value where the key=" + String.valueOf(i); dc.wire().getValueOut().typedMarshallable(myData); time += 300; stp.currentTimeMillis(time);
@Test public void testMultipleAppenders() { try (ChronicleQueue syncQ = builder(getTmpDir(), this.wireType) .rollCycle(TEST_DAILY) .build()) { ExcerptAppender syncA = syncQ.acquireAppender(); assumeFalse(syncA.padToCacheAlignMode() == WORD); ExcerptAppender syncB = syncQ.acquireAppender(); ExcerptAppender syncC = syncQ.acquireAppender(); int count = 0; for (int i = 0; i < 3; i++) { syncA.writeText("hello A" + i); assertEquals(count++, (int) syncA.lastIndexAppended()); syncB.writeText("hello B" + i); assertEquals(count++, (int) syncB.lastIndexAppended()); try (DocumentContext dc = syncC.writingDocument(true)) { dc.wire().getValueOut().text("some meta " + i); } } String expected = expectedMultipleAppenders(); assertEquals(expected, syncQ.dump()); } }
dc.wire().getValueOut().text("hi-" + i); lastCycle = wqueue.rollCycle().toCycle(dc.index());
documentContext.wire().getValueOut().text("one"); documentContext.wire().getValueOut().text("two"); documentContext.wire().getValueOut().text("meta1"); documentContext.wire().getValueOut().text("three"); documentContext.wire().getValueOut().text("meta2"); documentContext.wire().getValueOut().text("meta3"); documentContext.wire().getValueOut().text("four");
/** * @return ByteBuffer, with self bootstrapping header in [position, limit) range */ private static <K, V> ByteBuffer writeHeader( FileChannel fileChannel, VanillaChronicleMap<K, V, ?> map) throws IOException { ByteBuffer headerBuffer = ByteBuffer.allocate( SELF_BOOTSTRAPPING_HEADER_OFFSET + MAX_BOOTSTRAPPING_HEADER_SIZE); headerBuffer.order(LITTLE_ENDIAN); Bytes<ByteBuffer> headerBytes = Bytes.wrapForWrite(headerBuffer); headerBytes.writePosition(SELF_BOOTSTRAPPING_HEADER_OFFSET); Wire wire = new TextWire(headerBytes); wire.getValueOut().typedMarshallable(map); int headerLimit = (int) headerBytes.writePosition(); int headerSize = headerLimit - SELF_BOOTSTRAPPING_HEADER_OFFSET; // First set readiness bit to READY, to compute checksum correctly //noinspection PointlessBitwiseExpression headerBuffer.putInt(SIZE_WORD_OFFSET, READY | DATA | headerSize); long checksum = headerChecksum(headerBuffer, headerSize); headerBuffer.putLong(HEADER_OFFSET, checksum); // Set readiness bit to NOT_COMPLETE, because the Chronicle Map instance is not actually // ready yet //noinspection PointlessBitwiseExpression headerBuffer.putInt(SIZE_WORD_OFFSET, NOT_COMPLETE | DATA | headerSize); // Write the size-prefixed blob to the file headerBuffer.position(0).limit(headerLimit); writeFully(fileChannel, 0, headerBuffer); headerBuffer.position(SELF_BOOTSTRAPPING_HEADER_OFFSET); return headerBuffer; }
final String debugMessage = "!! Skipped due to recovery of locked header !! By thread " + Thread.currentThread().getName() + ", pid " + OS.getProcessId(); wire.getValueOut().text(debugMessage); final StringWriter stackVisitor = new StringWriter(); new RuntimeException().printStackTrace(new PrintWriter(stackVisitor)); wire.getValueOut().text(stackTrace);