Skip to content

Commit

Permalink
Merge branch 'tim/add-canceld-method' into 'master'
Browse files Browse the repository at this point in the history
fix: Add should_cancel method to StateSyncClient API

 

See merge request dfinity-lab/public/ic!13113
  • Loading branch information
tthebst committed Jun 23, 2023
2 parents 0707f6b + fe747bd commit ebd2866
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitlab/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ go_deps.bzl @dfinity-lab/teams/idx
/rs/interfaces/src/dkg.rs @dfinity-lab/teams/consensus-owners
/rs/interfaces/src/execution_environment.rs @dfinity-lab/teams/execution-owners @dfinity-lab/teams/runtime-owners
/rs/interfaces/src/messaging.rs @dfinity-lab/teams/message-routing-owners
/rs/interfaces/src/state_sync_client.rs @dfinity-lab/teams/message-routing-owners @dfinity-lab/teams/networking-team
/rs/interfaces/state_manager/ @dfinity-lab/teams/message-routing-owners
/rs/interfaces/state_sync_client.rs @dfinity-lab/teams/message-routing-owners @dfinity-lab/teams/networking-team
/rs/interfaces/transport/ @dfinity-lab/teams/networking-team
/rs/log_analyzer/ @dfinity-lab/teams/ic-testing-verification
/rs/memory_tracker/ @dfinity-lab/teams/runtime-owners
Expand Down
10 changes: 7 additions & 3 deletions rs/interfaces/src/state_sync_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ pub trait StateSyncClient: Send + Sync {
/// Returns the Id of the latest available state or None if no state is available.
fn latest_state(&self) -> Option<StateSyncArtifactId>;
/// Initiates new state sync for the specified Id. Returns None if the state should not be synced.
/// If `Some(..)` is returned a new state sync is initated.
/// If `Some(..)` is returned a new state sync is initiated.
/// Callers of this interface need to uphold the following: `start_state_sync` is not called again
/// before the previously returned object is dropped.
/// TODO: (NET-1469) In the future the mentiond caller restriction should be lifted.
/// TODO: (NET-1469) In the future the mentioned caller restriction should be lifted.
fn start_state_sync(
&self,
id: &StateSyncArtifactId,
) -> Option<Box<dyn Chunkable + Send + Sync>>;
/// Get a specifc chunk from the specified state.
/// Returns true if a state sync with the specified Id can be cancelled because a newer state is available.
/// The result of this function is only meaningful the Id refers to a active state sync started with `start_state_sync`.
/// TODO: (NET-1469) In the future this API should be made safer by only allowing the id of a previously initiated state sync.
fn should_cancel(&self, id: &StateSyncArtifactId) -> bool;
/// Get a specific chunk from the specified state.
fn chunk(&self, id: &StateSyncArtifactId, chunk_id: ChunkId) -> Option<ArtifactChunk>;
/// Finish a state sync by delivering the `StateSyncMessage` returned in `Chunkable::add_chunks`.
/// TODO: (NET-1469) In the future peer_id should be removed from this interface since it has no relevance.
Expand Down
9 changes: 7 additions & 2 deletions rs/state_manager/src/state_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,18 @@ impl StateSyncClient for StateSync {
Some(self.get_chunk_tracker(id))
}

/// Blocking. Makes synchroneous file system calls.
/// Non-Blocking.
fn should_cancel(&self, id: &StateSyncArtifactId) -> bool {
self.get_priority_function()(id, &()) == Priority::Drop
}

/// Blocking. Makes synchronous file system calls.
fn chunk(&self, id: &StateSyncArtifactId, chunk_id: ChunkId) -> Option<ArtifactChunk> {
let msg = self.get_validated_by_identifier(id)?;
Box::new(msg).get_chunk(chunk_id)
}

/// Blocking. Makes synchroneous file system calls.
/// Blocking. Makes synchronous file system calls.
fn deliver_state_sync(&self, msg: StateSyncMessage, peer_id: NodeId) {
let _ = self.process_changes(
&SysTimeSource::new(),
Expand Down

0 comments on commit ebd2866

Please sign in to comment.