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
15 changes: 15 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ enum-map = "2.6.3"
env_logger = "0.10"
ethnum = { version = "1.5.0", features = ["serde"] }
flate2 = "1.0.24"
flume = { version = "0.11", default-features = false, features = ["async"] }
foldhash = "0.1.4"
fs-err = "2.9.0"
fs_extra = "1.3.0"
Expand Down
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dirs.workspace = true
enum-as-inner.workspace = true
enum-map.workspace = true
flate2.workspace = true
flume.workspace = true
fs2.workspace = true
futures.workspace = true
futures-util.workspace = true
Expand Down
47 changes: 27 additions & 20 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ 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::{system_tables, StModuleRow};
use spacetimedb_datastore::system_tables::{
system_tables, StModuleRow, ST_CLIENT_ID, ST_CONNECTION_CREDENTIALS_ID, ST_VIEW_SUB_ID,
};
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,
Expand Down Expand Up @@ -1406,7 +1408,7 @@ impl RelationalDB {
self.inner.delete_by_rel_mut_tx(tx, table_id, relation)
}

/// Clear all rows from a table without dropping it.
/// Clears all rows from a table without dropping it.
pub fn clear_table(&self, tx: &mut MutTx, table_id: TableId) -> Result<usize, DBError> {
let rows_deleted = tx.clear_table(table_id)?;
Ok(rows_deleted)
Expand All @@ -1417,6 +1419,17 @@ impl RelationalDB {
Ok(tx.clear_all_views()?)
}

/// Empties the system tables tracking clients.
pub fn clear_all_clients(&self) -> Result<(), DBError> {
self.with_auto_commit(Workload::Internal, |mut_tx| {
self.clear_all_views(mut_tx)?;
self.clear_table(mut_tx, ST_CONNECTION_CREDENTIALS_ID)?;
self.clear_table(mut_tx, ST_CLIENT_ID)?;
self.clear_table(mut_tx, ST_VIEW_SUB_ID)?;
Ok(())
})
}

pub fn create_sequence(&self, tx: &mut MutTx, sequence_schema: SequenceSchema) -> Result<SequenceId, DBError> {
Ok(self.inner.create_sequence_mut_tx(tx, sequence_schema)?)
}
Expand Down Expand Up @@ -3049,43 +3062,37 @@ mod tests {
let stdb = TestDB::durable().expect("failed to create TestDB");

let timestamp = Timestamp::now();
let ctx = ReducerContext {
name: "abstract_concrete_proxy_factory_impl".into(),
caller_identity: Identity::__dummy(),
caller_connection_id: ConnectionId::ZERO,
timestamp,
arg_bsatn: Bytes::new(),
let workload = |name: &str| {
Workload::Reducer(ReducerContext {
name: name.into(),
caller_identity: Identity::__dummy(),
caller_connection_id: ConnectionId::ZERO,
timestamp,
arg_bsatn: Bytes::new(),
})
};
let workload1 = workload("abstract_concrete_proxy_factory_impl");

let row_ty = ProductType::from([("le_boeuf", AlgebraicType::I32)]);
let schema = table("test_table", row_ty.clone(), |builder| builder);

// Create an empty transaction
{
let tx = stdb.begin_mut_tx(IsolationLevel::Serializable, Workload::Reducer(ctx.clone()));
let tx = stdb.begin_mut_tx(IsolationLevel::Serializable, workload1.clone());
stdb.commit_tx(tx).expect("failed to commit empty transaction");
}

// Create an empty transaction pretending to be an
// `__identity_connected__` call.
{
let tx = stdb.begin_mut_tx(
IsolationLevel::Serializable,
Workload::Reducer(ReducerContext {
name: "__identity_connected__".into(),
caller_identity: Identity::__dummy(),
caller_connection_id: ConnectionId::ZERO,
timestamp,
arg_bsatn: Bytes::new(),
}),
);
let tx = stdb.begin_mut_tx(IsolationLevel::Serializable, workload("__identity_connected__"));
stdb.commit_tx(tx)
.expect("failed to commit empty __identity_connected__ transaction");
}

// Create a non-empty transaction including reducer info
let table_id = {
let mut tx = stdb.begin_mut_tx(IsolationLevel::Serializable, Workload::Reducer(ctx));
let mut tx = stdb.begin_mut_tx(IsolationLevel::Serializable, workload1);
let table_id = stdb.create_table(&mut tx, schema).expect("failed to create table");
insert(&stdb, &mut tx, table_id, &product!(AlgebraicValue::I32(0))).expect("failed to insert row");
stdb.commit_tx(tx).expect("failed to commit tx");
Expand Down
Loading
Loading