add destroy to nodeblockstore as well

This commit is contained in:
Rostyslav Tyshko 2024-12-09 04:01:20 +01:00
parent 84c7eaf1d0
commit c8b1ce56d8
2 changed files with 11 additions and 5 deletions

View File

@ -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<Self> {
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<Block> {
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)?)
}
}

View File

@ -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)?;
}
}