Skip to content

Commit

Permalink
fix(kura): Inline kura initialization into constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
  • Loading branch information
Erigara committed May 17, 2024
1 parent 9d91c77 commit 6fd6600
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,10 @@ impl Iroha<ToriiNotStarted> {
.into_non_empty_vec(),
);

let kura = Kura::new(&config.kura).change_context(StartError::InitKura)?;
let (kura, block_count) = Kura::new(&config.kura).change_context(StartError::InitKura)?;
let kura_thread_handler = Kura::start(Arc::clone(&kura));
let live_query_store_handle = LiveQueryStore::from_config(config.live_query_store).start();

let block_count = kura.init().change_context(StartError::InitKura)?;

let state = match try_read_snapshot(
config.snapshot.store_dir.resolve_relative_path(),
&kura,
Expand Down
2 changes: 1 addition & 1 deletion core/benches/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn measure_block_size_for_n_executors(n_executors: u32) {
debug_output_new_blocks: false,
store_dir: WithOrigin::inline(dir.path().to_path_buf()),
};
let kura = iroha_core::kura::Kura::new(&cfg).unwrap();
let (kura, _) = iroha_core::kura::Kura::new(&cfg).unwrap();
let _thread_handle = iroha_core::kura::Kura::start(kura.clone());

let query_handle = LiveQueryStore::test().start();
Expand Down
10 changes: 5 additions & 5 deletions core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Kura {
/// Fails if there are filesystem errors when trying
/// to access the block store indicated by the provided
/// path.
pub fn new(config: &Config) -> Result<Arc<Self>> {
pub fn new(config: &Config) -> Result<(Arc<Self>, BlockCount)> {
let store_dir = config.store_dir.resolve_relative_path();
let mut block_store = BlockStore::new(&store_dir, LockStatus::Unlocked);
block_store.create_files_if_they_do_not_exist()?;
Expand All @@ -65,7 +65,9 @@ impl Kura {
block_plain_text_path,
});

Ok(kura)
let block_count = kura.init()?;

Ok((kura, block_count))
}

/// Create a kura instance that doesn't write to disk. Instead it serves as a handler
Expand Down Expand Up @@ -104,7 +106,7 @@ impl Kura {
/// - file storage is unavailable
/// - data in file storage is invalid or corrupted
#[iroha_logger::log(skip_all, name = "kura_init")]
pub fn init(self: &Arc<Self>) -> Result<BlockCount> {
fn init(self: &Arc<Self>) -> Result<BlockCount> {
let mut block_store = self.block_store.lock();

let block_index_count: usize = block_store
Expand Down Expand Up @@ -1056,8 +1058,6 @@ mod tests {
),
debug_output_new_blocks: false,
})
.unwrap()
.init()
.unwrap();
}
}

0 comments on commit 6fd6600

Please sign in to comment.