A buffered, backpressured write cursor over a ChunkStore.
More...
#include <cpp/a11/stores/chunk_store_writer.h>
A buffered, backpressured write cursor over a ChunkStore.
A writer admits data::Chunk values into a store in sequence, pacing the producer through a bounded buffer sized by its ChunkStoreWriterOptions. A background flush loop drains the queue into the store; persisted fragments can additionally be mirrored to attached wire streams. It is usable directly though most code reaches one through a node. State is reference-counted and held via shared_ptr.
◆ ~ChunkStoreWriter()
| a11::stores::ChunkStoreWriter::~ChunkStoreWriter |
( |
| ) |
|
|
default |
◆ AbortWithStatus()
| a11::Task a11::stores::ChunkStoreWriter::AbortWithStatus |
( |
absl::Status |
status | ) |
|
Abort the writer with an error status.
Propagates a failure downstream so readers observe the error instead of a clean end-of-stream.
- Parameters
-
| status | The error status to record. |
- Returns
- An awaitable that resolves once teardown completes.
◆ AttachStream()
| absl::Status a11::stores::ChunkStoreWriter::AttachStream |
( |
std::shared_ptr< net::WireStream > |
stream | ) |
|
Mirror persisted fragments to an additional wire stream.
After the store accepts a batch, the writer calls WireStream::Send() on each attached stream. A successful send means local transport admission, not remote delivery. A transport failure stops subsequent writes but cannot revoke store confirmations returned for the current batch. The writer keeps the stream alive while attached.
- Parameters
-
| stream | The wire stream to fan output out to. |
- Returns
- OK if the stream was attached, otherwise an error status.
◆ Cancel()
| a11::Task a11::stores::ChunkStoreWriter::Cancel |
( |
| ) |
|
Stop the writer immediately, discarding any queued chunks.
- Returns
- An awaitable that resolves once teardown completes.
◆ Create()
Create a writer over store.
- Parameters
-
| store | The store to persist chunks to. |
| options | Tuning for offset, sticky-mimetype compression, and how much is buffered/flushed at once. |
- Returns
- A shared, ready-to-use writer, or an error status if the options are invalid.
◆ DetachStream()
| absl::Status a11::stores::ChunkStoreWriter::DetachStream |
( |
const std::shared_ptr< net::WireStream > & |
stream | ) |
|
Stop mirroring fragments to a previously attached wire stream.
- Parameters
-
| stream | The stream to detach. |
- Returns
- OK if the stream was detached, or an error if it was not attached.
◆ DrainAndClose()
| a11::Task a11::stores::ChunkStoreWriter::DrainAndClose |
( |
| ) |
|
Flush every queued chunk, then close the writer.
This closes the backing store to further writes, but it does not append a final fragment. The producer must mark its last chunk final=true (or write a null final chunk through AsyncNode) before draining when readers need a final sequence number to identify the logical end of the stream.
- Returns
- An awaitable that resolves once the flush and storage close complete.
◆ EnqueueChunk()
Enqueue a chunk, exposing backpressure and confirmation separately.
Unlike PutChunk(), this returns both awaitables: admitted resolves once the chunk is accepted into the bounded queue and confirmation resolves with the sequence assigned by the backing store. Await admission to pace production and confirmation to know the store accepted the write.
- Parameters
-
| chunk | The chunk to enqueue. |
| seq | Optional explicit sequence number; assigned automatically if unset. |
| final | Whether this chunk establishes the logical final sequence. This does not close the writer or backing store. |
| ensure_started | Whether to start the flush loop as part of enqueuing. |
- Returns
- A ChunkStoreWrite holding the admission and confirmation awaitables.
◆ EnsureStarted()
| void a11::stores::ChunkStoreWriter::EnsureStarted |
( |
| ) |
|
Start the background flush loop if it is not already running.
Writing normally starts the loop lazily; call this to begin flushing before the first chunk is enqueued.
◆ GetAbortStatus()
| std::optional< absl::Status > a11::stores::ChunkStoreWriter::GetAbortStatus |
( |
| ) |
const |
- Returns
- The status the writer was aborted with, or empty if not aborted.
◆ GetStatus()
| std::optional< absl::Status > a11::stores::ChunkStoreWriter::GetStatus |
( |
| ) |
const |
- Returns
- The writer's terminal status, or empty while still open.
◆ IsWritable()
| bool a11::stores::ChunkStoreWriter::IsWritable |
( |
| ) |
const |
- Returns
- Whether the writer still accepts chunks (false once drained, closed, or aborted).
◆ options()
- Returns
- The options this writer was created with.
◆ PutChunk()
| a11::Future< std::uint32_t > a11::stores::ChunkStoreWriter::PutChunk |
( |
data::Chunk |
chunk, |
|
|
std::optional< std::uint32_t > |
seq = std::nullopt, |
|
|
bool |
final = false |
|
) |
| |
Write a chunk and await backing-store confirmation.
Convenience path for callers that only need confirmation, without observing queue admission separately.
- Parameters
-
| chunk | The chunk to write. |
| seq | Optional explicit sequence number; assigned automatically if unset. |
| final | Whether this chunk establishes the logical final sequence. This does not close the writer or backing store. |
- Returns
- An awaitable that resolves with the stored sequence number.
◆ queue_size()
| size_t a11::stores::ChunkStoreWriter::queue_size |
( |
| ) |
const |
- Returns
- The number of chunks currently waiting in the flush queue.
◆ store()
| std::shared_ptr< ChunkStore > a11::stores::ChunkStoreWriter::store |
( |
| ) |
const |
- Returns
- The store this writer persists chunks to.
◆ WaitForBufferToDrain()
| a11::Task a11::stores::ChunkStoreWriter::WaitForBufferToDrain |
( |
| ) |
|
Wait until the in-flight write buffer empties.
A backpressure checkpoint before enqueuing more chunks.
- Returns
- An awaitable that resolves once the buffer has drained.
The documentation for this class was generated from the following files: