Skip to content

refactor: extract total_count_ to InnerIndexInterface base class#2157

Open
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:total_count
Open

refactor: extract total_count_ to InnerIndexInterface base class#2157
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:total_count

Conversation

@LHT129
Copy link
Copy Markdown
Collaborator

@LHT129 LHT129 commented Jun 8, 2026

Summary

Move total_count_ from HGraph, BruteForce, and WARP into the InnerIndexInterface base class as std::atomic<uint64_t>.

Changes

  • Add std::atomic<uint64_t> total_count_{0} to the protected section of InnerIndexInterface
  • Remove the per-index total_count_ member from HGraph, BruteForce, and WARP
  • Update BruteForce and WARP to use atomic operations (.load(), .store(), prefix ++/--) for all total_count_ accesses
  • HGraph was already using std::atomic<uint64_t> so its usage is unchanged

Motivation

  • Eliminates code duplication across index implementations
  • Ensures thread-safe access uniformly (BruteForce and WARP previously used non-atomic uint64_t)
  • Provides a consistent base for future index implementations

Supersedes #1682 (closed due to directory restructure in #2127).
Closes: #1681

@LHT129 LHT129 self-assigned this Jun 8, 2026
@LHT129 LHT129 added kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) version/1.0 labels Jun 8, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jun 8, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Require kind label

Wonderful, this rule succeeded.
  • label~=^kind/

🟢 Require version label

Wonderful, this rule succeeded.
  • label~=^version/

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors total_count_ into a shared atomic member variable in InnerIndexInterface, updating its usage across the BruteForce and WARP implementations. The review feedback identifies critical race conditions in the Add methods of both algorithms, where total_count_ is incremented before data insertion is complete, potentially exposing uninitialized data to concurrent searches. Additionally, the reviewer recommends caching total_count_.load() in WARP search and range search methods to prevent inconsistencies and reduce atomic load overhead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/algorithm/warp/warp.cpp
Comment thread src/algorithm/bruteforce/bruteforce.cpp
Comment thread src/algorithm/warp/warp.cpp Outdated
Comment thread src/algorithm/warp/warp.cpp Outdated
Comment thread src/algorithm/warp/warp.cpp
Move total_count_ from HGraph, BruteForce, and WARP into the
InnerIndexInterface base class as std::atomic<uint64_t>. This eliminates
code duplication, ensures consistent thread-safe access across all index
implementations, and unifies the element count management.

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Assisted-by: ClaudeCode:claude-opus-4-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) size/M version/1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Extract total_count to InnerIndexInterface base class

1 participant