Skip to main content

chronon::observe::ReorderBuffer

Cycle-sorted buffer for observation events backed by an arena. More...

#include <ReorderBuffer.hpp>

Public Types

Name
using ReorderBufferConfigConfig

Public Functions

Name
voidupdateMinCycle(uint64_t min_cycle)
Update the minimum observed cycle across producer threads.
ArenaSnapshotsnapshotArena(const std::vector< BufferedRecord > & records) const
Copies only the contiguous range [min_offset, max_end) referenced by records.
size_tsize() const
uint64_tminCycle() const
voidflushReady(std::vector< BufferedRecord > & out)
Flush events below the watermark, sorted by cycle.
voidflushAll(std::vector< BufferedRecord > & out)
Flush every remaining event, sorted by cycle. Use at shutdown.
boolempty() const
const Config &config() const
voidcompactArena()
PRECONDITION: flushed records have been fully consumed.
boolbufferEvent(const ObservationQueue::RecordHeader * header, const std::byte * data, size_t data_size)
Appends record into the arena.
const std::byte *arenaData(uint32_t offset) const
ReorderBuffer(const Config & config =Config{})

Detailed Description

class chronon::observe::ReorderBuffer;

Cycle-sorted buffer for observation events backed by an arena.

No per-event heap allocations; flushes use a hybrid watermark strategy:

  1. Primary (cycle-based): events with cycle < (min_cycle - watermark_cycles) are safe to flush. During warm-up (min_cycle <= watermark_cycles) cycle-based flushing pauses to preserve the safety gap for out-of-order events.
  2. Secondary (count-based): once the buffer exceeds max_buffer_events, the oldest half is force-flushed regardless of cycle — a safety valve against runaway growth.
  3. Shutdown: flushAll() sorts and returns whatever remains.

Producer hot path is untouched; all complexity lives on the consumer side.

Public Types Documentation

using Config

using chronon::observe::ReorderBuffer::Config = ReorderBufferConfig;

Public Functions Documentation

function updateMinCycle

inline void updateMinCycle(
uint64_t min_cycle
)

Update the minimum observed cycle across producer threads.

Events with cycle < (min_cycle - watermark_cycles) become eligible for flush.

function snapshotArena

ArenaSnapshot snapshotArena(
const std::vector< BufferedRecord > & records
) const

Copies only the contiguous range [min_offset, max_end) referenced by records.

function size

inline size_t size() const

function minCycle

inline uint64_t minCycle() const

function flushReady

void flushReady(
std::vector< BufferedRecord > & out
)

Flush events below the watermark, sorted by cycle.

IMPORTANT: returned records reference arena data; the caller MUST call compactArena() after fully processing them to reclaim arena space.

function flushAll

void flushAll(
std::vector< BufferedRecord > & out
)

Flush every remaining event, sorted by cycle. Use at shutdown.

Clears the internal buffer; arena data remains valid until the next bufferEvent() or compactArena() call.

function empty

inline bool empty() const

function config

inline const Config & config() const

function compactArena

void compactArena()

PRECONDITION: flushed records have been fully consumed.

function bufferEvent

bool bufferEvent(
const ObservationQueue::RecordHeader * header,
const std::byte * data,
size_t data_size
)

Appends record into the arena.

Return: false if cycle extraction failed.

function arenaData

inline const std::byte * arenaData(
uint32_t offset
) const

function ReorderBuffer

inline explicit ReorderBuffer(
const Config & config =Config{}
)

Updated on 2026-05-26 at 05:42:33 +0000