VLink  2.1.0
A high-performance communication middleware
vlink::TriggerRecorder Class Reference

MessageLoop-based rolling in-memory recorder that dumps a pre/post window to a bag on trigger. More...

#include <trigger_recorder.h>

Inheritance diagram for vlink::TriggerRecorder:
Collaboration diagram for vlink::TriggerRecorder:

Classes

struct  Config
 Recorder-wide configuration; passed once to the constructor and read-only afterwards. More...
 
struct  TriggerParams
 Per-trigger parameters; a pure data struct with no RPC or protobuf dependency. More...
 
struct  UrlConfig
 Per-URL overrides; any field left negative falls back to the matching Config default. More...
 

Public Types

enum  OverflowPolicy : uint8_t { kCoverOldest = 0 , kDropNewest = 1 }
 What to do when a byte cap (per-URL max_size or global max_cache_size) would be exceeded. More...
 
enum  FileType : uint8_t { kVdb = 0 , kVcap = 1 }
 On-disk container format for the dumped bag. More...
 
using RawSub = Subscriber< Bytes >
 Raw byte subscriber owned by the recorder for one discovered URL. More...
 
using RawSubFactory = Function< std::shared_ptr< RawSub >(const std::string &url, InitType type)>
 Caller-side constructor for raw subscribers. More...
 
 Internal queue implementation type. More...
 Back-pressure strategy applied when the bounded queue is at capacity. More...
 Built-in priority levels for kPriorityType loops; higher values dispatch first. More...

Public Member Functions

 TriggerRecorder (const Config &config, RawSubFactory &&factory)
 Builds the recorder and acquires every fallible resource; the loop is not running yet. More...
 
 ~TriggerRecorder () override
 Requests quit and joins the recorder loop thread. More...
 
bool dump (const TriggerParams &params={})
 Requests a dump of the pre/post window around the current instant. More...
 
bool dump (const TriggerParams &params, std::string &out_file)
 Requests a dump and returns its selected output path when accepted. More...
 
bool is_dumping () const noexcept
 Reports whether a dump is currently in flight. More...
 
void bind_trigger_interface (const std::shared_ptr< TriggerPluginInterface > &trigger_interface)
 Binds the trigger plugin notified across the recorder's life cycle and dump pipeline. More...
 
void clear_trigger_interface ()
 Detaches the trigger plugin (equivalent to bind_trigger_interface(nullptr)). More...
 
void bind_bag_interface (const std::shared_ptr< BagPluginInterface > &bag_interface)
 Binds the bag reorder plugin applied inside the write path of every dump. More...
 
void clear_bag_interface ()
 Detaches the bag reorder plugin (equivalent to bind_bag_interface(nullptr)). More...
 

Static Public Attributes

static constexpr int64_t kMaxWindowMs = std::numeric_limits<int64_t>::max() / 4000
 Maximum accepted pre / post / retention-guard window length in milliseconds. More...
 

Protected Member Functions

void on_begin () override
 Hook invoked once on the loop thread before the first task runs. More...
 
void on_end () override
 Hook invoked once on the loop thread after the last task runs. More...
 

Detailed Description

MessageLoop-based rolling in-memory recorder that dumps a pre/post window to a bag on trigger.

Construct with a Config and RawSubFactory, call async_run(), then wait for on_begin() to complete (for example with invoke_task([](){}).wait()) before using dump(). Dumps are serialised and execute on the recorder loop. Wait for is_dumping() to become false before shutdown when an accepted dump must be preserved; quit() abandons a dump that is still waiting for its post-trigger window.

Member Typedef Documentation

◆ RawSub

Raw byte subscriber owned by the recorder for one discovered URL.

◆ RawSubFactory

using vlink::TriggerRecorder::RawSubFactory = Function<std::shared_ptr<RawSub>(const std::string& url, InitType type)>

Caller-side constructor for raw subscribers.

The factory must return a fresh subscriber for url using the supplied type. It may apply caller-side transport properties that must precede init(), but must not initialize or start listening; the recorder applies getter semantics, loss tracking, schema metadata and discovery settings before it calls init() and listen(). The callable runs synchronously on the discovery-viewer thread and therefore must be short, non-blocking and must not re-enter this recorder.

Keeping construction in the caller's translation unit is significant: the transport modules linked by the caller propagate their VLINK_SUPPORT_* definitions there, allowing the header-only URL dispatcher to select those linked backends.

Member Enumeration Documentation

◆ FileType

On-disk container format for the dumped bag.

Enumerator
kVdb 

SQLite-backed VDB container (.vdb).

kVcap 

MCAP container (.vcap).

◆ OverflowPolicy

What to do when a byte cap (per-URL max_size or global max_cache_size) would be exceeded.

Eviction is always local to the URL receiving the incoming frame: even when the global cap is the one exceeded, kCoverOldest only reclaims space from that URL's own ring, so pressure from one URL never evicts another URL's buffered history. When the ingesting URL's ring cannot free enough space, the incoming frame is dropped.

Enumerator
kCoverOldest 

Evict the oldest buffered frame(s) to make room for the newest.

kDropNewest 

Discard the incoming frame and keep the existing buffer.

Constructor & Destructor Documentation

◆ TriggerRecorder()

vlink::TriggerRecorder::TriggerRecorder ( const Config config,
RawSubFactory &&  factory 
)

Builds the recorder and acquires every fallible resource; the loop is not running yet.

Validates the configuration and factory, creates Config::dump_dir and constructs the discovery viewer. Buffering begins only after async_run().

Parameters
configRecorder-wide configuration, copied and validated internally.
factoryFactory that constructs a fresh, uninitialized subscriber for each discovered URL.
Exceptions
Exception::RuntimeErrorWhen the configuration or factory is invalid, dump_dir cannot be created, or discovery setup fails.

◆ ~TriggerRecorder()

vlink::TriggerRecorder::~TriggerRecorder ( )
override

Requests quit and joins the recorder loop thread.

Member Function Documentation

◆ bind_bag_interface()

void vlink::TriggerRecorder::bind_bag_interface ( const std::shared_ptr< BagPluginInterface > &  bag_interface)

Binds the bag reorder plugin applied inside the write path of every dump.

This is the data-plane reorder plugin, distinct from the trigger plugin bound by bind_trigger_interface(). The recorder attaches it to the internal BagWriter of each dump via BagWriter::bind_bag_interface(); its on_write() hook parses the true data-plane time out of each payload and re-emits frames reordered by that time before they are persisted. The host owns plugin loading and lifetime, then supplies the resulting interface here. Passing nullptr detaches it, so dumps fall back to capture-time order. Bind before async_run() or after the recorder has stopped.

Parameters
bag_interfaceBag reorder plugin interface instance to bind, or nullptr to detach.

◆ bind_trigger_interface()

void vlink::TriggerRecorder::bind_trigger_interface ( const std::shared_ptr< TriggerPluginInterface > &  trigger_interface)

Binds the trigger plugin notified across the recorder's life cycle and dump pipeline.

This is the post-dump behaviour plugin, distinct from the bag reorder plugin bound by bind_bag_interface(). Its hooks (see TriggerPluginInterface) fire as the recorder starts / stops, on each trigger, and around each dump – most importantly on_dump_finished() once a bag is written, the place to upload or archive it. It never rewrites frames. Passing nullptr detaches the current plugin. Bind before async_run() or after the recorder has stopped; binding while it is running is rejected so one recorder run always has one stable lifecycle observer.

Parameters
trigger_interfaceTrigger plugin interface instance to bind, or nullptr to detach.

◆ clear_bag_interface()

void vlink::TriggerRecorder::clear_bag_interface ( )

Detaches the bag reorder plugin (equivalent to bind_bag_interface(nullptr)).

◆ clear_trigger_interface()

void vlink::TriggerRecorder::clear_trigger_interface ( )

Detaches the trigger plugin (equivalent to bind_trigger_interface(nullptr)).

◆ dump() [1/2]

bool vlink::TriggerRecorder::dump ( const TriggerParams params,
std::string &  out_file 
)

Requests a dump and returns its selected output path when accepted.

Parameters
paramsPer-trigger overrides.
out_fileSelected path on success; cleared when the request is rejected.
Returns
true when the dump was accepted and out_file was set.

◆ dump() [2/2]

bool vlink::TriggerRecorder::dump ( const TriggerParams params = {})

Requests a dump of the pre/post window around the current instant.

Non-blocking: it timestamps the trigger, rejects the call if a dump is already in flight, and enqueues the actual capture / reorder / write onto the recorder loop. When the selected URLs have a positive effective post window, execution is delayed by their largest effective post plus retention_guard_ms; otherwise it is enqueued immediately. The dump completes asynchronously. The set of participating URLs is selected and frozen when the call is accepted: topics discovered afterwards do not contribute to this dump, and a topic going offline (Config::destroy_on_offline) still contributes its already-buffered window. Calling quit() does not drain a dump that is still waiting for its post-trigger window.

Parameters
paramsOptional per-trigger overrides (reason, file name, shrunk windows).
Returns
true when the dump was accepted and enqueued; false for an invalid window, before on_begin() completes, when stopped or already dumping, or when the dump task cannot be enqueued.

◆ is_dumping()

bool vlink::TriggerRecorder::is_dumping ( ) const
noexcept

Reports whether a dump is currently in flight.

Returns
true while a trigger's capture / write is running.

◆ on_begin()

void vlink::TriggerRecorder::on_begin ( )
overrideprotectedvirtual

Hook invoked once on the loop thread before the first task runs.

Subclasses override to perform per-thread initialisation.

Reimplemented from vlink::MessageLoop.

◆ on_end()

void vlink::TriggerRecorder::on_end ( )
overrideprotectedvirtual

Hook invoked once on the loop thread after the last task runs.

Subclasses override to perform per-thread cleanup.

Reimplemented from vlink::MessageLoop.

Member Data Documentation

◆ kMaxWindowMs

constexpr int64_t vlink::TriggerRecorder::kMaxWindowMs = std::numeric_limits<int64_t>::max() / 4000
staticconstexpr

Maximum accepted pre / post / retention-guard window length in milliseconds.

Chosen so that the largest retention sum, pre + max_post_all + 2*retention_guard (four terms, each at most this bound), still converts to microseconds without overflowing int64_t. Config values and per-trigger TriggerParams windows beyond this bound are rejected; control-plane frontends (e.g. vlink-trigger) validate user input against the same constant.


The documentation for this class was generated from the following file: