Skip to content

Read-only ID tracker - #8887

Merged
generall merged 2 commits into
devfrom
read-only-id-tracker
May 6, 2026
Merged

generall merged 2 commits into
devfrom
read-only-id-tracker

Conversation

@generall

@generall generall commented May 4, 2026

Copy link
Copy Markdown
Member

No description provided.

@generall
generall force-pushed the read-only-id-tracker branch from 1298341 to f5c4e24 Compare May 4, 2026 13:59
@generall
generall requested a review from dancixx May 4, 2026 22:06
@generall
generall marked this pull request as ready for review May 4, 2026 22:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@lib/segment/src/id_tracker/immutable_id_tracker/read_only/id_tracker_read.rs`:
- Around line 37-43: ReadOnlyImmutableIdTracker's deleted_point_bitslice and
is_deleted_point currently read from self.mappings (stale) instead of the
live-reload-backed self.deleted; update these two methods
(deleted_point_bitslice and is_deleted_point on ReadOnlyImmutableIdTracker) to
consult the StoredBitSlice<MmapFile> stored in self.deleted (use the
StoredBitSlice API — e.g., as_bitslice()/bits()/Deref to BitSlice — to return a
&BitSlice and to test a bit) so live-reload updates are reflected, or if
mappings is truly authoritative remove the unused deleted field and its
documentation instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 594311ff-2706-4574-86c5-9a3782e2b8be

📥 Commits

Reviewing files that changed from the base of the PR and between fd4e25d and 5b2b74a.

📒 Files selected for processing (8)
  • lib/segment/src/id_tracker/id_tracker_base/mod.rs
  • lib/segment/src/id_tracker/id_tracker_base/read_only_tracker_enum.rs
  • lib/segment/src/id_tracker/immutable_id_tracker/mod.rs
  • lib/segment/src/id_tracker/immutable_id_tracker/read_only/id_tracker_read.rs
  • lib/segment/src/id_tracker/immutable_id_tracker/read_only/mod.rs
  • lib/segment/src/id_tracker/mutable_id_tracker/mod.rs
  • lib/segment/src/id_tracker/mutable_id_tracker/read_only/id_tracker_read.rs
  • lib/segment/src/id_tracker/mutable_id_tracker/read_only/mod.rs

Comment on lines +37 to +43
fn deleted_point_bitslice(&self) -> &BitSlice {
self.mappings.deleted()
}

fn is_deleted_point(&self, internal_id: PointOffsetType) -> bool {
self.mappings.is_deleted_point(internal_id)
}

@coderabbitai coderabbitai Bot May 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

deleted_point_bitslice and is_deleted_point bypass the live-reload deleted field

ReadOnlyImmutableIdTracker holds a deleted: StoredBitSlice<MmapFile> field specifically to "support live-reload of externally deleted points", yet both deletion-query methods delegate to self.mappings instead:

fn deleted_point_bitslice(&self) -> &BitSlice {
    self.mappings.deleted()          // reads stale in-memory state
}

fn is_deleted_point(&self, internal_id: PointOffsetType) -> bool {
    self.mappings.is_deleted_point(internal_id)   // same
}

In the mutable ImmutableIdTracker, the deleted_wrapper and mappings stay in sync because every drop() call updates both. The read-only tracker has no such mutation path, so any live-reload that updates self.deleted will never be reflected in these two methods — the tracker will report stale deletion state.

If self.mappings is always guaranteed to be the authoritative source (e.g., live-reload refreshes mappings rather than deleted), the deleted field becomes vestigial and should be removed or documented as unused. Otherwise the read path needs to consult self.deleted.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/segment/src/id_tracker/immutable_id_tracker/read_only/id_tracker_read.rs`
around lines 37 - 43, ReadOnlyImmutableIdTracker's deleted_point_bitslice and
is_deleted_point currently read from self.mappings (stale) instead of the
live-reload-backed self.deleted; update these two methods
(deleted_point_bitslice and is_deleted_point on ReadOnlyImmutableIdTracker) to
consult the StoredBitSlice<MmapFile> stored in self.deleted (use the
StoredBitSlice API — e.g., as_bitslice()/bits()/Deref to BitSlice — to return a
&BitSlice and to test a bit) so live-reload updates are reflected, or if
mappings is truly authoritative remove the unused deleted field and its
documentation instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a valid concern.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

Let me look at the StoredBitSlice API and the struct to propose a concrete fix.


🏁 Script executed:

#!/bin/bash
# Find StoredBitSlice definition and its API
rg -rn "StoredBitSlice" --type rust -C 5 | head -100

# Find ReadOnlyImmutableIdTracker struct
rg -rn "ReadOnlyImmutableIdTracker" --type rust -C 10 | head -80

Length of output: 13991


Let me check the StoredBitSlice API methods:


🏁 Script executed:

#!/bin/bash
# Get the full StoredBitSlice implementation
cat lib/common/common/src/stored_bitslice.rs

Length of output: 20196


@timvisee, glad you agree — here's a concrete fix proposal.

The core issue: StoredBitSlice<MmapFile> has no Deref<Target = BitSlice> impl. Its API offers:

  • read_all() -> Result<Cow<'_, BitSlice>> — zero-copy Cow::Borrowed for mmap backends
  • get_bit(bit_index: u64) -> Result<Option<bool>>

is_deleted_point — straightforward fix

Consult both the external deletion state (self.deleted) and the mappings, OR-ing them together:

fn is_deleted_point(&self, internal_id: PointOffsetType) -> bool {
    let externally_deleted = self
        .deleted
        .get_bit(internal_id as u64)
        .ok()
        .flatten()
        .unwrap_or(false);
    externally_deleted || self.mappings.is_deleted_point(internal_id)
}

deleted_point_bitslice — two options depending on design intent

The trait method signature is fn deleted_point_bitslice(&self) -> &BitSlice. Since StoredBitSlice doesn't Deref to BitSlice, returning a plain reference requires extracting it from read_all().

Option A — self.deleted is the authoritative/complete deletion state (i.e., mappings carries no deletion info in this read-only path, so self.deleted fully replaces self.mappings.deleted()):

fn deleted_point_bitslice(&self) -> &BitSlice {
    // For MmapFile backend, read_all() returns Cow::Borrowed (zero-copy)
    match self.deleted.read_all().expect("failed to read deleted bitslice") {
        std::borrow::Cow::Borrowed(slice) => slice,
        std::borrow::Cow::Owned(_) => {
            unreachable!("MmapFile always returns a borrowed bitslice")
        }
    }
}

Option B — self.deleted is an overlay on top of self.mappings.deleted() (both must be checked):

In this case, deleted_point_bitslice can't return a merged &BitSlice without storing the merged result somewhere. This would require either:

  • Caching the merged bitslice in the struct (e.g., a pre-computed deleted_combined: BitVec), or
  • Changing the IdTrackerRead trait signature for this method

Recommendation: Could you confirm whether self.deleted is the sole source of deletion truth for this read-only tracker (Option A), or whether it overlays deletions on top of self.mappings.deleted() (Option B)? That determines whether Option A's approach is safe or whether the struct needs a cached field. If it's Option A, the deleted field should also be documented to clarify this, and deleted_point_bitslice should not delegate to self.mappings.deleted() at all.

( ˶ᵔ ᵕ ᵔ˶ )


🧠 Learnings used
Learnt from: IvanPleshkov
Repo: qdrant/qdrant PR: 8246
File: lib/segment/src/segment/segment_ops.rs:691-696
Timestamp: 2026-02-27T19:23:23.760Z
Learning: In code that computes offsets or casts counts to PointOffsetType (u32), avoid unsafe or unchecked casts from usize to PointOffsetType. Do not cast unless you can guarantee the value is < PointOffsetType::MAX, for example by assertions or by design constraints (as in versions_store.rs and segment internal IDs). When such a cast is necessary, validate the bound first and add an explicit assertion or guard, documenting the invariant to prevent overflow and maintain correctness across segments.

Learnt from: generall
Repo: qdrant/qdrant PR: 8322
File: lib/edge/src/lib.rs:213-237
Timestamp: 2026-03-08T01:28:03.360Z
Learning: Use SaveOnDisk<T> from common::save_on_disk for atomic persist-then-swap semantics when a config or in-memory struct must be kept in memory and persisted atomically on mutation. Prefer SaveOnDisk<T> over combining parking_lot::RwLock<T> with manual save() calls. Note: write_optional (returns Option<T>) is appropriate for fallible mutations where returning None skips both save and swap. In the qdrant/qdrant repo, the type is located at lib/common/common/src/save_on_disk.rs; migrate relevant in-memory config mutations to use SaveOnDisk<T> to ensure atomic persistence.

Learnt from: generall
Repo: qdrant/qdrant PR: 8368
File: lib/common/common/src/disk_cache/controller.rs:129-129
Timestamp: 2026-03-17T19:36:24.259Z
Learning: In this repository, all builds target 64-bit systems. Do not flag casts from u64 to usize (for example file length via f.metadata()?.len() as usize) as potentially unsafe. These casts are acceptable because 32-bit targets are not supported. Apply this guidance across all Rust sources in the codebase unless explicit overrides exist.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, deleted bitslice is supposed to be used to identify which points were removed in a background, once we identify those points, we remove them from mapping. Bitslice is not acting as a source of truth for read operations. It will be more clear once we actually implement live-reload functions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@qdrant qdrant deleted a comment from coderabbitai Bot May 5, 2026
@generall
generall merged commit a10698c into dev May 6, 2026
15 checks passed
@generall
generall deleted the read-only-id-tracker branch May 6, 2026 10:18
timvisee pushed a commit that referenced this pull request May 8, 2026
* wip: read-only id tracker for mutable data

* read-only id tracker
@generall generall added this to the Live-reload milestone May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants