Skip to content

Commit 24f9ea2

Browse files
committed
rpc-index: reset db by dropping it
1 parent ebe75b1 commit 24f9ea2

File tree

1 file changed

+7
-56
lines changed

1 file changed

+7
-56
lines changed

crates/sui-core/src/rpc_index.rs

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -204,60 +204,6 @@ impl IndexStoreTables {
204204
)
205205
}
206206

207-
/// Lists all Column Families present in the on-disk database
208-
fn list_cfs(&self) -> Vec<String> {
209-
let path = self.meta.db.path_for_pruning();
210-
typed_store::rocks::list_tables(path.to_path_buf()).unwrap()
211-
}
212-
213-
/// Lists all Column Families that are known about in-code as defined in `IndexStoreTables`
214-
fn known_cfs() -> Vec<String> {
215-
IndexStoreTables::describe_tables().into_keys().collect()
216-
}
217-
218-
/// Lists all Column Families that are present on-disk but not known by this version of code as
219-
/// defined in `IndexStoreTables`
220-
fn unknown_cfs(&self) -> Vec<String> {
221-
let known_cfs = Self::known_cfs();
222-
self.list_cfs()
223-
.into_iter()
224-
.filter(|cf| !known_cfs.contains(cf))
225-
.collect()
226-
}
227-
228-
fn drop_cf(&mut self, cf: &str) -> Result<(), TypedStoreError> {
229-
self.meta
230-
.db
231-
.drop_cf(cf)
232-
.map_err(typed_store::rocks::errors::typed_store_err_from_rocks_err)
233-
}
234-
235-
fn create_cf(&mut self, cf: &str) -> Result<(), TypedStoreError> {
236-
self.meta
237-
.db
238-
.create_cf(cf, &typed_store::rocks::default_db_options().options)
239-
.map_err(typed_store::rocks::errors::typed_store_err_from_rocks_err)
240-
}
241-
242-
fn reset_cf(&mut self, cf: &str) -> Result<(), TypedStoreError> {
243-
self.drop_cf(cf)?;
244-
self.create_cf(cf)
245-
}
246-
247-
fn reset_db(&mut self) -> Result<(), TypedStoreError> {
248-
// Drop unknown cfs
249-
for cf in self.unknown_cfs() {
250-
self.drop_cf(&cf)?;
251-
}
252-
253-
// Reset known cfs
254-
for cf in Self::known_cfs() {
255-
self.reset_cf(&cf)?;
256-
}
257-
258-
Ok(())
259-
}
260-
261207
fn needs_to_do_initialization(&self, checkpoint_store: &CheckpointStore) -> bool {
262208
(match self.meta.get(&()) {
263209
Ok(Some(metadata)) => metadata.version != CURRENT_DB_VERSION,
@@ -706,12 +652,17 @@ impl RpcIndexStore {
706652
let path = Self::db_path(dir);
707653

708654
let tables = {
709-
let mut tables = IndexStoreTables::open(&path);
655+
let tables = IndexStoreTables::open(&path);
710656

711657
// If the index tables are uninitialized or on an older version then we need to
712658
// populate them
713659
if tables.needs_to_do_initialization(checkpoint_store) {
714-
tables.reset_db().expect("unable to reset rpc-index db");
660+
let mut tables = {
661+
drop(tables);
662+
typed_store::rocks::safe_drop_db(path.clone())
663+
.expect("unable to destroy old rpc-index db");
664+
IndexStoreTables::open(path)
665+
};
715666

716667
tables
717668
.init(

0 commit comments

Comments
 (0)