diff --git a/docs/api/error-registry.json b/docs/api/error-registry.json index 1c17f27ef7..55ff5027eb 100644 --- a/docs/api/error-registry.json +++ b/docs/api/error-registry.json @@ -1392,11 +1392,26 @@ "message": "SQLite database is closed.", "statuses": [] }, + { + "code": "deferred_commits_unsupported", + "message": "SQLite deferred commits are unavailable.", + "statuses": [] + }, + { + "code": "durability_failed", + "message": "SQLite commits could not be made durable.", + "statuses": [] + }, { "code": "invalid_bind_parameter", "message": "Invalid SQLite bind parameter.", "statuses": [] }, + { + "code": "invalid_commit_ticket", + "message": "Invalid SQLite commit ticket.", + "statuses": [] + }, { "code": "invalid_compile_options", "message": "SQLite requires SQLITE_ENABLE_BATCH_ATOMIC_WRITE and SQLITE_DIRECT_OVERFLOW_READ=0. Rebuild with LIBSQLITE3_FLAGS=\"SQLITE_ENABLE_BATCH_ATOMIC_WRITE SQLITE_DIRECT_OVERFLOW_READ=0\".", @@ -1432,6 +1447,11 @@ "message": "Remote SQLite is unavailable.", "statuses": [] }, + { + "code": "statement_failed", + "message": "SQLite statement failed.", + "statuses": [] + }, { "code": "storage_overloaded", "message": "SQLite storage is overloaded.", @@ -1442,6 +1462,11 @@ "message": "SQLite storage timed out.", "statuses": [] }, + { + "code": "sync_unsupported", + "message": "Synchronous SQLite is unavailable.", + "statuses": [] + }, { "code": "transaction_closed", "message": "SQLite transaction coordinator is closed.", diff --git a/engine/artifacts/errors/sqlite.deferred_commits_unsupported.json b/engine/artifacts/errors/sqlite.deferred_commits_unsupported.json new file mode 100644 index 0000000000..92202cd95b --- /dev/null +++ b/engine/artifacts/errors/sqlite.deferred_commits_unsupported.json @@ -0,0 +1,5 @@ +{ + "code": "deferred_commits_unsupported", + "group": "sqlite", + "message": "SQLite deferred commits are unavailable." +} \ No newline at end of file diff --git a/engine/artifacts/errors/sqlite.durability_failed.json b/engine/artifacts/errors/sqlite.durability_failed.json new file mode 100644 index 0000000000..63c14c7e6b --- /dev/null +++ b/engine/artifacts/errors/sqlite.durability_failed.json @@ -0,0 +1,5 @@ +{ + "code": "durability_failed", + "group": "sqlite", + "message": "SQLite commits could not be made durable." +} \ No newline at end of file diff --git a/engine/artifacts/errors/sqlite.invalid_commit_ticket.json b/engine/artifacts/errors/sqlite.invalid_commit_ticket.json new file mode 100644 index 0000000000..7fe23ed12d --- /dev/null +++ b/engine/artifacts/errors/sqlite.invalid_commit_ticket.json @@ -0,0 +1,5 @@ +{ + "code": "invalid_commit_ticket", + "group": "sqlite", + "message": "Invalid SQLite commit ticket." +} \ No newline at end of file diff --git a/engine/artifacts/errors/sqlite.statement_failed.json b/engine/artifacts/errors/sqlite.statement_failed.json new file mode 100644 index 0000000000..780242668a --- /dev/null +++ b/engine/artifacts/errors/sqlite.statement_failed.json @@ -0,0 +1,5 @@ +{ + "code": "statement_failed", + "group": "sqlite", + "message": "SQLite statement failed." +} \ No newline at end of file diff --git a/engine/artifacts/errors/sqlite.sync_unsupported.json b/engine/artifacts/errors/sqlite.sync_unsupported.json new file mode 100644 index 0000000000..42e3436059 --- /dev/null +++ b/engine/artifacts/errors/sqlite.sync_unsupported.json @@ -0,0 +1,5 @@ +{ + "code": "sync_unsupported", + "group": "sqlite", + "message": "Synchronous SQLite is unavailable." +} \ No newline at end of file diff --git a/engine/packages/sqlite-embedded/src/query.rs b/engine/packages/sqlite-embedded/src/query.rs index 5a8c895741..7a85f5f3d5 100644 --- a/engine/packages/sqlite-embedded/src/query.rs +++ b/engine/packages/sqlite-embedded/src/query.rs @@ -1,7 +1,7 @@ use std::error::Error; use std::ffi::{CStr, CString}; use std::fmt; -use std::os::raw::c_char; +use std::os::raw::{c_char, c_int}; use std::ptr; use anyhow::{Result, anyhow}; @@ -29,9 +29,14 @@ pub struct SqliteQueryProfile { #[derive(Debug)] pub struct SqliteStatementError { + /// SQLite's extended result code, or -1 when the error did not come from SQLite. pub code: i32, pub statement_index: u32, pub message: String, + /// SQLite's own message, without the operation that failed. + pub detail: String, + /// Byte offset into the statement's SQL of the token SQLite blamed, when it named one. + pub offset: Option, } impl fmt::Display for SqliteStatementError { @@ -262,6 +267,8 @@ pub fn execute_single_statement( code: -1, statement_index: 0, message: "sqlite execute only supports a single statement".to_owned(), + detail: "sqlite execute only supports a single statement".to_owned(), + offset: None, } .into()); } @@ -331,6 +338,8 @@ pub fn execute_single_statement_profiled( code: -1, statement_index: 0, message: "sqlite execute only supports a single statement".to_owned(), + detail: "sqlite execute only supports a single statement".to_owned(), + offset: None, } .into()); } @@ -877,16 +886,23 @@ fn has_non_whitespace_tail(tail: *const c_char) -> bool { bytes.iter().any(|byte| !byte.is_ascii_whitespace()) } +// The bundled SQLite has `sqlite3_error_offset`, but libsqlite3-sys's default bindings target an +// older SQLite that predates it. +unsafe extern "C" { + fn sqlite3_error_offset(db: *mut sqlite3) -> c_int; +} + fn sqlite_error(db: *mut sqlite3, statement_index: u32, context: &str) -> anyhow::Error { - let (code, detail) = unsafe { + let (code, detail, offset) = unsafe { if db.is_null() { - (-1, "unknown sqlite error".to_string()) + (-1, "unknown sqlite error".to_string(), -1) } else { ( sqlite3_extended_errcode(db), CStr::from_ptr(sqlite3_errmsg(db)) .to_string_lossy() .into_owned(), + sqlite3_error_offset(db), ) } }; @@ -894,6 +910,8 @@ fn sqlite_error(db: *mut sqlite3, statement_index: u32, context: &str) -> anyhow code, statement_index, message: format!("{context}: {detail}"), + detail, + offset: u32::try_from(offset).ok(), } .into() } diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/config.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/config.rs index 81196dfefd..d93f22696c 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/config.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/config.rs @@ -392,6 +392,10 @@ pub struct ActorConfig { /// on the TS side). Gates the inspector database tab. pub has_database: bool, pub remote_sqlite: bool, + /// Commits SQLite writes locally and makes them durable in the background, so writes and + /// state saves resolve before they are durable. Only for embedders that gate every output + /// on `SqliteDb::when_durable`. Not user-facing. Requires local native SQLite. + pub sqlite_deferred_commits: bool, pub sqlite_profiling: SqliteProfilingConfig, pub tracing: Arc, /// Whether the user declared actor state (`state: ...` or `createState`). @@ -430,6 +434,7 @@ pub struct ActorConfigInput { pub icon: Option, pub has_database: Option, pub remote_sqlite: Option, + pub sqlite_deferred_commits: Option, pub sqlite_profiling: Option, pub tracing: Option, pub has_state: Option, @@ -462,6 +467,7 @@ impl ActorConfig { icon: config.icon, has_database: config.has_database.unwrap_or(false), remote_sqlite: config.remote_sqlite.unwrap_or(false), + sqlite_deferred_commits: config.sqlite_deferred_commits.unwrap_or(false), sqlite_profiling: config .sqlite_profiling .map(SqliteProfilingConfig::from_input) @@ -590,6 +596,7 @@ impl Default for ActorConfig { icon: None, has_database: false, remote_sqlite: false, + sqlite_deferred_commits: false, sqlite_profiling: SqliteProfilingConfig::default(), tracing: Arc::default(), has_state: false, diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/schedule.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/schedule.rs index da959aa27a..ac2f0b340b 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/schedule.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/schedule.rs @@ -904,6 +904,7 @@ impl ActorContext { self.next_schedule_timestamp(false).await?, self.run_wake_at(), ); + self.wait_for_durable_schedule().await?; self.sync_alarm_timestamp(next_alarm) } @@ -912,9 +913,24 @@ impl ActorContext { self.next_schedule_timestamp(true).await?, self.run_wake_at(), ); + self.wait_for_durable_schedule().await?; self.sync_alarm_timestamp(next_alarm) } + /// With deferred commits, the schedule rows the next alarm comes from can still be local. + /// Pushing the alarm first could leave the engine, after a crash, without the wakeup of a + /// durable schedule whose cancellation was lost. Awaited commits are durable already. + async fn wait_for_durable_schedule(&self) -> Result<()> { + if !self.0.schedule_dirty_since_push.load(Ordering::SeqCst) { + return Ok(()); + } + let ticket = self.sql().commit_ticket(); + if ticket == 0 { + return Ok(()); + } + self.sql().when_durable(ticket).await + } + /// Pushes `next_alarm` to the engine unless it equals the last alarm this generation /// pushed. A generation starts with no last pushed alarm, so its first sync pushes any /// next alarm; see `force_next_alarm_push`. diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/deferred_bootstrap.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/deferred_bootstrap.rs index a20baf8982..1d4f173b87 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/deferred_bootstrap.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/deferred_bootstrap.rs @@ -55,7 +55,7 @@ impl SqliteDb { return Ok(()); } let transaction = self - .begin_named_transaction(Some(BOOTSTRAP_TRANSACTION_NAME), None) + .begin_internal_transaction(BOOTSTRAP_TRANSACTION_NAME) .await .context("begin deferred sqlite bootstrap")?; transaction diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/mod.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/mod.rs index 424726ef1e..bd78f7c812 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/mod.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/mod.rs @@ -37,8 +37,10 @@ mod envoy_sqlite_transport; pub(crate) mod pool_metrics; #[cfg(feature = "sqlite-local")] pub(crate) mod profiling; +mod sync; mod tx; +pub(crate) use tx::HostThreadLease; pub use tx::{ DEFAULT_TRANSACTION_TIMEOUT, ManualTransactionOpenError, SqliteTransaction, TRANSACTION_COORDINATOR_QUEUE_CAPACITY, TransactionConnectionLostError, @@ -61,11 +63,12 @@ use sqlite_embedded::{ NativeDatabaseHandle, open_database_from_transport_on_pool, open_new_database_from_transport_on_pool, }, + query::SqliteStatementError, vfs::{CommitMode, CorkClose, DatabaseFailure, SqliteVfsMetrics, SqliteVfsMetricsSnapshot}, worker::{ - SQLITE_WORKER_QUEUE_CAPACITY, SqlitePool, SqliteWorkerCloseTimeoutError, - SqliteWorkerClosingError, SqliteWorkerDeadError, SqliteWorkerFatalError, - SqliteWorkerOverloadedError, SqliteWorkerResult, + SQLITE_WORKER_QUEUE_CAPACITY, SqlitePool, SqliteWorkerBusyError, + SqliteWorkerCloseTimeoutError, SqliteWorkerClosingError, SqliteWorkerDeadError, + SqliteWorkerFatalError, SqliteWorkerOverloadedError, SqliteWorkerResult, }, }; @@ -258,11 +261,24 @@ pub struct SqliteDb { /// always sets up sqlite storage under the hood, so handle/actor_id are /// not a reliable signal for whether the user opted in; this flag is. enabled: bool, + /// Opens the local database in deferred-commit mode. See + /// `ActorConfig::sqlite_deferred_commits`. + deferred_commits: bool, + /// Set on handles used from a foreign runtime's host thread. See `sync.rs`. + host_thread: bool, + /// Set on handles that synchronous calls run on. They fail with `sqlite.writer_busy` instead + /// of waiting for the writer gate or for another command, and their commits fail with + /// `sqlite.storage_overloaded` instead of waiting for storage to catch up. + sync_call: bool, invocation_telemetry: Option, #[cfg(feature = "sqlite-local")] // Forced-sync: native SQLite handles are used inside spawn_blocking and // synchronous diagnostic accessors. db: Arc>>, + /// How the native database ended, kept after its handle is released so commit tickets + /// taken before the close still answer. See `sync.rs`. + #[cfg(feature = "sqlite-local")] + closed_db: Arc>>, #[cfg(feature = "sqlite-local")] open_lock: Arc>, #[cfg(feature = "sqlite-local")] @@ -293,10 +309,15 @@ impl Default for SqliteDb { SqliteBackend::RemoteEnvoy }, enabled: false, + deferred_commits: false, + host_thread: false, + sync_call: false, invocation_telemetry: None, #[cfg(feature = "sqlite-local")] db: Default::default(), #[cfg(feature = "sqlite-local")] + closed_db: Default::default(), + #[cfg(feature = "sqlite-local")] open_lock: Default::default(), #[cfg(feature = "sqlite-local")] worker_failure_task: Default::default(), @@ -333,10 +354,15 @@ impl SqliteDb { generation, backend: select_sqlite_backend(remote_sqlite)?, enabled, + deferred_commits: false, + host_thread: false, + sync_call: false, invocation_telemetry: None, #[cfg(feature = "sqlite-local")] db: Default::default(), #[cfg(feature = "sqlite-local")] + closed_db: Default::default(), + #[cfg(feature = "sqlite-local")] open_lock: Default::default(), #[cfg(feature = "sqlite-local")] worker_failure_task: Default::default(), @@ -352,6 +378,16 @@ impl SqliteDb { }) } + /// Opts the database into deferred commits. Fails unless the backend is local native SQLite, + /// because only the native VFS can commit locally. + pub fn with_deferred_commits(mut self, enabled: bool) -> Result { + if enabled && self.backend != SqliteBackend::LocalNative { + return Err(SqliteRuntimeError::DeferredCommitsUnsupported.build()); + } + self.deferred_commits = enabled; + Ok(self) + } + #[cfg(feature = "sqlite-local")] pub(crate) fn set_vfs_metrics(&mut self, metrics: Arc) { self.vfs_metrics = Some(metrics); @@ -449,6 +485,11 @@ impl SqliteDb { let generation = config .generation .ok_or_else(|| sqlite_not_configured("generation"))?; + let commit_mode = if self.deferred_commits { + CommitMode::Deferred + } else { + CommitMode::Awaited + }; let opened = if _new { open_new_database_from_transport_on_pool( self.worker_pool.as_ref(), @@ -457,7 +498,7 @@ impl SqliteDb { generation, rt_handle, vfs_metrics, - CommitMode::Awaited, + commit_mode, ) .await } else { @@ -468,12 +509,13 @@ impl SqliteDb { generation, rt_handle, vfs_metrics, - CommitMode::Awaited, + commit_mode, ) .await }; let native_db = self.map_local_worker_result(opened)?; self.start_worker_failure_monitor(native_db.clone(), config); + *self.closed_db.lock() = None; *self.db.lock() = Some(native_db); if let Some(metrics) = self.vfs_metrics.as_ref() { metrics.set_worker_active(true); @@ -496,13 +538,14 @@ impl SqliteDb { #[cfg(feature = "sqlite-local")] async fn local_exec(&self, sql: String) -> Result { self.open().await?; - self.map_local_worker_result(self.native_db_handle()?.exec(sql).await) + self.map_local_worker_result(self.statement_db_handle()?.exec(sql).await) } #[cfg(feature = "sqlite-local")] async fn local_exec_profiled(&self, sql: String) -> Result> { self.open().await?; - self.map_local_worker_result(self.native_db_handle()?.exec_profiled(sql).await) + self.map_local_worker_result(self.statement_db_handle()?.exec_profiled(sql).await) + .map(|reply| self.map_local_worker_reply(reply)) } #[cfg(not(feature = "sqlite-local"))] @@ -517,7 +560,7 @@ impl SqliteDb { params: Option>, ) -> Result { self.open().await?; - self.map_local_worker_result(self.native_db_handle()?.execute(sql, params).await) + self.map_local_worker_result(self.statement_db_handle()?.execute(sql, params).await) } #[cfg(feature = "sqlite-local")] @@ -527,7 +570,12 @@ impl SqliteDb { params: Option>, ) -> Result> { self.open().await?; - self.map_local_worker_result(self.native_db_handle()?.execute_profiled(sql, params).await) + self.map_local_worker_result( + self.statement_db_handle()? + .execute_profiled(sql, params) + .await, + ) + .map(|reply| self.map_local_worker_reply(reply)) } #[cfg(not(feature = "sqlite-local"))] @@ -894,7 +942,7 @@ impl SqliteDb { let db = self.clone().with_invocation_telemetry(None); let batch = async move { let transaction = db - .begin_named_transaction(Some(EXECUTE_BATCH_TRANSACTION_NAME), None) + .begin_internal_transaction(EXECUTE_BATCH_TRANSACTION_NAME) .await?; let mut results = Vec::with_capacity(statements.len()); for statement in statements { @@ -1109,6 +1157,10 @@ impl SqliteDb { // must still be able to observe the worker reaching CLOSED/DEAD before // another actor generation can take ownership of SQLite. if release_handle { + *self.closed_db.lock() = Some(sync::ClosedDatabase { + commit_seq: native_db.commit_seq(), + flush_error: native_db.flush_error(), + }); self.db.lock().take(); } result?; @@ -1178,6 +1230,17 @@ impl SqliteDb { .ok_or_else(|| SqliteRuntimeError::Closed.build()) } + /// The native handle a statement runs on. A synchronous call's commits never wait. + #[cfg(feature = "sqlite-local")] + fn statement_db_handle(&self) -> Result { + let native_db = self.native_db_handle()?; + Ok(if self.sync_call { + native_db.with_commit_admission(sqlite_embedded::vfs::CommitAdmission::Refuse) + } else { + native_db + }) + } + #[cfg(feature = "sqlite-local")] fn map_local_worker_result(&self, result: Result) -> Result { match result { @@ -1191,6 +1254,21 @@ impl SqliteDb { } } + /// Profiled worker calls carry the statement's own result inside a successful reply. Only + /// statement errors are structured here; other errors stay raw for the Actor Runtime + /// Socket's wire mapping. + #[cfg(feature = "sqlite-local")] + fn map_local_worker_reply(&self, mut reply: SqliteWorkerResult) -> SqliteWorkerResult { + reply.result = reply.result.map_err(|error| { + if error.downcast_ref::().is_some() { + map_local_worker_error(error) + } else { + error + } + }); + reply + } + #[cfg(feature = "sqlite-local")] fn report_worker_fatal(&self, error: &anyhow::Error) { let Ok(config) = self.runtime_config() else { @@ -1249,6 +1327,29 @@ impl SqliteDb { } } + /// Whether this generation reported a SQLite crash to the engine, which restarts the actor + /// from durable state. Nothing this generation writes afterwards can become durable. + pub(crate) fn generation_failed(&self) -> bool { + self.worker_fatal_reported.load(Ordering::Acquire) + } + + /// Restarts the owning actor from durable state, as a flush failure does: the engine records + /// a crash, and the database breaks so every later write fails, including the final state + /// save. Native database providers use it when their in-memory state can no longer be + /// trusted. Idempotent. + pub fn abort_generation(&self, reason: impl Into) { + let message = format!("actor aborted: {}", reason.into()); + // Report before breaking the database, so the crash carries this reason rather than the + // flush failure the break raises. + if let Ok(config) = self.runtime_config() { + report_sqlite_worker_fatal(&self.worker_fatal_reported, config, message.clone()); + } + #[cfg(feature = "sqlite-local")] + if let Ok(db) = self.native_db_handle() { + db.break_database(message); + } + } + pub fn runtime_config(&self) -> Result { Ok(SqliteRuntimeConfig { handle: self.handle()?, @@ -1278,10 +1379,24 @@ impl SqliteDb { statement_count: usize, error: &anyhow::Error, ) { - let structured = RivetError::extract(error); + let typed = typed_worker_error_for_log(error); + let structured = RivetError::extract(typed.as_ref().unwrap_or(error)); // Engine rollouts can disconnect after a mutation was sent but before its response arrives. // The transport already reports the disconnect, so keep this operation-level event compact. - if structured.group() == "sqlite" && structured.code() == "remote_indeterminate_result" { + if is_expected_refusal(&structured) { + tracing::debug!( + actor_id = self.actor_id.as_deref().unwrap_or(""), + generation = ?self.generation, + backend = ?self.backend, + operation, + group = structured.group(), + code = structured.code(), + error_message = %structured.message(), + "sqlite operation refused; the caller may retry it" + ); + } else if structured.group() == "sqlite" + && structured.code() == "remote_indeterminate_result" + { tracing::debug!( actor_id = self.actor_id.as_deref().unwrap_or(""), generation = ?self.generation, @@ -1629,6 +1744,49 @@ fn sqlite_worker_fatal_message(error: &anyhow::Error) -> String { format!("sqlite worker failed: {error}") } +#[cfg(feature = "sqlite-local")] +fn storage_runtime_error(storage: &sqlite_embedded::vfs::SqliteStorageError) -> anyhow::Error { + match storage { + sqlite_embedded::vfs::SqliteStorageError::Overloaded { + retry_after_ms, + message, + } => SqliteRuntimeError::StorageOverloaded { + retry_after_ms: *retry_after_ms, + message: message.clone(), + } + .build(), + sqlite_embedded::vfs::SqliteStorageError::Timeout { operation } => { + SqliteRuntimeError::StorageTimeout { + operation: operation.clone(), + } + .build() + } + } +} + +/// The typed error a raw local worker error reports to its caller, for a log that runs before +/// the caller maps it: the profiled statement path keeps storage and busy errors raw. +#[cfg(feature = "sqlite-local")] +fn typed_worker_error_for_log(error: &anyhow::Error) -> Option { + if let Some(storage) = error.downcast_ref::() { + return Some(storage_runtime_error(storage)); + } + error + .downcast_ref::() + .map(|_| SqliteRuntimeError::WriterBusy.build()) +} + +#[cfg(not(feature = "sqlite-local"))] +fn typed_worker_error_for_log(_error: &anyhow::Error) -> Option { + None +} + +/// Whether a failed operation is a refusal the caller is expected to retry, which load makes +/// routine: one log line per refused call at error level would bury real failures. +fn is_expected_refusal(error: &RivetError) -> bool { + error.group() == "sqlite" && matches!(error.code(), "storage_overloaded" | "writer_busy") +} + #[cfg(feature = "sqlite-local")] fn map_local_worker_error(error: anyhow::Error) -> anyhow::Error { if let Some(too_large) = @@ -1641,22 +1799,25 @@ fn map_local_worker_error(error: anyhow::Error) -> anyhow::Error { } if let Some(storage) = error.downcast_ref::() { - return match storage { - sqlite_embedded::vfs::SqliteStorageError::Overloaded { - retry_after_ms, - message, - } => SqliteRuntimeError::StorageOverloaded { - retry_after_ms: *retry_after_ms, - message: message.clone(), - } - .build(), - sqlite_embedded::vfs::SqliteStorageError::Timeout { operation } => { - SqliteRuntimeError::StorageTimeout { - operation: operation.clone(), - } - .build() - } - }; + return storage_runtime_error(storage); + } + + // The statement is the actor's own SQL, so SQLite's message is safe to return. The statement + // error stays in the chain for the Actor Runtime Socket's wire mapping. + if let Some(statement) = error.downcast_ref::() { + return SqliteRuntimeError::StatementFailed { + message: statement.detail.clone(), + code: statement.code, + offset: statement.offset, + } + .build() + .context(SqliteStatementError { + code: statement.code, + statement_index: statement.statement_index, + message: statement.message.clone(), + detail: statement.detail.clone(), + offset: statement.offset, + }); } if let Some(indeterminate) = @@ -1668,6 +1829,10 @@ fn map_local_worker_error(error: anyhow::Error) -> anyhow::Error { .build(); } + if error.downcast_ref::().is_some() { + return SqliteRuntimeError::WriterBusy.build(); + } + if error .downcast_ref::() .is_some() diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/sync.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/sync.rs new file mode 100644 index 0000000000..e833562ab4 --- /dev/null +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/sync.rs @@ -0,0 +1,263 @@ +//! Synchronous SQLite calls for foreign runtimes whose host thread runs user code. +//! +//! A synchronous call blocks its caller, so it only runs where writes never wait on the network: +//! - The actor must opt into deferred commits. A write then commits locally and returns. A write +//! while storage is too far behind fails with `sqlite.storage_overloaded` instead of waiting. +//! A cold page read can still wait on depot. +//! - A synchronous call never waits behind other work. It fails fast with the retryable +//! `sqlite.writer_busy` while a transaction is open or waiting for the writer, including an +//! internal one such as a state save, or while a statement on the database is queued or +//! running. Either may wait on storage for as long as storage is behind. When that statement +//! is itself waiting for earlier commits to flush, the call fails with +//! `sqlite.storage_overloaded` instead. A host-thread transaction also could only finish on +//! the blocked thread. A `ROLLBACK` is never refused, because it cannot wait on storage. + +use std::future::Future; +use std::time::Duration; + +use anyhow::Result; + +use super::{BindParam, ExecuteResult, QueryResult, SqliteDb, SqliteTransaction}; +use crate::error::SqliteRuntimeError; + +/// How a native database ended. A ticket at or below `commit_seq` was durable when it closed, +/// unless the close left `flush_error`. +#[cfg(feature = "sqlite-local")] +#[derive(Clone)] +pub(super) struct ClosedDatabase { + pub(super) commit_seq: u64, + pub(super) flush_error: Option, +} + +impl SqliteDb { + /// Returns a handle for code that runs on a foreign runtime's host thread. Transactions + /// begun through it count as host-thread transactions, which synchronous calls never wait + /// for. + pub fn for_host_thread(&self) -> Self { + let mut db = self.clone(); + db.host_thread = true; + db + } + + fn for_sync_call(&self) -> Self { + let mut db = self.clone(); + db.sync_call = true; + db + } + + pub fn execute_sync( + &self, + sql: impl Into, + params: Option>, + ) -> Result { + self.ensure_sync_supported()?; + self.ensure_no_host_thread_transaction()?; + let db = self.for_sync_call(); + let sql = sql.into(); + wait_on_runtime(async move { db.execute(sql, params).await }) + } + + pub fn exec_sync(&self, sql: impl Into) -> Result { + self.ensure_sync_supported()?; + self.ensure_no_host_thread_transaction()?; + let db = self.for_sync_call(); + let sql = sql.into(); + wait_on_runtime(async move { db.exec(sql).await }) + } + + /// Begins a host-thread transaction. The caller must finish it with `commit_sync` or + /// `rollback_sync`, or it rolls back at its timeout. + pub fn begin_transaction_sync( + &self, + name: Option, + timeout: Option, + ) -> Result { + self.ensure_sync_supported()?; + self.ensure_no_host_thread_transaction()?; + let db = self.for_host_thread().for_sync_call(); + wait_on_runtime(async move { db.begin_named_transaction(name.as_deref(), timeout).await }) + } + + /// Returns the ticket of the latest local commit in this generation. Pass it to + /// `when_durable` to wait until that commit and every earlier one reach depot. + pub fn commit_ticket(&self) -> u64 { + #[cfg(feature = "sqlite-local")] + { + if let Some(native_db) = self.db.lock().as_ref() { + return native_db.commit_seq(); + } + self.closed_db + .lock() + .as_ref() + .map_or(0, |closed| closed.commit_seq) + } + #[cfg(not(feature = "sqlite-local"))] + { + 0 + } + } + + /// Resolves once the commit `ticket` names is durable. Rejects with + /// `sqlite.durability_failed` once the generation's database broke, even for a ticket that + /// was already durable, because the generation is stopping. + pub async fn when_durable(&self, ticket: u64) -> Result<()> { + #[cfg(feature = "sqlite-local")] + { + use sqlite_embedded::vfs::FlushError; + + let Some(native_db) = self.db.lock().as_ref().cloned() else { + return self.closed_outcome(ticket); + }; + native_db + .wait_for_flush(ticket) + .await + .map_err(|error| match error { + FlushError::InvalidSequence { requested, current } => { + SqliteRuntimeError::InvalidCommitTicket { + ticket: requested, + current, + } + .build() + } + FlushError::RetryDeadlineExceeded { .. } + | FlushError::HeadDiverged { .. } + | FlushError::Aborted(_) + | FlushError::Fenced(_) => SqliteRuntimeError::DurabilityFailed { + message: error.to_string(), + } + .build(), + }) + } + #[cfg(not(feature = "sqlite-local"))] + { + let _ = ticket; + Err(sync_unsupported("this build has no local SQLite")) + } + } + + /// Answers for a ticket once the database closed, from how the close ended. + #[cfg(feature = "sqlite-local")] + fn closed_outcome(&self, ticket: u64) -> Result<()> { + let closed = self.closed_db.lock().clone(); + match closed { + Some(ClosedDatabase { + flush_error: Some(error), + .. + }) => Err(SqliteRuntimeError::DurabilityFailed { + message: error.to_string(), + } + .build()), + Some(ClosedDatabase { commit_seq, .. }) if ticket <= commit_seq => Ok(()), + None if ticket == 0 => Ok(()), + closed => Err(SqliteRuntimeError::InvalidCommitTicket { + ticket, + current: closed.map_or(0, |closed| closed.commit_seq), + } + .build()), + } + } + + pub(super) fn ensure_sync_supported(&self) -> Result<()> { + #[cfg(feature = "sqlite-local")] + { + if self.backend() != super::SqliteBackend::LocalNative { + return Err(sync_unsupported("the actor uses remote SQLite")); + } + let Some(native_db) = self.db.lock().as_ref().cloned() else { + return Err(sync_unsupported("the database is not open")); + }; + if native_db.commit_mode() != sqlite_embedded::vfs::CommitMode::Deferred { + return Err(sync_unsupported( + "the actor did not opt into deferred commits, so a write would wait on the network", + )); + } + // A runtime task that blocks on another runtime task can starve the runtime. + if tokio::task::try_id().is_some() { + return Err(sync_unsupported( + "the caller is an asynchronous runtime task", + )); + } + Ok(()) + } + #[cfg(not(feature = "sqlite-local"))] + { + Err(sync_unsupported("this build has no local SQLite")) + } + } + + fn ensure_no_host_thread_transaction(&self) -> Result<()> { + if self.transaction_coordinator.host_thread_lease_count() > 0 { + return Err(SqliteRuntimeError::WriterBusy.build()); + } + Ok(()) + } +} + +impl SqliteTransaction { + pub fn execute_sync( + &self, + sql: impl Into, + params: Option>, + ) -> Result { + self.db.ensure_sync_supported()?; + let transaction = self.clone(); + let sql = sql.into(); + wait_on_runtime(async move { transaction.execute(sql, params).await }) + } + + pub fn exec_sync(&self, sql: impl Into) -> Result { + self.db.ensure_sync_supported()?; + let transaction = self.clone(); + let sql = sql.into(); + wait_on_runtime(async move { transaction.exec(sql).await }) + } + + pub fn commit_sync(&self) -> Result<()> { + self.db.ensure_sync_supported()?; + let transaction = self.clone(); + wait_on_runtime(async move { transaction.commit().await }) + } + + pub fn rollback_sync(&self) -> Result<()> { + self.db.ensure_sync_supported()?; + let transaction = self.clone(); + wait_on_runtime(async move { transaction.rollback().await }) + } +} + +/// Drives `future` to completion on the calling thread. The caller must be a thread that entered +/// the runtime, not one of its tasks, because blocking a runtime task could stall the work the +/// future waits on. +#[cfg(feature = "sqlite-local")] +fn wait_on_runtime(future: F) -> Result +where + F: Future>, +{ + if tokio::task::try_id().is_some() { + return Err(sync_unsupported( + "the caller is an asynchronous runtime task", + )); + } + let runtime = tokio::runtime::Handle::try_current() + .map_err(|_| sync_unsupported("the calling thread has no runtime"))?; + // The profiled statement path leaves worker errors raw; a synchronous caller gets the typed + // error, such as the retryable `sqlite.storage_overloaded`. + runtime + .block_on(future) + .map_err(super::map_local_worker_error) +} + +#[cfg(not(feature = "sqlite-local"))] +fn wait_on_runtime(_future: F) -> Result +where + F: Future>, +{ + Err(sync_unsupported("this build has no local SQLite")) +} + +fn sync_unsupported(reason: &str) -> anyhow::Error { + SqliteRuntimeError::SyncUnsupported { + reason: reason.to_owned(), + } + .build() +} diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/tx.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/tx.rs index 474fcccd7c..2ad8953099 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/tx.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/sqlite/tx.rs @@ -5,7 +5,7 @@ use std::{ future::Future, sync::{ Arc, - atomic::{AtomicU64, Ordering}, + atomic::{AtomicU64, AtomicUsize, Ordering}, }, time::Duration, }; @@ -48,7 +48,7 @@ static UNNAMED_TRANSACTION_WARNINGS: AtomicU64 = AtomicU64::new(0); #[derive(Clone)] pub struct SqliteTransaction { - db: SqliteDb, + pub(super) db: SqliteDb, key: String, } @@ -91,6 +91,9 @@ pub(super) struct TransactionCoordinator { /// Cancelled when the coordinator closes so begins parked behind a manual /// transaction stop waiting. closed_token: CancellationToken, + /// Transactions owned by a foreign runtime's host thread, open or waiting for the writer. + /// Only that thread can finish them, so a synchronous call there must not wait for them. + host_thread_leases: Arc, } pub(super) struct TransactionCoordinatorState { @@ -215,10 +218,28 @@ pub(super) struct ActiveTransaction { gate_guard: Option>, operation: Arc>, timeout_task: Option, + _host_thread_lease: Option, #[cfg(feature = "sqlite-local")] profile: Option, } +/// Counts one host-thread transaction from the call that begins it until it ends. Synchronous +/// calls fail fast with `sqlite.writer_busy` while any is counted. +pub(crate) struct HostThreadLease(Arc); + +impl HostThreadLease { + fn new(count: &Arc) -> Self { + count.fetch_add(1, Ordering::AcqRel); + Self(Arc::clone(count)) + } +} + +impl Drop for HostThreadLease { + fn drop(&mut self) { + self.0.fetch_sub(1, Ordering::AcqRel); + } +} + #[derive(Clone, Copy)] pub(super) enum TransactionTerminalState { Committed, @@ -290,10 +311,27 @@ impl Default for TransactionCoordinator { waiters: AtomicU64::new(0), manual_transaction_waiters: AtomicU64::new(0), closed_token: CancellationToken::new(), + host_thread_leases: Arc::new(AtomicUsize::new(0)), } } } +impl TransactionCoordinator { + pub(super) fn host_thread_lease_count(&self) -> usize { + self.host_thread_leases.load(Ordering::Acquire) + } +} + +impl SqliteDb { + /// Counts a transaction this handle is about to begin as owned by the host thread, when the + /// handle is a host-thread one. Callers take it before creating the begin future, so a + /// begin that has not run yet already counts. + pub(crate) fn reserve_host_thread_lease(&self) -> Option { + self.host_thread + .then(|| HostThreadLease::new(&self.transaction_coordinator.host_thread_leases)) + } +} + impl SqliteDb { pub(super) fn try_transaction_admission(&self) -> Result { match Arc::clone(&self.transaction_coordinator.admission).try_acquire_owned() { @@ -317,11 +355,20 @@ impl SqliteDb { pub(super) async fn begin_admitted_operation(&self) -> Result { let epoch = self.transaction_coordinator.epoch.load(Ordering::Acquire); let permit = self.try_transaction_admission()?; - let wait = CoordinatorWaitGuard::new(self); - let gate = Arc::clone(&self.transaction_coordinator.gate) - .read_owned() - .await; - drop(wait); + let gate = if self.sync_call { + // A transaction holds the gate for as long as its statements and commit take, which + // is unbounded while storage is behind, so a synchronous call never waits for it. + Arc::clone(&self.transaction_coordinator.gate) + .try_read_owned() + .map_err(|_| crate::error::SqliteRuntimeError::WriterBusy.build())? + } else { + let wait = CoordinatorWaitGuard::new(self); + let gate = Arc::clone(&self.transaction_coordinator.gate) + .read_owned() + .await; + drop(wait); + gate + }; let state = self.transaction_coordinator.state.lock().await; if state.closed { return Err(transaction_coordinator_closed_error()); @@ -340,20 +387,47 @@ impl SqliteDb { }) } - pub async fn begin_transaction(&self, timeout: Option) -> Result { - self.begin_named_transaction(None, timeout).await + pub fn begin_transaction( + &self, + timeout: Option, + ) -> impl Future> + use<> { + self.begin_named_transaction(None, timeout) } - pub async fn begin_named_transaction( + /// Begins a transaction. On a host-thread handle the transaction counts as the host + /// thread's from this call, before the returned future first runs, so a synchronous call + /// made while the begin is still pending fails fast instead of waiting on it. + pub fn begin_named_transaction( &self, name: Option<&str>, timeout: Option, + ) -> impl Future> + use<> { + let lease = self.reserve_host_thread_lease(); + let db = self.clone(); + let name = name.map(ToOwned::to_owned); + async move { db.begin_leased_transaction(lease, name, timeout).await } + } + + /// Begins a transaction core runs to completion itself, such as a batch. It never counts as + /// the host thread's. A synchronous call still fails with `sqlite.writer_busy` while it is + /// open, because its commit may wait on storage. + pub(super) async fn begin_internal_transaction(&self, name: &str) -> Result { + self.begin_leased_transaction(None, Some(name.to_owned()), None) + .await + } + + /// Begins a transaction that holds `lease`, if any, until it ends. + pub(crate) async fn begin_leased_transaction( + &self, + lease: Option, + name: Option, + timeout: Option, ) -> Result { #[cfg(feature = "sqlite-local")] let max_name_bytes = self.profiling.config.max_transaction_name_bytes; #[cfg(not(feature = "sqlite-local"))] let max_name_bytes = MAX_TRANSACTION_NAME_BYTES; - if let Some(name) = name { + if let Some(name) = name.as_deref() { if name.is_empty() { return Err(transaction_invalid_argument_error( "transaction name must not be empty", @@ -367,8 +441,9 @@ impl SqliteDb { } self.begin_transaction_with_key_and_name( uuid::Uuid::new_v4().to_string(), - name.map(ToOwned::to_owned), + name, timeout, + lease, ) .await } @@ -378,6 +453,7 @@ impl SqliteDb { key: impl Into, name: Option, timeout: Option, + lease: Option, ) -> Result { #[cfg(feature = "sqlite-local")] let started_at = @@ -402,6 +478,7 @@ impl SqliteDb { key, timeout, name, + lease, #[cfg(feature = "sqlite-local")] started_at, ) @@ -417,6 +494,7 @@ impl SqliteDb { key: String, timeout: Duration, _name: Option, + host_thread_lease: Option, #[cfg(feature = "sqlite-local")] started_at: Option, ) -> Result { #[cfg(feature = "sqlite-local")] @@ -504,6 +582,7 @@ impl SqliteDb { gate_guard: Some(gate_guard), operation, timeout_task: None, + _host_thread_lease: host_thread_lease, #[cfg(feature = "sqlite-local")] profile: started_at.map(|started_at| { let mut profile = TransactionProfile::new( @@ -541,8 +620,11 @@ impl SqliteDb { timeout_task.cancel(); } drop(state); + // The expiry rollback runs on a runtime task, not the host thread, so it may wait. + let mut expiry_db = self.clone(); + expiry_db.sync_call = false; spawn_transaction_timeout( - self.clone(), + expiry_db, key.clone(), timeout, timeout_task, @@ -581,9 +663,15 @@ impl SqliteDb { let deadline = crate::time::Instant::now() + timeout; let mut wait_guard = None; loop { - let gate_guard = Arc::clone(&self.transaction_coordinator.gate) - .write_owned() - .await; + let gate_guard = if self.sync_call { + Arc::clone(&self.transaction_coordinator.gate) + .try_write_owned() + .map_err(|_| crate::error::SqliteRuntimeError::WriterBusy.build())? + } else { + Arc::clone(&self.transaction_coordinator.gate) + .write_owned() + .await + }; let Some(mut explicit_transaction) = self.subscribe_explicit_transaction() else { return Ok(gate_guard); }; @@ -591,6 +679,11 @@ impl SqliteDb { return Ok(gate_guard); } drop(gate_guard); + // Only the host thread can end a manual transaction, and a synchronous call is + // blocking that thread. + if self.sync_call { + return Err(crate::error::SqliteRuntimeError::WriterBusy.build()); + } if wait_guard.is_none() { wait_guard = Some(ManualTransactionWaitGuard::new(self, timeout)); diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/state.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/state.rs index af883d95fd..6634dc9992 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/state.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/state.rs @@ -1,3 +1,4 @@ +use std::future::Future; use std::sync::atomic::Ordering; use std::sync::{Arc, Weak}; use std::time::Duration; @@ -23,7 +24,9 @@ use crate::actor::task::LifecycleEvent; use crate::actor::task_types::StateMutationReason; use crate::error::{ActorLifecycle, ActorRuntime}; use crate::runtime::RuntimeSpawner; -use crate::sqlite::{BindParam, ExecuteResult, SqliteBatchStatement, SqliteTransaction}; +use crate::sqlite::{ + BindParam, ExecuteResult, HostThreadLease, SqliteBatchStatement, SqliteDb, SqliteTransaction, +}; use crate::types::SaveStateOpts; /// Profiling name for a state transaction whose caller gives no name. @@ -384,6 +387,36 @@ impl ActorContext { &self, name: Option<&str>, timeout: Option, + ) -> Result { + self.begin_state_transaction_on(self.invocation_sql(), None, name, timeout) + .await + } + + /// Begins a state transaction owned by a foreign runtime's host thread. It counts as a + /// host-thread transaction from this call, before the returned future first runs, so a + /// synchronous SQLite call made while it is pending or open fails fast instead of waiting on + /// work only the blocked host thread could finish. + pub fn begin_host_thread_state_transaction( + &self, + name: Option<&str>, + timeout: Option, + ) -> impl Future> + use<> { + let sql = self.invocation_sql().for_host_thread(); + let lease = sql.reserve_host_thread_lease(); + let ctx = self.clone(); + let name = name.map(ToOwned::to_owned); + async move { + ctx.begin_state_transaction_on(sql, lease, name.as_deref(), timeout) + .await + } + } + + async fn begin_state_transaction_on( + &self, + sql: SqliteDb, + lease: Option, + name: Option<&str>, + timeout: Option, ) -> Result { self.clear_pending_save(); let save_guard = Arc::clone(&self.0.save_guard).lock_owned().await; @@ -412,9 +445,12 @@ impl ActorContext { .filter(|conn| conn.is_hibernatable()) .map(|conn| (conn.id().to_owned(), conn.state())) .collect(); - let sql = self.invocation_sql(); let transaction = match sql - .begin_named_transaction(Some(name.unwrap_or(STATE_TRANSACTION_NAME)), timeout) + .begin_leased_transaction( + lease, + Some(name.unwrap_or(STATE_TRANSACTION_NAME).to_owned()), + timeout, + ) .await { Ok(transaction) => transaction, diff --git a/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs b/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs index de2541bd53..09f2c85a70 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/actor/task.rs @@ -2294,7 +2294,14 @@ impl ActorTask { "failed to roll back manual sqlite transaction before the final state save" ); } - let final_save = self.save_final_state().await; + // A generation that reported a SQLite crash cannot persist, so its final save would + // only fail and skip the cleanup below that releases SQLite. The engine restarts the + // actor from durable state. + let final_save = if self.ctx.sql().generation_failed() { + Ok(()) + } else { + self.save_final_state().await + }; // No later save can run, so outstanding waiters learn their state was not written. self.ctx.fail_unpersisted_save_requests(); final_save?; diff --git a/rivetkit-rust/packages/rivetkit-core/src/error.rs b/rivetkit-rust/packages/rivetkit-core/src/error.rs index 1f9ae1ed0a..130cbf521c 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/error.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/error.rs @@ -306,7 +306,7 @@ pub(crate) enum SqliteRuntimeError { #[error( "writer_busy", "SQLite writer is busy.", - "SQLite writer is busy because a transaction is already open." + "SQLite writer is busy because a transaction is open or another command is running; retry once it ends." )] WriterBusy, @@ -361,4 +361,45 @@ pub(crate) enum SqliteRuntimeError { "Remote SQLite generation is stale: {reason}" )] RemoteFenceMismatch { reason: String }, + + #[error( + "deferred_commits_unsupported", + "SQLite deferred commits are unavailable.", + "SQLite deferred commits require local native SQLite. Turn off remote SQLite for this actor, or do not opt it into deferred commits." + )] + DeferredCommitsUnsupported, + + #[error( + "statement_failed", + "SQLite statement failed.", + "SQLite statement failed: {message} (SQLite result code {code}, error offset {offset:?})" + )] + StatementFailed { + message: String, + /// SQLite's extended result code. + code: i32, + /// Byte offset into the SQL of the token SQLite blamed, when it named one. + offset: Option, + }, + + #[error( + "sync_unsupported", + "Synchronous SQLite is unavailable.", + "Synchronous SQLite is unavailable because {reason}." + )] + SyncUnsupported { reason: String }, + + #[error( + "durability_failed", + "SQLite commits could not be made durable.", + "SQLite commits could not be made durable, so the actor is restarting: {message}" + )] + DurabilityFailed { message: String }, + + #[error( + "invalid_commit_ticket", + "Invalid SQLite commit ticket.", + "SQLite commit ticket {ticket} is ahead of the latest commit {current}." + )] + InvalidCommitTicket { ticket: u64, current: u64 }, } diff --git a/rivetkit-rust/packages/rivetkit-core/src/registry/mod.rs b/rivetkit-rust/packages/rivetkit-core/src/registry/mod.rs index 7b8bbc4d9c..532af26514 100644 --- a/rivetkit-rust/packages/rivetkit-core/src/registry/mod.rs +++ b/rivetkit-rust/packages/rivetkit-core/src/registry/mod.rs @@ -1447,7 +1447,8 @@ impl RegistryDispatcher { Some(generation as u64), factory.config().has_database, factory.config().remote_sqlite, - )?; + )? + .with_deferred_commits(factory.config().sqlite_deferred_commits)?; #[cfg(feature = "sqlite-local")] sql.set_worker_pool(self.sqlite_pool.clone()); let ctx = ActorContext::build( diff --git a/rivetkit-typescript/packages/rivetkit-napi/src/actor_factory.rs b/rivetkit-typescript/packages/rivetkit-napi/src/actor_factory.rs index 2ced2efd9b..40df0457db 100644 --- a/rivetkit-typescript/packages/rivetkit-napi/src/actor_factory.rs +++ b/rivetkit-typescript/packages/rivetkit-napi/src/actor_factory.rs @@ -1101,6 +1101,7 @@ impl From for ActorConfigInput { icon: value.icon, has_database: value.has_database, remote_sqlite: value.remote_sqlite, + sqlite_deferred_commits: None, sqlite_profiling: value.sqlite_profiling.map(Into::into), tracing: value.tracing.map(Into::into), has_state: value.has_state, diff --git a/rivetkit-typescript/packages/rivetkit-wasm/src/lib.rs b/rivetkit-typescript/packages/rivetkit-wasm/src/lib.rs index f56c3a0e3e..7e35cb58e0 100644 --- a/rivetkit-typescript/packages/rivetkit-wasm/src/lib.rs +++ b/rivetkit-typescript/packages/rivetkit-wasm/src/lib.rs @@ -240,6 +240,7 @@ impl From for ActorConfigInput { icon: config.icon, has_database: config.has_database, remote_sqlite: config.remote_sqlite, + sqlite_deferred_commits: None, sqlite_profiling: config.sqlite_profiling.map(Into::into), tracing: None, has_state: config.has_state,