Skip to content

Commit 1000bc4

Browse files
committed
fix(sqlite): disable incomplete preload hint flush
1 parent dc5e609 commit 1000bc4

1 file changed

Lines changed: 14 additions & 175 deletions

File tree

  • rivetkit-rust/packages/rivetkit-core/src/actor

rivetkit-rust/packages/rivetkit-core/src/actor/sqlite.rs

Lines changed: 14 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use tokio::sync::Mutex as AsyncMutex;
2222
#[cfg(feature = "sqlite-local")]
2323
use tokio::task::JoinHandle;
2424
#[cfg(feature = "sqlite-local")]
25-
use tokio::time::{interval, timeout};
25+
use tokio::time::interval;
2626
#[cfg(feature = "sqlite-local")]
2727
use tracing::Instrument;
2828

@@ -32,7 +32,7 @@ use crate::error::SqliteRuntimeError;
3232
use depot_client::{
3333
database::{NativeDatabaseHandle, open_database_from_envoy},
3434
optimization_flags::sqlite_optimization_flags,
35-
vfs::{SqliteVfsMetrics, SqliteVfsMetricsSnapshot, VfsPreloadHintSnapshot},
35+
vfs::{SqliteVfsMetrics, SqliteVfsMetricsSnapshot},
3636
};
3737

3838
#[cfg(not(feature = "sqlite-local"))]
@@ -48,8 +48,6 @@ pub struct SqliteVfsMetricsSnapshot {
4848

4949
#[cfg(feature = "sqlite-local")]
5050
const PRELOAD_HINT_FLUSH_INTERVAL: Duration = Duration::from_secs(30);
51-
#[cfg(feature = "sqlite-local")]
52-
const PRELOAD_HINT_FLUSH_TIMEOUT: Duration = Duration::from_secs(5);
5351

5452
#[derive(Clone)]
5553
pub struct SqliteRuntimeConfig {
@@ -464,18 +462,9 @@ impl SqliteDb {
464462
}
465463

466464
pub fn metrics(&self) -> Option<SqliteVfsMetricsSnapshot> {
467-
#[cfg(feature = "sqlite-local")]
468-
{
469-
self.db
470-
.lock()
471-
.as_ref()
472-
.map(NativeDatabaseHandle::sqlite_vfs_metrics)
473-
}
474-
475-
#[cfg(not(feature = "sqlite-local"))]
476-
{
477-
None
478-
}
465+
// Preload-hint metrics are disabled until depot-client exposes a
466+
// stable `NativeDatabaseHandle::sqlite_vfs_metrics` surface.
467+
None
479468
}
480469

481470
pub fn runtime_config(&self) -> Result<SqliteRuntimeConfig> {
@@ -623,171 +612,21 @@ impl SqliteDb {
623612

624613
#[cfg(feature = "sqlite-local")]
625614
async fn enqueue_preload_hint_flush_best_effort(
626-
db: Arc<Mutex<Option<NativeDatabaseHandle>>>,
627-
handle: EnvoyHandle,
628-
actor_id: String,
629-
generation: u64,
615+
_db: Arc<Mutex<Option<NativeDatabaseHandle>>>,
616+
_handle: EnvoyHandle,
617+
_actor_id: String,
618+
_generation: u64,
630619
) {
631-
let snapshot = match snapshot_preload_hints(db).await {
632-
Ok(Some(snapshot)) => snapshot,
633-
Ok(None) => return,
634-
Err(error) => {
635-
tracing::warn!(
636-
actor_id = %actor_id,
637-
?error,
638-
reason = "shutdown",
639-
"sqlite preload hint snapshot failed"
640-
);
641-
return;
642-
}
643-
};
644-
if snapshot.pgnos.is_empty() && snapshot.ranges.is_empty() {
645-
return;
646-
}
647-
648-
let hint_count = snapshot.pgnos.len() + snapshot.ranges.len();
649-
let request = protocol::SqlitePersistPreloadHintsRequest {
650-
actor_id: actor_id.clone(),
651-
generation,
652-
hints: protocol_preload_hints(snapshot),
653-
};
654-
match handle.sqlite_persist_preload_hints_fire_and_forget(request) {
655-
Ok(()) => {
656-
tracing::debug!(
657-
actor_id = %actor_id,
658-
generation,
659-
reason = "shutdown",
660-
hint_count,
661-
"sqlite preload hint flush queued"
662-
);
663-
}
664-
Err(error) => {
665-
tracing::warn!(
666-
actor_id = %actor_id,
667-
generation,
668-
reason = "shutdown",
669-
hint_count,
670-
?error,
671-
"sqlite preload hint flush queue failed"
672-
);
673-
}
674-
}
675620
}
676621

677622
#[cfg(feature = "sqlite-local")]
678623
async fn flush_preload_hints_best_effort(
679-
db: Arc<Mutex<Option<NativeDatabaseHandle>>>,
680-
handle: EnvoyHandle,
681-
actor_id: String,
682-
generation: u64,
683-
reason: &'static str,
624+
_db: Arc<Mutex<Option<NativeDatabaseHandle>>>,
625+
_handle: EnvoyHandle,
626+
_actor_id: String,
627+
_generation: u64,
628+
_reason: &'static str,
684629
) {
685-
let snapshot = match snapshot_preload_hints(db).await {
686-
Ok(Some(snapshot)) => snapshot,
687-
Ok(None) => return,
688-
Err(error) => {
689-
tracing::warn!(
690-
actor_id = %actor_id,
691-
?error,
692-
reason,
693-
"sqlite preload hint snapshot failed"
694-
);
695-
return;
696-
}
697-
};
698-
if snapshot.pgnos.is_empty() && snapshot.ranges.is_empty() {
699-
return;
700-
}
701-
702-
let hint_count = snapshot.pgnos.len() + snapshot.ranges.len();
703-
let request = protocol::SqlitePersistPreloadHintsRequest {
704-
actor_id: actor_id.clone(),
705-
generation,
706-
hints: protocol_preload_hints(snapshot),
707-
};
708-
let response = timeout(
709-
PRELOAD_HINT_FLUSH_TIMEOUT,
710-
handle.sqlite_persist_preload_hints(request),
711-
)
712-
.await;
713-
match response {
714-
Ok(Ok(protocol::SqlitePersistPreloadHintsResponse::SqlitePersistPreloadHintsOk)) => {
715-
tracing::debug!(
716-
actor_id = %actor_id,
717-
generation,
718-
reason,
719-
hint_count,
720-
"sqlite preload hints flushed"
721-
);
722-
}
723-
Ok(Ok(protocol::SqlitePersistPreloadHintsResponse::SqliteFenceMismatch(mismatch))) => {
724-
tracing::debug!(
725-
actor_id = %actor_id,
726-
generation,
727-
reason,
728-
hint_count,
729-
fence_reason = %mismatch.reason,
730-
"sqlite preload hint flush skipped after fence mismatch"
731-
);
732-
}
733-
Ok(Ok(protocol::SqlitePersistPreloadHintsResponse::SqliteErrorResponse(error))) => {
734-
tracing::warn!(
735-
actor_id = %actor_id,
736-
generation,
737-
reason,
738-
hint_count,
739-
error = %error.message,
740-
"sqlite preload hint flush failed"
741-
);
742-
}
743-
Ok(Err(error)) => {
744-
tracing::warn!(
745-
actor_id = %actor_id,
746-
generation,
747-
reason,
748-
hint_count,
749-
?error,
750-
"sqlite preload hint flush failed"
751-
);
752-
}
753-
Err(_) => {
754-
tracing::warn!(
755-
actor_id = %actor_id,
756-
generation,
757-
reason,
758-
hint_count,
759-
timeout_ms = PRELOAD_HINT_FLUSH_TIMEOUT.as_millis() as u64,
760-
"sqlite preload hint flush timed out"
761-
);
762-
}
763-
}
764-
}
765-
766-
#[cfg(feature = "sqlite-local")]
767-
async fn snapshot_preload_hints(
768-
db: Arc<Mutex<Option<NativeDatabaseHandle>>>,
769-
) -> Result<Option<VfsPreloadHintSnapshot>> {
770-
tokio::task::spawn_blocking(move || {
771-
let guard = db.lock();
772-
Ok(guard.as_ref().map(NativeDatabaseHandle::snapshot_preload_hints))
773-
})
774-
.await
775-
.context("join sqlite preload hint snapshot task")?
776-
}
777-
778-
#[cfg(feature = "sqlite-local")]
779-
fn protocol_preload_hints(snapshot: VfsPreloadHintSnapshot) -> protocol::SqlitePreloadHints {
780-
protocol::SqlitePreloadHints {
781-
pgnos: snapshot.pgnos,
782-
ranges: snapshot
783-
.ranges
784-
.into_iter()
785-
.map(|range| protocol::SqlitePreloadHintRange {
786-
start_pgno: range.start_pgno,
787-
page_count: range.page_count,
788-
})
789-
.collect(),
790-
}
791630
}
792631

793632
struct RemoteSqliteConfig {

0 commit comments

Comments
 (0)