116 #include <string_view>
117 #include <unordered_map>
118 #include <unordered_set>
121 #include "../base/functional.h"
122 #include "../base/macros.h"
123 #include "../base/message_loop.h"
124 #include "../impl/types.h"
129 class SchemaPluginInterface;
171 bool wal_mode{
false};
172 bool enable_limit{
false};
173 bool split_name_by_time{
false};
174 bool sync_mode{
false};
175 bool optimize_on_exit{
false};
176 int64_t max_row_count{5'000'000'000LL};
177 int64_t max_bytes_size{1024LL * 1024LL * 1024LL * 512LL};
178 int64_t split_by_size{1024LL * 1024LL * 1024LL * 1LL};
179 int64_t split_by_time{0};
180 int64_t begin_time{0};
181 int64_t cache_size{1024LL * 1024LL * 4};
182 int64_t compress_start_size{128};
183 int64_t compress_level{3};
184 int64_t max_task_depth{20000};
185 int64_t max_memory_size{1024LL * 1024LL * 1024LL * 2LL};
186 int64_t start_timestamp{0};
215 using SystemClock = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>;
229 [[nodiscard]]
static std::shared_ptr<BagWriter>
create(
const std::string& path,
const Config& config = {});
243 [[nodiscard]]
static std::shared_ptr<BagWriter>
filter_get(
const std::string& path);
343 int64_t
push(
const Frame& frame,
bool immediate =
false);
384 [[nodiscard]]
bool fail() const noexcept;
393 explicit operator
bool() const noexcept;
398 void clear() noexcept;
403 [[nodiscard]] virtual
bool is_dumping() const = 0;
413 [[nodiscard]] virtual
bool is_split_mode() const = 0;
420 [[nodiscard]] virtual
int get_split_index() const = 0;
432 virtual
void set_url_loss(const std::
string& url,
double loss);
435 virtual int64_t record(const
Frame& frame,
bool immediate) = 0;
437 virtual int64_t get_record_timestamp() const = 0;
439 std::
string convert_recorded_url(const std::
string& url) const;
441 std::vector<std::
string> recorded_urls_for_origin(const std::
string& url) const;
443 std::
string recover_recorded_url(const std::
string& url) const;
445 void get_url_meta(const std::
string& url, const std::
string& ser,
int& url_index,
int& ser_index) const;
447 void get_url_meta(
int url_index,
int ser_index, std::
string& url, std::
string& ser) const;
449 std::mutex& sample_mutex();
451 std::unordered_map<std::
string,
double>& url_loss_map_ref();
453 std::unordered_map<std::
string,
double>& total_url_loss_map_ref();
455 static const std::
string& get_default_tag_name();
457 static const std::
string& get_default_app_name();
461 static int32_t get_default_timezone_diff();
465 static std::
string get_format_date(
SystemClock* current =
nullptr,
bool file_format = false);
469 void detach_plugin();
472 void learn_recorded_url(const std::
string& origin_url, const std::
string& recorded_url);
475 std::unique_ptr<Impl> impl_;
Unified plugin contract for rewriting bag traffic on both playback (read) and recording (write).
Asynchronous VLink message recorder built on top of MessageLoop.
Definition: bag_writer.h:140
virtual void clear_plugin_interface()
Detaches the currently bound plugin, if any.
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 bind_plugin_interface(const std::shared_ptr< BagPluginInterface > &plugin_interface)
Attaches a custom frame-forwarding plugin to this writer.
bool fail() const noexcept
Returns whether a previous operator<< observed a write failure.
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:153
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.
virtual void register_schema_callback(SchemaCallback &&callback)=0
Installs the resolver invoked when an unseen serialisation type is recorded.
virtual bool push_schema(const SchemaData &schema_data, bool immediate=false)=0
Embeds a schema descriptor into the bag for downstream introspection.
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:215
virtual void register_split_callback(SplitCallback &&callback, bool before)=0
Installs a hook fired around split rotation.
int64_t push(const Frame &frame, bool immediate=false)
Records a single frame to the bag.
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:134
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:207
ActionType
Labels for messages captured by the recording infrastructure.
Definition: types.h:185
Recording behaviour, split policy and resource budgets.
Definition: bag_writer.h:168
Config()
Definition: bag_writer.h:189
std::unordered_set< std::string > ignore_compress_urls
URLs whose payloads must never be compressed.
Definition: bag_writer.h:187
std::string tag_name
Optional tag stored in the bag header.
Definition: bag_writer.h:169
One recorded or replayed message as it flows through the bag pipeline.
Definition: types.h:230
Wire-format-neutral wrapper around one serialised schema blob.
Definition: types.h:301