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/// Schema migration system (versioned migrations).
41pub mod migrations;
42/// What a live store's schema says about `namespace` (ADR-189).
43pub mod namespace_census;
44/// Moving records between namespaces (ADR-189).
45pub mod namespace_move;
46/// A store fixture reproducing the namespace split, for the move's own arms.
47#[cfg(any(test, feature = "test-support"))]
48pub mod namespace_move_fixture;
49/// Feature-gated namespace-bounded FTS5 trigram prototype.
50#[cfg(feature = "namespace-trigram-proto")]
51pub mod namespace_trigram_proto;
52/// WAL-mode connection pool: one writer, N concurrent readers.
53pub mod pool;
54mod read_cancellation;
55/// `SqlAccess` trait bridge to `ConnectionPool`.
56pub mod sql_bridge;
57#[cfg(any(test, feature = "test-support"))]
58mod statement_observer;
59/// Per-substrate store implementations (entity, note, graph, event, text, vectors, sparse).
60pub mod stores;
61/// Append-only NDJSON writer-timeout event sink (crate-internal).
62mod timeout_sink;
63/// Metadata-only copy-size estimate for guarded VACUUM admission.
64mod vacuum_capacity;
65/// Cross-process WAL-pin attribution sidecar (ADR-091 Amendment 2 Plank B).
66/// The sidecar write path (heartbeat/beacon) and identity primitives are
67/// portable; directory collection (`enumerate_live`/`housekeep_live`) is
68/// Unix-only — its only caller is the daemon's checkpoint task, and daemon
69/// mode itself requires Unix (see `khive-mcp/src/serve.rs`).
70pub mod walpin;
71/// Single-writer task and bounded write queue (ADR-067 Component A).
72pub mod writer_task;
73
74#[cfg(test)]
75mod writer_busy_fixture;
76
77#[cfg(test)]
78mod test_process;
79
80#[cfg(test)]
81mod lease_latency_tests;
82
83pub use backend::StorageBackend;
84pub use checkpoint::{
85    checkpoint_once, run_checkpoint_task, CheckpointConfig, CheckpointLifecycleOwner,
86    CheckpointTick,
87};
88pub use checkpoint::{run_session_sweep_task, SessionSweepConfig, SweepBackend};
89pub use database_owner_identity::{DatabaseOwnerIdentity, DatabaseOwnerIdentityError};
90pub use disk_guard::harness_scoped_process_leases;
91pub use disk_guard_config::{
92    default_volume_lock_dir, require_volume_lock_dir, resolve_disk_guard_config,
93    DiskGuardConfigSource, DiskGuardEnvironment, EffectiveDiskGuardConfig,
94};
95pub use error::{
96    SqliteError, SQLITE_WAL_CAPACITY_REFUSED_STAGE, SQLITE_WAL_CAPACITY_UNAVAILABLE_STAGE,
97};
98pub use fts_maintenance::{
99    fts_maintenance_counters, FtsIndexStructure, FtsLevelStructure, FtsMaintenanceCounters,
100    FtsSegmentDiagnostics,
101};
102pub use khive_storage::{
103    await_request_read_phase, effective_request_read_deadline, ensure_request_read_active,
104    inherit_request_read_cancellation, inherit_request_read_context, request_read_is_cancelled,
105    request_read_timeout_from_env, scope_request_read_cancellation, scope_request_read_deadline,
106    scope_request_read_deadline_at, wait_for_request_read_cancellation, RequestReadDeadline,
107    DEFAULT_REQUEST_READ_TIMEOUT_SECS,
108};
109pub use migrations::{
110    inspect_schema_is_current, inspect_schema_version, query_embedding_models, read_schema_version,
111    run_migrations, run_migrations_with_policy, EmbeddingModelRegistryRecord, Migration,
112    MigrationWritePolicy, ServiceSchemaPlan, VersionedMigration, MIGRATIONS,
113};
114pub use pool::{
115    CheckpointGuard, CheckpointResult, ConnectionPool, PoolConfig, ReaderGuard, ReaderRow,
116    WalCeilingPolicy, WalCeilingSource, WriterGuard,
117};
118#[cfg(any(test, feature = "test-support"))]
119pub use read_cancellation::scope_test_read_progress;
120pub use read_cancellation::{sqlite_interrupt_grace_from_env, DEFAULT_SQLITE_INTERRUPT_GRACE_MS};
121pub use sql_bridge::SqlBridge;
122#[cfg(any(test, feature = "test-support"))]
123pub use statement_observer::{StartedStatement, StatementStartObservation};
124pub use writer_task::WriterTaskHandle;
125
126#[cfg(test)]
127mod namespace_move_fixture_tests;
128#[cfg(test)]
129mod stream_schema_tests;
130
131#[cfg(test)]
132mod reader_lease_tests;
133
134#[cfg(test)]
135mod raw_sql_reader_admission_tests;