Remove dead code (#9719)

This commit is contained in:
Arnaud Gourlay
2026-08-04 11:16:58 +02:00
committed by generall
parent 6e856f7791
commit bc5ff2acd7
21 changed files with 8 additions and 498 deletions
Generated
-1
View File
@@ -8372,7 +8372,6 @@ dependencies = [
name = "trififo"
version = "0.0.0"
dependencies = [
"ahash",
"cap",
"criterion",
"foyer",
-2
View File
@@ -35,8 +35,6 @@ use crate::shards::shard_config::ShardConfig;
pub type CollectionId = String;
pub type ShardVersion = usize;
/// Path to a shard directory
pub fn shard_path(collection_path: &Path, shard_id: ShardId) -> PathBuf {
collection_path.join(shard_id.to_string())
-2
View File
@@ -170,5 +170,3 @@ pub trait ShardOperation {
/// and wait till they are finished.
async fn stop_gracefully(self);
}
pub type ShardOperationSS = dyn ShardOperation + Send + Sync;
@@ -47,12 +47,6 @@ impl CounterCell {
self.set(self.get() + delta);
}
/// Multiply the counters value by `amount`.
#[inline]
pub fn multiplied(&self, amount: usize) {
self.set(self.get() * amount)
}
/// Resets the counter to 0.
pub fn clear(&self) {
self.counter.set(0);
@@ -85,22 +85,6 @@ pub trait HwMeasurementIteratorExt: Iterator {
f(&hw_counter).incr_delta(total_count / fraction);
})
}
/// Measures the hardware usage of an iterator with the size of a single value being represented as a fraction.
fn measure_hw_with_cell_and_fraction<R>(
self,
hw_cell: &HardwareCounterCell,
fraction: usize,
mut f: R,
) -> OnFinalCount<Self, impl FnMut(usize)>
where
Self: Sized,
R: FnMut(&HardwareCounterCell) -> &CounterCell,
{
OnFinalCount::new(self, move |total_count| {
f(hw_cell).incr_delta(total_count / fraction);
})
}
}
impl<I: Iterator> HwMeasurementIteratorExt for I {}
@@ -2,10 +2,8 @@
use std::collections::hash_map::Entry;
use std::hash::Hash;
use std::iter::{Once, once};
use ahash::AHashMap;
use itertools::Either;
pub trait FallibleIteratorExt: Iterator + Sized {
/// Like [`itertools::Itertools::unique`], but for iterators over [`Result`].
@@ -38,24 +36,6 @@ impl<I: Iterator + Sized> FallibleIteratorExt for I {
}
}
pub trait TransposeResultIter<I, T, E> {
/// Convert `Result<Iterator<Item = Result<T, E>>, E>`
/// into `Iterator<Item = Result<T, E>>`
fn into_result_iter(self) -> Either<I, Once<Result<T, E>>>;
}
impl<I, T, E> TransposeResultIter<I, T, E> for Result<I, E>
where
I: Iterator<Item = Result<T, E>>,
{
fn into_result_iter(self) -> Either<I, Once<Result<T, E>>> {
match self {
Ok(iter) => Either::Left(iter),
Err(err) => Either::Right(once(Err(err))),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
+1 -1
View File
@@ -14,7 +14,7 @@ mod fallible;
pub mod ordering_iterator;
pub mod stoppable_iter;
pub use fallible::{FallibleIteratorExt, TransposeResultIter};
pub use fallible::FallibleIteratorExt;
pub trait IteratorExt: Iterator {
/// Periodically check if the iteration should be stopped.
-8
View File
@@ -227,14 +227,6 @@ impl<W: Write + Seek> BuilderExt<W> {
}
impl<W: Send + Write + Seek + 'static> BuilderExt<W> {
/// Append a file to the tar archive.
pub async fn append_file(&self, src: &Path, dst: &Path) -> io::Result<()> {
let src = src.to_path_buf();
let dst = join_relative(&self.path, dst)?;
self.run_async(move |tar| tar.append_path_with_name(src, dst))
.await
}
/// Append a new entry to the tar archive with the given file contents.
///
/// # Panics
-2
View File
@@ -9,8 +9,6 @@ pub const DEFAULT_PAGE_SIZE_BYTES: usize = 32 * 1024 * 1024; // 32MB
pub const DEFAULT_REGION_SIZE_BLOCKS: usize = 8_192;
pub const DEFAULT_USE_COMPRESSION: bool = true;
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Default)]
pub enum Compression {
None,
-3
View File
@@ -40,9 +40,6 @@ pub type SizedTypeFor<V> = <<V as PostingValue>::Handler as ValueHandler>::Sized
/// Posting list of ids, where ids are compressed.
pub type IdsPostingList = PostingList<()>;
/// Non-owning posting list of ids, where ids are compressed.
pub type IdsPostingListView<'a> = PostingListView<'a, ()>;
pub use builder::PostingBuilder;
pub use iterator::PostingIterator;
pub use posting_list::{PostingChunk, PostingElement, PostingList, RemainderPosting};
@@ -1,44 +0,0 @@
use common::types::PointOffsetType;
use roaring::RoaringBitmap;
/// A [`FilterContext`] backed by a pre-materialized set of matching points.
///
/// Built by evaluating a filter once (e.g. collecting
/// [`PayloadIndexRead::iter_filtered_points`]) so that every subsequent
/// [`check`] is a bitmap probe instead of a full per-condition evaluation
/// against the payload indexes.
///
/// Pays off whenever the same filter would otherwise be checked more than
/// once per point — e.g. facet counting, where every posting-list element of
/// every value is tested against the same filter, and points holding several
/// values are tested once per value.
///
/// Note that, unlike the lazy `StructFilterContext`, the set is fixed at
/// construction time: whatever visibility rules (deleted points, deferred
/// cutoff) the producing iterator applied are baked in.
///
/// [`PayloadIndexRead::iter_filtered_points`]: crate::index::PayloadIndexRead::iter_filtered_points
/// [`check`]: FilterContext::check
pub struct BitmapFilterContext(RoaringBitmap);
impl BitmapFilterContext {
/// Whether `point_id` matched the filter.
pub fn check(&self, point_id: PointOffsetType) -> bool {
self.0.contains(point_id)
}
/// Number of points matching the materialized filter.
pub fn len(&self) -> usize {
self.0.len() as usize
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl FromIterator<PointOffsetType> for BitmapFilterContext {
fn from_iter<I: IntoIterator<Item = PointOffsetType>>(iter: I) -> Self {
Self(RoaringBitmap::from_iter(iter))
}
}
@@ -74,14 +74,6 @@ impl MutableGeoIndex {
}))
}
#[expect(dead_code)] // FIXME(rocksdb): leftover after removing rocksdb
#[inline]
pub(in super::super) fn clear(&mut self) -> OperationResult<()> {
self.storage.clear().map_err(|err| {
OperationError::service_error(format!("Failed to clear mutable geo index: {err}"))
})
}
#[inline]
pub(in super::super) fn wipe(self) -> OperationResult<()> {
self.storage.wipe().map_err(|err| {
@@ -30,7 +30,6 @@ pub mod read_only;
/// - "some", "text", "here" - 16 bytes
pub(super) const BLOCK_SIZE_KEYWORD: usize = 16;
pub type IdRefIter<'a> = Box<dyn Iterator<Item = &'a PointOffsetType> + 'a>;
pub type IdIter<'a> = Box<dyn Iterator<Item = PointOffsetType> + 'a>;
pub enum MapIndex<N: MapIndexKey + ?Sized>
@@ -1,94 +1,17 @@
//! The [`Encodable`] key-format trait: on-disk key encoding/decoding and
//! encoded-order comparison shared by every numeric-index storage variant.
//! The [`Encodable`] bound shared by every numeric-index storage variant's
//! key type.
use chrono::DateTime;
use common::types::PointOffsetType;
use serde::Serialize;
use serde::de::DeserializeOwned;
use crate::index::key_encoding::{
decode_f64_key_ascending, decode_i64_key_ascending, decode_u128_key_ascending,
encode_f64_key_ascending, encode_i64_key_ascending, encode_u128_key_ascending,
};
use crate::types::{DateTimePayloadType, FloatPayloadType, IntPayloadType};
pub trait Encodable: Copy + Serialize + DeserializeOwned + 'static {
fn encode_key(&self, id: PointOffsetType) -> Vec<u8>;
pub trait Encodable: Copy + Serialize + DeserializeOwned + 'static {}
fn decode_key(key: &[u8]) -> (PointOffsetType, Self);
impl Encodable for IntPayloadType {}
fn cmp_encoded(&self, other: &Self) -> std::cmp::Ordering;
}
impl Encodable for u128 {}
impl Encodable for IntPayloadType {
fn encode_key(&self, id: PointOffsetType) -> Vec<u8> {
encode_i64_key_ascending(*self, id)
}
impl Encodable for FloatPayloadType {}
fn decode_key(key: &[u8]) -> (PointOffsetType, Self) {
decode_i64_key_ascending(key)
}
fn cmp_encoded(&self, other: &Self) -> std::cmp::Ordering {
self.cmp(other)
}
}
impl Encodable for u128 {
fn encode_key(&self, id: PointOffsetType) -> Vec<u8> {
encode_u128_key_ascending(*self, id)
}
fn decode_key(key: &[u8]) -> (PointOffsetType, Self) {
decode_u128_key_ascending(key)
}
fn cmp_encoded(&self, other: &Self) -> std::cmp::Ordering {
self.cmp(other)
}
}
impl Encodable for FloatPayloadType {
fn encode_key(&self, id: PointOffsetType) -> Vec<u8> {
encode_f64_key_ascending(*self, id)
}
fn decode_key(key: &[u8]) -> (PointOffsetType, Self) {
decode_f64_key_ascending(key)
}
fn cmp_encoded(&self, other: &Self) -> std::cmp::Ordering {
if self.is_nan() && other.is_nan() {
return std::cmp::Ordering::Equal;
}
if self.is_nan() {
return std::cmp::Ordering::Less;
}
if other.is_nan() {
return std::cmp::Ordering::Greater;
}
self.partial_cmp(other).unwrap()
}
}
/// Encodes timestamps as i64 in microseconds
impl Encodable for DateTimePayloadType {
fn encode_key(&self, id: PointOffsetType) -> Vec<u8> {
encode_i64_key_ascending(self.timestamp(), id)
}
fn decode_key(key: &[u8]) -> (PointOffsetType, Self) {
let (id, timestamp) = decode_i64_key_ascending(key);
let datetime =
DateTime::from_timestamp(timestamp / 1000, (timestamp % 1000) as u32 * 1_000_000)
.unwrap_or_else(|| {
log::warn!("Failed to decode timestamp {timestamp}, fallback to UNIX_EPOCH");
DateTime::UNIX_EPOCH
});
(id, datetime.into())
}
fn cmp_encoded(&self, other: &Self) -> std::cmp::Ordering {
self.timestamp().cmp(&other.timestamp())
}
}
impl Encodable for DateTimePayloadType {}
@@ -52,9 +52,6 @@ use crate::index::visited_pool::{VisitedListHandle, VisitedPool};
use crate::vector_storage::RawScorer;
use crate::vector_storage::query_scorer::QueryScorerBytes;
pub type LinkContainer = Vec<PointOffsetType>;
pub type LayersContainer = Vec<LinkContainer>;
pub const HNSW_GRAPH_FILE: &str = "graph.bin";
pub const HNSW_LINKS_FILE: &str = "links.bin";
-265
View File
@@ -1,265 +0,0 @@
const FLOAT_NAN: u8 = 0x00;
const FLOAT_NEG: u8 = 0x01;
const FLOAT_ZERO: u8 = 0x02;
const FLOAT_POS: u8 = 0x03;
const F64_KEY_LEN: usize = 13;
const I64_KEY_LEN: usize = 12;
const U128_KEY_LEN: usize = 20;
/// Encode a f64 into `buf`
///
/// The encoded format for a f64 is :
///
/// **for positives:** the f64 bits ( in IEEE 754 format ) are re-interpreted as an int64 and
/// encoded using big-endian order.
///
/// **for negative** f64 : invert all the bits and encode it using bit-endian order.
///
/// A single-byte prefix tag is appended to the front of the encoding slice to ensures that
/// NaNs are always sorted first.
///
/// This approach was inspired by <https://github.com/cockroachdb/cockroach/blob/master/pkg/util/encoding/float.go>
///
///
/// #f64 encoding format
///
///```text
/// 0 1 9
/// ┌───────────────────┬─────────────────┐
/// │ Float Type │ NEG: !key_val │
/// │ NAN/NEG/ZERO/POS | POS: key_val │
/// │ (big-endian) │ (big-endian) │
/// └───────────────────┴─────────────────┘
/// ```
///
pub fn encode_f64_ascending(val: f64, buf: &mut Vec<u8>) {
if val.is_nan() {
buf.push(FLOAT_NAN);
buf.extend([0_u8; std::mem::size_of::<f64>()]);
return;
}
if val == 0f64 {
buf.push(FLOAT_ZERO);
buf.extend([0_u8; std::mem::size_of::<f64>()]);
return;
}
let f_as_u64 = val.to_bits();
if f_as_u64 & (1 << 63) != 0 {
let f = !f_as_u64;
buf.push(FLOAT_NEG);
buf.extend(f.to_be_bytes());
} else {
buf.push(FLOAT_POS);
buf.extend(f_as_u64.to_be_bytes());
}
}
/// Decode a f64 from a slice.
pub fn decode_f64_ascending(buf: &[u8]) -> f64 {
match buf[0] {
FLOAT_NAN => f64::NAN,
FLOAT_NEG => {
let u = u64::from_be_bytes(buf[1..9].try_into().expect("cannot decode f64"));
let f = !u;
f64::from_bits(f)
}
FLOAT_ZERO => 0f64,
FLOAT_POS => {
let u = u64::from_be_bytes(buf[1..9].try_into().expect("cannot decode f64"));
f64::from_bits(u)
}
_ => panic!("invalid f64 prefix"),
}
}
/// Encode a i64 into `buf` so that is sorts ascending.
pub fn encode_i64_ascending(val: i64, buf: &mut Vec<u8>) {
let i = val ^ i64::MIN;
buf.extend(i.to_be_bytes());
}
/// Decode a i64 from a slice
pub fn decode_i64_ascending(buf: &[u8]) -> i64 {
let i = i64::from_be_bytes(buf[0..8].try_into().expect("cannot decode i64"));
i ^ i64::MIN
}
/// Encodes a f64 key so that it sort in ascending order.
///
/// The key is compound by the numeric value of the key plus a u32 representing
/// the payload offset within the payload store.
///
/// # float key encoding format
///
///```text
///
/// 0 1 9 13
/// ┌───────────────────┬─────────────────┬──────────────┐
/// │ Float Type │ NEG: !key_val │ │
/// │ NAN/NEG/ZERO/POS | POS: key_val │ point_offset │
/// │ (big-endian) │ (big-endian) │ │
/// └───────────────────┴─────────────────┴──────────────┘
/// ```
///
pub fn encode_f64_key_ascending(key_val: f64, point_offset: u32) -> Vec<u8> {
let mut buf = Vec::with_capacity(F64_KEY_LEN);
encode_f64_ascending(key_val, &mut buf);
buf.extend(point_offset.to_be_bytes());
buf
}
pub fn decode_f64_key_ascending(buf: &[u8]) -> (u32, f64) {
(
u32::from_be_bytes(
(&buf[F64_KEY_LEN - std::mem::size_of::<u32>()..])
.try_into()
.unwrap(),
),
decode_f64_ascending(buf),
)
}
/// Encodes a i64 key so that it sort in ascending order.
///
/// The key is compound by the numeric value of the key plus a u32 representing
/// the payload offset within the payload store.
///
/// # int key encoding format
///
///```text
///
/// 0 8 12
/// ┌────────────────────┬──────────────┐
/// │ key_val ^ i64::MIN │ point_offset │
/// │ (big-endian) │ (big-endian) │
/// └────────────────────┴──────────────┘
///```
pub fn encode_i64_key_ascending(key_val: i64, point_offset: u32) -> Vec<u8> {
let mut buf = Vec::with_capacity(I64_KEY_LEN);
encode_i64_ascending(key_val, &mut buf);
buf.extend(point_offset.to_be_bytes());
buf
}
pub fn decode_i64_key_ascending(buf: &[u8]) -> (u32, i64) {
(
u32::from_be_bytes(
(&buf[I64_KEY_LEN - std::mem::size_of::<u32>()..])
.try_into()
.unwrap(),
),
decode_i64_ascending(buf),
)
}
/// Encodes a u128 key so that it sort in ascending order.
///
/// The key is compound by the numeric value of the key plus a u32 representing
/// the payload offset within the payload store.
///
/// # int key encoding format
///
///```text
///
/// 0 16 20
/// ┌─────────────────────┬──────────────┐
/// │ key_val │ point_offset │
/// │ (big-endian) │ (big-endian) │
/// └─────────────────────┴──────────────┘
///```
pub fn encode_u128_key_ascending(key_val: u128, point_offset: u32) -> Vec<u8> {
let mut buf = Vec::with_capacity(U128_KEY_LEN);
buf.extend(key_val.to_be_bytes());
buf.extend(point_offset.to_be_bytes());
buf
}
pub fn decode_u128_key_ascending(buf: &[u8]) -> (u32, u128) {
(
u32::from_be_bytes(
(&buf[U128_KEY_LEN - std::mem::size_of::<u32>()..])
.try_into()
.unwrap(),
),
u128::from_be_bytes(buf[0..16].try_into().expect("cannot decode u128")),
)
}
#[cfg(test)]
mod tests {
use std::cmp::Ordering;
use crate::index::key_encoding::{
decode_f64_ascending, decode_i64_ascending, encode_f64_ascending, encode_i64_ascending,
};
#[test]
fn test_encode_f64() {
test_f64_encoding_roundtrip(0.42342);
test_f64_encoding_roundtrip(0f64);
test_f64_encoding_roundtrip(f64::NAN);
test_f64_encoding_roundtrip(-0.423423983);
}
#[test]
fn test_encode_i64() {
test_i64_encoding_roundtrip(i64::MIN);
test_i64_encoding_roundtrip(i64::MAX);
test_i64_encoding_roundtrip(0);
test_i64_encoding_roundtrip(41262);
test_i64_encoding_roundtrip(-98793);
}
#[test]
fn test_f64_lex_order() {
let mut nan_buf = Vec::new();
let mut zero_buf = Vec::new();
let mut pos_buf = Vec::new();
let mut neg_buf = Vec::new();
encode_f64_ascending(f64::NAN, &mut nan_buf);
encode_f64_ascending(0f64, &mut zero_buf);
encode_f64_ascending(0.2435224412, &mut pos_buf);
encode_f64_ascending(-0.82976347, &mut neg_buf);
assert_eq!(nan_buf.cmp(&neg_buf), Ordering::Less);
assert_eq!(neg_buf.cmp(&zero_buf), Ordering::Less);
assert_eq!(zero_buf.cmp(&pos_buf), Ordering::Less);
}
#[test]
fn test_i64_lex_order() {
let mut zero_buf = Vec::new();
let mut pos_buf = Vec::new();
let mut neg_buf = Vec::new();
encode_i64_ascending(0, &mut zero_buf);
encode_i64_ascending(123, &mut pos_buf);
encode_i64_ascending(-4324, &mut neg_buf);
assert_eq!(neg_buf.cmp(&zero_buf), Ordering::Less);
assert_eq!(zero_buf.cmp(&pos_buf), Ordering::Less);
}
fn test_f64_encoding_roundtrip(val: f64) {
let mut buf = Vec::new();
encode_f64_ascending(val, &mut buf);
let dec_val = decode_f64_ascending(buf.as_slice());
if val.is_nan() {
assert!(dec_val.is_nan());
return;
}
assert_eq!(val, dec_val);
}
fn test_i64_encoding_roundtrip(val: i64) {
let mut buf = Vec::new();
encode_i64_ascending(val, &mut buf);
let res = decode_i64_ascending(buf.as_slice());
assert_eq!(val, res);
}
}
-1
View File
@@ -1,7 +1,6 @@
mod condition_checker;
pub mod field_index;
pub mod hnsw_index;
mod key_encoding;
mod memory_reporter;
pub mod payload_config;
mod payload_index_base;
-17
View File
@@ -2428,23 +2428,6 @@ impl<'a> From<&'a Map<String, Value>> for OwnedPayloadRef<'a> {
}
}
/// Payload interface structure which ensures that user is allowed to pass payload in
/// both - array and single element forms.
///
/// Example:
///
/// Both versions should work:
/// ```json
/// {..., "payload": {"city": {"type": "keyword", "value": ["Berlin", "London"] }}},
/// {..., "payload": {"city": {"type": "keyword", "value": "Moscow" }}},
/// ```
#[derive(Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq, Clone)]
#[serde(untagged, rename_all = "snake_case")]
pub enum PayloadVariant<T> {
List(Vec<T>),
Value(T),
}
/// All possible names of payload types
#[derive(
Debug, Deserialize, Serialize, JsonSchema, Anonymize, Clone, Copy, PartialEq, Hash, Eq, EnumIter,
@@ -211,13 +211,6 @@ impl InvertedIndexRam {
self.total_sparse_size += new_vector_size
}
pub fn total_posting_elements_size(&self) -> usize {
self.postings
.iter()
.map(|posting| posting.elements.len() * size_of::<PostingElementEx>())
.sum()
}
}
#[cfg(feature = "testing")]
@@ -169,8 +169,4 @@ impl TableOfContent {
}
Ok(upload_dir)
}
pub fn clear_all_tmp_directories(&self) -> CollectionResult<()> {
clear_tmp_directories(&self.storage_config)
}
}
-3
View File
@@ -12,9 +12,6 @@ workspace = true
[features]
bench_all = []
[dependencies]
ahash = {workspace = true}
[dev-dependencies]
itertools = { workspace = true }
strum = { workspace = true }