use of io.airlift.airline.Arguments in project cassandra by apache.
the class Compare method compare.
public static void compare(String querylog, List<String> arguments) {
List<ChronicleQueue> readQueues = null;
try (ResultHandler rh = new ResultHandler(arguments, null, null);
ChronicleQueue queryQ = SingleChronicleQueueBuilder.single(querylog).readOnly(true).build();
FQLQueryIterator queries = new FQLQueryIterator(queryQ.createTailer(), 1)) {
readQueues = arguments.stream().map(s -> SingleChronicleQueueBuilder.single(s).readOnly(true).build()).collect(Collectors.toList());
List<Iterator<ResultHandler.ComparableResultSet>> its = readQueues.stream().map(q -> new StoredResultSetIterator(q.createTailer())).collect(Collectors.toList());
while (queries.hasNext()) rh.handleResults(queries.next(), resultSets(its));
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (readQueues != null)
readQueues.forEach(Closeable::close);
}
}
use of io.airlift.airline.Arguments in project cassandra by apache.
the class Replay method replay.
public static void replay(String keyspace, List<String> arguments, List<String> targetHosts, List<File> resultPaths, String queryStorePath, boolean replayDDLStatements) {
// how many fql queries should we read in to memory to be able to sort them?
int readAhead = 200;
List<ChronicleQueue> readQueues = null;
List<FQLQueryIterator> iterators = null;
List<Predicate<FQLQuery>> filters = new ArrayList<>();
if (keyspace != null)
filters.add(fqlQuery -> fqlQuery.keyspace() == null || fqlQuery.keyspace().equals(keyspace));
if (!replayDDLStatements)
filters.add(fqlQuery -> {
boolean notDDLStatement = !fqlQuery.isDDLStatement();
if (!notDDLStatement)
logger.info("Excluding DDL statement from replaying: {}", ((FQLQuery.Single) fqlQuery).query);
return notDDLStatement;
});
try {
readQueues = arguments.stream().map(s -> SingleChronicleQueueBuilder.single(s).readOnly(true).build()).collect(Collectors.toList());
iterators = readQueues.stream().map(ChronicleQueue::createTailer).map(tailer -> new FQLQueryIterator(tailer, readAhead)).collect(Collectors.toList());
try (MergeIterator<FQLQuery, List<FQLQuery>> iter = MergeIterator.get(iterators, FQLQuery::compareTo, new Reducer());
QueryReplayer replayer = new QueryReplayer(iter, targetHosts, resultPaths, filters, queryStorePath)) {
replayer.replay();
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (iterators != null)
iterators.forEach(AbstractIterator::close);
if (readQueues != null)
readQueues.forEach(Closeable::close);
}
}
use of io.airlift.airline.Arguments 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;
}
}
}
Aggregations