Coordinated binary write sink with optional chunked write-behind and a delayed-seek page map. More...
#include <StormByte/buffer/io/buffered_writer.hxx>

Classes | |
| class | Parameters |
| Writer knobs. More... | |
Public Member Functions | |
| const StormByte::String::String & | Path () const noexcept |
| Locator stored at construction. | |
| enum Location | Location () const noexcept |
| Where Path points. | |
| virtual | operator bool () const noexcept final |
| Whether the sink is prepared to write. | |
| virtual enum State | State () const noexcept final |
| Session state. | |
Lifecycle | |
| BufferedWriter (const BufferedWriter &)=delete | |
| Copy constructor is deleted. | |
| BufferedWriter (BufferedWriter &&other) noexcept | |
| Move constructor. | |
| virtual | ~BufferedWriter () noexcept |
| Virtual destructor. | |
| BufferedWriter & | operator= (const BufferedWriter &)=delete |
| Copy assignment is deleted. | |
| BufferedWriter & | operator= (BufferedWriter &&other) noexcept |
| Move assignment. | |
Session | |
| virtual bool | Open () final |
| Arm the origin. | |
| virtual bool | Close () final |
| Flush then close the origin. | |
| virtual bool | Rewind () final |
| Re-arm: Close then Open when currently armed. | |
| virtual bool | IsOpen () const noexcept final |
| Whether Open succeeded and Close has not. | |
| virtual Result | Flush () final |
| Materialise every dirty page, drain the ring and OriginFlush. | |
| virtual Result | Truncate () final |
| Drop dirty pages and the ring, then truncate the origin. | |
Write | |
| virtual Result | Write (const FIFO &src) final |
Write every unread byte of src. | |
| virtual Result | Write (FIFO &src) final |
Write every unread byte of src. | |
| virtual Result | Write (std::span< const std::byte > src) final |
| Write the whole span. | |
Position | |
| virtual StormByte::ByteSize | Tell () const noexcept |
| Logical write offset. | |
| virtual StormByte::ByteSize | Dirty () const noexcept |
| Bytes not yet on the origin. | |
| virtual StormByte::ByteSize | Size () const noexcept |
| Logical sink length in bytes. | |
| virtual Result | Seek (std::ptrdiff_t offset, Position mode) |
| Move the write cursor. | |
Telemetry | |
| const StormByte::Shared< StormByte::Buffer::WriteTelemetry > | Telemetry () const noexcept |
| Shared write counters. | |
Policy | |
| virtual StormByte::ByteSize | WriteChunk () const noexcept |
| Configured origin push unit. | |
| virtual void | WriteChunk (StormByte::ByteSize bytes) |
| Set origin push unit. | |
| virtual std::size_t | BackPressure () const noexcept |
| Configured dirty cap in WriteChunk units. | |
| virtual void | BackPressure (std::size_t chunks) |
| Set dirty cap in WriteChunk units. | |
| virtual StormByte::ByteSize | MaxMemory () const noexcept |
| Byte budget for dirty pages that are not yet on the origin. | |
| virtual void | MaxMemory (StormByte::ByteSize bytes) |
| Set the dirty-page budget. | |
| virtual std::chrono::milliseconds | MaxWait () const noexcept |
| Wait cap for OriginPush. | |
| virtual void | MaxWait (std::chrono::milliseconds wait) |
| Set wait cap for OriginPush. | |
Protected Member Functions | |
| STORMBYTE_FORCE_INLINE | BufferedWriter (StormByte::String::String path, enum Location location, Parameters parameters={}) |
| Construct an unopened coordinator (State::Unavailable). | |
| BufferedWriter (StormByte::String::String path, enum Location location, StormByte::ByteSize write_chunk, std::size_t back_pressure, std::chrono::milliseconds max_wait, StormByte::ByteSize max_memory) | |
| Construct an unopened coordinator (State::Unavailable). | |
| void | SetState (enum State state) noexcept |
| Publish session state from a leaf hook. | |
| void | SetTell (StormByte::ByteSize offset) noexcept |
| Publish the logical write offset from a leaf Seek. | |
| virtual void | Setup () |
| Leaf policy hook. | |
| virtual StormByte::Shared< StormByte::Buffer::WriteTelemetry > | CreateTelemetry () const |
| Allocate the telemetry object this instance will keep. | |
| virtual bool | WillWrite (StormByte::ByteSize n) const |
Whether n more bytes can be accepted now. | |
Origin hooks | |
| virtual Result | OriginOpen ()=0 |
| Arm the device and SetState. | |
| virtual Result | OriginClose ()=0 |
| Release the device and SetState Unavailable. | |
| virtual Result | OriginPush (std::span< const std::byte > data)=0 |
Write data to the device. | |
| virtual Result | OriginFlush ()=0 |
| Make accepted bytes visible on the device. | |
| virtual Result | OriginTruncate ()=0 |
| Discard origin contents. | |
| virtual Result | OriginSeek (StormByte::ByteSize absolute) |
Seek the origin to absolute. | |
Friends | |
| class | StormByte::Buffer::Backend::IO::BufferedWriter |
| class | StormByte::Buffer::Backend::Bridge |
Coordinated binary write sink with optional chunked write-behind and a delayed-seek page map.
Public base for byte destinations. Leaves implement the Origin* hooks and may override Setup, Seek, Size, WillWrite and CreateTelemetry. They do not override Write, Flush, Open, Close, Rewind or Truncate.
Close then Open is a valid round-trip. Destructor of a leaf must call Close while the leaf vtable is live.operator bool is true when State is Idle.
Write consumes the whole visible source or nothing (atomic). FIFO is read from the current read position (FIFO::Read is const; the cursor is mutable). The FIFO / span is left untouched on Status::TryAgain, Status::Failed and Status::Error.Write is lazy until MaxMemory. The origin is touched only when dirty pages exceed MaxMemory (GC), or on Flush / Close. MaxMemory == 0 stores no pages: each Write goes to the origin (and to the ring when both ring knobs are on).This is not magic RAM. Local seeks and seeks into a still-dirty past stay in the map. Distant random writes need a larger MaxMemory or the farthest-past island is evicted to the origin (that eviction is real I/O and may block). A jump far ahead is supported only while it fits; it is not the typical case. The typical case is a correction near the write high-water and a seek back to that front.
GC evicts the farthest past first, in a contiguous run, so one OriginSeek covers a cheap sequential push. Future islands are evicted only when no evictable past remains.
A durable-progress ratio is Materialized / HighWater when HighWater > 0. HighWater is the maximum logical cursor this session. Tell is the cursor and may sit behind HighWater. Materialized is what the origin already holds. Do not use Accepted or Tell as the denominator. After a sequential session Close, Materialized equals HighWater.
0 disables the drain pipe. Both > 0 enable an internal SPSC ring used only to push a GC / Flush / Close run. Capacity is BackPressure * WriteChunk bytes. A Write that would exceed that cap returns Status::TryAgain. The worker does not empty the page map just because the origin cursor is aligned.Setters take effect immediately. Turning the ring off or lowering the cap below Dirty flushes dirty bytes first and may block. Setting MaxMemory does not Flush and does not resize the ring.
Public Flush and the Flush inside Close count toward MeanRate. Internal worker / GC drains do not. A cache Write can look like GiB/s; that is the caller rate. The explicit Flush is what reflects the origin.
Typical correction inside resident dirty pages is O(1) with respect to the device. A Write / Seek that trips GC may block on origin I/O on purpose: random access on a slow device is more expensive than that wait.
Default Size is Tell (includes dirty pages). A file leaf returns max(filesystem size, Tell).
Write or worker). 0ms waits without limit. The ring itself is not timed. Setting MaxWait does not abort an in-flight push.StormByte::Buffer::Backend::Bridge. Default asks the ring cap. Leaves may tighten it (disk space, socket). The answer is indicative: another process, quotas or a network filesystem can still make the later Write fail.StormByte::Shared of StormByte::Buffer::WriteTelemetry. The user cannot reseat the handle. The office updates the same object. Default dynamic type is IO::WriteTelemetry. Accumulators start at construction and do not reset on Close. Materialized and HighWater are levels, not accumulators. MeanRate is the caller rate, not disk throughput.m_io. The worker is not stopped. Moved-from is Unavailable.
|
delete |
Copy constructor is deleted.
|
noexcept |
Move constructor.
| other | Instance to take from. Left Unavailable. |
|
virtualnoexcept |
Virtual destructor.
Stops the worker. Does not call Origin*.
Leaves must call Close in their destructor.
|
inlineprotected |
Construct an unopened coordinator (State::Unavailable).
| path | Locator. Stored once. |
| location | Location::Local or Location::Remote. Stored once. |
| parameters | Omitted knobs are 0 / 0 ms. Resolved in the caller. |
|
protected |
Construct an unopened coordinator (State::Unavailable).
| path | Locator. Stored once. |
| location | Location::Local or Location::Remote. Stored once. |
| write_chunk | Initial WriteChunk in bytes. |
| back_pressure | Initial BackPressure in chunk units. |
| max_wait | Initial MaxWait. |
| max_memory | Initial MaxMemory in bytes. |
DLL boundary. Children that already resolved knobs call this.
|
virtualnoexcept |
Configured dirty cap in WriteChunk units.
|
virtual |
Set dirty cap in WriteChunk units.
Takes effect immediately.
| chunks | 0 disables the ring. Otherwise cap is chunks * WriteChunk. |
May block. Zero, or a cap below Dirty, flushes dirty bytes before the setter returns. Not deferred to the next Write.
|
finalvirtual |
Flush then close the origin.
true if State is Unavailable afterwards.Idempotent on an already closed instance. Blocking. Flush failure leaves State::Fault and returns false. The Flush counts toward MeanRate.
|
protectedvirtual |
Allocate the telemetry object this instance will keep.
Called once, after the most-derived constructor, the first time telemetry is needed. Must not return empty.
|
virtualnoexcept |
Bytes not yet on the origin.
|
finalvirtual |
Materialise every dirty page, drain the ring and OriginFlush.
Blocking. Tell is unchanged. Counts toward MeanRate. Internal worker drains do not.
|
finalvirtualnoexcept |
|
noexcept |
Where Path points.
Does not change.
|
virtualnoexcept |
Byte budget for dirty pages that are not yet on the origin.
Independent of WriteChunk / BackPressure.
|
virtual |
Set the dirty-page budget.
Takes effect immediately.
| bytes | 0 disables the page map. |
Does not Flush. Does not resize the ring. A value below current dirty pages trips GC and may block.
|
virtualnoexcept |
Wait cap for OriginPush.
0ms waits without limit.
|
virtual |
Set wait cap for OriginPush.
Takes effect on the next push.
| wait | 0ms = unlimited. |
Does not cancel an in-flight OriginPush. Does not Flush.
|
finalvirtual |
|
explicitfinalvirtualnoexcept |
Whether the sink is prepared to write.
true if State is State::Idle.
|
noexcept |
Move assignment.
| other | Instance to take from. Left Unavailable. |
|
delete |
Copy assignment is deleted.
|
protectedpure virtual |
Release the device and SetState Unavailable.
Implemented in StormByte::Buffer::IO::BufferedFileWriter.
|
protectedpure virtual |
Make accepted bytes visible on the device.
The base calls this after a completed direct Write and after Flush has drained the ring. Do not buffer here.
Implemented in StormByte::Buffer::IO::BufferedFileWriter.
|
protectedpure virtual |
Arm the device and SetState.
Implemented in StormByte::Buffer::IO::BufferedFileWriter.
|
protectedpure virtual |
Write data to the device.
Do not buffer in the hook.
| data | Contiguous octets. May be a full WriteChunk or a tail. |
Implemented in StormByte::Buffer::IO::BufferedFileWriter.
|
protectedvirtual |
Seek the origin to absolute.
| absolute | Byte offset from the start. |
Default fails. File and remote leaves override this. Public Seek does not call this; GC / Flush / Close do.
Reimplemented in StormByte::Buffer::IO::BufferedFileWriter, and StormByte::Buffer::IO::BufferedLocationWriter.
|
protectedpure virtual |
Discard origin contents.
Network may no-op Ok.
Implemented in StormByte::Buffer::IO::BufferedFileWriter.
|
noexcept |
Locator stored at construction.
Does not change.
A file path, socket://… or http://… . A file leaf's path is always a local filesystem path.
|
finalvirtual |
|
virtual |
Move the write cursor.
| offset | Byte offset. |
| mode | Position::Absolute or Position::Relative. |
Updates Tell only. Does not Flush. Does not call OriginSeek. Fails when the leaf OriginSeek cannot move the device (default hook). O(1) for a typical in-cache correction; may block later when a Write trips GC.
|
protectednoexcept |
Publish session state from a leaf hook.
| state | New State. |
|
protectednoexcept |
|
protectedvirtual |
Leaf policy hook.
Called from Open before the origin.
Default does nothing. File uses it for the path-only ctor. The most-derived vtable is live.
Reimplemented in StormByte::Buffer::IO::BufferedLocationWriter.
|
virtualnoexcept |
Logical sink length in bytes.
Not optional. A file leaf returns max(filesystem size, Tell). A remote leaf overrides this.
Reimplemented in StormByte::Buffer::IO::BufferedLocationWriter.
|
finalvirtualnoexcept |
Session state.
|
noexcept |
Shared write counters.
Same instance for the life of this writer.
The user cannot reseat the handle. The office updates the same object. Survivors keep the last values.
|
virtualnoexcept |
Logical write offset.
|
finalvirtual |
Drop dirty pages and the ring, then truncate the origin.
|
protectedvirtual |
Whether n more bytes can be accepted now.
| n | Byte count to probe. |
true if the ring (or direct mode) can take n.Indicative. Another writer, quotas or the filesystem can still reject the later Write. Override to tighten (disk space, socket window). Used by StormByte::Buffer::Backend::Bridge.
Reimplemented in StormByte::Buffer::IO::BufferedFileWriter.
Write every unread byte of src.
| src | Source FIFO. Read from the current position. |
Write every unread byte of src.
| src | Source FIFO. Read from the current position. |
|
finalvirtual |
Write the whole span.
| src | Octets to copy. |
|
virtualnoexcept |
Configured origin push unit.
|
virtual |
|
friend |
|
friend |