Skip to content

Commit 0bc55b5

Browse files
committed
sqld: disable checkpoint on primary conn create
This commit changes our primary connection initialization code in two ways to achieve the ability to disable checkpointing the wal. 1) We ignore the initial checkpoint that we call directly into sqlite3 before we restore from bottomless. There is a fixme above that explains why we need this but to me right now its not totally clear why without digging deeper into the internals of bottomless. We should do this but for the moment this unblocks us and from the fixme comment it does not sound unsafe rather doing extra work potentially. 2) When bottomless needs to get the local change counter is creates a sqlite connection. When this connection drops it seems like it checkpoints the wal. I took a brief look at the `sqlite3_close` code and did not find anything obvious, I have been told in the past that sqlite3 likes to checkpoint at weird points so this could be one of those. For the moment, the temporary fix like above is to `std::mem::forget` the connection so that `Drop` never gets called and thus `sqlite3_close` never gets called. With both of these changes we now don't checkpoint the wal unless we hit the max size or interval (which for testing I have set very high). This changes are not enabled by default but must be enabled by setting the following env var: ``` LIBSQL_DISABLE_INIT_CHECKPOINTING=1 ```
1 parent e5ab7c4 commit 0bc55b5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

bottomless/src/replicator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,12 @@ impl Replicator {
935935
})?;
936936
tracing::trace!("Local change counter: {change_counter}");
937937

938+
// TODO: we shouldn't leak the connection here but for some reason when this connection get
939+
// dropped it seems to checkpoint the database
940+
if std::env::var("LIBSQL_BOTTOMLESS_DISABLE_INIT_CHECKPOINTING").is_ok() {
941+
std::mem::forget(conn);
942+
}
943+
938944
Ok(change_counter.to_be_bytes())
939945
}
940946

libsql-server/src/namespace/configurator/helpers.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ pub(super) async fn make_primary_connection_maker(
8484

8585
let bottomless_replicator = match primary_config.bottomless_replication {
8686
Some(ref options) => {
87-
tracing::debug!("Checkpointing before initializing bottomless");
88-
crate::replication::primary::logger::checkpoint_db(&db_path.join("data"))?;
89-
tracing::debug!("Checkpointed before initializing bottomless");
87+
// TODO: figure out why we really need this the fixme above is not clear enough but
88+
// disabling this allows us to prevent checkpointing of the wal file.
89+
if std::env::var("LIBSQL_DISABLE_INIT_CHECKPOINTING").is_err() {
90+
tracing::debug!("Checkpointing before initializing bottomless");
91+
crate::replication::primary::logger::checkpoint_db(&db_path.join("data"))?;
92+
tracing::debug!("Checkpointed before initializing bottomless");
93+
} else {
94+
tracing::warn!("Disabling initial checkpoint before bottomless");
95+
}
96+
9097
let options = make_bottomless_options(options, bottomless_db_id, name.clone());
9198
let (replicator, did_recover) =
9299
init_bottomless_replicator(db_path.join("data"), options, &restore_option).await?;

0 commit comments

Comments
 (0)