Repository: qdrant/qdrant
File: src/tonic/api/collections_api.rs (Rust)

Code before:
            access,
            timeout.map(std::time::Duration::from_secs),
        )
        .await?;
        Ok(Response::new(UpdateCollectionClusterSetupResponse {
            result,
        }))
    }

    async fn list_shard_keys(
        &self,
        mut request: Request<ListShardKeysRequest>,
    ) -> Result<Response<ListShardKeysResponse>, Status> {
        validate(request.get_ref())?;
        let timing = Instant::now();
        let access = extract_access(&mut request);

        // Nothing to verify here.
        let pass = new_unchecked_verification_pass();

        let shard_keys: CollectionShardKeys = do_get_collection_shard_keys(
            self.dispatcher.toc(&access, &pass),
            access,
            request.into_inner().collection_name.as_str(),
        )
        .await?;
        let response = ListShardKeysResponse {
            shard_keys: shard_keys.into(),
            time: timing.elapsed().as_secs_f64(),
        };
        Ok(Response::new(response))
    }

    async fn create_shard_key(
        &self,
        mut request: Request<CreateShardKeyRequest>,
    ) -> Result<Response<CreateShardKeyResponse>, Status> {
        let access = extract_access(&mut request);

        let CreateShardKeyRequest {
            collection_name,
            request,
            timeout,
        } = request.into_inner();

        let Some(request) = request else {
            return Err(Status::new(tonic::Code::InvalidArgument, "empty request"));
        };

        let timeout = timeout.map(std::time::Duration::from_secs);


Review comment (suggestion):
Shard keys are only used when custom sharding is enabled.

I wonder if it makes sense to just return an error if custom sharding is not enabled.

Code after:
            access,
            timeout.map(std::time::Duration::from_secs),
        )
        .await?;
        Ok(Response::new(UpdateCollectionClusterSetupResponse {
            result,
        }))
    }

    async fn list_shard_keys(
        &self,
        mut request: Request<ListShardKeysRequest>,
    ) -> Result<Response<ListShardKeysResponse>, Status> {
        validate(request.get_ref())?;
        let timing = Instant::now();
        let access = extract_access(&mut request);

        // Nothing to verify here.
        let pass = new_unchecked_verification_pass();

        let result = do_get_collection_shard_keys(
            self.dispatcher.toc(&access, &pass),
            access,
            request.into_inner().collection_name.as_str(),
        )
        .await?;

        let response = ListShardKeysResponse::from((timing, result));
        Ok(Response::new(response))
    }

    async fn create_shard_key(
        &self,
        mut request: Request<CreateShardKeyRequest>,
    ) -> Result<Response<CreateShardKeyResponse>, Status> {
        let access = extract_access(&mut request);

        let CreateShardKeyRequest {
            collection_name,
            request,
            timeout,
        } = request.into_inner();

        let Some(request) = request else {
            return Err(Status::new(tonic::Code::InvalidArgument, "empty request"));
        };

        let timeout = timeout.map(std::time::Duration::from_secs);

        let operation = ClusterOperations::CreateShardingKey(CreateShardingKeyOperation {
            create_sharding_key: request.try_into()?,