VLink  2.1.0
A high-performance communication middleware
vlink::TriggerRecorder类 参考

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

#include <trigger_recorder.h>

类 vlink::TriggerRecorder 继承关系图:
vlink::TriggerRecorder 的协作图:

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

Public 类型

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. 更多...
 
enum  FileType : uint8_t { kVdb = 0 , kVcap = 1 }
 On-disk container format for the dumped bag. 更多...
 
using RawSub = Subscriber< Bytes >
 Raw byte subscriber owned by the recorder for one discovered URL. 更多...
 
using RawSubFactory = Function< std::shared_ptr< RawSub >(const std::string &url, InitType type)>
 Caller-side constructor for raw subscribers. 更多...
 
 Internal queue implementation type. 更多...
 Back-pressure strategy applied when the bounded queue is at capacity. 更多...
 Built-in priority levels for kPriorityType loops; higher values dispatch first. 更多...

Public 成员函数

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

静态 Public 属性

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

Protected 成员函数

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

详细描述

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.

成员类型定义说明

◆ 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.

成员枚举类型说明

◆ FileType

On-disk container format for the dumped bag.

枚举值
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.

枚举值
kCoverOldest 

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

kDropNewest 

Discard the incoming frame and keep the existing buffer.

构造及析构函数说明

◆ 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().

参数
configRecorder-wide configuration, copied and validated internally.
factoryFactory that constructs a fresh, uninitialized subscriber for each discovered URL.
异常
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.

成员函数说明

◆ 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.

参数
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.

参数
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.

参数
paramsPer-trigger overrides.
out_fileSelected path on success; cleared when the request is rejected.
返回
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.

参数
paramsOptional per-trigger overrides (reason, file name, shrunk windows).
返回
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.

返回
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.

重载 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.

重载 vlink::MessageLoop .

类成员变量说明

◆ 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.


该类的文档由以下文件生成: