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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
sudo chmod 777 /stdb

- name: Run cargo test
run: cargo test --all --features odb_rocksdb,odb_sled,tracelogging
run: cargo test --all --features odb_rocksdb,odb_sled

lints:
name: Lints
Expand All @@ -52,7 +52,7 @@ jobs:
run: cargo fmt --all -- --check

- name: Run cargo clippy
run: cargo clippy --all --tests --features odb_rocksdb,odb_sled,tracelogging -- -D warnings
run: cargo clippy --all --tests --features odb_rocksdb,odb_sled -- -D warnings

wasm_bindings:
name: Build and test wasm bindings
Expand Down
10 changes: 0 additions & 10 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ members = [
"crates/sats",
"crates/testing",
"crates/vm",
"crates/replay",
"crates/client-api",
"crates/sdk",
"crates/client-api-messages",
Expand Down
1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ wasmtime.workspace = true
insta.workspace = true

[features]
tracelogging = []
standalone = ["spacetimedb-standalone"]
default = ["standalone"]
4 changes: 0 additions & 4 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pub fn get_subcommands() -> Vec<Command> {
list::cli(),
init::cli(),
build::cli(),
#[cfg(feature = "tracelogging")]
tracelog::cli(),
server::cli(),
#[cfg(feature = "standalone")]
start::cli(ProgramMode::CLI),
Expand All @@ -54,8 +52,6 @@ pub async fn exec_subcommand(config: Config, cmd: &str, args: &ArgMatches) -> Re
"init" => init::exec(config, args).await,
"build" => build::exec(config, args).await,
"server" => server::exec(config, args).await,
#[cfg(feature = "tracelogging")]
"tracelog" => tracelog::exec(config, args).await,
#[cfg(feature = "standalone")]
"start" => start::exec(args).await,
unknown => Err(anyhow::anyhow!("Invalid subcommand: {}", unknown)),
Expand Down
3 changes: 0 additions & 3 deletions crates/cli/src/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ pub mod repl;
pub mod server;
pub mod sql;
pub mod version;

#[cfg(feature = "tracelogging")]
pub mod tracelog;
3 changes: 0 additions & 3 deletions crates/client-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ edition = "2021"
license-file = "LICENSE"
description = "The HTTP API for SpacetimeDB"

[features]
tracelogging = ["spacetimedb-core/tracelogging"]

[dependencies]
spacetimedb-core = { path = "../core", version = "0.6.1" }
tokio = { version = "1.2", features = ["full"] }
Expand Down
1 change: 0 additions & 1 deletion crates/client-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ pub trait ControlCtx: ControlNodeDelegate + Send + Sync {
host_type: HostType,
num_replicas: u32,
force: bool,
trace_log: bool,
) -> Result<(), anyhow::Error>;

async fn update_database(
Expand Down
16 changes: 0 additions & 16 deletions crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,21 +761,10 @@ pub struct PublishDatabaseQueryParams {
#[serde(default)]
clear: bool,
name_or_address: Option<NameOrAddress>,
trace_log: Option<bool>,
#[serde(default)]
register_tld: bool,
}

#[cfg(not(feature = "tracelogging"))]
fn should_trace(_trace_log: Option<bool>) -> bool {
false
}

#[cfg(feature = "tracelogging")]
fn should_trace(trace_log: Option<bool>) -> bool {
trace_log.unwrap_or(false)
}

pub async fn publish(
State(ctx): State<Arc<dyn ControlCtx>>,
Path(PublishDatabaseParams {}): Path<PublishDatabaseParams>,
Expand All @@ -787,7 +776,6 @@ pub async fn publish(
name_or_address,
host_type,
clear,
trace_log,
register_tld,
} = query_params;

Expand Down Expand Up @@ -841,8 +829,6 @@ pub async fn publish(

let num_replicas = 1;

let trace_log = should_trace(trace_log);

let op = match control_ctx_find_database(&*ctx, &db_address).await? {
Some(db) => {
if db.identity != auth.identity {
Expand All @@ -857,7 +843,6 @@ pub async fn publish(
host_type,
num_replicas,
clear,
trace_log,
)
.await
.map_err(log_and_500)?;
Expand Down Expand Up @@ -905,7 +890,6 @@ pub async fn publish(
host_type,
num_replicas,
false,
trace_log,
)
.await
.map_err(log_and_500)?;
Expand Down
3 changes: 0 additions & 3 deletions crates/client-api/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ pub mod identity;
pub mod metrics;
pub mod prometheus;
pub mod subscribe;

#[cfg(feature = "tracelogging")]
pub mod tracelog;
3 changes: 1 addition & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ rocksdb = {workspace = true, optional = true}
# Optional storage engines.
odb_rocksdb = ["dep:rocksdb"]
odb_sled = []
tracelogging = []
default = ["tracelogging", "odb_sled"]
default = ["odb_sled"]

[dev-dependencies]
rusqlite.workspace = true
Expand Down
4 changes: 0 additions & 4 deletions crates/core/src/database_instance_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::sync::{Arc, Mutex};
pub struct DatabaseInstanceContext {
pub database_instance_id: u64,
pub database_id: u64,
pub trace_log: bool,
pub identity: Identity,
pub address: Address,
pub logger: Arc<Mutex<DatabaseLogger>>,
Expand All @@ -34,7 +33,6 @@ impl DatabaseInstanceContext {
storage,
instance_id,
database.id,
database.trace_log,
database.identity,
database.address,
db_path,
Expand All @@ -54,7 +52,6 @@ impl DatabaseInstanceContext {
storage: Storage,
database_instance_id: u64,
database_id: u64,
trace_log: bool,
identity: Identity,
address: Address,
db_path: PathBuf,
Expand All @@ -80,7 +77,6 @@ impl DatabaseInstanceContext {
Arc::new(Self {
database_instance_id,
database_id,
trace_log,
identity,
address,
logger: Arc::new(Mutex::new(DatabaseLogger::open(log_path))),
Expand Down
16 changes: 0 additions & 16 deletions crates/core/src/host/host_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,6 @@ impl HostController {
fn take_module_host(&self, instance_id: u64) -> Option<ModuleHost> {
self.modules.lock().unwrap().remove(&instance_id)
}

/// If a module's DB activity is being traced (for diagnostics etc.), retrieves the current contents of its trace stream.
#[cfg(feature = "tracelogging")]
pub async fn get_trace(&self, instance_id: u64) -> Result<Option<bytes::Bytes>, anyhow::Error> {
let module_host = self.get_module_host(instance_id)?;
let trace = module_host.get_trace().await.unwrap();
Ok(trace)
}

/// If a module's DB activity is being traced (for diagnostics etc.), stop tracing it.
#[cfg(feature = "tracelogging")]
pub async fn stop_trace(&self, instance_id: u64) -> Result<(), anyhow::Error> {
let module_host = self.get_module_host(instance_id)?;
module_host.stop_trace().await.unwrap();
Ok(())
}
}

impl Default for HostController {
Expand Down
65 changes: 2 additions & 63 deletions crates/core/src/host/instance_env.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
use parking_lot::{Mutex, MutexGuard};
use prometheus::HistogramVec;
use spacetimedb_lib::{bsatn, ProductValue};
use std::ops::DerefMut;
use std::sync::Arc;
use std::time::SystemTime;

use crate::database_instance_context::DatabaseInstanceContext;
use crate::database_logger::{BacktraceProvider, LogLevel, Record};
use crate::db::datastore::locking_tx_datastore::MutTxId;
use crate::db::datastore::traits::{DataRow, IndexDef};
use crate::error::{IndexError, NodesError};
use crate::util::prometheus_handle::HistogramVecHandle;
use crate::util::ResultInspectExt;
use crate::worker_metrics::{INSTANCE_ENV_DELETE_BY_COL_EQ, INSTANCE_ENV_INSERT};

use super::scheduler::{ScheduleError, ScheduledReducerId, Scheduler};
use super::timestamp::Timestamp;
use super::tracelog::instance_trace::TraceLog;
use crate::vm::DbProgram;
use spacetimedb_lib::filter::CmpArgs;
use spacetimedb_lib::identity::AuthCtx;
Expand All @@ -30,7 +25,6 @@ pub struct InstanceEnv {
pub dbic: Arc<DatabaseInstanceContext>,
pub scheduler: Scheduler,
pub tx: TxSlot,
pub trace_log: Option<Arc<Mutex<TraceLog>>>,
}

#[derive(Clone, Default)]
Expand All @@ -40,16 +34,11 @@ pub struct TxSlot {

// Generic 'instance environment' delegated to from various host types.
impl InstanceEnv {
pub fn new(
dbic: Arc<DatabaseInstanceContext>,
scheduler: Scheduler,
trace_log: Option<Arc<Mutex<TraceLog>>>,
) -> Self {
pub fn new(dbic: Arc<DatabaseInstanceContext>, scheduler: Scheduler) -> Self {
Self {
dbic,
scheduler,
tx: TxSlot::default(),
trace_log,
}
}

Expand Down Expand Up @@ -78,25 +67,7 @@ impl InstanceEnv {
log::trace!("MOD({}): {}", self.dbic.address.to_abbreviated_hex(), record.message);
}

/// Starts histogram prometheus measurements for `table_id`.
fn measure(&self, table_id: u32, hist: &'static HistogramVec) -> HistogramVecHandle {
let values = vec![self.dbic.address.to_hex(), format!("{}", table_id)];
let mut measure = HistogramVecHandle::new(hist, values);
measure.start();
measure
}

/// When we have a `TraceLog` available,
/// run the provided `logic` on it.
fn with_trace_log(&self, logic: impl FnOnce(&mut TraceLog)) {
if let Some(trace_log) = &self.trace_log {
logic(&mut trace_log.lock());
}
}

pub fn insert(&self, table_id: u32, buffer: &[u8]) -> Result<ProductValue, NodesError> {
let measure = self.measure(table_id, &INSTANCE_ENV_INSERT);

let stdb = &*self.dbic.relational_db;
let tx = &mut *self.get_tx()?;

Expand All @@ -119,15 +90,6 @@ impl InstanceEnv {
}
})?;

self.with_trace_log(|l| {
l.insert(
measure.start_instant.unwrap(),
measure.elapsed(),
table_id,
buffer.into(),
)
});

Ok(ret)
}

Expand Down Expand Up @@ -182,8 +144,6 @@ impl InstanceEnv {
/// Returns an error if no columns were deleted or if the column wasn't found.
#[tracing::instrument(skip_all)]
pub fn delete_by_col_eq(&self, table_id: u32, col_id: u32, value: &[u8]) -> Result<u32, NodesError> {
let measure = self.measure(table_id, &INSTANCE_ENV_DELETE_BY_COL_EQ);

let stdb = &*self.dbic.relational_db;
let tx = &mut *self.get_tx()?;

Expand All @@ -200,17 +160,6 @@ impl InstanceEnv {
.inspect_err_(|e| log::error!("delete_by_col_eq(table_id: {table_id}): {e}"))?
.ok_or(NodesError::ColumnValueNotFound)?;

self.with_trace_log(|l| {
l.delete_by_col_eq(
measure.start_instant.unwrap(),
measure.elapsed(),
table_id,
col_id,
value.into(),
count,
)
});

Ok(count)
}

Expand Down Expand Up @@ -285,8 +234,6 @@ impl InstanceEnv {
/// Errors with `TableNotFound` if the table does not exist.
#[tracing::instrument(skip_all)]
pub fn get_table_id(&self, table_name: String) -> Result<u32, NodesError> {
let now = SystemTime::now();

let stdb = &*self.dbic.relational_db;
let tx = &mut *self.get_tx()?;

Expand All @@ -295,8 +242,6 @@ impl InstanceEnv {
.table_id_from_name(tx, &table_name)?
.ok_or(NodesError::TableNotFound)?;

self.with_trace_log(|l| l.get_table_id(now, now.elapsed().unwrap(), table_name, table_id));

Ok(table_id)
}

Expand All @@ -318,8 +263,6 @@ impl InstanceEnv {
index_type: u8,
col_ids: Vec<u8>,
) -> Result<(), NodesError> {
let now = SystemTime::now();

let stdb = &*self.dbic.relational_db;
let tx = &mut *self.get_tx()?;

Expand Down Expand Up @@ -347,16 +290,12 @@ impl InstanceEnv {
let index = IndexDef {
table_id,
col_id,
name: index_name.clone(),
name: index_name,
is_unique,
};

stdb.create_index(tx, index)?;

self.with_trace_log(|l| {
l.create_index(now, now.elapsed().unwrap(), index_name, table_id, index_type, &col_ids)
});

Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion crates/core/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mod wasmer;
// Visible for integration testing.
pub mod instance_env;
mod timestamp;
pub mod tracelog;
mod wasm_common;

pub use host_controller::{
Expand Down
Loading