Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DbTool] add a few commands to modify database with minimal safety checks #11612

Merged
merged 6 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Force rewind highest checkpoint execution watermark
  • Loading branch information
mwtian committed May 10, 2023
commit ef2bc5a2419e09acf7144c003bcb8e8299806666
11 changes: 11 additions & 0 deletions crates/sui-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ impl CheckpointStore {
}
}

pub fn set_highest_executed_checkpoint(
williampsmith marked this conversation as resolved.
Show resolved Hide resolved
&self,
checkpoint: &VerifiedCheckpoint,
) -> Result<(), TypedStoreError> {
self.watermarks.insert(
&CheckpointWatermark::HighestExecuted,
&(*checkpoint.sequence_number(), *checkpoint.digest()),
)?;
Ok(())
}

pub fn insert_checkpoint_contents(
&self,
contents: CheckpointContents,
Expand Down
46 changes: 44 additions & 2 deletions crates/sui-tool/src/db_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use self::db_dump::{dump_table, duplicate_objects_summary, list_tables, table_summary, StoreName};
use self::index_search::{search_index, SearchRange};
use crate::db_tool::db_dump::{compact, print_table_metadata};
use anyhow::bail;
use clap::Parser;
use std::path::{Path, PathBuf};
use sui_core::authority::authority_store_tables::AuthorityPerpetualTables;
Expand All @@ -22,8 +23,9 @@ pub enum DbToolCommand {
IndexSearchCount(IndexSearchCountOptions),
TableSummary(Options),
DuplicatesSummary,
ResetDB,
ListDBMetadata(Options),
ResetDB,
RewindCheckpointExecution(RewindCheckpointExecutionOptions),
Compact,
}

Expand Down Expand Up @@ -73,6 +75,16 @@ pub struct Options {
epoch: Option<EpochId>,
}

#[derive(Parser)]
#[clap(rename_all = "kebab-case")]
pub struct RewindCheckpointExecutionOptions {
#[clap(long = "epoch")]
epoch: EpochId,

#[clap(long = "checkpoint-sequence-number")]
checkpoint_sequence_number: u64,
}

pub fn execute_db_tool_command(db_path: PathBuf, cmd: DbToolCommand) -> anyhow::Result<()> {
match cmd {
DbToolCommand::ListTables => print_db_all_tables(db_path),
Expand All @@ -88,10 +100,13 @@ pub fn execute_db_tool_command(db_path: PathBuf, cmd: DbToolCommand) -> anyhow::
print_db_table_summary(d.store_name, d.epoch, db_path, &d.table_name)
}
DbToolCommand::DuplicatesSummary => print_db_duplicates_summary(db_path),
DbToolCommand::ResetDB => reset_db_to_genesis(&db_path),
DbToolCommand::ListDBMetadata(d) => {
print_table_metadata(d.store_name, d.epoch, db_path, &d.table_name)
}
DbToolCommand::ResetDB => reset_db_to_genesis(&db_path),
DbToolCommand::RewindCheckpointExecution(d) => {
rewind_checkpoint_execution(&db_path, d.epoch, d.checkpoint_sequence_number)
}
DbToolCommand::Compact => compact(db_path),
DbToolCommand::IndexSearchKeyRange(rg) => {
let res = search_index(
Expand Down Expand Up @@ -184,6 +199,33 @@ pub fn reset_db_to_genesis(path: &Path) -> anyhow::Result<()> {
Ok(())
}

// Force sets the highest executed checkpoint.
// NOTE: Does not force re-execution of transactions yet.
// Run with: cargo run --package sui-tool -- db-tool --db-path /opt/sui/db/authorities_db/live rewind-checkpoint-execution --epoch 3 --checkpoint-sequence-number 300000
williampsmith marked this conversation as resolved.
Show resolved Hide resolved
pub fn rewind_checkpoint_execution(
path: &Path,
epoch: EpochId,
checkpoint_sequence_number: u64,
) -> anyhow::Result<()> {
let checkpoint_db = CheckpointStore::open_tables_read_write(
path.join("checkpoints"),
MetricConf::default(),
None,
None,
);
let Some(checkpoint) = checkpoint_db.get_checkpoint_by_sequence_number(checkpoint_sequence_number)? else {
bail!("Checkpoint {checkpoint_sequence_number} not found!");
};
if epoch != checkpoint.epoch() {
bail!(
"Checkpoint {checkpoint_sequence_number} is in epoch {} not {epoch}!",
checkpoint.epoch()
);
}
checkpoint_db.set_highest_executed_checkpoint(&checkpoint)?;
Ok(())
}

pub fn print_db_table_summary(
store: StoreName,
epoch: Option<EpochId>,
Expand Down