Search in sources :

Example 71 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.

the class BinAuditLoggerTest method testSelectRoundTripQuery.

@Test
public void testSelectRoundTripQuery() throws Throwable {
    createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
    execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra");
    execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test");
    String cql = "SELECT id, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE id = ?";
    Session session = sessionNet();
    PreparedStatement pstmt = session.prepare(cql);
    ResultSet rs = session.execute(pstmt.bind(1));
    assertEquals(1, rs.all().size());
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
        ExcerptTailer tailer = queue.createTailer();
        assertTrue(tailer.readDocument(wire -> {
            assertEquals(0L, wire.read("version").int16());
            assertEquals("audit", wire.read("type").text());
            assertThat(wire.read("message").text(), containsString(AuditLogEntryType.PREPARE_STATEMENT.toString()));
        }));
        assertTrue(tailer.readDocument(wire -> {
            assertEquals(0L, wire.read("version").int16());
            assertEquals("audit", wire.read("type").text());
            assertThat(wire.read("message").text(), containsString(AuditLogEntryType.SELECT.toString()));
        }));
        assertFalse(tailer.readDocument(wire -> {
        }));
    }
}
Also used : ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) BeforeClass(org.junit.BeforeClass) CQLTester(org.apache.cassandra.cql3.CQLTester) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) PreparedStatement(com.datastax.driver.core.PreparedStatement) Assert.assertThat(org.junit.Assert.assertThat) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ResultSet(com.datastax.driver.core.ResultSet) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) Assert.assertFalse(org.junit.Assert.assertFalse) Session(com.datastax.driver.core.Session) RollCycles(net.openhft.chronicle.queue.RollCycles) BinLogTest(org.apache.cassandra.utils.binlog.BinLogTest) Path(java.nio.file.Path) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) Session(com.datastax.driver.core.Session) Test(org.junit.Test) BinLogTest(org.apache.cassandra.utils.binlog.BinLogTest)

Example 72 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue 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)

Example 73 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.

the class FQLReplayTest method testQueryIterator.

@Test
public void testQueryIterator() throws IOException {
    File f = generateQueries(100, false);
    int queryCount = 0;
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(f).build();
        FQLQueryIterator iter = new FQLQueryIterator(queue.createTailer(), 1)) {
        long last = -1;
        while (iter.hasNext()) {
            FQLQuery q = iter.next();
            assertTrue(q.queryStartTime >= last);
            last = q.queryStartTime;
            queryCount++;
        }
    }
    assertEquals(100, queryCount);
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) File(java.io.File) Test(org.junit.Test)

Example 74 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.

the class FQLReplayTest method readResultFile.

private static List<Pair<FQLQuery, ResultHandler.ComparableResultSet>> readResultFile(File dir, File queryDir) {
    List<Pair<FQLQuery, ResultHandler.ComparableResultSet>> resultSets = new ArrayList<>();
    try (ChronicleQueue q = SingleChronicleQueueBuilder.single(dir).build();
        ChronicleQueue queryQ = SingleChronicleQueueBuilder.single(queryDir).build()) {
        ExcerptTailer queryTailer = queryQ.createTailer();
        FQLQueryReader queryReader = new FQLQueryReader();
        Compare.StoredResultSetIterator resultSetIterator = new Compare.StoredResultSetIterator(q.createTailer());
        // we need to materialize the rows in-memory to compare them easier in these tests
        while (resultSetIterator.hasNext()) {
            ResultHandler.ComparableResultSet resultSetFromDisk = resultSetIterator.next();
            Iterator<ResultHandler.ComparableRow> rowIterFromDisk = resultSetFromDisk.iterator();
            queryTailer.readDocument(queryReader);
            FQLQuery query = queryReader.getQuery();
            List<ResultHandler.ComparableRow> rows = new ArrayList<>();
            while (rowIterFromDisk.hasNext()) {
                rows.add(rowIterFromDisk.next());
            }
            resultSets.add(Pair.create(query, new StoredResultSet(resultSetFromDisk.getColumnDefinitions(), resultSetIterator.hasNext(), resultSetFromDisk.wasFailed(), resultSetFromDisk.getFailureException(), rows::iterator)));
        }
    }
    return resultSets;
}
Also used : ArrayList(java.util.ArrayList) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Compare(org.apache.cassandra.fqltool.commands.Compare) Pair(org.apache.cassandra.utils.Pair)

Example 75 with ChronicleQueue

use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.

the class FQLReplayTest method testOrderedReplay.

@Test
public void testOrderedReplay() throws IOException {
    File f = generateQueries(100, true);
    int queryCount = 0;
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(f).build();
        FQLQueryIterator iter = new FQLQueryIterator(queue.createTailer(), 101)) {
        long last = -1;
        while (iter.hasNext()) {
            FQLQuery q = iter.next();
            assertTrue(q.queryStartTime >= last);
            last = q.queryStartTime;
            queryCount++;
        }
    }
    assertEquals(100, queryCount);
}
Also used : ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) File(java.io.File) Test(org.junit.Test)

Aggregations

ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)80 Test (org.junit.Test)59 ExcerptAppender (net.openhft.chronicle.queue.ExcerptAppender)37 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)37 File (java.io.File)36 DocumentContext (net.openhft.chronicle.wire.DocumentContext)21 ArrayList (java.util.ArrayList)16 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)14 MethodReader (net.openhft.chronicle.bytes.MethodReader)12 List (java.util.List)11 IOException (java.io.IOException)9 MappedFile (net.openhft.chronicle.bytes.MappedFile)8 Path (java.nio.file.Path)7 Bytes (net.openhft.chronicle.bytes.Bytes)7 Collections (java.util.Collections)6 RollCycles (net.openhft.chronicle.queue.RollCycles)6 NotNull (org.jetbrains.annotations.NotNull)6 ByteBuffer (java.nio.ByteBuffer)5 MappedBytes (net.openhft.chronicle.bytes.MappedBytes)5 Histogram (net.openhft.chronicle.core.util.Histogram)5