-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c731ab9
commit a0045fe
Showing
3 changed files
with
50 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,44 @@ | ||
use dolos::wal::redb::WalStore; | ||
use miette::{bail, Context, IntoDiagnostic}; | ||
use tracing::info; | ||
|
||
use crate::feedback::Feedback; | ||
|
||
#[derive(Debug, clap::Args, Default)] | ||
pub struct Args {} | ||
pub struct Args { | ||
/// Skip the bootstrap if there's already data in the stores | ||
#[arg(long, action)] | ||
skip_if_not_empty: bool, | ||
} | ||
|
||
fn open_empty_wal(config: &crate::Config) -> miette::Result<WalStore> { | ||
fn open_empty_wal(config: &crate::Config, args: &Args) -> miette::Result<Option<WalStore>> { | ||
let wal = crate::common::open_wal(config)?; | ||
|
||
let is_empty = wal.is_empty().into_diagnostic()?; | ||
|
||
if !is_empty { | ||
bail!("can't continue with data already available"); | ||
if args.skip_if_not_empty { | ||
return Ok(None); | ||
} else { | ||
bail!("can't continue with data already available"); | ||
} | ||
} | ||
|
||
Ok(wal) | ||
Ok(Some(wal)) | ||
} | ||
|
||
pub fn run(config: &crate::Config, _args: &Args, _feedback: &Feedback) -> miette::Result<()> { | ||
let mut wal = open_empty_wal(config).context("opening WAL")?; | ||
|
||
wal.initialize_from_origin() | ||
.into_diagnostic() | ||
.context("initializing WAL")?; | ||
|
||
Ok(()) | ||
pub fn run(config: &crate::Config, args: &Args, _feedback: &Feedback) -> miette::Result<()> { | ||
match open_empty_wal(config, args).context("opening WAL")? { | ||
Some(mut wal) => { | ||
wal.initialize_from_origin() | ||
.into_diagnostic() | ||
.context("initializing WAL")?; | ||
|
||
Ok(()) | ||
} | ||
None => { | ||
info!("Skipping bootstrap, data already present."); | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters