Skip to content

[UIO] Open UniversalMapIndex with S::Fs - #9256

Merged
coszio merged 2 commits into
devfrom
fs-open-map-index
Jun 1, 2026
Merged

coszio merged 2 commits into
devfrom
fs-open-map-index

Conversation

@coszio

@coszio coszio commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Makes sure to use S::Fs for opening UniversalMapIndex

@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: d7617225-ffae-4128-b7c4-0e8468be529d

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec286a and 51516a0.

📒 Files selected for processing (3)
  • lib/common/common/src/universal_io/error.rs
  • lib/common/common/src/universal_io/mod.rs
  • lib/segment/src/index/field_index/map_index/universal_map_index/lifecycle.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/segment/src/index/field_index/map_index/universal_map_index/lifecycle.rs

📝 Walkthrough

Walkthrough

This PR refactors UniversalMapIndex to accept a configurable filesystem abstraction instead of hardcoding MmapFs. open and build are generic over a filesystem type S (UniversalRead/UniversalWrite) and take an explicit fs: &S::Fs; config and bitset IO use read_json_via and StoredBitSlice::::open. Call sites in builders.rs and lifecycle.rs now import MmapFs and pass &MmapFs to preserve existing mmap-backed behavior. An OkNotFound helper and is_not_found() were added and re-exported from universal_io.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • qdrant/qdrant#9234: Related refactor applying the same generic-S universal IO loading/build pattern to another index type.
  • qdrant/qdrant#8961: Related changes touching StoredBitSlice internals and storage-typed read/write handling.

Suggested labels

release:1.18.0

Suggested reviewers

  • ffuugoo
  • xzfc

Poem

🐇 I threaded MmapFs through every file and nook,
FS traits now sing when the index I brook,
read_json_via hums, bitsets open with care,
A rabbit’s small refactor hops everywhere,
🥕 Indexes build clean in fresh, portable air.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: making UniversalMapIndex use the generic filesystem abstraction S::Fs instead of being tied to MmapFs.
Description check ✅ Passed The description directly relates to the changeset by describing the use of S::Fs for opening UniversalMapIndex, which is the core refactoring across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
lib/segment/src/index/field_index/map_index/universal_map_index/lifecycle.rs (2)

41-75: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

open still bypasses S::Fs for part of the index state.

Line 42 probes the host filesystem with Path::is_file(), and Lines 65-75 still load deleted.bin through MmapFs. That means this new generic open(fs, ...) will return Ok(None) or merge the wrong deletion bitmap as soon as a non-MmapFs backend is used. Please route both checks through the supplied filesystem abstraction instead of the local path APIs.

🤖 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/index/field_index/map_index/universal_map_index/lifecycle.rs`
around lines 41 - 75, The code still probes the real host FS and opens the
deletion bitmap via MmapFs instead of using the supplied filesystem abstraction:
replace the direct Path::is_file() check on config_path and any local Path APIs
with the corresponding S::Fs methods (e.g. fs.exists/is_file or metadata via the
provided fs) when deciding whether to return Ok(None) and when reading config
(read_json_via already accepts fs so ensure it uses the same check), and pass
the supplied fs into MmapBitSlice::open (instead of MmapFs) so deleted_path is
opened through the provided filesystem abstraction; keep the same
Populate/do_populate logic and other opens (UniversalHashMap::open,
StoredPointToValues::open) unchanged except for using the supplied fs where
applicable.

107-177: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

build still writes multiple artifacts outside the supplied filesystem.

Lines 122-145 persist config, hashmap, and point_to_values via local/mmap-specific helpers, then Line 177 reopens the index through fs. With any backend other than MmapFs, the new generic build(fs, ...) will create a split index where some files live behind fs and others do not. Either keep build mmap-only for now, or move all writes behind the universal IO abstraction before exposing the generic signature.

🤖 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/index/field_index/map_index/universal_map_index/lifecycle.rs`
around lines 107 - 177, The build function currently writes config, hashmap and
point-to-values using mmap-specific helpers (atomic_save_json,
serialize_hashmap, StoredPointToValues::<N, MmapFile>::from_iter and MmapFs)
while reopening via the generic fs in Self::open, causing split storage
backends; fix by either making build accept/require an MmapFs (narrow the
signature) OR replace all mmap-specific writes with fs-backed implementations:
use fs.create/write for config (instead of atomic_save_json), implement or call
a serialize_hashmap variant that writes through S::Fs, replace
StoredPointToValues::<N, MmapFile>::from_iter with the generic
StoredPointToValues::<N, S::File>::from_iter (or a constructor that uses fs),
and ensure create_and_ensure_length and StoredBitSlice::<S>::open operate
exclusively via the provided fs so all artifacts live behind the supplied S::Fs
before calling Self::open.
🤖 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.

Outside diff comments:
In
`@lib/segment/src/index/field_index/map_index/universal_map_index/lifecycle.rs`:
- Around line 41-75: The code still probes the real host FS and opens the
deletion bitmap via MmapFs instead of using the supplied filesystem abstraction:
replace the direct Path::is_file() check on config_path and any local Path APIs
with the corresponding S::Fs methods (e.g. fs.exists/is_file or metadata via the
provided fs) when deciding whether to return Ok(None) and when reading config
(read_json_via already accepts fs so ensure it uses the same check), and pass
the supplied fs into MmapBitSlice::open (instead of MmapFs) so deleted_path is
opened through the provided filesystem abstraction; keep the same
Populate/do_populate logic and other opens (UniversalHashMap::open,
StoredPointToValues::open) unchanged except for using the supplied fs where
applicable.
- Around line 107-177: The build function currently writes config, hashmap and
point-to-values using mmap-specific helpers (atomic_save_json,
serialize_hashmap, StoredPointToValues::<N, MmapFile>::from_iter and MmapFs)
while reopening via the generic fs in Self::open, causing split storage
backends; fix by either making build accept/require an MmapFs (narrow the
signature) OR replace all mmap-specific writes with fs-backed implementations:
use fs.create/write for config (instead of atomic_save_json), implement or call
a serialize_hashmap variant that writes through S::Fs, replace
StoredPointToValues::<N, MmapFile>::from_iter with the generic
StoredPointToValues::<N, S::File>::from_iter (or a constructor that uses fs),
and ensure create_and_ensure_length and StoredBitSlice::<S>::open operate
exclusively via the provided fs so all artifacts live behind the supplied S::Fs
before calling Self::open.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 831f5d73-17c7-4021-a812-8ec78daf4f85

📥 Commits

Reviewing files that changed from the base of the PR and between 2b667df and 3ec286a.

📒 Files selected for processing (3)
  • lib/segment/src/index/field_index/map_index/builders.rs
  • lib/segment/src/index/field_index/map_index/lifecycle.rs
  • lib/segment/src/index/field_index/map_index/universal_map_index/lifecycle.rs

Comment on lines +42 to +46
@@ -36,22 +43,22 @@ impl<N: MapIndexKey + Key + ?Sized> UniversalMapIndex<N> {
return Ok(None);
}

let config: UniversalMapIndexConfig = read_json(&config_path)?;
let config: UniversalMapIndexConfig = read_json_via(fs, &config_path)?;

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.

Suggested change
let config: UniversalMapIndexConfig = read_json_via(fs, &config_path)?;
let config: UniversalMapIndexConfig = match read_json_via(fs, &config_path) {
Ok(config) => config,
Err(err) => {
return if err.is_not_found() {
Ok(None)
} else {
Err(OperationError::from(err))
};
}
};

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.

we need to avoid config_path.is_file(). First - it is not implemented, second - it is extra call

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.

P.S. is_not_found needs to be implemented

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Implemented in 51516a0

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.

here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I missed this, thanks

51516a0

@generall generall mentioned this pull request Jun 1, 2026
9 tasks done
@coszio
coszio merged commit e0d9489 into dev Jun 1, 2026
16 checks passed
@coszio
coszio deleted the fs-open-map-index branch June 1, 2026 18:46
timvisee pushed a commit that referenced this pull request Jun 3, 2026
* open UniversalMapIndex with `S::Fs`

* Not found is Ok(None)
@xzfc xzfc mentioned this pull request Jun 3, 2026
34 of 36 tasks
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.

3 participants