Skip to content

Commit

Permalink
Add command to remove object lock
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtian committed May 10, 2023
1 parent d4ebf0e commit d1ce05a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
33 changes: 33 additions & 0 deletions crates/sui-core/src/authority/authority_store_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,46 @@ impl AuthorityPerpetualTables {
let mut wb = self.objects.batch();
for object in objects {
wb.delete_batch(&self.objects, [object])?;
self.remove_object_lock_batch(&mut wb, object)?;
}
wb.delete_batch(&self.executed_transactions_to_checkpoint, [digest])?;
wb.delete_batch(&self.executed_effects, [digest])?;
wb.write()?;
Ok(())
}

pub fn has_object_lock(&self, object: &ObjectKey) -> bool {
self.owned_object_transaction_locks
.iter_with_bounds(
Some((object.0, object.1, ObjectDigest::MIN)),
Some((object.0, object.1, ObjectDigest::MAX)),
)
.next()
.is_some()
}

pub fn remove_object_lock(&self, object: &ObjectKey) -> SuiResult<ObjectRef> {
let mut wb = self.objects.batch();
let object_ref = self.remove_object_lock_batch(&mut wb, object)?;
wb.write()?;
Ok(object_ref)
}

fn remove_object_lock_batch(
&self,
wb: &mut DBBatch,
object: &ObjectKey,
) -> SuiResult<ObjectRef> {
wb.delete_range(
&self.owned_object_transaction_locks,
&(object.0, object.1, ObjectDigest::MIN),
&(object.0, object.1, ObjectDigest::MAX),
)?;
let object_ref = self.get_object_or_tombstone(object.0)?.unwrap();
wb.insert_batch(&self.owned_object_transaction_locks, [(object_ref, None)])?;
Ok(object_ref)
}

pub fn database_is_empty(&self) -> SuiResult<bool> {
Ok(self
.objects
Expand Down
38 changes: 37 additions & 1 deletion crates/sui-tool/src/db_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use clap::Parser;
use std::path::{Path, PathBuf};
use sui_core::authority::authority_store_tables::AuthorityPerpetualTables;
use sui_core::checkpoints::CheckpointStore;
use sui_types::base_types::EpochId;
use sui_types::base_types::{EpochId, ObjectID, SequenceNumber};
use sui_types::digests::TransactionDigest;
use sui_types::effects::TransactionEffectsAPI;
use sui_types::storage::ObjectKey;
use typed_store::rocks::MetricConf;
pub mod db_dump;
mod index_search;
Expand All @@ -27,6 +28,7 @@ pub enum DbToolCommand {
DuplicatesSummary,
ListDBMetadata(Options),
PrintTransactionCheckpoint(PrintTransactionOptions),
RemoveObjectLock(RemoveObjectLockOptions),
RemoveTransaction(RemoveTransactionOptions),
ResetDB,
RewindCheckpointExecution(RewindCheckpointExecutionOptions),
Expand Down Expand Up @@ -96,6 +98,19 @@ pub struct RemoveTransactionOptions {
confirm: bool,
}

#[derive(Parser)]
#[clap(rename_all = "kebab-case")]
pub struct RemoveObjectLockOptions {
#[clap(long, help = "The object ID to remove")]
id: ObjectID,

#[clap(long, help = "The object version to remove")]
version: u64,

#[clap(long)]
confirm: bool,
}

#[derive(Parser)]
#[clap(rename_all = "kebab-case")]
pub struct RewindCheckpointExecutionOptions {
Expand Down Expand Up @@ -126,6 +141,7 @@ pub fn execute_db_tool_command(db_path: PathBuf, cmd: DbToolCommand) -> anyhow::
}
DbToolCommand::PrintTransactionCheckpoint(d) => print_transaction_checkpoint(&db_path, d),
DbToolCommand::ResetDB => reset_db_to_genesis(&db_path),
DbToolCommand::RemoveObjectLock(d) => remove_object_lock(&db_path, d),
DbToolCommand::RemoveTransaction(d) => remove_transaction(&db_path, d),
DbToolCommand::RewindCheckpointExecution(d) => {
rewind_checkpoint_execution(&db_path, d.epoch, d.checkpoint_sequence_number)
Expand Down Expand Up @@ -235,6 +251,26 @@ pub fn remove_transaction(path: &Path, opt: RemoveTransactionOptions) -> anyhow:
println!("Proceeding to remove transaction {:?} in 5s ..", opt.digest);
std::thread::sleep(std::time::Duration::from_secs(5));
perpetual_db.remove_executed_effects_and_outputs(&opt.digest, &objects_to_remove)?;
println!("Done!");
}
Ok(())
}

pub fn remove_object_lock(path: &Path, opt: RemoveObjectLockOptions) -> anyhow::Result<()> {
let perpetual_db = AuthorityPerpetualTables::open(&path.join("store"), None);
let key = ObjectKey(opt.id, SequenceNumber::from_u64(opt.version));
if !opt.confirm && !perpetual_db.has_object_lock(&key) {
bail!("Owned object lock for {:?} is not found!", key);
};
println!("Removing owned object lock for {:?}", key);
if opt.confirm {
println!(
"Proceeding to remove owned object lock for {:?} in 5s ..",
key
);
std::thread::sleep(std::time::Duration::from_secs(5));
let created_ref = perpetual_db.remove_object_lock(&key)?;
println!("Done! Lock is now initialized for {:?}", created_ref);
}
Ok(())
}
Expand Down

0 comments on commit d1ce05a

Please sign in to comment.