Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

bottomless: checkpoint before initializing bottomless #726

Merged
merged 2 commits into from
Oct 3, 2023
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
7 changes: 5 additions & 2 deletions bottomless/src/replicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,11 @@ impl Replicator {
},
};

tracing::info!("Restoring from generation {}", generation);
self.restore_from(generation, timestamp).await
let (action, recovered) = self.restore_from(generation, timestamp).await?;
tracing::info!(
"Restoring from generation {generation}: action={action:?}, recovered={recovered}"
);
Ok((action, recovered))
}

pub async fn get_last_consistent_frame(&self, generation: &Uuid) -> Result<u32> {
Expand Down
12 changes: 12 additions & 0 deletions sqld/src/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,18 @@ impl Namespace<PrimaryDatabase> {

tokio::fs::create_dir_all(&db_path).await?;

// FIXME: due to a bug in logger::checkpoint_db we call regular checkpointing code
// instead of our virtual WAL one. It's a bit tangled to fix right now, because
// we need WAL context for checkpointing, and WAL context needs the ReplicationLogger...
// So instead we checkpoint early, *before* bottomless gets initialized. That way
// we're sure bottomless won't try to back up any existing WAL frames and will instead
// treat the existing db file as the source of truth.
if config.bottomless_replication.is_some() {
tracing::debug!("Checkpointing before initializing bottomless");
crate::replication::primary::logger::checkpoint_db(&db_path.join("data"))?;
tracing::debug!("Checkpointed before initializing bottomless");
}

let bottomless_replicator = if let Some(options) = &config.bottomless_replication {
let options = make_bottomless_options(options, name.clone());
let (replicator, did_recover) =
Expand Down
5 changes: 4 additions & 1 deletion sqld/src/replication/primary/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ unsafe impl WalHook for ReplicationLoggerHook {
assert_eq!(page_size, 4096);
let wal_ptr = wal as *mut _;
let last_valid_frame = wal.hdr.mxFrame;
tracing::trace!("Last valid frame before applying: {last_valid_frame}");
let ctx = Self::wal_extract_ctx(wal);

let mut frame_count = 0;
Expand Down Expand Up @@ -948,7 +949,9 @@ impl ReplicationLogger {
}
}

fn checkpoint_db(data_path: &Path) -> anyhow::Result<()> {
// FIXME: calling rusqlite::Connection's checkpoint here is a bug,
// we need to always call our virtual WAL methods.
pub fn checkpoint_db(data_path: &Path) -> anyhow::Result<()> {
let wal_path = match data_path.parent() {
Some(path) => path.join("data-wal"),
None => return Ok(()),
Expand Down