Repository: qdrant/qdrant
File: lib/collection/src/shards/shard_holder/mod.rs (Rust)

Code before:
        self.rings.remove(&shard_key.clone().into());
        for shard_id in remove_shard_ids {
            self.drop_and_remove_shard(shard_id).await?;
            self.shard_id_to_key_mapping.remove(&shard_id);
        }
        Ok(())
    }

    fn rebuild_rings(&mut self) {
        let mut rings = match self.sharding_method {
            // With auto sharding, we have a single hash ring
            ShardingMethod::Auto => HashMap::from([(None, HashRingRouter::single())]),
            // With custom sharding, we have a hash ring per shard key
            ShardingMethod::Custom => HashMap::new(),
        };

        // Add shards and shard keys
        let ids_to_key = self.get_shard_id_to_key_mapping();
        for shard_id in self.shards.keys() {
            let shard_key = ids_to_key.get(shard_id).cloned();
            debug_assert!(
                matches!(
                    (self.sharding_method, &shard_key),
                    (ShardingMethod::Auto, None) | (ShardingMethod::Custom, Some(_)),
                ),
                "auto sharding cannot have shard key, custom sharding must have shard key",
            );
            rings
                .entry(shard_key)
                .or_insert_with(HashRingRouter::single)
                .add(*shard_id);
        }

        // Restore resharding hash ring if resharding is active and haven't reached
        // `WriteHashRingCommitted` stage yet
        if let Some(state) = self.resharding_state.read().deref() {
            let ring = rings
                .get_mut(&state.shard_key)
                .expect("must have hash ring for current resharding shard key");

            ring.start_resharding(state.shard_id, state.direction);

            if state.stage >= ReshardStage::WriteHashRingCommitted {
                ring.commit_resharding();
            }
        }

        self.rings = rings;
    }

    pub async fn apply_shards_state(

Review comment (suggestion):
```suggestion
                "auto sharding cannot have shard key, custom sharding must have shard key ({:?}, {shard_key:?})",
                self.sharding_method,
```

Code after:
        self.rings.remove(&shard_key.clone().into());
        for shard_id in remove_shard_ids {
            self.drop_and_remove_shard(shard_id).await?;
            self.shard_id_to_key_mapping.remove(&shard_id);
        }
        Ok(())
    }

    fn rebuild_rings(&mut self) {
        let mut rings = match self.sharding_method {
            // With auto sharding, we have a single hash ring
            ShardingMethod::Auto => HashMap::from([(None, HashRingRouter::single())]),
            // With custom sharding, we have a hash ring per shard key
            ShardingMethod::Custom => HashMap::new(),
        };

        // Add shards and shard keys
        let ids_to_key = self.get_shard_id_to_key_mapping();
        for shard_id in self.shards.keys() {
            let shard_key = ids_to_key.get(shard_id).cloned();
            debug_assert!(
                matches!(
                    (self.sharding_method, &shard_key),
                    (ShardingMethod::Auto, None) | (ShardingMethod::Custom, Some(_)),
                ),
                "auto sharding cannot have shard key, custom sharding must have shard key ({:?}, {shard_key:?})",
                self.sharding_method,
            );
            rings
                .entry(shard_key)
                .or_insert_with(HashRingRouter::single)
                .add(*shard_id);
        }

        // Restore resharding hash ring if resharding is active and haven't reached
        // `WriteHashRingCommitted` stage yet
        if let Some(state) = self.resharding_state.read().deref() {
            let ring = rings
                .get_mut(&state.shard_key)
                .expect("must have hash ring for current resharding shard key");

            ring.start_resharding(state.shard_id, state.direction);

            if state.stage >= ReshardStage::WriteHashRingCommitted {
                ring.commit_resharding();
            }
        }

        self.rings = rings;
    }