Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"crates/commitlog",
"crates/core",
"crates/data-structures",
"crates/datastore",
"crates/durability",
"crates/execution",
"crates/expr",
Expand Down Expand Up @@ -104,6 +105,7 @@ spacetimedb-codegen = { path = "crates/codegen", version = "1.2.0" }
spacetimedb-commitlog = { path = "crates/commitlog", version = "1.2.0" }
spacetimedb-core = { path = "crates/core", version = "1.2.0" }
spacetimedb-data-structures = { path = "crates/data-structures", version = "1.2.0" }
spacetimedb-datastore = { path = "crates/datastore", version = "1.2.0" }
spacetimedb-durability = { path = "crates/durability", version = "1.2.0" }
spacetimedb-execution = { path = "crates/execution", version = "1.2.0" }
spacetimedb-expr = { path = "crates/expr", version = "1.2.0" }
Expand Down
1 change: 1 addition & 0 deletions crates/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bench = false
spacetimedb-client-api = { path = "../client-api" }
spacetimedb-core = { path = "../core", features = ["test"] }
spacetimedb-data-structures.workspace = true
spacetimedb-datastore.workspace = true
spacetimedb-execution = { path = "../execution" }
spacetimedb-lib = { path = "../lib" }
spacetimedb-paths.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/benches/delete_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use criterion::{
use itertools::Itertools;
use rand::{prelude::*, seq::SliceRandom};
use smallvec::SmallVec;
use spacetimedb::db::datastore::locking_tx_datastore::delete_table;
use spacetimedb_data_structures::map::HashSet;
use spacetimedb_datastore::locking_tx_datastore::delete_table;
use spacetimedb_sats::layout::Size;
use spacetimedb_table::indexes::{PageIndex, PageOffset, RowPointer, SquashedOffset};
use std::collections::BTreeSet;
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/benches/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use spacetimedb::error::DBError;
use spacetimedb::execution_context::Workload;
use spacetimedb::host::module_host::DatabaseTableUpdate;
use spacetimedb::identity::AuthCtx;
use spacetimedb::messages::websocket::BsatnFormat;
Expand All @@ -12,6 +11,7 @@ use spacetimedb::subscription::{collect_table_update, TableUpdateType};
use spacetimedb::{db::relational_db::RelationalDB, messages::websocket::Compression};
use spacetimedb_bench::database::BenchDatabase as _;
use spacetimedb_bench::spacetime_raw::SpacetimeRaw;
use spacetimedb_datastore::execution_context::Workload;
use spacetimedb_execution::pipelined::PipelinedProject;
use spacetimedb_primitives::{col_list, TableId};
use spacetimedb_query::compile_subscription;
Expand Down
2 changes: 1 addition & 1 deletion crates/bench/src/spacetime_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
ResultBench,
};
use spacetimedb::db::relational_db::{tests_utils::TestDB, RelationalDB};
use spacetimedb::execution_context::Workload;
use spacetimedb_datastore::execution_context::Workload;
use spacetimedb_primitives::{ColId, IndexId, TableId};
use spacetimedb_sats::{bsatn, AlgebraicValue};
use spacetimedb_schema::{
Expand Down
1 change: 1 addition & 0 deletions crates/client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "The HTTP API for SpacetimeDB"
spacetimedb-client-api-messages.workspace = true
spacetimedb-core.workspace = true
spacetimedb-data-structures.workspace = true
spacetimedb-datastore.workspace = true
spacetimedb-lib = { workspace = true, features = ["serde"] }
spacetimedb-paths.workspace = true
spacetimedb-schema.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/client-api/src/routes/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ use spacetimedb::client::{
ClientActorId, ClientConfig, ClientConnection, DataMessage, MessageExecutionError, MessageHandleError,
MeteredReceiver, Protocol,
};
use spacetimedb::execution_context::WorkloadType;
use spacetimedb::host::module_host::ClientConnectedError;
use spacetimedb::host::NoSuchModule;
use spacetimedb::util::spawn_rayon;
use spacetimedb::worker_metrics::WORKER_METRICS;
use spacetimedb::Identity;
use spacetimedb_client_api_messages::websocket::{self as ws_api, Compression};
use spacetimedb_datastore::execution_context::WorkloadType;
use spacetimedb_lib::connection_id::{ConnectionId, ConnectionIdForUrl};
use std::time::Instant;
use tokio::sync::{mpsc, watch};
Expand Down
3 changes: 2 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spacetimedb-data-structures.workspace = true
spacetimedb-lib = { workspace = true, features = ["serde", "metrics_impls"] }
spacetimedb-client-api-messages.workspace = true
spacetimedb-commitlog.workspace = true
spacetimedb-datastore.workspace = true
spacetimedb-durability.workspace = true
spacetimedb-memory-usage.workspace = true
spacetimedb-metrics.workspace = true
Expand Down Expand Up @@ -131,7 +132,7 @@ default = ["unindexed_iter_by_col_range_warn"]
# Enable timing for wasm ABI calls
spacetimedb-wasm-instance-env-times = []
# Enable test helpers and utils
test = ["spacetimedb-commitlog/test"]
test = ["spacetimedb-commitlog/test", "spacetimedb-datastore/test"]
# Perfmaps for profiling modules
perfmap = []

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/client/message_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::messages::{SubscriptionUpdateMessage, SwitchedServerMessage, ToProtocol, TransactionUpdateMessage};
use super::{ClientConnection, DataMessage, Protocol};
use crate::energy::EnergyQuanta;
use crate::execution_context::WorkloadType;
use crate::host::module_host::{EventStatus, ModuleEvent, ModuleFunctionCall};
use crate::host::{ReducerArgs, ReducerId};
use crate::identity::Identity;
use crate::messages::websocket::{CallReducer, ClientMessage, OneOffQuery};
use crate::worker_metrics::WORKER_METRICS;
use spacetimedb_datastore::execution_context::WorkloadType;
use spacetimedb_lib::de::serde::DeserializeWrapper;
use spacetimedb_lib::identity::RequestId;
use spacetimedb_lib::{bsatn, ConnectionId, Timestamp};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/client/messages.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{ClientConfig, DataMessage, Protocol};
use crate::execution_context::WorkloadType;
use crate::host::module_host::{EventStatus, ModuleEvent};
use crate::host::ArgsTuple;
use crate::messages::websocket as ws;
Expand All @@ -10,6 +9,7 @@ use spacetimedb_client_api_messages::websocket::{
BsatnFormat, Compression, FormatSwitch, JsonFormat, OneOffTable, RowListLen, WebsocketFormat,
SERVER_MSG_COMPRESSION_TAG_BROTLI, SERVER_MSG_COMPRESSION_TAG_GZIP, SERVER_MSG_COMPRESSION_TAG_NONE,
};
use spacetimedb_datastore::execution_context::WorkloadType;
use spacetimedb_lib::identity::RequestId;
use spacetimedb_lib::ser::serde::SerializeWrapper;
use spacetimedb_lib::{ConnectionId, TimeDuration};
Expand Down
10 changes: 3 additions & 7 deletions crates/core/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ use std::sync::Arc;
use enum_map::EnumMap;
use tokio::sync::mpsc;

use crate::{
db::datastore::{locking_tx_datastore::datastore::TxMetrics, traits::TxData},
execution_context::WorkloadType,
subscription::ExecutionCounters,
};
use crate::subscription::ExecutionCounters;
use spacetimedb_datastore::execution_context::WorkloadType;
use spacetimedb_datastore::{locking_tx_datastore::datastore::TxMetrics, traits::TxData};

pub mod datastore;
pub mod db_metrics;
pub mod relational_db;
pub mod update;
Comment thread
cloutiertyler marked this conversation as resolved.

Expand Down
69 changes: 36 additions & 33 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
use super::datastore::error::{DatastoreError, TableError};
use super::datastore::locking_tx_datastore::committed_state::CommittedState;
use super::datastore::locking_tx_datastore::datastore::TxMetrics;
use super::datastore::locking_tx_datastore::state_view::{
IterByColEqMutTx, IterByColRangeMutTx, IterMutTx, IterTx, StateView,
};
use super::datastore::system_tables::{StFields, StVarFields, StVarName, StVarRow, ST_MODULE_ID, ST_VAR_ID};
use super::datastore::traits::{
InsertFlags, IsolationLevel, Metadata, MutTx as _, MutTxDatastore, Program, RowTypeForTable, Tx as _, TxDatastore,
UpdateFlags,
};
use super::datastore::{
locking_tx_datastore::{
datastore::Locking,
state_view::{IterByColEqTx, IterByColRangeTx},
},
traits::TxData,
};
use super::db_metrics::DB_METRICS;
use crate::db::datastore::system_tables::StModuleRow;
use crate::db::MetricsRecorderQueue;
use crate::error::{DBError, DatabaseError, RestoreSnapshotError};
use crate::execution_context::{ReducerContext, Workload, WorkloadType};
use crate::messages::control_db::HostType;
use crate::subscription::ExecutionCounters;
use crate::util::{asyncify, spawn_rayon};
Expand All @@ -31,6 +10,28 @@ use futures::channel::mpsc;
use futures::StreamExt;
use parking_lot::RwLock;
use spacetimedb_commitlog as commitlog;
use spacetimedb_datastore::db_metrics::DB_METRICS;
use spacetimedb_datastore::error::{DatastoreError, TableError};
use spacetimedb_datastore::execution_context::{ReducerContext, Workload, WorkloadType};
use spacetimedb_datastore::locking_tx_datastore::committed_state::CommittedState;
use spacetimedb_datastore::locking_tx_datastore::datastore::TxMetrics;
use spacetimedb_datastore::locking_tx_datastore::state_view::{
IterByColEqMutTx, IterByColRangeMutTx, IterMutTx, IterTx, StateView,
};
use spacetimedb_datastore::locking_tx_datastore::{MutTxId, TxId};
use spacetimedb_datastore::system_tables::StModuleRow;
use spacetimedb_datastore::system_tables::{StFields, StVarFields, StVarName, StVarRow, ST_MODULE_ID, ST_VAR_ID};
use spacetimedb_datastore::traits::{
InsertFlags, IsolationLevel, Metadata, MutTx as _, MutTxDatastore, Program, RowTypeForTable, Tx as _, TxDatastore,
UpdateFlags,
};
use spacetimedb_datastore::{
locking_tx_datastore::{
datastore::Locking,
state_view::{IterByColEqTx, IterByColRangeTx},
},
traits::TxData,
};
use spacetimedb_durability::{self as durability, TxOffset};
use spacetimedb_lib::db::auth::StAccess;
use spacetimedb_lib::db::raw_def::v9::{btree, RawModuleDefV9Builder, RawSql};
Expand Down Expand Up @@ -62,8 +63,10 @@ use std::path::Path;
use std::sync::Arc;
use tokio::sync::watch;

pub type MutTx = <Locking as super::datastore::traits::MutTx>::MutTx;
pub type Tx = <Locking as super::datastore::traits::Tx>::Tx;
// NOTE(cloutiertyler): We should be using the associated types, but there is
// a bug in the Rust compiler that prevents us from doing so.
pub type MutTx = MutTxId; //<Locking as spacetimedb_datastore::traits::MutTx>::MutTx;
pub type Tx = TxId; //<Locking as spacetimedb_datastore::traits::Tx>::Tx;

type RowCountFn = Arc<dyn Fn(TableId, &str) -> i64 + Send + Sync>;

Expand Down Expand Up @@ -855,7 +858,7 @@ impl RelationalDB {
/// If `(tx_data, ctx)` should be appended to the commitlog, do so.
///
/// Note that by this stage,
/// [`crate::db::datastore::locking_tx_datastore::committed_state::tx_consumes_offset`]
/// [`spacetimedb_datastore::locking_tx_datastore::committed_state::tx_consumes_offset`]
/// has already decided based on the reducer and operations whether the transaction should be appended;
/// this method is responsible only for reading its decision out of the `tx_data`
/// and calling `durability.append_tx`.
Expand Down Expand Up @@ -1682,10 +1685,10 @@ fn default_row_count_fn(db: Identity) -> RowCountFn {
#[cfg(any(test, feature = "test"))]
pub mod tests_utils {
use super::*;
use crate::db::datastore::locking_tx_datastore::tx::TxId;
use crate::db::datastore::locking_tx_datastore::MutTxId;
use core::ops::Deref;
use durability::EmptyHistory;
use spacetimedb_datastore::locking_tx_datastore::MutTxId;
use spacetimedb_datastore::locking_tx_datastore::TxId;
use spacetimedb_fs_utils::compression::CompressType;
use spacetimedb_lib::{bsatn::to_vec, ser::Serialize};
use spacetimedb_paths::server::SnapshotDirPath;
Expand Down Expand Up @@ -2065,22 +2068,22 @@ mod tests {

use super::tests_utils::begin_mut_tx;
use super::*;
use crate::db::datastore::error::{DatastoreError, IndexError};
use crate::db::datastore::system_tables::{
system_tables, StConstraintRow, StIndexRow, StSequenceRow, StTableRow, ST_CONSTRAINT_ID, ST_INDEX_ID,
ST_SEQUENCE_ID, ST_TABLE_ID,
};
use crate::db::relational_db::tests_utils::{
begin_tx, insert, make_snapshot, with_auto_commit, with_read_only, TestDB,
};
use crate::execution_context::ReducerContext;
use anyhow::bail;
use bytes::Bytes;
use commitlog::payload::txdata;
use commitlog::Commitlog;
use durability::EmptyHistory;
use pretty_assertions::{assert_eq, assert_matches};
use spacetimedb_data_structures::map::IntMap;
use spacetimedb_datastore::error::{DatastoreError, IndexError};
use spacetimedb_datastore::execution_context::ReducerContext;
use spacetimedb_datastore::system_tables::{
system_tables, StConstraintRow, StIndexRow, StSequenceRow, StTableRow, ST_CONSTRAINT_ID, ST_INDEX_ID,
ST_SEQUENCE_ID, ST_TABLE_ID,
};
use spacetimedb_fs_utils::compression::{CompressCount, CompressType};
use spacetimedb_lib::db::raw_def::v9::{btree, RawTableDefBuilder};
use spacetimedb_lib::error::ResultTest;
Expand Down Expand Up @@ -2983,7 +2986,7 @@ mod tests {
/// fixed a bug where replaying deletes to `st_client` would fail due to an unpopulated index.
#[test]
fn replay_delete_from_st_client() {
use crate::db::datastore::system_tables::{StClientRow, ST_CLIENT_ID};
use spacetimedb_datastore::system_tables::{StClientRow, ST_CLIENT_ID};

let row_0 = StClientRow {
identity: Identity::ZERO.into(),
Expand Down
8 changes: 3 additions & 5 deletions crates/core/src/db/update.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::datastore::locking_tx_datastore::MutTxId;
use super::relational_db::RelationalDB;
use crate::database_logger::SystemLogger;
use crate::sql::parser::RowLevelExpr;
use spacetimedb_data_structures::map::HashMap;
use spacetimedb_datastore::locking_tx_datastore::MutTxId;
use spacetimedb_lib::db::auth::StTableType;
use spacetimedb_lib::identity::AuthCtx;
use spacetimedb_lib::AlgebraicValue;
Expand Down Expand Up @@ -263,12 +263,10 @@ fn auto_migrate_database(
mod test {
use super::*;
use crate::{
db::{
datastore::locking_tx_datastore::PendingSchemaChange,
relational_db::tests_utils::{begin_mut_tx, insert, TestDB},
},
db::relational_db::tests_utils::{begin_mut_tx, insert, TestDB},
host::module_host::create_table_from_def,
};
use spacetimedb_datastore::locking_tx_datastore::PendingSchemaChange;
use spacetimedb_lib::db::raw_def::v9::{btree, RawModuleDefV9Builder, TableAccess};
use spacetimedb_sats::{product, AlgebraicType::U64};
use spacetimedb_schema::{auto_migrate::ponder_migrate, def::ModuleDef};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use spacetimedb_schema::relation::FieldName;
use spacetimedb_vm::errors::{ErrorKind, ErrorLang, ErrorType, ErrorVm};
use spacetimedb_vm::expr::Crud;

pub use crate::db::datastore::error::{DatastoreError, IndexError, SequenceError, TableError};
pub use spacetimedb_datastore::error::{DatastoreError, IndexError, SequenceError, TableError};

#[derive(Error, Debug, PartialEq, Eq)]
pub enum ClientError {
Expand Down
Loading
Loading