Search in sources :

Example 1 with BATCH

use of org.apache.cassandra.fql.FullQueryLogger.BATCH in project cassandra by apache.

the class FullQueryLoggerTest method assertRoundTripBatch.

private void assertRoundTripBatch(@Nullable String keyspace) {
    try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
        ExcerptTailer tailer = queue.createTailer();
        assertTrue(tailer.readDocument(wire -> {
            assertEquals(0, wire.read(VERSION).int16());
            assertEquals(BATCH, wire.read(TYPE).text());
            assertEquals(1L, wire.read(QUERY_START_TIME).int64());
            ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32(), true);
            assertEquals(ProtocolVersion.CURRENT, protocolVersion);
            QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wire.read(QUERY_OPTIONS).bytes()), protocolVersion);
            compareQueryOptions(QueryOptions.DEFAULT, queryOptions);
            assertEquals(Long.MIN_VALUE, wire.read(GENERATED_TIMESTAMP).int64());
            assertEquals(Integer.MIN_VALUE, wire.read(GENERATED_NOW_IN_SECONDS).int32());
            assertEquals(keyspace, wire.read(FullQueryLogger.KEYSPACE).text());
            assertEquals("UNLOGGED", wire.read(BATCH_TYPE).text());
            ValueIn in = wire.read(QUERIES);
            assertEquals(2, in.int32());
            assertEquals("foo1", in.text());
            assertEquals("foo2", in.text());
            in = wire.read(VALUES);
            assertEquals(2, in.int32());
            assertEquals(2, in.int32());
            assertTrue(Arrays.equals(new byte[1], in.bytes()));
            assertTrue(Arrays.equals(new byte[2], in.bytes()));
            assertEquals(0, in.int32());
        }));
    }
}
Also used : Arrays(java.util.Arrays) BATCH_TYPE(org.apache.cassandra.fql.FullQueryLogger.BATCH_TYPE) File(org.apache.cassandra.io.util.File) StringUtils(org.apache.commons.lang3.StringUtils) ByteBuffer(java.nio.ByteBuffer) GENERATED_NOW_IN_SECONDS(org.apache.cassandra.fql.FullQueryLogger.GENERATED_NOW_IN_SECONDS) Unpooled(io.netty.buffer.Unpooled) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SINGLE_QUERY(org.apache.cassandra.fql.FullQueryLogger.SINGLE_QUERY) After(org.junit.After) VERSION(org.apache.cassandra.fql.FullQueryLogger.VERSION) Path(java.nio.file.Path) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer) QueryState(org.apache.cassandra.service.QueryState) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) Util(org.apache.cassandra.Util) QUERY(org.apache.cassandra.fql.FullQueryLogger.QUERY) SingleChronicleQueueBuilder(net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder) List(java.util.List) FileUtils(org.apache.cassandra.io.util.FileUtils) Assert.assertFalse(org.junit.Assert.assertFalse) BinLogTest(org.apache.cassandra.utils.binlog.BinLogTest) VALUES(org.apache.cassandra.fql.FullQueryLogger.VALUES) ObjectSizes(org.apache.cassandra.utils.ObjectSizes) BeforeClass(org.junit.BeforeClass) CQLTester(org.apache.cassandra.cql3.CQLTester) BatchStatement(org.apache.cassandra.cql3.statements.BatchStatement) ArrayList(java.util.ArrayList) BATCH(org.apache.cassandra.fql.FullQueryLogger.BATCH) PROTOCOL_VERSION(org.apache.cassandra.fql.FullQueryLogger.PROTOCOL_VERSION) Query(org.apache.cassandra.fql.FullQueryLogger.Query) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) LinkedList(java.util.LinkedList) Nullable(javax.annotation.Nullable) QUERY_START_TIME(org.apache.cassandra.fql.FullQueryLogger.QUERY_START_TIME) Semaphore(java.util.concurrent.Semaphore) ClientState(org.apache.cassandra.service.ClientState) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TYPE(org.apache.cassandra.fql.FullQueryLogger.TYPE) Batch(org.apache.cassandra.fql.FullQueryLogger.Batch) GENERATED_TIMESTAMP(org.apache.cassandra.fql.FullQueryLogger.GENERATED_TIMESTAMP) WireOut(net.openhft.chronicle.wire.WireOut) ValueIn(net.openhft.chronicle.wire.ValueIn) RollCycles(net.openhft.chronicle.queue.RollCycles) Type(org.apache.cassandra.cql3.statements.BatchStatement.Type) QUERY_OPTIONS(org.apache.cassandra.fql.FullQueryLogger.QUERY_OPTIONS) Collections(java.util.Collections) QueryOptions(org.apache.cassandra.cql3.QueryOptions) Assert.assertEquals(org.junit.Assert.assertEquals) QUERIES(org.apache.cassandra.fql.FullQueryLogger.QUERIES) ValueIn(net.openhft.chronicle.wire.ValueIn) ChronicleQueue(net.openhft.chronicle.queue.ChronicleQueue) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) QueryOptions(org.apache.cassandra.cql3.QueryOptions) ExcerptTailer(net.openhft.chronicle.queue.ExcerptTailer)

Example 2 with BATCH

use of org.apache.cassandra.fql.FullQueryLogger.BATCH in project cassandra by apache.

the class FullQueryLoggerTest method testBatchWeight.

@Test
public void testBatchWeight() {
    // An empty batch should have weight
    Batch batch = new Batch(Type.UNLOGGED, new ArrayList<>(), new ArrayList<>(), QueryOptions.DEFAULT, queryState(), 1);
    assertTrue(batch.weight() > 0);
    // make sure that a batch with keyspace set has a higher weight
    Batch batch2 = new Batch(Type.UNLOGGED, new ArrayList<>(), new ArrayList<>(), QueryOptions.DEFAULT, queryState("ABABA"), 1);
    assertTrue(batch.weight() < batch2.weight());
    StringBuilder sb = new StringBuilder();
    for (int ii = 0; ii < 1024 * 1024; ii++) {
        sb.append('a');
    }
    // The weight of the list containing queries should be reflected
    List<String> bigList = new ArrayList(100000);
    for (int ii = 0; ii < 100000; ii++) {
        bigList.add("");
    }
    batch = new Batch(Type.UNLOGGED, bigList, new ArrayList<>(), QueryOptions.DEFAULT, queryState(), 1);
    assertTrue(batch.weight() > ObjectSizes.measureDeep(bigList));
    // The size of the query should be reflected
    bigList = new ArrayList(1);
    bigList.add(sb.toString());
    batch = new Batch(Type.UNLOGGED, bigList, new ArrayList<>(), QueryOptions.DEFAULT, queryState(), 1);
    assertTrue(batch.weight() > ObjectSizes.measureDeep(bigList));
    bigList = null;
    // The size of the list of values should be reflected
    List<List<ByteBuffer>> bigValues = new ArrayList<>(100000);
    for (int ii = 0; ii < 100000; ii++) {
        bigValues.add(new ArrayList<>(0));
    }
    bigValues.get(0).add(ByteBuffer.allocate(1024 * 1024 * 5));
    batch = new Batch(Type.UNLOGGED, new ArrayList<>(), bigValues, QueryOptions.DEFAULT, queryState(), 1);
    assertTrue(batch.weight() > ObjectSizes.measureDeep(bigValues));
    // As should the size of the values
    QueryOptions largeOptions = QueryOptions.forInternalCalls(Arrays.asList(ByteBuffer.allocate(1024 * 1024)));
    batch = new Batch(Type.UNLOGGED, new ArrayList<>(), new ArrayList<>(), largeOptions, queryState(), 1);
    assertTrue(batch.weight() > 1024 * 1024);
}
Also used : Batch(org.apache.cassandra.fql.FullQueryLogger.Batch) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) QueryOptions(org.apache.cassandra.cql3.QueryOptions) BinLogTest(org.apache.cassandra.utils.binlog.BinLogTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 QueryOptions (org.apache.cassandra.cql3.QueryOptions)2 Batch (org.apache.cassandra.fql.FullQueryLogger.Batch)2 Unpooled (io.netty.buffer.Unpooled)1 ByteBuffer (java.nio.ByteBuffer)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Nullable (javax.annotation.Nullable)1 ChronicleQueue (net.openhft.chronicle.queue.ChronicleQueue)1 ExcerptTailer (net.openhft.chronicle.queue.ExcerptTailer)1 RollCycles (net.openhft.chronicle.queue.RollCycles)1 SingleChronicleQueueBuilder (net.openhft.chronicle.queue.impl.single.SingleChronicleQueueBuilder)1 ValueIn (net.openhft.chronicle.wire.ValueIn)1 WireOut (net.openhft.chronicle.wire.WireOut)1 Util (org.apache.cassandra.Util)1