Search code examples
aeron

Aeron Archive determine the end of recording


I replay a recording using the Aeron Archive. How can I determine that the recording has ended? Is there a way to provide a callback which is triggered when the recording runs out of data? At the moment I use a simple heartbeat-style workaround which tracks the timestamp of the last message (measured by consumer) and if a timeout has passed I decide that there is no more data. This workaround looks unreliable: there can be many reasons why it didn't receive data for a long time. What is the best practice of determining the end of recording?

There is a subquestion here. When I use a ReplayMerge, how can I determine that I already replayed all historical data and now I follow the live stream?


Solution

  • I found out a way to do it reliably. Suppose that we are replaying a recording with startPosition = 123456 and stopPosition = 234567. When we receive a message in a FragmentHandler we should look into the header contents.

    onFragment(DirectBuffer buffer, int offset, int length, Header header)
    

    The reliable indicator that there is no more data looks like this:

    boolean isLast = stopPosition == header.position();
    

    There is also a wrong way to do it. Do not do this!

    Image image = (Image)header.context();
    boolean isLast = image.isEndOfStream();
    

    This approach doesn't work.