Search in sources :

Example 1 with Closeable

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);
    }
}
Also used : ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Iterator(java.util.Iterator) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) AbstractIterator(com.google.common.collect.AbstractIterator) Closeable(net.openhft.chronicle.core.io.Closeable) StoredResultSet(org.apache.cassandra.fqltool.StoredResultSet) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Command(io.airlift.airline.Command) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) List(java.util.List) Option(io.airlift.airline.Option) ResultHandler(org.apache.cassandra.fqltool.ResultHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FQLQueryIterator(org.apache.cassandra.fqltool.FQLQueryIterator) Arguments(io.airlift.airline.Arguments) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) FQLQueryIterator(org.apache.cassandra.fqltool.FQLQueryIterator) ResultHandler(org.apache.cassandra.fqltool.ResultHandler) FQLQueryIterator(org.apache.cassandra.fqltool.FQLQueryIterator)

Example 2 with Closeable

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);
    }
}
Also used : Util(org.apache.cassandra.tools.Util) Iterator(java.util.Iterator) Files(java.nio.file.Files) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) AssertStatus.assertTrue(org.psjava.util.AssertStatus.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Closeable(net.openhft.chronicle.core.io.Closeable) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) Objects(java.util.Objects) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) List(java.util.List) Lists(com.google.common.collect.Lists) Collections(java.util.Collections) QueryOptions(org.apache.cassandra.cql3.QueryOptions) Compare(org.apache.cassandra.fqltool.commands.Compare) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Iterator(java.util.Iterator) Objects(java.util.Objects) File(java.io.File) Test(org.junit.Test)

Example 3 with Closeable

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);
    }
}
Also used : MergeIterator(org.apache.cassandra.utils.MergeIterator) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) LoggerFactory(org.slf4j.LoggerFactory) Closeable(net.openhft.chronicle.core.io.Closeable) Collectors(java.util.stream.Collectors) QueryReplayer(org.apache.cassandra.fqltool.QueryReplayer) File(java.io.File) ArrayList(java.util.ArrayList) Command(io.airlift.airline.Command) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) List(java.util.List) Option(io.airlift.airline.Option) FQLQuery(org.apache.cassandra.fqltool.FQLQuery) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FQLQueryIterator(org.apache.cassandra.fqltool.FQLQueryIterator) Arguments(io.airlift.airline.Arguments) AbstractIterator(org.apache.cassandra.utils.AbstractIterator) FQLQuery(org.apache.cassandra.fqltool.FQLQuery) ArrayList(java.util.ArrayList) Predicate(java.util.function.Predicate) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ArrayList(java.util.ArrayList) List(java.util.List) QueryReplayer(org.apache.cassandra.fqltool.QueryReplayer) FQLQueryIterator(org.apache.cassandra.fqltool.FQLQueryIterator)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Closeable (net.openhft.chronicle.core.io.Closeable)3 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)3 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Arguments (io.airlift.airline.Arguments)2 Command (io.airlift.airline.Command)2 Option (io.airlift.airline.Option)2 File (java.io.File)2 Iterator (java.util.Iterator)2 FQLQueryIterator (org.apache.cassandra.fqltool.FQLQueryIterator)2 AbstractIterator (com.google.common.collect.AbstractIterator)1 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Predicate (java.util.function.Predicate)1