Skip to main content

khive_db/
lib.rs

1//! SQLite storage backend for the khive knowledge graph runtime.
2//!
3//! Provides entity, note, event, edge, FTS5 text search, and optional
4//! `sqlite-vec` vector storage over a WAL-mode connection pool.
5//!
6//! # Terminal write settlement
7//! Pooled, standalone, and lifetime write owners retain their volume lease
8//! through rollback or successful owned connection close. If a retired
9//! connection remains outside autocommit and close also fails, cleanup reports
10//! the path, volume, rollback and close errors, returns a terminal
11//! outcome-unknown error, and poisons the pool so it refuses every later write
12//! and releases the lease. The process keeps running: the host decides whether
13//! to exit.
14
15/// Concrete storage backend providing capability-trait factories.
16pub mod backend;
17/// Periodic WAL checkpoint task.
18pub mod checkpoint;
19// Kept internal while the code-map constructor and SQLite callback wiring land.
20#[allow(dead_code)]
21mod code_map_vfs;
22mod connection_settlement;
23/// Durable database owner identity paired with the opened physical file.
24pub mod database_owner_identity;
25/// Read-only-by-intent database-integrity and WAL/checkpoint diagnostics.
26pub mod diagnostics;
27/// Physical-volume identity and bounded cooperative SQLite admission lease.
28mod disk_guard;
29mod disk_guard_config;
30/// Environment readers with explicit parse/default and boolean policies.
31pub mod env;
32/// Error types for the SQLite layer.
33pub mod error;
34/// SQLite extension registration (sqlite-vec auto-extension).
35pub mod extension;
36/// Physical file identity shared by pool admission and backend alias routing.
37#[cfg(any(unix, windows))]
38pub mod file_identity;
39mod fts_maintenance;
40/// Read predicates and transaction assertions for the graph-lint caller.
41pub mod graph_lint;
42/// Schema migration system (versioned migrations).
43pub mod migrations;
44/// What a live store's schema says about `namespace` (ADR-189).
45pub mod namespace_census;
46/// Moving records between namespaces (ADR-189).
47pub mod namespace_move;
48/// A store fixture reproducing the namespace split, for the move's own arms.
49#[cfg(any(test, feature = "test-support"))]
50pub mod namespace_move_fixture;
51/// Feature-gated namespace-bounded FTS5 trigram prototype.
52#[cfg(feature = "namespace-trigram-proto")]
53pub mod namespace_trigram_proto;
54/// WAL-mode connection pool: one writer, N concurrent readers.
55pub mod pool;
56mod read_cancellation;
57/// `SqlAccess` trait bridge to `ConnectionPool`.
58pub mod sql_bridge;
59/// Pure statement-list builders for caller-owned SQL execution.
60pub mod statement_lists;
61#[cfg(any(test, feature = "test-support"))]
62mod statement_observer;
63/// Per-substrate store implementations (entity, note, graph, event, text, vectors, sparse).
64pub mod stores;
65/// Append-only NDJSON writer-timeout event sink (crate-internal).
66mod timeout_sink;
67/// Metadata-only copy-size estimate for guarded VACUUM admission.
68mod vacuum_capacity;
69/// Cross-process WAL-pin attribution sidecar (ADR-091 Amendment 2 Plank B).
70/// The sidecar write path (heartbeat/beacon) and identity primitives are
71/// portable; directory collection (`enumerate_live`/`housekeep_live`) is
72/// Unix-only — its only caller is the daemon's checkpoint task, and daemon
73/// mode itself requires Unix (see `khive-mcp/src/serve.rs`).
74pub mod walpin;
75/// Single-writer task and bounded write queue (ADR-067 Component A).
76pub mod writer_task;
77
78#[cfg(test)]
79mod writer_busy_fixture;
80
81#[cfg(test)]
82mod test_process;
83
84#[cfg(test)]
85mod lease_latency_tests;
86
87pub use backend::StorageBackend;
88pub use checkpoint::{
89    checkpoint_once, run_checkpoint_task, CheckpointConfig, CheckpointLifecycleOwner,
90    CheckpointTick,
91};
92pub use checkpoint::{run_session_sweep_task, SessionSweepConfig, SweepBackend};
93pub use database_owner_identity::{DatabaseOwnerIdentity, DatabaseOwnerIdentityError};
94pub use disk_guard::harness_scoped_process_leases;
95pub use disk_guard_config::{
96    default_volume_lock_dir, require_volume_lock_dir, resolve_disk_guard_config,
97    DiskGuardConfigSource, DiskGuardEnvironment, EffectiveDiskGuardConfig,
98};
99pub use error::{
100    SqliteError, SQLITE_WAL_CAPACITY_REFUSED_STAGE, SQLITE_WAL_CAPACITY_UNAVAILABLE_STAGE,
101};
102pub use fts_maintenance::{
103    fts_maintenance_counters, FtsIndexStructure, FtsLevelStructure, FtsMaintenanceCounters,
104    FtsSegmentDiagnostics,
105};
106pub use khive_storage::{
107    await_request_read_phase, effective_request_read_deadline, ensure_request_read_active,
108    inherit_request_read_cancellation, inherit_request_read_context, request_read_is_cancelled,
109    request_read_timeout_from_env, scope_request_read_cancellation, scope_request_read_deadline,
110    scope_request_read_deadline_at, wait_for_request_read_cancellation, RequestReadDeadline,
111    DEFAULT_REQUEST_READ_TIMEOUT_SECS,
112};
113pub use migrations::{
114    inspect_integrity, inspect_page_accounting, inspect_schema_is_current, inspect_schema_version,
115    query_embedding_models, read_schema_version, run_migrations, run_migrations_with_policy,
116    EmbeddingModelRegistryRecord, Migration, MigrationWritePolicy, PageAccounting,
117    ServiceSchemaPlan, VersionedMigration, MIGRATIONS,
118};
119pub use pool::{
120    CheckpointGuard, CheckpointResult, ConnectionPool, PoolConfig, ReaderGuard, ReaderRow,
121    WalCeilingPolicy, WalCeilingSource, WriterGuard,
122};
123#[cfg(any(test, feature = "test-support"))]
124pub use read_cancellation::scope_test_read_progress;
125pub use read_cancellation::{sqlite_interrupt_grace_from_env, DEFAULT_SQLITE_INTERRUPT_GRACE_MS};
126pub use sql_bridge::SqlBridge;
127#[cfg(any(test, feature = "test-support"))]
128pub use statement_observer::{StartedStatement, StatementStartObservation};
129pub use writer_task::WriterTaskHandle;
130
131#[cfg(test)]
132mod namespace_move_fixture_tests;
133#[cfg(test)]
134mod stream_schema_tests;
135
136#[cfg(test)]
137mod reader_lease_tests;
138
139#[cfg(test)]
140mod raw_sql_reader_admission_tests;