use of net.openhft.chronicle.core.io.Closeable 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 net.openhft.chronicle.core.io.Closeable in project cassandra by apache.
the class FQLCompareTest method compareEqual.
@Test
public void compareEqual() throws IOException {
List<String> targetHosts = Lists.newArrayList("hosta", "hostb");
File tmpDir = Files.createTempDirectory("testresulthandler").toFile();
File queryDir = Files.createTempDirectory("queries").toFile();
List<File> resultPaths = generateResultSets(targetHosts, tmpDir, queryDir, false, false);
ResultComparator comparator = new ResultComparator();
List<ChronicleQueue> readQueues = null;
try {
readQueues = resultPaths.stream().map(s -> SingleChronicleQueueBuilder.single(s).readOnly(true).build()).collect(Collectors.toList());
List<Iterator<ResultHandler.ComparableResultSet>> its = readQueues.stream().map(q -> new Compare.StoredResultSetIterator(q.createTailer())).collect(Collectors.toList());
List<ResultHandler.ComparableResultSet> resultSets = Compare.resultSets(its);
while (resultSets.stream().allMatch(Objects::nonNull)) {
assertTrue(comparator.compareColumnDefinitions(targetHosts, query(), resultSets.stream().map(ResultHandler.ComparableResultSet::getColumnDefinitions).collect(Collectors.toList())));
List<Iterator<ResultHandler.ComparableRow>> rows = resultSets.stream().map(Iterable::iterator).collect(Collectors.toList());
List<ResultHandler.ComparableRow> toCompare = ResultHandler.rows(rows);
while (toCompare.stream().allMatch(Objects::nonNull)) {
assertTrue(comparator.compareRows(targetHosts, query(), ResultHandler.rows(rows)));
toCompare = ResultHandler.rows(rows);
}
resultSets = Compare.resultSets(its);
}
} finally {
if (readQueues != null)
readQueues.forEach(Closeable::close);
}
}
use of net.openhft.chronicle.core.io.Closeable 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);
}
}
Aggregations