120 #include <string_view>
121 #include <unordered_map>
122 #include <unordered_set>
125 #include "../base/functional.h"
126 #include "../base/macros.h"
127 #include "../base/message_loop.h"
128 #include "../impl/types.h"
132 class BagPluginInterface;
133 class SchemaPluginInterface;
175 bool wal_mode{
false};
176 bool enable_limit{
false};
177 bool split_name_by_time{
false};
178 bool sync_mode{
false};
179 bool optimize_on_exit{
false};
180 int64_t max_row_count{5'000'000'000LL};
181 int64_t max_bytes_size{1024LL * 1024LL * 1024LL * 512LL};
182 int64_t split_by_size{1024LL * 1024LL * 1024LL * 1LL};
183 int64_t split_by_time{0};
184 int64_t begin_time{0};
185 int64_t cache_size{1024LL * 1024LL * 4};
186 int64_t compress_start_size{128};
187 int64_t compress_level{3};
188 int64_t max_task_depth{20000};
189 int64_t max_memory_size{1024LL * 1024LL * 1024LL * 2LL};
190 int64_t start_timestamp{0};
219 using SystemClock = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>;
233 [[nodiscard]]
static std::shared_ptr<BagWriter>
create(
const std::string& path,
const Config& config = {});
247 [[nodiscard]]
static std::shared_ptr<BagWriter>
filter_get(
const std::string& path);
392 [[nodiscard]]
bool fail() const noexcept;
401 explicit operator
bool() const noexcept;
406 void clear() noexcept;
411 [[nodiscard]] virtual
bool is_dumping() const = 0;
421 [[nodiscard]] virtual
bool is_split_mode() const = 0;
428 [[nodiscard]] virtual
int get_split_index() const = 0;
440 virtual
void set_url_loss(const std::
string& url,
double loss);
443 virtual int64_t record(const
Frame& frame, int64_t timestamp) = 0;
445 virtual int64_t get_record_timestamp() const = 0;
460 virtual
void close();
470 static std::
string get_format_date(
SystemClock* current =
nullptr,
bool file_format = false);
473 std::
string convert_recorded_url(const std::
string& url) const;
475 std::vector<std::
string> recorded_urls_for_origin(const std::
string& url) const;
477 std::
string recover_recorded_url(const std::
string& url) const;
479 void get_url_meta(const std::
string& url, const std::
string& ser,
int& url_index,
int& ser_index) const;
481 void get_url_meta(
int url_index,
int ser_index, std::
string& url, std::
string& ser) const;
483 std::mutex& sample_mutex();
485 std::unordered_map<std::
string,
double>& url_loss_map_ref();
487 std::unordered_map<std::
string,
double>& total_url_loss_map_ref();
489 static const std::
string& get_default_tag_name();
491 static const std::
string& get_default_app_name();
495 static int32_t get_default_timezone_diff();
501 void detach_plugin();
508 void set_fail() noexcept;
511 void learn_recorded_url(const std::
string& origin_url, const std::
string& recorded_url);
514 std::unique_ptr<Impl> impl_;
Asynchronous VLink message recorder built on top of MessageLoop.
Definition: bag_writer.h:144
virtual void bind_bag_interface(const std::shared_ptr< BagPluginInterface > &bag_interface)
Attaches a custom frame-forwarding plugin to this writer.
BagWriter(const std::string &path, const Config &config={})
Constructs the base writer and opens the output file.
static std::shared_ptr< BagWriter > filter_get(const std::string &path)
Returns the cached writer for path, lazily creating and starting one.
virtual void clear_bag_interface()
Detaches the currently bound plugin, if any.
bool fail() const noexcept
Returns whether a stream operation, deferred backend write or finalisation has failed.
BagWriter & operator<<(const SchemaData &schema_data)
Streaming shorthand for push_schema(schema_data).
virtual ~BagWriter()
Halts the loop, flushes pending writes and closes the file.
BagWriter & operator<<(const Frame &frame)
Streaming shorthand for push(frame).
CompressType
Compression codec selector understood by the writer backends.
Definition: bag_writer.h:157
static std::shared_ptr< BagWriter > create(const std::string &path, const Config &config={})
Builds the concrete writer matching the extension of path.
static BagWriter * global_get()
Returns the singleton writer driven by the VLINK_BAG_PATH environment variable.
int64_t push(const Frame &frame)
Records a single frame to the bag.
virtual bool push_schema(const SchemaData &schema_data)=0
Embeds a schema descriptor into the bag for downstream introspection.
virtual void register_schema_callback(SchemaCallback &&callback)=0
Installs the resolver invoked when an unseen serialisation type is recorded.
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > SystemClock
System clock alias used when formatting timestamps into split file names.
Definition: bag_writer.h:219
virtual void register_split_callback(SplitCallback &&callback, bool before)=0
Installs a hook fired around split rotation.
Serial task dispatcher with selectable queue backend and bounded timer registry.
Definition: message_loop.h:126
Move-only type-erased callable analogue of std::move_only_function with pool spill.
Definition: functional.h:135
Polymorphic contract for runtime schema lookup and dynamic message construction.
Definition: schema_plugin_interface.h:78
#define VLINK_EXPORT
Definition: macros.h:81
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
Definition: macros.h:174
SchemaType
Coarse runtime schema family used by discovery, bag metadata and proxy routing.
Definition: types.h:203
ActionType
Labels for messages captured by the recording infrastructure.
Definition: types.h:181
Recording behaviour, split policy and resource budgets.
Definition: bag_writer.h:172
Config()
Definition: bag_writer.h:193
std::unordered_set< std::string > ignore_compress_urls
URLs whose payloads must never be compressed.
Definition: bag_writer.h:191
std::string tag_name
Optional tag stored in the bag header.
Definition: bag_writer.h:173
One recorded or replayed message as it flows through the bag pipeline.
Definition: types.h:226
Wire-format-neutral wrapper around one serialised schema blob.
Definition: types.h:297