Repository: qdrant/qdrant
File: lib/shard/src/proxy_segment/segment_entry.rs (Rust)

Code before:

    fn delete_field_index(&mut self, op_num: u64, key: PayloadKeyTypeRef) -> OperationResult<bool> {
        if self.version() > op_num {
            return Ok(false);
        }

        self.version = cmp::max(self.version, op_num);

        // Store index change to later propagate to optimized/wrapped segment
        self.changed_indexes
            .insert(key.clone(), ProxyIndexChange::Delete(op_num));

        Ok(true)
    }

    fn delete_field_index_if_incompatible(
        &mut self,
        op_num: SeqNumberType,
        key: PayloadKeyTypeRef,
        field_schema: &PayloadFieldSchema,
    ) -> OperationResult<bool> {
        if self.version() > op_num {
            return Ok(false);
        }

        self.version = cmp::max(self.version, op_num);

        self.changed_indexes.insert(
            key.clone(),
            ProxyIndexChange::DeleteIfIncompatible(op_num, field_schema.clone()),
        );

        Ok(true)
    }

    fn build_field_index(
        &self,
        op_num: SeqNumberType,
        _key: PayloadKeyTypeRef,
        field_type: &PayloadFieldSchema,
        _hw_counter: &HardwareCounterCell,
    ) -> OperationResult<BuildFieldIndexResult> {
        if self.version() > op_num {
            return Ok(BuildFieldIndexResult::SkippedByVersion);
        }

        Ok(BuildFieldIndexResult::Built {
            indexes: vec![], // No actual index is built in proxy segment, they will be created later
            schema: field_type.clone(),
        })
    }

Review comment (suggestion):
This implementation seemed redundant and this `.info()` and `.size_info()` function are called only in tests.

Code after:

        // This is a best estimate
        let num_vectors = wrapped_info
            .num_vectors
            .saturating_sub(deleted_points_count * vector_name_count);

        let num_indexed_vectors = if wrapped_info.segment_type == SegmentType::Indexed {
            wrapped_info
                .num_vectors
                .saturating_sub(deleted_points_count * vector_name_count)
        } else {
            0
        };

        let vector_data = wrapped_info.vector_data;

        SegmentInfo {
            uuid: wrapped_info.uuid,
            segment_type: SegmentType::Special,
            num_vectors,
            num_indexed_vectors,
            num_points: self.available_point_count(),
            num_deleted_vectors: wrapped_info.num_deleted_vectors
                + deleted_points_count * vector_name_count,
            vectors_size_bytes: wrapped_info.vectors_size_bytes, //  + write_info.vectors_size_bytes,
            payloads_size_bytes: wrapped_info.payloads_size_bytes,
            ram_usage_bytes: wrapped_info.ram_usage_bytes,
            disk_usage_bytes: wrapped_info.disk_usage_bytes,
            is_appendable: false,
            index_schema: wrapped_info.index_schema,
            vector_data,
        }
    }

    fn config(&self) -> &SegmentConfig {
        &self.wrapped_config
    }

    fn is_appendable(&self) -> bool {
        false
    }

    fn flusher(&self, force: bool) -> Option<Flusher> {
        let wrapped_segment = self.wrapped_segment.get();
        let wrapped_segment_guard = wrapped_segment.read();
        wrapped_segment_guard.flusher(force)
    }

    fn drop_data(self) -> OperationResult<()> {
        self.wrapped_segment.drop_data()
    }