use of net.openhft.chronicle.queue.impl.WireStore in project Chronicle-Queue by OpenHFT.
the class QueueInspector method getWritingThreadId.
public int getWritingThreadId() {
final WireStore wireStore = queue.storeForCycle(queue.cycle(), queue.epoch(), false);
if (wireStore != null) {
final long position = wireStore.writePosition();
final int header = wireStore.bytes().readVolatileInt(position);
if (Wires.isReady(header)) {
final long nextHeaderPosition = position + Wires.lengthOf(header) + Wires.SPB_HEADER_SIZE;
final int unfinishedHeader = wireStore.bytes().readVolatileInt(nextHeaderPosition);
if (Wires.isNotComplete(unfinishedHeader) && unfinishedHeader != 0) {
return Wires.extractTidFromHeader(unfinishedHeader);
}
}
}
return NO_CURRENT_WRITER;
}
use of net.openhft.chronicle.queue.impl.WireStore in project Chronicle-Queue by OpenHFT.
the class EofMarkerOnEmptyQueueTest method shouldRecoverFromEmptyQueueOnRoll.
@Test
public void shouldRecoverFromEmptyQueueOnRoll() throws Exception {
final AtomicLong clock = new AtomicLong(System.currentTimeMillis());
try (final SingleChronicleQueue queue = SingleChronicleQueueBuilder.binary(tmpFolder.newFolder()).rollCycle(RollCycles.TEST_SECONDLY).timeProvider(clock::get).timeoutMS(1_000).testBlockSize().build()) {
final ExcerptAppender appender = queue.acquireAppender();
final DocumentContext context = appender.writingDocument();
// start to write a message, but don't close the context - simulates crashed writer
final long expectedEofMarkerPosition = context.wire().bytes().writePosition() - Wires.SPB_HEADER_SIZE;
context.wire().writeEventName("foo").int32(1);
final int startCycle = queue.cycle();
clock.addAndGet(TimeUnit.SECONDS.toMillis(1L));
final int nextCycle = queue.cycle();
// ensure that the cycle file will roll
assertThat(startCycle, is(not(nextCycle)));
Executors.newSingleThreadExecutor().submit(() -> {
try (final DocumentContext nextCtx = queue.acquireAppender().writingDocument()) {
nextCtx.wire().writeEventName("bar").int32(7);
}
}).get(3, TimeUnit.SECONDS);
final WireStore firstCycleStore = queue.storeForCycle(startCycle, 0, false);
final long firstCycleWritePosition = firstCycleStore.writePosition();
// assert that no write was completed
assertThat(firstCycleWritePosition, is(0L));
final ExcerptTailer tailer = queue.createTailer();
int recordCount = 0;
int lastItem = -1;
while (true) {
try (final DocumentContext readCtx = tailer.readingDocument()) {
if (!readCtx.isPresent()) {
break;
}
final StringBuilder name = new StringBuilder();
final ValueIn field = readCtx.wire().readEventName(name);
recordCount++;
lastItem = field.int32();
}
}
assertThat(firstCycleStore.bytes().readVolatileInt(expectedEofMarkerPosition), is(Wires.END_OF_DATA));
assertThat(recordCount, is(1));
assertThat(lastItem, is(7));
}
}
Aggregations