Create a RecoveryBuffer
the minimum number of messages
the minimum number of time indices
The size of the indices and times arrays
A utility function that limits a position to an index in the circular
indices array.
An array containing indices
An array containing messages
The size of the messages array
A utility function that limits a position to an index in the circular
messages array.
Index of the head message in the messages circular buffer array.
Index of the tail message in the messages circular buffer array.
An array containing time stamps
Index of the head timestamp in the times circular buffer array.
Index of the tail timestamp in the times circular buffer array.
Clears this buffer
Remove all elements added at or before the timestamp.
the timestamp. Follows the same properties as used in RecoveryBuffer#markTime
Inform this recovery buffer of the current timestamp. Subsequent messages put in the buffer are recorded as older than this timestamp.
Add a message to the buffer. If the buffer is full, the oldest message is discarded
the message
If there are at least N messages in the buffer, pass the N most recent messages to the consumer function and return true. Otherwise return false.
This is a non-destructive operation.
the number of messages to recover
the consumer function to be called with recovered messages (in order)
false if there are not N messages, in which case consumer will not be called.
Remove elements from the buffer
Get the number of messages
the number of messages that can be recovered
Copyright © 2025 DiffusionData Ltd. All Rights Reserved.
Port of the Java RecoveryBuffer implementation, with a bounded number of entries.
Timestamps are recorded in a timestamp index. The timestamp index also has a fixed upper size bound.
This implementation expects timestamp parameters in milliseconds. It rounds timestamps to reduce the required index size and the number of index updates.
The recovery buffer is implemented as a bounded circular buffer of (timestamp, messages index) pairs. Each entry states that messages with earlier indexes than its index were added at its timestamp or earlier. This serves to timestamp ranges of .messages, allowing us to flush stale entries.
Each call to markTime adds an entry, possibly evicting messages referred to by an older entry for which there is no longer room.
Some invariants:
[timesHead, timesTail).indices[timesHead] == -1<=> the timestamp index is empty.timesHead == timesTail<=> either the timestamp index is empty, orindices[timesHead] >= 0and the timestamp index isfull.size == 0=> the timestamp index is empty.i,indices[i] >= 0and is either equal to tail or points to a non-null entry in messages.Peter Hughes
5.8