Skip to content

Commit 6cd1128

Browse files
committed
upgrade nightly, upgrade rusqlite to use sqlite3_trace_v2 and log slow queries, upgrade cr-sqlite fixing segfault to upgrade from 0.16
1 parent fc739db commit 6cd1128

File tree

11 files changed

+75
-57
lines changed

11 files changed

+75
-57
lines changed

Cargo.lock

Lines changed: 46 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ rand = { version = "0.8.5", features = ["small_rng"] }
5252
rangemap = { version = "1.5.1", features = ["serde1"] }
5353
rcgen = { version = "0.11.1", features = ["x509-parser"] }
5454
rhai = { version = "1.15.1", features = ["sync"] }
55-
rusqlite = { version = "0.30.0", features = ["serde_json", "time", "bundled", "uuid", "array", "load_extension", "column_decltype", "vtab", "functions", "chrono", "series", "trace"] }
55+
rusqlite = { version = "0.32.1", features = ["serde_json", "time", "bundled", "uuid", "array", "load_extension", "column_decltype", "vtab", "functions", "chrono", "series", "trace"], git = "https://github.com/rusqlite/rusqlite", rev = "c9f77814ddc99825f9c8eb52a0acb8d00f447f17" }
5656
rustls = { version = "0.21.0", features = ["dangerous_configuration", "quic"] }
5757
rustls-pemfile = "1.0.2"
5858
seahash = "4.1.0"

crates/corro-agent/src/agent/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ pub async fn handle_sync(
906906

907907
debug!("found {} candidates to synchronize with", candidates.len());
908908

909-
let desired_count = cmp::max(cmp::min(candidates.len() / 100, 10), 3);
909+
let desired_count = (candidates.len() / 100).clamp(3, 10);
910910
debug!("Selected {desired_count} nodes to sync with");
911911

912912
let mut rng = StdRng::from_entropy();

crates/corro-agent/src/api/public/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ async fn execute_schema(agent: &Agent, statements: Vec<String>) -> eyre::Result<
462462

463463
new_schema.constrain()?;
464464

465-
block_in_place(|| {
465+
// conn.trace(Some(|sql| debug!(sql)));
466+
467+
let apply_res = block_in_place(|| {
466468
let tx = conn.immediate_transaction()?;
467469

468470
apply_schema(&tx, &schema_write, &mut new_schema)?;
@@ -480,7 +482,11 @@ async fn execute_schema(agent: &Agent, statements: Vec<String>) -> eyre::Result<
480482
agent.pool().drain_read();
481483

482484
Ok::<_, eyre::Report>(())
483-
})?;
485+
});
486+
487+
// conn.trace(None);
488+
489+
apply_res?;
484490

485491
*schema_write = new_schema;
486492

-384 Bytes
Binary file not shown.
-384 Bytes
Binary file not shown.
-4.63 KB
Binary file not shown.
-568 Bytes
Binary file not shown.

crates/corro-types/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ pub fn apply_schema(
361361
schema_to_merge.tables.insert(name.clone(), parsed_table);
362362
}
363363

364+
debug!("selecting crsql_as_crr");
364365
tx.execute_batch(&format!("SELECT crsql_as_crr('{name}'); CREATE INDEX IF NOT EXISTS corro_{name}__crsql_clock_site_id_dbv ON {name}__crsql_clock (site_id, db_version);"))?;
366+
debug!("done selecting as crr");
365367

366368
if schema_to_merge.tables.contains_key(name) {
367369
// just merged!

crates/corro-types/src/sqlite.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::{
22
ops::{Deref, DerefMut},
3-
time::Instant,
3+
time::{Duration, Instant},
44
};
55

66
use once_cell::sync::Lazy;
7-
use rusqlite::{params, Connection, Transaction};
7+
use rusqlite::{params, trace::TraceEventCodes, Connection, Transaction};
88
use sqlite_pool::SqliteConn;
99
use tempfile::TempDir;
10-
use tracing::{error, info, trace};
10+
use tracing::{error, info, trace, warn};
1111

1212
pub type SqlitePool = sqlite_pool::Pool<CrConn>;
1313
pub type SqlitePoolError = sqlite_pool::PoolError;
@@ -42,7 +42,19 @@ pub fn rusqlite_to_crsqlite(mut conn: rusqlite::Connection) -> rusqlite::Result<
4242
init_cr_conn(&mut conn)?;
4343
setup_conn(&conn)?;
4444
sqlite_functions::add_to_connection(&conn)?;
45-
conn.trace(Some(|sql| trace!("{sql}")));
45+
46+
const SLOW_THRESHOLD: Duration = Duration::from_secs(1);
47+
conn.trace_v2(
48+
TraceEventCodes::SQLITE_TRACE_PROFILE,
49+
Some(|event| {
50+
if let rusqlite::trace::TraceEvent::Profile(stmt_ref, duration) = event {
51+
if duration >= SLOW_THRESHOLD {
52+
warn!("SLOW query {duration:?} => {}", stmt_ref.sql());
53+
}
54+
}
55+
}),
56+
);
57+
4658
Ok(CrConn(conn))
4759
}
4860

0 commit comments

Comments
 (0)