Chronicle Roll Files Daily

848 views Asked by At

I am trying to implement Chronicle Queue into our system and had a question regarding rolling of files daily but at a specific time as per the local time zone of the process. I read few write-ups regarding how to specify roll cycle but as per documentation the epoch time works as per midnight UTC. What would I need to do to configure a roll cycle let's say every day at 5PM local time zone of the process running? Any suggestions?

public class TestRollCycle {

    public class TestClass implements TestEvent {
        private int counter = 1;

        @Override
        public void setOrGetEvent(String event) {
            System.out.println("Counter Read Value: " + counter);
            counter++;
        }
    }

    public interface TestEvent {
        void setOrGetEvent(String event);
    }

    @Test
    public void testRollProducer() {
        int insertCount = 1;
        String pathOfFile = "rollPath";
        // Epoch is 5:15PM EDT
        SingleChronicleQueue producerQueue = SingleChronicleQueueBuilder.binary(pathOfFile).epoch(32940000).build();
        ExcerptAppender myAppender = producerQueue.acquireAppender();
        TestEvent eventWriter = myAppender.methodWriter(TestEvent.class);

        while (true) {
            String testString = "Insert String";
            eventWriter.setOrGetEvent(testString);

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Counter Write Value: " + insertCount);
            insertCount++;
        }
    }

    @Test
    public void testRollConsumer() throws InterruptedException {
        String pathOfFile = "rollPath";
        // Epoch is 5:15PM EDT
        SingleChronicleQueue producerQueue = SingleChronicleQueueBuilder.binary(pathOfFile).epoch(32940000).build();
        TestClass myClass = new TestClass();
        ExcerptTailer trailer = producerQueue.createTailer();
        MethodReader methodReader = trailer.methodReader(myClass);

        while (true) {
            if (!methodReader.readOne()) {
                Thread.sleep(1000);
            } else {
                //System.out.println(trailer.index());
            }
        }
    }
}
2

There are 2 answers

5
Peter Lawrey On

This is a feature we added to Chronicle Queue Enterprise. I suggest you contact [email protected] if you are will to pay for it.

6
Mark Price On

I think there's a problem in your test - the epoch of 32940000 supplied to the queue builder is 9hr 15m from midnight, so 9:15AM UTC or 5:15AM EDT. It should be another 12 hours later for the roll-time to be 5:15PM.

I've added a test that documents the current behaviour for your use-case, and it passes as expected. Can you double-check that you're supplying the correct epoch offset, and perhaps implement a StoreFileListener in order to capture/log any roll events.

The roll will not actually occur until an event is written to the queue that is after the roll-time boundary. So an idle queue that is not being written-to will not roll without input events.

The test is on github:

https://github.com/OpenHFT/Chronicle-Queue/blob/master/src/test/java/net/openhft/chronicle/queue/impl/single/QueueEpochTest.java