Search code examples
cassandrachronicle

How to read cassandra FQL logs in java?


I have a bunch of cassandra FQL logs with the "cq4" extension. I would like to read them in Java, is there a Java class that those log entries can be mapped into?

These are the logs I see.

enter image description here

I want to read this with this code:

import net.openhft.chronicle.Chronicle;
import net.openhft.chronicle.ChronicleQueueBuilder;
import net.openhft.chronicle.ExcerptTailer;

import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException {
        Chronicle chronicle = ChronicleQueueBuilder.indexed("/Users/pavelorekhov/Desktop/fql_logs").build();
        ExcerptTailer tailer = chronicle.createTailer();
        while (tailer.nextIndex()) {
            tailer.readInstance(/*class goes here*/)
        }
    }
}

I think from the code and screenshot you can understand what kind of class I need in order to read log entries into objects. Does that class exist in some cassandra maven dependency?


Solution

  • I ended up cloning cassandra's github repo from here: https://github.com/apache/cassandra

    In their code they have the FQLQueryIterator class which you can use to read logs, like so:

    SingleChronicleQueue scq = SingleChronicleQueueBuilder.builder().path("/Users/pavelorekhov/Desktop/fql_logs").build();
    ExcerptTailer excerptTailer = scq.createTailer();
    
    FQLQueryIterator iterator = new FQLQueryIterator(excerptTailer, 1);
    
    while (iterator.hasNext()) {
        FQLQuery fqlQuery = iterator.next(); // object that holds the log entry
        // do whatever you need to do with that log entry...
    }