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