A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
chunk_store_reader.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
24#ifndef A11_STORES_CHUNK_STORE_READER_H_
25#define A11_STORES_CHUNK_STORE_READER_H_
26
27#include <cstddef>
28#include <cstdint>
29#include <memory>
30#include <optional>
31
32#include <absl/status/status.h>
33#include <absl/status/statusor.h>
34#include <absl/time/time.h>
35
37#include "a11/data/types.h"
39
40namespace a11::stores {
41
53 bool ordered = true;
55 bool pop_chunks = false;
57 std::uint64_t num_chunks_to_buffer = 32;
59 std::uint32_t offset = 0;
61 std::optional<std::uint64_t> max_chunks_to_read = {};
63 bool sticky_mimetype = false;
64
71 absl::Status Validate() const;
72};
73
85 public:
98 static absl::StatusOr<std::shared_ptr<ChunkStoreReader>> Create(
99 std::shared_ptr<ChunkStore> store, ChunkStoreReaderOptions options = {});
100
101 ~ChunkStoreReader() = default;
102
109 void EnsureStarted();
110
117 void Cancel();
118
126 absl::Status GetStatus() const;
127
135 [[nodiscard]] a11::Task Done() const;
136
147 absl::Duration timeout = absl::InfiniteDuration());
148
173 size_t limit, absl::Duration timeout = absl::InfiniteDuration());
174
176 [[nodiscard]] std::shared_ptr<ChunkStore> store() const;
178 [[nodiscard]] ChunkStoreReaderOptions options() const;
180 [[nodiscard]] size_t buffer_size() const;
181
182 private:
183 struct State;
184
185 explicit ChunkStoreReader(std::shared_ptr<State> state)
186 : state_(std::move(state)) {}
187
188 std::shared_ptr<State> state_;
189};
190
191} // namespace a11::stores
192
193#endif // A11_STORES_CHUNK_STORE_READER_H_
A11's pluggable storage interface for streamed node data: an ordered, appendable log of fragments key...
An ordered, buffered read cursor over a ChunkStore.
Definition chunk_store_reader.h:84
ChunkStoreReaderOptions options() const
Definition chunk_store_reader.cc:806
size_t buffer_size() const
Definition chunk_store_reader.cc:810
void EnsureStarted()
Start the background read pump if it is not already running.
Definition chunk_store_reader.cc:732
a11::Future< std::vector< std::optional< data::NodeFragment > > > NextMany(size_t limit, absl::Duration timeout=absl::InfiniteDuration())
Get up to limit fragments in one await.
Definition chunk_store_reader.cc:759
a11::Task Done() const
Await completion of the background read pump.
Definition chunk_store_reader.cc:745
a11::Future< std::optional< data::NodeFragment > > Next(absl::Duration timeout=absl::InfiniteDuration())
Get the next fragment from the store.
Definition chunk_store_reader.cc:749
std::shared_ptr< ChunkStore > store() const
Definition chunk_store_reader.cc:802
static absl::StatusOr< std::shared_ptr< ChunkStoreReader > > Create(std::shared_ptr< ChunkStore > store, ChunkStoreReaderOptions options={})
Create a reader over store.
Definition chunk_store_reader.cc:710
absl::Status GetStatus() const
Get the reader's current status.
Definition chunk_store_reader.cc:740
void Cancel()
Stop the background read pump.
Definition chunk_store_reader.cc:736
Completion values used by every asynchronous A11 operation.
std::optional< absl::Duration > timeout
Definition main.cc:144
Definition node_map.h:45
Tunables controlling how a ChunkStoreReader delivers and buffers fragments.
Definition chunk_store_reader.h:51
bool ordered
Whether fragments are delivered strictly in sequence order.
Definition chunk_store_reader.h:53
std::uint32_t offset
Sequence number at which reading begins.
Definition chunk_store_reader.h:59
bool pop_chunks
Whether fragments are removed from the store as they are read.
Definition chunk_store_reader.h:55
std::optional< std::uint64_t > max_chunks_to_read
Optional cap on the total number of fragments to read.
Definition chunk_store_reader.h:61
absl::Status Validate() const
Validate that the options are internally consistent.
Definition chunk_store_reader.cc:47
std::uint64_t num_chunks_to_buffer
Maximum number of fragments to prefetch into the buffer.
Definition chunk_store_reader.h:57
bool sticky_mimetype
Whether ordered reads inherit the last explicitly set chunk mimetype.
Definition chunk_store_reader.h:63
Definition chunk_store_reader.cc:59
A11's core wire value types: chunks, node fragments and messages.