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

Code before:
                continue;
            }

            tar.blocking_append_file(&entry.path(), Path::new(&entry.file_name()))
                .map_err(|err| {
                    CollectionError::service_error(format!("Error while archiving WAL: {err}"))
                })?;
        }
        Ok(())
    }

    pub fn snapshot_manifest(&self) -> CollectionResult<SnapshotManifest> {
        self.segments()
            .read()
            .snapshot_manifest()
            .map_err(CollectionError::from)
    }

    pub fn estimate_cardinality<'a>(
        &'a self,
        filter: Option<&'a Filter>,
        hw_counter: &HardwareCounterCell,
    ) -> CollectionResult<CardinalityEstimation> {
        let segments = self.segments().read();
        let cardinality = segments
            .iter()
            .map(|(_id, segment)| {
                segment
                    .get()
                    .read()
                    .estimate_point_count(filter, hw_counter)
            })
            .fold(CardinalityEstimation::exact(0), |acc, x| {
                CardinalityEstimation {
                    primary_clauses: vec![],
                    min: acc.min + x.min,
                    exp: acc.exp + x.exp,
                    max: acc.max + x.max,
                }
            });
        Ok(cardinality)
    }

    pub async fn read_filtered<'a>(
        &'a self,
        filter: Option<&'a Filter>,
        runtime_handle: &Handle,
        hw_counter: HwMeasurementAcc,
    ) -> CollectionResult<BTreeSet<PointIdType>> {
        let segments = self.segments.clone();
        SegmentsSearcher::read_filtered(segments, filter, runtime_handle, hw_counter).await

Review comment (suggestion):
I did not find an alternative to cloning the incoming `Filter` as it can't be bound to `'a` to be transferred to a spawned task.

Code after:
                continue;
            }

            tar.blocking_append_file(&entry.path(), Path::new(&entry.file_name()))
                .map_err(|err| {
                    CollectionError::service_error(format!("Error while archiving WAL: {err}"))
                })?;
        }
        Ok(())
    }

    pub fn snapshot_manifest(&self) -> CollectionResult<SnapshotManifest> {
        self.segments()
            .read()
            .snapshot_manifest()
            .map_err(CollectionError::from)
    }

    pub async fn estimate_cardinality<'a>(
        &'a self,
        filter: Option<&'a Filter>,
        hw_measurement_acc: &HwMeasurementAcc,
    ) -> CollectionResult<CardinalityEstimation> {
        let segments = self.segments.clone();
        let hw_counter = hw_measurement_acc.get_counter_cell();
        // clone filter for spawning task
        let filter = filter.cloned();
        let cardinality = tokio::task::spawn_blocking(move || {
            let segments = segments.read(); // blocking sync lock
            segments
                .iter()
                .map(|(_id, segment)| {
                    segment
                        .get()
                        .read() // blocking sync lock
                        .estimate_point_count(filter.as_ref(), &hw_counter)
                })
                .fold(CardinalityEstimation::exact(0), |acc, x| {
                    CardinalityEstimation {
                        primary_clauses: vec![],
                        min: acc.min + x.min,
                        exp: acc.exp + x.exp,
                        max: acc.max + x.max,
                    }
                })
        })
        .await?;
        Ok(cardinality)
    }

    pub async fn read_filtered<'a>(