Skip to content

Commit

Permalink
Set replica state function does not need to be async anymore (qdrant#…
Browse files Browse the repository at this point in the history
  • Loading branch information
timvisee committed Nov 8, 2024
1 parent 1aeaf73 commit 567eb36
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
6 changes: 2 additions & 4 deletions lib/collection/src/collection/shard_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl Collection {
};

if transfer.to == self.this_peer_id {
replica_set.set_replica_state(transfer.to, state).await?;
replica_set.set_replica_state(transfer.to, state)?;
} else {
replica_set.add_remote(transfer.to, state).await?;
}
Expand Down Expand Up @@ -319,9 +319,7 @@ impl Collection {
// and so failed transfer does not introduce any inconsistencies to points
// that are not affected by resharding in all other shards
} else if transfer.sync {
replica_set
.set_replica_state(transfer.to, ReplicaState::Dead)
.await?;
replica_set.set_replica_state(transfer.to, ReplicaState::Dead)?;
} else {
replica_set.remove_peer(transfer.to).await?;
}
Expand Down
8 changes: 2 additions & 6 deletions lib/collection/src/shards/replica_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,19 +602,15 @@ impl ShardReplicaSet {
state: ReplicaState,
) -> CollectionResult<()> {
if peer_id == self.this_peer_id() {
self.set_replica_state(peer_id, state).await?;
self.set_replica_state(peer_id, state)?;
} else {
// Create remote shard if necessary
self.add_remote(peer_id, state).await?;
}
Ok(())
}

pub async fn set_replica_state(
&self,
peer_id: PeerId,
state: ReplicaState,
) -> CollectionResult<()> {
pub fn set_replica_state(&self, peer_id: PeerId, state: ReplicaState) -> CollectionResult<()> {
log::debug!(
"Changing local shard {}:{} state from {:?} to {state:?}",
self.collection_id,
Expand Down
10 changes: 4 additions & 6 deletions lib/collection/src/shards/replica_set/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,10 @@ mod tests {
// at build time the replicas are all dead, they need to be activated
assert_eq!(rs.highest_alive_replica_peer_id(), None);

rs.set_replica_state(1, ReplicaState::Active).await.unwrap();
rs.set_replica_state(3, ReplicaState::Active).await.unwrap();
rs.set_replica_state(4, ReplicaState::Active).await.unwrap();
rs.set_replica_state(5, ReplicaState::Partial)
.await
.unwrap();
rs.set_replica_state(1, ReplicaState::Active).unwrap();
rs.set_replica_state(3, ReplicaState::Active).unwrap();
rs.set_replica_state(4, ReplicaState::Active).unwrap();
rs.set_replica_state(5, ReplicaState::Partial).unwrap();

assert_eq!(rs.highest_replica_peer_id(), Some(5));
assert_eq!(rs.highest_alive_replica_peer_id(), Some(4));
Expand Down
1 change: 0 additions & 1 deletion lib/collection/src/shards/shard_holder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ impl ShardHolder {
log::warn!("Local shard {collection_id}:{} stuck in Initializing state, changing to Active", replica_set.shard_id);
replica_set
.set_replica_state(local_peer_id, ReplicaState::Active)
.await
.expect("Failed to set local shard state");
}
let shard_key = shard_id_to_key_mapping.get(&shard_id).cloned();
Expand Down
2 changes: 1 addition & 1 deletion lib/collection/src/shards/shard_holder/resharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl ShardHolder {
// Revert replicas in `Resharding` state back into `Active` state
for (peer, state) in shard.peers() {
if state == ReplicaState::Resharding {
shard.set_replica_state(peer, ReplicaState::Active).await?;
shard.set_replica_state(peer, ReplicaState::Active)?;
}
}

Expand Down

0 comments on commit 567eb36

Please sign in to comment.