use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class Dump method dump.
public static void dump(List<String> arguments, String rollCycle, boolean follow) {
StringBuilder sb = new StringBuilder();
ReadMarshallable reader = wireIn -> {
sb.setLength(0);
int version = wireIn.read(BinLog.VERSION).int16();
if (version > FullQueryLogger.CURRENT_VERSION) {
throw new IORuntimeException("Unsupported record version [" + version + "] - highest supported version is [" + FullQueryLogger.CURRENT_VERSION + ']');
}
String type = wireIn.read(BinLog.TYPE).text();
if (!FullQueryLogger.SINGLE_QUERY.equals((type)) && !FullQueryLogger.BATCH.equals((type))) {
throw new IORuntimeException("Unsupported record type field [" + type + "] - supported record types are [" + FullQueryLogger.SINGLE_QUERY + ", " + FullQueryLogger.BATCH + ']');
}
sb.append("Type: ").append(type).append(System.lineSeparator());
long queryStartTime = wireIn.read(FullQueryLogger.QUERY_START_TIME).int64();
sb.append("Query start time: ").append(queryStartTime).append(System.lineSeparator());
int protocolVersion = wireIn.read(FullQueryLogger.PROTOCOL_VERSION).int32();
sb.append("Protocol version: ").append(protocolVersion).append(System.lineSeparator());
QueryOptions options = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wireIn.read(FullQueryLogger.QUERY_OPTIONS).bytes()), ProtocolVersion.decode(protocolVersion, true));
long generatedTimestamp = wireIn.read(FullQueryLogger.GENERATED_TIMESTAMP).int64();
sb.append("Generated timestamp:").append(generatedTimestamp).append(System.lineSeparator());
int generatedNowInSeconds = wireIn.read(FullQueryLogger.GENERATED_NOW_IN_SECONDS).int32();
sb.append("Generated nowInSeconds:").append(generatedNowInSeconds).append(System.lineSeparator());
switch(type) {
case (FullQueryLogger.SINGLE_QUERY):
dumpQuery(options, wireIn, sb);
break;
case (FullQueryLogger.BATCH):
dumpBatch(options, wireIn, sb);
break;
default:
throw new IORuntimeException("Log entry of unsupported type " + type);
}
System.out.print(sb.toString());
System.out.flush();
};
// Backoff strategy for spinning on the queue, not aggressive at all as this doesn't need to be low latency
Pauser pauser = Pauser.millis(100);
List<ChronicleQueue> queues = arguments.stream().distinct().map(path -> SingleChronicleQueueBuilder.single(new File(path)).readOnly(true).rollCycle(RollCycles.valueOf(rollCycle)).build()).collect(Collectors.toList());
List<ExcerptTailer> tailers = queues.stream().map(ChronicleQueue::createTailer).collect(Collectors.toList());
boolean hadWork = true;
while (hadWork) {
hadWork = false;
for (ExcerptTailer tailer : tailers) {
while (tailer.readDocument(reader)) {
hadWork = true;
}
}
if (follow) {
if (!hadWork) {
// Chronicle queue doesn't support blocking so use this backoff strategy
pauser.pause();
}
// Don't terminate the loop even if there wasn't work
hadWork = true;
}
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class FullQueryLoggerTest method testRoundTripBatchWithKeyspace.
@Test
public void testRoundTripBatchWithKeyspace() throws Exception {
configureFQL();
logBatch(Type.UNLOGGED, Arrays.asList("foo1", "foo2"), Arrays.asList(Arrays.asList(ByteBuffer.allocate(1), ByteBuffer.allocateDirect(2)), Collections.emptyList()), QueryOptions.DEFAULT, queryState("abcdefgh"), 1);
Util.spinAssertEquals(true, () -> {
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
return queue.createTailer().readingDocument().isPresent();
}
}, 60);
assertRoundTripBatch("abcdefgh");
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class FullQueryLoggerTest method testRoundTripBatchWithKeyspaceNull.
@Test
public void testRoundTripBatchWithKeyspaceNull() throws Exception {
configureFQL();
logBatch(Type.UNLOGGED, Arrays.asList("foo1", "foo2"), Arrays.asList(Arrays.asList(ByteBuffer.allocate(1), ByteBuffer.allocateDirect(2)), Collections.emptyList()), QueryOptions.DEFAULT, queryState(), 1);
Util.spinAssertEquals(true, () -> {
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
return queue.createTailer().readingDocument().isPresent();
}
}, 60);
assertRoundTripBatch(null);
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class AuditLogViewerTest method testIgnoreFutureVersionRecord.
@Test
public void testIgnoreFutureVersionRecord() {
List<String> records = new ArrayList<>();
records.add("Test foo bar 1");
records.add("Test foo bar 2");
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(path.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptAppender appender = queue.acquireAppender();
// Write future record
appender.writeDocument(createFutureRecord());
// Write bunch of current records
records.forEach(s -> appender.writeDocument(new BinAuditLogger.Message(s)));
// Read those written records
List<String> actualRecords = new ArrayList<>();
AuditLogViewer.dump(ImmutableList.of(path.toString()), RollCycles.TEST_SECONDLY.toString(), false, true, actualRecords::add);
// Assert all current records are present
assertRecordsMatch(records, actualRecords);
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class AuditLogViewerTest method testIgnoreUnknownTypeRecord.
@Test
public void testIgnoreUnknownTypeRecord() {
List<String> records = new ArrayList<>();
records.add("Test foo bar 1");
records.add("Test foo bar 2");
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(path.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptAppender appender = queue.acquireAppender();
// Write unrecognized type record
appender.writeDocument(createUnknownTypeRecord());
// Write bunch of supported records
records.forEach(s -> appender.writeDocument(new BinAuditLogger.Message(s)));
// Read those written records
List<String> actualRecords = new ArrayList<>();
AuditLogViewer.dump(ImmutableList.of(path.toString()), RollCycles.TEST_SECONDLY.toString(), false, true, actualRecords::add);
// Assert all supported records are present
assertRecordsMatch(records, actualRecords);
}
}
Aggregations