22#ifndef A11_STORES_SQLITE_CHUNK_STORE_H_
23#define A11_STORES_SQLITE_CHUNK_STORE_H_
32#include <absl/status/status.h>
33#include <absl/status/statusor.h>
34#include <absl/time/time.h>
39#include "a11/stores/internal/sqlite_database.h"
53 internal::SqliteSynchronous::kNormal;
100 struct ConstructorToken {};
111 static absl::StatusOr<std::shared_ptr<SQLiteChunkStore>>
Create(
112 std::string node_id);
124 static absl::StatusOr<std::shared_ptr<SQLiteChunkStore>>
Create(
125 std::string node_id, std::string
root);
139 static absl::StatusOr<std::shared_ptr<SQLiteChunkStore>>
Create(
140 std::string node_id,
const std::string&
root,
151 absl::Time deadline)
override;
155 absl::Time deadline,
size_t limit)
override;
158 std::vector<data::NodeFragment>
fragments)
override;
165 absl::Status status,
bool return_status_if_already_closed)
override;
167 absl::StatusOr<std::string>
GetId()
const override;
195 [[nodiscard]] std::string
root()
const;
198 std::shared_ptr<internal::SqliteDatabase> database,
200 : node_id_(std::move(node_id)),
201 database_(std::move(database)),
202 options_(std::move(
options)) {}
207 enum class ReadKind { kSequence, kArrivalOrder };
210 absl::Time deadline);
212 const std::string node_id_;
213 const std::shared_ptr<internal::SqliteDatabase> database_;
222 struct ConstructorToken {};
235 static absl::StatusOr<std::shared_ptr<SQLiteChunkStoreFactory>>
Create(
239 static absl::StatusOr<std::shared_ptr<SQLiteChunkStoreFactory>>
Create(
240 const std::string&
root);
245 static absl::StatusOr<std::shared_ptr<SQLiteChunkStoreFactory>>
Create();
266 absl::StatusOr<std::shared_ptr<SQLiteChunkStore>>
Open(std::string node_id);
269 [[nodiscard]] std::string
root()
const;
280 std::shared_ptr<internal::SqliteDatabase> database,
282 : database_(std::move(database)), options_(std::move(
options)) {}
285 const std::shared_ptr<internal::SqliteDatabase> database_;
A11's pluggable storage interface for streamed node data: an ordered, appendable log of fragments key...
Shared handle to one asynchronous result.
Definition future.h:125
Abstract, pluggable backing store for the data of a node: an ordered, appendable log of fragments.
Definition chunk_store.h:67
a11::Future< data::NodeFragment > GetByArrivalOrder(std::uint64_t arrival_order)
Get a fragment by arrival order, waiting indefinitely.
Definition chunk_store.h:116
a11::Future< data::NodeFragment > Get(std::uint32_t seq)
Get the fragment at a sequence number, waiting indefinitely.
Definition chunk_store.h:82
a11::Future< std::vector< std::optional< data::NodeFragment > > > Next()
Get the next logical-sequence fragment, waiting indefinitely.
Definition chunk_store.h:149
a11::Future< absl::Status > CloseWritesWithStatus(absl::Status status)
Seal the store against further writes with a terminal status.
Definition chunk_store.h:274
Creates SQLiteChunkStores that share one database per root.
Definition sqlite_chunk_store.h:220
a11::Future< size_t > SweepOrphanBlobs()
Delete unreferenced blob files older than the configured grace period.
Definition sqlite_chunk_store.cc:584
const SQLiteChunkStoreOptions & options() const
The validated storage policy applied to every store created here.
Definition sqlite_chunk_store.h:272
std::string root() const
The root this factory creates stores under.
Definition sqlite_chunk_store.cc:580
static std::string DefaultRoot()
The process-wide default storage root.
Definition sqlite_chunk_store.cc:525
SQLiteChunkStoreFactory(ConstructorToken, std::shared_ptr< internal::SqliteDatabase > database, SQLiteChunkStoreOptions options)
Definition sqlite_chunk_store.h:279
absl::StatusOr< std::shared_ptr< SQLiteChunkStore > > Open(std::string node_id)
Open a store for node_id under this factory's root.
Definition sqlite_chunk_store.cc:572
static absl::StatusOr< std::shared_ptr< SQLiteChunkStoreFactory > > Create()
Create a factory at the default root with the environment/default policy.
Definition sqlite_chunk_store.cc:568
A persistent ChunkStore backed by store.sqlite and a blobs/ directory.
Definition sqlite_chunk_store.h:98
absl::StatusOr< std::string > GetId() const override
Get the store's node identifier.
Definition sqlite_chunk_store.cc:616
a11::Future< std::uint32_t > GetSeqForArrivalOrder(std::uint64_t arrival_order) override
Translate an arrival order into the sequence number of that fragment.
Definition sqlite_chunk_store.cc:1229
a11::Future< size_t > Size() override
Get the number of fragments currently in the store.
Definition sqlite_chunk_store.cc:1279
a11::Future< data::NodeFragment > Get(std::uint32_t seq, absl::Time deadline) override
Get the fragment stored at a sequence number.
Definition sqlite_chunk_store.cc:627
a11::Future< size_t > SweepOrphanBlobs()
Delete unreferenced blob files older than the configured grace period.
Definition sqlite_chunk_store.cc:1399
a11::Future< SQLiteChunkStoreMetadata > GetMetadata()
Read all node-level state in one row read, without listing fragments.
Definition sqlite_chunk_store.cc:1295
a11::Future< std::optional< absl::Status > > GetWriteStatus() override
Observe write closure without changing the shared read cursor.
Definition sqlite_chunk_store.cc:1324
static absl::StatusOr< std::shared_ptr< SQLiteChunkStore > > Create(std::string node_id)
Create a store for node_id under the process-default root.
Definition sqlite_chunk_store.cc:611
a11::Future< std::vector< std::uint32_t > > PutMany(std::vector< data::NodeFragment > fragments) override
Append several fragments in one batch.
Definition sqlite_chunk_store.cc:862
a11::Future< absl::Status > CloseWritesWithStatus(absl::Status status, bool return_status_if_already_closed) override
Seal the store against further writes with a terminal status.
Definition sqlite_chunk_store.cc:1162
~SQLiteChunkStore() override=default
a11::Future< data::NodeFragment > ClearData(std::uint32_t seq) override
Erase the payload of the fragment at a sequence number while keeping its slot.
Definition sqlite_chunk_store.cc:1075
a11::Future< std::vector< std::optional< data::NodeFragment > > > Next()
Get the next logical-sequence fragment, waiting indefinitely.
Definition chunk_store.h:149
SQLiteChunkStore(ConstructorToken, std::string node_id, std::shared_ptr< internal::SqliteDatabase > database, SQLiteChunkStoreOptions options)
Definition sqlite_chunk_store.h:197
a11::Future< std::uint32_t > Put(data::NodeFragment fragment) override
Append one fragment to the log.
Definition sqlite_chunk_store.cc:854
const SQLiteChunkStoreOptions & options() const
The validated storage policy captured at construction.
Definition sqlite_chunk_store.h:190
std::string root() const
The storage root this store reads and writes under.
Definition sqlite_chunk_store.cc:620
a11::Future< std::optional< std::uint32_t > > GetFinalSeq() override
Get the sequence number explicitly marked as the final fragment.
Definition sqlite_chunk_store.cc:1262
a11::Future< data::NodeFragment > GetByArrivalOrder(std::uint64_t arrival_order, absl::Time deadline) override
Get the fragment identified by the order in which it arrived, rather than by its sequence number.
Definition sqlite_chunk_store.cc:632
a11::Future< std::vector< data::NodeFragment > > FindReferrers(size_t limit)
Find fragments elsewhere in the database whose NodeRef points at this node, newest sequence last.
Definition sqlite_chunk_store.cc:1335
std::string value
Definition discover.cc:100
Completion values used by every asynchronous A11 operation.
bool fragments
Definition runtime_streams.cc:32
std::uint32_t seq
Definition sqlite_chunk_store.cc:186
std::uint64_t arrival_order
Definition sqlite_chunk_store.cc:187
One piece of a node's stream: an inline chunk or a node reference.
Definition types.h:366
Storage layout policy for SQLiteChunkStore.
Definition sqlite_chunk_store.h:44
std::string owner_id
Owner recorded for attribution and filtering; not enforced.
Definition sqlite_chunk_store.h:49
friend bool operator==(const SQLiteChunkStoreOptions &, const SQLiteChunkStoreOptions &)=default
absl::Status Validate() const
Validate the threshold, owner id and durations.
Definition sqlite_chunk_store.cc:454
absl::Duration blob_grace_period
How long an unreferenced blob must survive before a sweep may remove it.
Definition sqlite_chunk_store.h:62
size_t inline_data_threshold
Payloads above this size use blob files; smaller ones stay in SQLite.
Definition sqlite_chunk_store.h:46
absl::Duration cross_process_poll_interval
Poll interval for commits by other processes; zero disables polling.
Definition sqlite_chunk_store.h:57
static absl::StatusOr< SQLiteChunkStoreOptions > FromEnvironment()
Read storage policy from the A11_SQLITE_CHUNK_STORE_* environment values.
Definition sqlite_chunk_store.cc:474
internal::SqliteSynchronous synchronous
Durability level applied with PRAGMA synchronous.
Definition sqlite_chunk_store.h:52
A11's core wire value types: chunks, node fragments and messages.