Skip to content

Commit

Permalink
Updated the implementation to show the relationship to the semaphore.
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Mar 13, 2024
1 parent 8b3be42 commit 551baf6
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions crates/services/importer/src/importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,13 @@ where
if let Some(channel) = previous_block_result {
let _ = channel.await;
}
let mut guard = self
.database
.try_lock()
.expect("Semaphore prevents from multiple access to teh database");
let database = guard.deref_mut();

self._commit_result(result)
self._commit_result(result, database)
}

/// The method commits the result of the block execution and notifies about a new imported block.
Expand All @@ -207,12 +212,11 @@ where
),
err
)]
fn _commit_result(&self, result: UncommittedResult<Changes>) -> Result<(), Error> {
let mut guard = self
.database
.try_lock()
.expect("Semaphore prevents from multiple access to teh database");
let database = guard.deref_mut();
fn _commit_result(
&self,
result: UncommittedResult<Changes>,
database: &mut D,
) -> Result<(), Error> {
let (result, changes) = result.into();
let block = &result.sealed_block.entity;
let consensus = &result.sealed_block.consensus;
Expand Down Expand Up @@ -456,7 +460,13 @@ where
}

let start = Instant::now();
let commit_result = self._commit_result(result);

let mut guard = self
.database
.try_lock()
.expect("Semaphore prevents from multiple access to teh database");
let database = guard.deref_mut();
let commit_result = self._commit_result(result, database);
let commit_time = start.elapsed().as_secs_f64();
let time = execute_time + commit_time;
importer_metrics().execute_and_commit_duration.observe(time);
Expand Down

0 comments on commit 551baf6

Please sign in to comment.