Skip to main content

fsqlite_mvcc/
lib.rs

1// Peer credentials and ancillary fd passing now use the `nix` crate (stable Rust)
2// instead of nightly #![feature(peer_credentials_unix_socket)] and
3// #![feature(unix_socket_ancillary_data)].
4
5//! MVCC page-level versioning for concurrent writers.
6//!
7//! This crate is intentionally small in early phases: it defines the core MVCC
8//! primitives and the cross-process witness/lock-table coordination types.
9
10pub mod begin_concurrent;
11pub mod bocpd;
12pub mod cache_aligned;
13pub mod cell_delta_wal;
14pub mod cell_mvcc_boundary;
15pub mod cell_routing;
16pub mod cell_visibility;
17pub mod commit_combiner;
18pub mod compat;
19pub mod conflict_model;
20pub mod conformal_martingale;
21pub mod coordinator_ipc;
22pub mod core_types;
23pub mod deterministic_rebase;
24pub mod differential_privacy;
25pub mod ebr;
26pub mod flat_combining;
27pub mod gc;
28pub mod history_compression;
29pub mod hot_witness_index;
30pub mod index_regen;
31pub mod invariants;
32pub mod left_right;
33pub mod lifecycle;
34pub mod materialize;
35pub mod observability;
36pub mod physical_merge;
37pub mod provenance;
38pub mod rcu;
39pub mod regime_monitor;
40pub mod retry_policy;
41pub mod rowid_alloc;
42pub mod seqlock;
43pub mod shared_lock_table;
44pub mod sheaf_conformal;
45pub mod shm;
46pub mod sketch_telemetry;
47pub mod ssi_abort_policy;
48pub mod ssi_validation;
49pub mod time_travel;
50pub mod two_phase_commit;
51pub mod witness_hierarchy;
52pub mod witness_objects;
53pub mod witness_plane;
54pub mod witness_publication;
55pub mod witness_refinement;
56pub mod write_coordinator;
57pub mod xor_delta;
58
59#[cfg(test)]
60mod ssi_anomaly_tests;
61
62pub use begin_concurrent::{
63    ConcurrentHandle, ConcurrentPageState, ConcurrentRegistry, ConcurrentSavepoint, FcwResult,
64    MAX_CONCURRENT_WRITERS, PreparedConcurrentCommit, SharedConcurrentHandle, SsiResult,
65    concurrent_abort, concurrent_clear_page_state, concurrent_commit, concurrent_commit_with_ssi,
66    concurrent_free_page, concurrent_page_is_freed, concurrent_page_state,
67    concurrent_prepare_write_page, concurrent_read_page, concurrent_restore_page_state,
68    concurrent_rollback_to_savepoint, concurrent_savepoint, concurrent_stage_prepared_write_page,
69    concurrent_track_write_conflict_page, concurrent_write_page,
70    finalize_prepared_concurrent_commit_with_ssi, is_concurrent_mode,
71    prepare_concurrent_commit_with_ssi, validate_first_committer_wins,
72};
73pub use bocpd::{BocpdConfig, BocpdMonitor, ConjugateModel, HazardFunction, RegimeStats};
74pub use cache_aligned::{
75    CACHE_LINE_BYTES, CLAIMING_TIMEOUT_NO_PID_SECS, CLAIMING_TIMEOUT_SECS, CacheAligned, RcriEntry,
76    RcriOverflowError, RecentlyCommittedReadersIndex, SLOT_PAYLOAD_MASK, SLOT_TAG_MASK,
77    SLOT_TAG_SHIFT, SharedTxnSlot, SlotAcquireError, TAG_CLAIMING, TAG_CLEANING, TxnSlotArray,
78    decode_payload, decode_tag, encode_claiming, encode_cleaning, is_sentinel, rcri_bloom,
79    slot_mode, slot_state,
80};
81pub use cell_delta_wal::{
82    CELL_DELTA_CHECKSUM_SIZE, CELL_DELTA_FRAME_TYPE, CELL_DELTA_HEADER_SIZE,
83    CELL_DELTA_MAX_DATA_LEN, CELL_DELTA_MIN_FRAME_SIZE, CellDeltaOp, CellDeltaRecoverySummary,
84    CellDeltaWalFrame, deserialize_cell_delta_batch, serialize_cell_delta_batch,
85};
86pub use cell_routing::{
87    CellMvccMode, EscalationResult, PageTrackingState, RoutingContext, RoutingDecision,
88    RoutingReason, TxnEscalationTracker, escalate_to_page_level, get_cell_mvcc_mode,
89    set_cell_mvcc_mode, should_use_cell_path,
90};
91pub use cell_visibility::{
92    CellConflict, CellDelta, CellDeltaArena, CellDeltaIdx, CellDeltaKind, CellGcStats, CellKey,
93    CellVisibilityLog, MutationOutcome, can_be_logical_insert, will_be_logical_delete,
94};
95pub use compat::{
96    CompatMode, CoordinatorProbeResult, HybridShmState, ReadLockOutcome, RecoveryPlan,
97    UpdatedLegacyShm, begin_concurrent_check, choose_reader_slot,
98};
99pub use conflict_model::{
100    AMS_SKETCH_VERSION, AmsEvidenceLedger, AmsSketch, AmsSketchConfig, AmsWindowCollector,
101    AmsWindowCollectorConfig, AmsWindowEstimate, DEFAULT_AMS_R, DEFAULT_HEAVY_HITTER_K,
102    DEFAULT_NITRO_PRECISION, DEFAULT_ZIPF_MAX_ITERS, HeadTailDecomposition, HeavyHitterLedgerEntry,
103    InstrumentationCounters, MAX_AMS_R, MAX_HEAVY_HITTER_K, MAX_NITRO_PRECISION, MIN_AMS_R,
104    MIN_HEAVY_HITTER_K, MIN_NITRO_PRECISION, NITRO_SKETCH_VERSION, NitroSketch, NitroSketchConfig,
105    SpaceSavingEntry, SpaceSavingSummary, WindowCloseReason, ZIPF_S_MAX, ZIPF_S_MIN, ZipfMleResult,
106    ams_sign, birthday_conflict_probability_m2, birthday_conflict_probability_uniform,
107    compute_head_tail_decomposition, dedup_write_set, effective_collision_pool,
108    effective_w_index_multiplier, effective_w_leaf_split, effective_w_root_split, exact_m2, mix64,
109    p_abort_attempt, p_drift, pairwise_conflict_probability, policy_collision_mass_input,
110    tps_estimate, validate_ams_r, validate_heavy_hitter_k, validate_nitro_precision,
111    zipf_mle_from_ranked_counts,
112};
113pub use conformal_martingale::{ConformalMartingaleConfig, ConformalMartingaleMonitor};
114pub use core_types::{
115    CommitIndex, CommitLog, CommitRecord, DrainProgress, DrainResult, GcHorizonResult,
116    InProcessPageLockTable, LOCK_TABLE_SHARDS, OrphanedSlotCleanupStats, RebuildError,
117    RebuildResult, SlotCleanupResult, Transaction, TransactionMode, TransactionState, VersionArena,
118    VersionIdx, cleanup_and_raise_gc_horizon, cleanup_orphaned_slots, raise_gc_horizon,
119    try_cleanup_orphaned_slot, try_cleanup_sentinel_slot,
120};
121pub use deterministic_rebase::{
122    BaseRowReader, RebaseEligibility, RebaseError, RebaseResult, RebaseSchemaLookup, ReplayResult,
123    TableConstraints, UpdateExpressionCandidate, can_emit_update_expression,
124    check_rebase_eligibility, check_schema_epoch, deterministic_rebase, replay_update_expression,
125};
126pub use differential_privacy::{
127    DpEngine, DpError, DpMetrics, DpQueryResult, NoiseMechanism, PrivacyBudget, dp_metrics,
128    reset_dp_metrics, sensitivity,
129};
130pub use ebr::{
131    EbrMetrics, EbrMetricsSnapshot, EbrRetireQueue, GLOBAL_EBR_METRICS, ReaderPinSnapshot,
132    StaleReaderConfig, VersionGuard, VersionGuardRegistry, VersionGuardTicket,
133};
134pub use flat_combining::{
135    FcHandle, FlatCombiner, FlatCombiningMetrics, MAX_FC_THREADS, OP_ADD, OP_READ,
136    flat_combining_metrics, reset_flat_combining_metrics,
137};
138pub use gc::{
139    GC_F_MAX_HZ, GC_F_MIN_HZ, GC_PAGES_BUDGET, GC_TARGET_CHAIN_LENGTH, GC_VERSIONS_BUDGET,
140    GcScheduler, GcTickResult, GcTodo, PruneResult, gc_tick, prune_page_chain,
141};
142pub use history_compression::{
143    CertificateVerificationError, CircuitBreakerEvent, CompressedPageHistory,
144    CompressedPageVersion, CompressedVersionData, HistoryCompressionError, MergeCertificate,
145    MergeCertificatePostState, MergeKind, VERIFIER_VERSION, are_intent_ops_independent,
146    circuit_breaker_check, collapse_join_max_updates, compress_page_history,
147    compute_footprint_digest, compute_op_digest, extract_join_max_constant, foata_normal_form,
148    generate_merge_certificate, is_join_max_int_update, is_mergeable_intent,
149    verify_merge_certificate,
150};
151pub use hot_witness_index::{
152    ColdPlaneMode, ColdWitnessStore, HotWitnessBucketEntry, HotWitnessIndex, bitset_to_slot_ids,
153};
154pub use index_regen::{
155    Collation, IndexDef, IndexKeyPart, IndexRegenError, IndexRegenOps, NoOpUniqueChecker,
156    UniqueChecker, apply_column_updates, compute_index_key, discard_stale_index_ops,
157    eval_rebase_expr, regenerate_index_ops,
158};
159pub use invariants::{
160    CHAIN_HEAD_EMPTY, CHAIN_HEAD_SHARDS, CasInstallResult, ChainHeadTable, SerializedWriteMutex,
161    SnapshotResolveTrace, TxnManager, VersionStore, VersionVisibilityRange, idx_to_version_pointer,
162    visible,
163};
164pub use left_right::{
165    LeftRight, LeftRightMetrics, LeftRightPair, LeftRightTriple, leftright_metrics,
166    reset_leftright_metrics,
167};
168pub use lifecycle::{BeginKind, CommitResponse, MvccError, Savepoint, TransactionManager};
169pub use materialize::{
170    DEFAULT_MATERIALIZATION_THRESHOLD, MaterializationError, MaterializationResult,
171    MaterializationTrigger, materialize_page, should_materialize_eagerly,
172};
173pub use observability::{
174    CasMetricsSnapshot, CasRetriesHistogram, SharedObserver, SnapshotReadMetricsSnapshot,
175    SsiMetricsSnapshot, VersionsTraversedHistogram, cas_metrics_snapshot, emit_conflict_resolved,
176    emit_fcw_base_drift, emit_page_lock_contention, emit_ssi_abort, mvcc_snapshot_established,
177    mvcc_snapshot_metrics_snapshot, mvcc_snapshot_released, record_cas_attempt,
178    record_snapshot_read_versions_traversed, record_ssi_abort, record_ssi_commit,
179    reset_cas_metrics, reset_mvcc_snapshot_metrics, reset_ssi_metrics, ssi_metrics_snapshot,
180};
181pub use physical_merge::{
182    CellOp, CellOpKind, FreeSpaceOp, HeaderOp, MergeError, MergeLadderResult, ParsedCell,
183    ParsedPage, RangeXorPatch, StructuredPagePatch, apply_patch, diff_parsed_pages,
184    evaluate_merge_ladder, merge_structured_patches, parse_btree_page, repack_btree_page,
185};
186pub use provenance::{
187    ProvenanceAnnotation, ProvenanceMetrics, ProvenanceMode, ProvenanceReport, ProvenanceToken,
188    ProvenanceTracker, TupleId, WhyNotResult, provenance_metrics, reset_provenance_metrics,
189    why_not,
190};
191pub use rcu::{
192    MAX_RCU_THREADS, QsbrHandle, QsbrRegistry, RcuCell, RcuMetrics, RcuPair, RcuTriple,
193    rcu_metrics, record_rcu_reclaimed, reset_rcu_metrics,
194};
195pub use regime_monitor::{RegimeMonitor, RegimeMonitorConfig};
196pub use retry_policy::{
197    BetaPosterior, ContentionBucketKey, DEFAULT_CANDIDATE_WAITS_MS, DEFAULT_STARVATION_THRESHOLD,
198    HazardModelParams, MAX_CONTENTION_BUCKETS, RetryAction, RetryController, RetryCostParams,
199    RetryEvidenceEntry, expected_loss_failnow, expected_loss_retry, gittins_index_approx,
200    gittins_threshold,
201};
202pub use rowid_alloc::{
203    AllocatorKey, ConcurrentRowIdAllocator, DEFAULT_RANGE_SIZE, LocalRowIdCache, RangeReservation,
204    RowIdAllocError, SQLITE_FULL, SQLITE_SCHEMA,
205};
206pub use seqlock::{
207    SeqLock, SeqLockPair, SeqLockTriple, SeqlockMetrics, reset_seqlock_metrics, seqlock_metrics,
208};
209pub use shared_lock_table::{
210    AcquireResult, DEFAULT_TABLE_CAPACITY, DrainStatus, RebuildLeaseError,
211    RebuildResult as SharedRebuildResult, SharedPageLockTable,
212};
213pub use sheaf_conformal::{
214    ConformalCalibratorConfig, ConformalOracleCalibrator, ConformalPrediction, InvariantScore,
215    OpportunityScore, OracleReport, PredictionSetEntry, Section, SheafObstruction, SheafResult,
216    check_sheaf_consistency, check_sheaf_consistency_with_chains,
217};
218pub use shm::{SharedMemoryLayout, ShmSnapshot};
219pub use sketch_telemetry::{
220    CMS_VERSION, CountMinSketch, CountMinSketchConfig, DEFAULT_ALLOC_SIZE_BUCKETS,
221    DEFAULT_CMS_DEPTH, DEFAULT_CMS_WIDTH, DEFAULT_LATENCY_BUCKETS_US, HISTOGRAM_VERSION,
222    HistogramSnapshot, MemoryAllocationTracker, MemoryTrackerSnapshot,
223    NITROSKETCH_STREAMING_VERSION, SketchTelemetryMetrics, SlidingWindowCms, SlidingWindowConfig,
224    SlidingWindowHistogram, SlidingWindowHistogramSnapshot, StreamingHistogram,
225    reset_sketch_telemetry_metrics, sketch_telemetry_metrics,
226};
227pub use ssi_abort_policy::{
228    AbortDecision, AbortDecisionEnvelope, ConformalCalibrator, ConformalConfig, CycleStatus,
229    DroHotPathDecision, DroLossMatrix, DroObservedRateKind, DroRadiusCertificate, DroRiskTolerance,
230    DroVolatilityTracker, DroVolatilityTrackerConfig, DroVolatilityTrackerError,
231    DroWindowObservation, LossMatrix, SsiDecisionCard, SsiDecisionCardDraft, SsiDecisionQuery,
232    SsiDecisionType, SsiEvidenceLedger, SsiFpMonitor, SsiFpMonitorConfig, SsiReadSetSummary,
233    TxnCost, Victim, VictimDecision, dro_wasserstein_radius, select_victim,
234};
235pub use ssi_validation::{
236    ActiveTxnView, CommittedReaderInfo, CommittedWriterInfo, DiscoveredEdge,
237    EvidenceRecordMetricsSnapshot, SsiAbortReason, SsiBusySnapshot, SsiEvidenceBudgetConfig,
238    SsiEvidenceRecordingMode, SsiState, SsiValidationOk, discover_incoming_edges,
239    discover_outgoing_edges, reset_ssi_evidence_metrics, set_ssi_evidence_budget_config,
240    set_ssi_evidence_recording_mode, ssi_evidence_budget_config, ssi_evidence_metrics_snapshot,
241    ssi_evidence_query, ssi_evidence_recording_mode, ssi_evidence_snapshot,
242    ssi_validate_and_publish,
243};
244pub use time_travel::{
245    TimeTravelError, TimeTravelSnapshot, TimeTravelTarget, create_time_travel_snapshot,
246    resolve_page_at_commit, resolve_timestamp_via_commit_log, resolve_timestamp_via_markers,
247};
248pub use two_phase_commit::{
249    COMMIT_MARKER_MAGIC, COMMIT_MARKER_MIN_SIZE, DatabaseId, GlobalCommitMarker, MAIN_DB_ID,
250    MAX_TOTAL_DATABASES, ParticipantState, PrepareResult, RecoveryAction, SQLITE_MAX_ATTACHED,
251    TEMP_DB_ID, TwoPhaseCoordinator, TwoPhaseError, TwoPhaseState,
252};
253pub use witness_hierarchy::{
254    HotWitnessIndexDerivationV1, HotWitnessIndexSizingV1, WitnessHierarchyConfigV1,
255    WitnessHotIndexManifestV1, WitnessSizingError, derive_range_keys, extract_prefix,
256    range_key_bucket_index, witness_key_canonical_bytes, witness_key_hash,
257};
258pub use witness_objects::{
259    AbortPolicy, AbortReason, AbortWitness, ColdPlaneRefinementResult, DependencyEdgeKind,
260    EcsCommitProof, EcsDependencyEdge, EcsReadWitness, EcsWriteWitness, EdgeKeyBasis,
261    HotPlaneCandidates, KeySummary, KeySummaryChunk, LogicalTime, WitnessDelta, WitnessDeltaKind,
262    WitnessParticipation, WriteKind, cold_plane_refine, hot_plane_discover,
263};
264pub use witness_plane::{WitnessSet, validate_txn_token, witness_keys_overlap};
265pub use witness_publication::{
266    ActiveSlotSnapshot, CommitMarkerStore, CommittedPublication, DefaultProofValidator,
267    GcEligibility, ProofCarryingCommit, ProofCarryingValidator, PublicationError, PublicationPhase,
268    ReservationId, ReservationToken, ValidationVerdict, WitnessGcCoordinator, WitnessPublisher,
269};
270pub use witness_refinement::{
271    RefinementBudget, RefinementDecision, RefinementPriority, RefinementResult, VoiMetrics,
272    refine_edges,
273};
274pub use write_coordinator::{
275    CommitWriteSet, CompatCommitRequest, CompatCommitResponse, CoordinatorLease, CoordinatorMode,
276    DEFAULT_MAX_BATCH_SIZE, DEFAULT_SPILL_THRESHOLD, NativePublishRequest, NativePublishResponse,
277    SpillHandle, SpillLoc, SpilledWriteSet, WriteCoordinator,
278};
279pub use xor_delta::{
280    DEFAULT_DELTA_THRESHOLD_PCT, DELTA_FIXED_OVERHEAD_BYTES, DELTA_HEADER_BYTES, DELTA_MAGIC,
281    DELTA_RUN_HEADER_BYTES, DELTA_SPARSE_OVERHEAD_PCT, DELTA_VERSION, DeltaEncoding, DeltaError,
282    DeltaThresholdConfig, SparseXorDeltaObject, count_nonzero_xor, decode_sparse_xor_delta,
283    encode_page_delta, encode_sparse_xor_delta, estimate_sparse_delta_size, max_delta_bytes,
284    reconstruct_chain_from_newest, use_delta,
285};