Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
739397a
dst
Shubham8287 Apr 3, 2026
1ae1d51
dst
Shubham8287 Apr 3, 2026
f26c11d
Merge branch 'master' into shub/dst
Shubham8287 Apr 11, 2026
927db4a
fix seed logic
Shubham8287 Apr 13, 2026
5555da3
remove dst levels
Shubham8287 Apr 14, 2026
90c0365
turbo influenced
Shubham8287 Apr 21, 2026
70b16a0
code organisation
Shubham8287 Apr 21, 2026
f52ef9e
local mocks
Shubham8287 Apr 22, 2026
63753df
remove deadcode
Shubham8287 Apr 22, 2026
749b118
target owned properties
Shubham8287 Apr 22, 2026
d8e3fd6
traits
Shubham8287 Apr 23, 2026
1372b3a
delete code
Shubham8287 Apr 23, 2026
dd33707
pluggable property
Shubham8287 Apr 23, 2026
3d96cf2
open close durability
Shubham8287 Apr 24, 2026
3cac9ef
typo
Shubham8287 Apr 24, 2026
0983c62
better properties
Shubham8287 Apr 24, 2026
bc93e1a
Merge remote-tracking branch 'origin/master' into shub/dst
Shubham8287 Apr 24, 2026
17a40c6
tmp
Shubham8287 Apr 27, 2026
7289133
broken standlone target
Shubham8287 Apr 28, 2026
19badab
cleanups
Shubham8287 Apr 29, 2026
12cf035
inmemory commitlog
Shubham8287 Apr 29, 2026
8b5f5bc
larger surface
Shubham8287 Apr 29, 2026
9d0e692
Merge branch 'master' into shub/dst
Shubham8287 Apr 29, 2026
858e09a
properties better
Shubham8287 Apr 29, 2026
c6fa137
improvements
Shubham8287 Apr 30, 2026
0e850dc
readability
Shubham8287 May 3, 2026
87f97ea
crash property
Shubham8287 May 4, 2026
22702a4
Merge branch 'master' into shub/dst
Shubham8287 May 4, 2026
b0490af
split properties
Shubham8287 May 4, 2026
831e9f2
improve relatioandb_commit:
Shubham8287 May 4, 2026
7282b9b
slim down to datastore focused
Shubham8287 May 5, 2026
f5197c4
improved simulator
Shubham8287 May 5, 2026
051f8ac
runtime crate
Shubham8287 May 5, 2026
37aa55b
snapshots sim
Shubham8287 May 6, 2026
d2b5eed
make dst snapshot in-memory
Shubham8287 May 6, 2026
8c6814d
Merge remote-tracking branch 'origin/master' into shub/dst
Shubham8287 May 7, 2026
27cb858
snapshot abstraction at worker
Shubham8287 May 7, 2026
692dfe2
cleanup
Shubham8287 May 7, 2026
76db165
Merge branch 'master' into shub/dst
Shubham8287 May 7, 2026
0b9875f
cleanup
Shubham8287 May 7, 2026
42e55dc
snapshot abstraction
Shubham8287 May 8, 2026
f508a04
lint
Shubham8287 May 8, 2026
5356b81
Add runtime crate and RuntimeDispatch integration
Shubham8287 May 8, 2026
c83ed2e
LockedFsRepo
Shubham8287 May 8, 2026
813e418
comments
Shubham8287 May 8, 2026
5946261
cleanup
Shubham8287 May 8, 2026
1f6bdcb
Merge remote-tracking branch 'origin/master' into shub/persistence-ab…
Shubham8287 May 11, 2026
2104ced
lint
Shubham8287 May 11, 2026
fc2e146
make sim module mostly non_std
Shubham8287 May 11, 2026
e4de2bd
drop durability in reopen test helper
Shubham8287 May 11, 2026
4050da2
Merge branch 'shub/persistence-abstraction' into shub/sim
Shubham8287 May 11, 2026
795a704
drop durability in test
Shubham8287 May 11, 2026
e072845
Merge branch 'shub/persistence-abstraction' into shub/sim
Shubham8287 May 11, 2026
425e728
fix snapshot compressor
Shubham8287 May 11, 2026
466481c
minor fixes
Shubham8287 May 11, 2026
7d1e21d
minor fix
Shubham8287 May 11, 2026
494b927
Merge branch 'shub/sim' into shub/dst
Shubham8287 May 12, 2026
13d53a5
fix
Shubham8287 May 12, 2026
a521298
fixes
Shubham8287 May 12, 2026
e59ac12
fix unneccessary diff
Shubham8287 May 12, 2026
d92ac0a
README
Shubham8287 May 12, 2026
d074cf0
polishing
Shubham8287 May 13, 2026
9789d70
more polishing
Shubham8287 May 13, 2026
8cd609c
update readme
Shubham8287 May 13, 2026
c62e8b2
Merge remote-tracking branch 'origin/master' into shub/sim
Shubham8287 May 13, 2026
730028f
Runtime -> Handle
Shubham8287 May 13, 2026
35cbea9
Apply suggestions from code review
Shubham8287 May 13, 2026
5af7fd9
Update crates/commitlog/src/lib.rs
Shubham8287 May 13, 2026
52783ce
compile fix
Shubham8287 May 13, 2026
30012db
lint
Shubham8287 May 13, 2026
d9f009b
fix Cargo.toml
Shubham8287 May 13, 2026
3b76725
endlines on README
Shubham8287 May 13, 2026
9996a16
comments
Shubham8287 May 13, 2026
a051857
Merge shub/sim into shub/dst
Shubham8287 May 13, 2026
d5992a2
add extern alloc
Shubham8287 May 14, 2026
6079ef0
remove futures dependency
Shubham8287 May 14, 2026
8601d78
coverage matrics
Shubham8287 May 13, 2026
b27b021
update determinism coverage
Shubham8287 May 14, 2026
4f6ca23
put extern alloc behing gate
Shubham8287 May 14, 2026
651f8c6
join handle cleanup
Shubham8287 May 14, 2026
74b283c
update readme
Shubham8287 May 14, 2026
15b98a0
README about blcoking code
Shubham8287 May 14, 2026
3c525f2
comment
Shubham8287 May 14, 2026
77ebb41
executor split
Shubham8287 May 14, 2026
5266bae
Merge branch 'shub/sim' into shub/dst
Shubham8287 May 14, 2026
1a49892
streamline properties
Shubham8287 May 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"crates/commitlog",
"crates/core",
"crates/data-structures",
"crates/dst",
"crates/datastore",
"crates/durability",
"crates/execution",
Expand All @@ -25,6 +26,7 @@ members = [
"crates/physical-plan",
"crates/primitives",
"crates/query",
"crates/runtime",
"crates/sats",
"crates/schema",
"crates/smoketests",
Expand Down Expand Up @@ -139,6 +141,7 @@ spacetimedb-pg = { path = "crates/pg", version = "=2.2.0" }
spacetimedb-physical-plan = { path = "crates/physical-plan", version = "=2.2.0" }
spacetimedb-primitives = { path = "crates/primitives", version = "=2.2.0" }
spacetimedb-query = { path = "crates/query", version = "=2.2.0" }
spacetimedb-runtime = { path = "crates/runtime", version = "=2.2.0" }
spacetimedb-sats = { path = "crates/sats", version = "=2.2.0" }
spacetimedb-schema = { path = "crates/schema", version = "=2.2.0" }
spacetimedb-standalone = { path = "crates/standalone", version = "=2.2.0" }
Expand Down
4 changes: 2 additions & 2 deletions crates/commitlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Options {
/// The canonical commitlog API over a repository backend `R`.
///
/// The default backend is the on-disk filesystem repository
/// [`repo::Fs`], but tests may supply another [`Repo`]
/// [`repo::Fs`], but tests and simulators may supply another [`Repo`]
/// implementation.
///
/// Records in the log are of type `T`, which canonically is instantiated to
Expand Down Expand Up @@ -203,7 +203,7 @@ where
{
/// Open the log in `repo` with [`Options`].
///
/// This is useful for tests which provide a repository
/// This is useful for tests and simulators which provide a repository
/// implementation other than [`repo::Fs`].
pub fn open_with_repo(repo: R, opts: Options) -> io::Result<Self> {
let inner = commitlog::Generic::open(repo, opts)?;
Expand Down
2 changes: 2 additions & 0 deletions crates/commitlog/src/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub trait RepoWithoutLockFile: Repo {}

impl<T: RepoWithoutLockFile> RepoWithoutLockFile for &T {}

impl RepoWithoutLockFile for Fs {}

#[cfg(any(test, feature = "test"))]
impl RepoWithoutLockFile for Memory {}

Expand Down
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ spacetimedb-primitives.workspace = true
spacetimedb-paths.workspace = true
spacetimedb-physical-plan.workspace = true
spacetimedb-query.workspace = true
spacetimedb-runtime = { workspace = true, features = ["tokio"] }
spacetimedb-sats = { workspace = true, features = ["serde"] }
spacetimedb-schema.workspace = true
spacetimedb-table.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/database_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use tokio::io::{AsyncRead, BufReader};
use tokio::io::{AsyncRead, BufReader, ReadBuf};
use tokio::sync::{broadcast, mpsc, oneshot};
use tokio_stream::wrappers::errors::BroadcastStreamRecvError;
use tokio_stream::wrappers::BroadcastStream;
Expand Down Expand Up @@ -592,7 +592,7 @@ fn seek_to(file: &mut File, buf: &mut [u8], num_lines: u32) -> io::Result<()> {
Ok(())
}

fn read_exact_at(file: &std::fs::File, buf: &mut [u8], offset: u64) -> io::Result<()> {
fn read_exact_at(file: &File, buf: &mut [u8], offset: u64) -> io::Result<()> {
#[cfg(unix)]
{
use std::os::unix::fs::FileExt;
Expand Down Expand Up @@ -641,7 +641,7 @@ impl MaybeFile {
}

impl AsyncRead for MaybeFile {
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut tokio::io::ReadBuf<'_>) -> Poll<io::Result<()>> {
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<io::Result<()>> {
match self.project() {
MaybeFileProj::File { inner } => inner.poll_read(cx, buf),
MaybeFileProj::Empty => Poll::Ready(Ok(())),
Expand Down
13 changes: 7 additions & 6 deletions crates/core/src/db/durability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use spacetimedb_datastore::{execution_context::ReducerContext, traits::TxData};
use spacetimedb_durability::Transaction;
use spacetimedb_lib::Identity;
use spacetimedb_sats::ProductValue;
use tokio::{runtime, time::timeout};

use crate::db::persistence::Durability;
use spacetimedb_runtime::Handle;

pub(super) fn request_durability(
durability: &Durability,
Expand All @@ -32,18 +32,19 @@ pub(super) fn request_durability(
}));
}

pub(super) fn spawn_close(durability: Arc<Durability>, runtime: &runtime::Handle, database_identity: Identity) {
let rt = runtime.clone();
rt.spawn(async move {
let label = format!("[{database_identity}]");
match timeout(Duration::from_secs(10), durability.close()).await {
pub(super) fn spawn_close(durability: Arc<Durability>, runtime: &Handle, database_identity: Identity) {
let label = format!("[{database_identity}]");
let runtime = runtime.clone();
runtime.clone().spawn(async move {
match runtime.timeout(Duration::from_secs(10), durability.close()).await {
Err(_elapsed) => {
error!("{label} timeout waiting for durability shutdown");
}
Ok(offset) => {
info!("{label} durability shut down at tx offset: {offset:?}");
}
}
log::info!("closing spawn close");
});
}

Expand Down
39 changes: 32 additions & 7 deletions crates/core/src/db/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use async_trait::async_trait;
use spacetimedb_commitlog::SizeOnDisk;
use spacetimedb_durability::{DurabilityExited, TxOffset};
use spacetimedb_paths::server::ServerDataDir;
use spacetimedb_snapshot::DynSnapshotRepo;
use spacetimedb_runtime::Handle;
use spacetimedb_snapshot::{DynSnapshotRepo, SnapshotStore};

use crate::{messages::control_db::Database, util::asyncify};

Expand Down Expand Up @@ -35,14 +36,16 @@ pub struct Persistence {
/// Currently the expectation is that the reported size is the commitlog
/// size only.
pub disk_size: DiskSizeFn,
/// Optional snapshot store used during database restore.
pub snapshot_store: Option<Arc<dyn SnapshotStore>>,
/// An optional [SnapshotWorker].
///
/// The current expectation is that snapshots are only enabled for
/// persistent (as opposed to in-memory) databases. This is enforced by
/// this type.
pub snapshots: Option<SnapshotWorker>,
/// The tokio runtime onto which durability-related tasks shall be spawned.
pub runtime: tokio::runtime::Handle,
/// Runtime onto which durability-related tasks shall be spawned.
pub runtime: Handle,
}

impl Persistence {
Expand All @@ -53,9 +56,20 @@ impl Persistence {
snapshots: Option<SnapshotWorker>,
runtime: tokio::runtime::Handle,
) -> Self {
Self::new_with_runtime(durability, disk_size, snapshots, Handle::tokio(runtime))
}

pub fn new_with_runtime(
durability: impl spacetimedb_durability::Durability<TxData = Txdata> + 'static,
disk_size: impl Fn() -> io::Result<SizeOnDisk> + Send + Sync + 'static,
snapshots: Option<SnapshotWorker>,
runtime: Handle,
) -> Self {
let snapshot_store = snapshots.as_ref().map(SnapshotWorker::snapshot_store);
Self {
durability: Arc::new(durability),
disk_size: Arc::new(disk_size),
snapshot_store,
snapshots,
runtime,
}
Expand All @@ -66,6 +80,13 @@ impl Persistence {
self.snapshots.as_ref().map(|worker| worker.snapshot_repo())
}

/// If snapshot restore is enabled, get the [SnapshotStore] to read from.
pub fn snapshot_store(&self) -> Option<Arc<dyn SnapshotStore>> {
self.snapshot_store
.clone()
.or_else(|| self.snapshots.as_ref().map(SnapshotWorker::snapshot_store))
}

/// Get the [TxOffset] reported as durable by the [Durability] impl.
///
/// Returns `Ok(None)` if no offset is durable yet, and `Err(DurabilityExited)`
Expand All @@ -91,12 +112,13 @@ impl Persistence {
Option<Arc<Durability>>,
Option<DiskSizeFn>,
Option<SnapshotWorker>,
Option<tokio::runtime::Handle>,
Option<Handle>,
) {
this.map(
|Self {
durability,
disk_size,
snapshot_store: _,
snapshots,
runtime,
}| (Some(durability), Some(disk_size), snapshots, Some(runtime)),
Expand Down Expand Up @@ -143,13 +165,15 @@ impl PersistenceProvider for LocalPersistenceProvider {
async fn persistence(&self, database: &Database, replica_id: u64) -> anyhow::Result<Persistence> {
let replica_dir = self.data_dir.replica(replica_id);
let snapshot_dir = replica_dir.snapshots();
let runtime = Handle::tokio_current();

let database_identity = database.database_identity;
let snapshot_worker =
asyncify(move || relational_db::open_snapshot_repo(snapshot_dir, database_identity, replica_id))
.await
.map(|repo| SnapshotWorker::new(repo, snapshot::Compression::Enabled))?;
let (durability, disk_size) = relational_db::local_durability(replica_dir, Some(&snapshot_worker)).await?;
.map(|repo| SnapshotWorker::new(repo, snapshot::Compression::Enabled, runtime.clone()))?;
let (durability, disk_size) =
relational_db::local_durability(replica_dir, runtime.clone(), Some(&snapshot_worker)).await?;

tokio::spawn(relational_db::snapshot_watching_commitlog_compressor(
snapshot_worker.subscribe(),
Expand All @@ -161,8 +185,9 @@ impl PersistenceProvider for LocalPersistenceProvider {
Ok(Persistence {
durability,
disk_size,
snapshot_store: Some(snapshot_worker.snapshot_store()),
snapshots: Some(snapshot_worker),
runtime: tokio::runtime::Handle::current(),
runtime,
})
}
}
Loading