Skip to content

enhance: fix data race and nil-slice edge case in BloomFilterSet.PkCandidateExist#49004

Open
korbonits wants to merge 1 commit intomilvus-io:masterfrom
korbonits:enhance/bloom-filter-pk-candidate-exist-race-fix
Open

enhance: fix data race and nil-slice edge case in BloomFilterSet.PkCandidateExist#49004
korbonits wants to merge 1 commit intomilvus-io:masterfrom
korbonits:enhance/bloom-filter-pk-candidate-exist-race-fix

Conversation

@korbonits
Copy link
Copy Markdown

Summary

BloomFilterSet.PkCandidateExist read s.currentStat and s.historyStats without holding statsMutex, while every other read method in the same struct (MayPkExist, BatchPkExist, GetMinPk, GetMaxPk, MemSize) takes the lock. A concurrent UpdatePkCandidate or AddHistoricalStats call (both write under lock) produces a data race detectable by -race.

Two issues fixed:

  1. Data race — add s.statsMutex.RLock() / RUnlock() to PkCandidateExist, consistent with all other read methods.
  2. Nil-slice false positive — replace s.historyStats != nil with an element-wise non-nil scan, matching the pattern already used by GetMinPk / GetMaxPk. An empty slice or a slice of all-nil entries is now correctly reported as "not ready."

issue: #48992

Test plan

  • Added TestPkCandidateExist covering: empty set, current stat only, nil-only historyStats slice, empty historyStats slice, valid historical stat with nil current.
  • Existing tests (TestInt64Pk, TestVarCharPk, TestHistoricalStat, TestMemSize) remain green.

🤖 Generated with Claude Code

…ndidateExist

PkCandidateExist read s.currentStat and s.historyStats without holding
statsMutex, unlike every other read method (MayPkExist, BatchPkExist,
GetMinPk, GetMaxPk, MemSize). A concurrent UpdatePkCandidate or
AddHistoricalStats call would produce a data race detectable by -race.

Also replace `s.historyStats != nil` with an element-wise non-nil scan,
matching the pattern already used by GetMinPk / GetMaxPk, so that an
empty or nil-only slice is not misreported as ready.

issue: milvus-io#48992

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Alex Korbonits <alex@korbonits.com>
@sre-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: korbonits
To complete the pull request process, please assign yanliang567 after the PR has been reviewed.
You can assign the PR to them by writing /assign @yanliang567 in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @korbonits! It looks like this is your first PR to milvus-io/milvus 🎉

@sre-ci-robot sre-ci-robot added the size/M Denotes a PR that changes 30-99 lines. label Apr 14, 2026
@mergify mergify bot added dco-passed DCO check passed. kind/enhancement Issues or changes related to enhancement labels Apr 14, 2026
@sre-ci-robot
Copy link
Copy Markdown
Contributor

[ci-v2-notice]
Notice: New ci-v2 system is enabled for this PR.

To rerun ci-v2 checks, comment with:

  • /ci-rerun-code-check // for ci-v2/code-check
  • /ci-rerun-build // for ci-v2/build
  • /ci-rerun-build-all // for ci-v2/build-all (multi-arch builds)
  • /ci-rerun-buildenv // for ci-v2/build-env (build milvus-env builder images)
  • /ci-rerun-ut-integration // for ci-v2/ut-integration, will rerun ci-v2/build
  • /ci-rerun-ut-go // for ci-v2/ut-go, will rerun ci-v2/build
  • /ci-rerun-ut-cpp // for ci-v2/ut-cpp
  • /ci-rerun-ut // for all ci-v2/ut-integration, ci-v2/ut-go, ci-v2/ut-cpp, will rerun ci-v2/build
  • /ci-rerun-e2e-default // for ci-v2/e2e-default
  • /ci-rerun-e2e-amd // for ci-v2/e2e-amd (e2e pool dispatcher)
  • /ci-rerun-build-ut-cov // for ci-v2/build-ut-cov (build + unit tests in one pipeline)
  • /ci-rerun-gosdk // for ci-v2/go-sdk (Go SDK E2E tests, ARM)

If you have any questions or requests, please contact @zhikunyao.

@korbonits
Copy link
Copy Markdown
Author

/ci-rerun-code-check

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.93%. Comparing base (de5662b) to head (c67866b).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #49004      +/-   ##
==========================================
- Coverage   77.93%   77.93%   -0.01%     
==========================================
  Files        2167     2167              
  Lines      356312   356321       +9     
==========================================
- Hits       277687   277686       -1     
- Misses      70054    70063       +9     
- Partials     8571     8572       +1     
Components Coverage Δ
Client 79.25% <ø> (ø)
Core 84.45% <ø> (ø)
Go 76.19% <100.00%> (-0.01%) ⬇️
Files with missing lines Coverage Δ
internal/querynodev2/pkoracle/bloom_filter_set.go 79.14% <100.00%> (+1.05%) ⬆️

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sre-ci-robot sre-ci-robot added low-code-coverage add test-label from zhikun, diff coverage > 80% and removed low-code-coverage add test-label from zhikun, diff coverage > 80% labels Apr 14, 2026
@korbonits
Copy link
Copy Markdown
Author

/ci-rerun-ut-go

@korbonits
Copy link
Copy Markdown
Author

/ci-rerun-gosdk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-passed DCO check passed. kind/enhancement Issues or changes related to enhancement size/M Denotes a PR that changes 30-99 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants