From c8b1ce56d8bc220daa6a9344d28aac6d5d690030 Mon Sep 17 00:00:00 2001 From: Rostyslav Tyshko Date: Mon, 9 Dec 2024 04:01:20 +0100 Subject: [PATCH] add destroy to nodeblockstore as well --- node_core/src/storage/block_store.rs | 10 ++++++++-- storage/src/lib.rs | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/node_core/src/storage/block_store.rs b/node_core/src/storage/block_store.rs index 2766f45..fae6846 100644 --- a/node_core/src/storage/block_store.rs +++ b/node_core/src/storage/block_store.rs @@ -1,6 +1,6 @@ use std::path::Path; -use anyhow::Result; +use anyhow::{Result, anyhow}; use storage::{block::Block, RocksDBIO}; pub struct NodeBlockStore { @@ -20,14 +20,20 @@ impl NodeBlockStore { ///Reopening existing database pub fn open_db_restart(location: &Path) -> Result { + NodeBlockStore::db_destroy(location)?; NodeBlockStore::open_db_with_genesis(location, None) } + ///Destroying existing database + fn db_destroy(location: &Path) -> Result<()> { + RocksDBIO::destroy(location).map_err(|err| anyhow!("RocksDBIO error: {}", err)) + } + pub fn get_block_at_id(&self, id: u64) -> Result { Ok(self.dbio.get_block(id)?) } pub fn put_block_at_id(&self, block: Block) -> Result<()> { - Ok(self.dbio.put_block(block)?) + Ok(self.dbio.put_block(block, false)?) } } diff --git a/storage/src/lib.rs b/storage/src/lib.rs index 20e5248..7a34a64 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -196,10 +196,10 @@ impl RocksDBIO { let cf_block = self.block_column(); if !first { - let last_curr_block = self.get_meta_last_block_in_db()?; + let last_curr_block = self.get_meta_last_block_in_db()?; - if block.block_id > last_curr_block { - self.put_meta_last_block_in_db(block.block_id)?; + if block.block_id > last_curr_block { + self.put_meta_last_block_in_db(block.block_id)?; } }