Skip to content

Fix non-atomic reads in PDisk quota calculation#32206

Merged
maximyurchuk merged 41 commits into
ydb-platform:mainfrom
serbel324:bs/pdisk/atomic-quota-race
Jan 19, 2026
Merged

Fix non-atomic reads in PDisk quota calculation#32206
maximyurchuk merged 41 commits into
ydb-platform:mainfrom
serbel324:bs/pdisk/atomic-quota-race

Conversation

@serbel324
Copy link
Copy Markdown
Collaborator

@serbel324 serbel324 commented Jan 16, 2026

Changelog entry

Read atomic variables in PDisk QuotaTracker with a proper method.
Fixes #31995

Changelog category

  • Bugfix

Copilot AI review requested due to automatic review settings January 16, 2026 10:11
@ydbot
Copy link
Copy Markdown
Collaborator

ydbot commented Jan 16, 2026

Run Extra Tests

Run additional tests for this PR. You can customize:

  • Test Size: small, medium, large (default: all)
  • Test Targets: any directory path (default: ydb/)
  • Sanitizers: ASAN, MSAN, TSAN
  • Coredumps: enable for debugging (default: off)
  • Additional args: custom ya make arguments

▶  Run tests

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 16, 2026

2026-01-16 10:13:24 UTC Pre-commit check linux-x86_64-relwithdebinfo for 13d8b8e has started.
2026-01-16 10:13:41 UTC Artifacts will be uploaded here
2026-01-16 10:15:54 UTC ya make is running...
2026-01-16 10:22:42 UTC Check cancelled

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes thread safety issues in PDisk quota calculation by ensuring atomic reads of shared variables and preventing division by zero.

Changes:

  • Added AtomicGet() calls for HardLimit and Free fields in the Print() method to ensure thread-safe reads
  • Modified EstimateSpaceColor() to read HardLimit atomically into a local variable and check for zero before division

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 160 to 161
*occupancy = hardLimit ? (double)(hardLimit - newFree) / hardLimit : 1.0;

Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

Lines 154-158 compute the occupancy value, but line 160 unconditionally overwrites it, making the preceding calculation dead code. Either remove lines 154-158 or remove line 160. If keeping line 160, note that it lacks the std::max protection from line 155 which prevents negative numerators when newFree exceeds hardLimit.

Suggested change
*occupancy = hardLimit ? (double)(hardLimit - newFree) / hardLimit : 1.0;

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 16, 2026

🟢 2026-01-16 10:24:16 UTC The validation of the Pull Request description is successful.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 16, 2026

2026-01-16 10:15:27 UTC Pre-commit check linux-x86_64-release-asan for 13d8b8e has started.
2026-01-16 10:15:45 UTC Artifacts will be uploaded here
2026-01-16 10:17:58 UTC ya make is running...
2026-01-16 10:22:57 UTC Check cancelled

@serbel324 serbel324 force-pushed the bs/pdisk/atomic-quota-race branch from 9136fef to 4ce38a0 Compare January 16, 2026 10:22
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 16, 2026

2026-01-16 10:24:28 UTC Pre-commit check linux-x86_64-relwithdebinfo for f83d4f9 has started.
2026-01-16 10:24:45 UTC Artifacts will be uploaded here
2026-01-16 10:26:59 UTC ya make is running...
🟡 2026-01-16 12:20:15 UTC Some tests failed, follow the links below. Going to retry failed tests...

Details

Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
45395 42320 0 9 3033 33

2026-01-16 12:20:33 UTC ya make is running... (failed tests rerun, try 2)
🟡 2026-01-16 12:25:48 UTC Some tests failed, follow the links below. Going to retry failed tests...

Details

Ya make output | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
464 (only retried tests) 450 0 1 0 13

2026-01-16 12:25:55 UTC ya make is running... (failed tests rerun, try 3)
🔴 2026-01-16 12:33:16 UTC Some tests failed, follow the links below.

Ya make output | Test bloat | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
146 (only retried tests) 135 0 1 0 10

🟢 2026-01-16 12:33:23 UTC Build successful.
🟢 2026-01-16 12:33:48 UTC ydbd size 2.3 GiB changed* by +736 Bytes, which is < 100.0 KiB vs main: OK

ydbd size dash main: 491ea35 merge: f83d4f9 diff diff %
ydbd size 2 503 402 864 Bytes 2 503 403 600 Bytes +736 Bytes +0.000%
ydbd stripped size 532 048 328 Bytes 532 048 392 Bytes +64 Bytes +0.000%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 16, 2026

2026-01-16 10:26:10 UTC Pre-commit check linux-x86_64-release-asan for f83d4f9 has started.
2026-01-16 10:26:28 UTC Artifacts will be uploaded here
2026-01-16 10:28:36 UTC ya make is running...
🟡 2026-01-16 11:37:07 UTC Some tests failed, follow the links below. This fail is not in blocking policy yet

Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
14753 14652 0 63 9 29

🟢 2026-01-16 11:37:21 UTC Build successful.
🟢 2026-01-16 11:37:51 UTC ydbd size 3.8 GiB changed* by -3.2 KiB, which is <= 0 Bytes vs main: OK

ydbd size dash main: 64b5345 merge: f83d4f9 diff diff %
ydbd size 4 115 960 488 Bytes 4 115 957 192 Bytes -3.2 KiB -0.000%
ydbd stripped size 1 540 010 352 Bytes 1 540 009 712 Bytes -640 Bytes -0.000%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@maximyurchuk maximyurchuk merged commit 219069b into ydb-platform:main Jan 19, 2026
6 of 9 checks passed
@ydbot
Copy link
Copy Markdown
Collaborator

ydbot commented Jan 19, 2026

Backport

To backport this PR, click the button next to the target branch and then click "Run workflow" in the Run Actions UI.

Branch Run
stable-25-3, stable-25-3-1, stable-25-4, stable-25-4-1 ▶  Backport
stable-25-4, stable-25-4-1 ▶  Backport
stable-25-4 ▶  Backport

▶  Backport manual

@ydbot
Copy link
Copy Markdown
Collaborator

ydbot commented Jan 19, 2026

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[25.4] ThreadSanitizer: data race @ /ydb/ydb/core/blobstorage/pdisk/blobstorage_pdisk_chunk_tracker.h:65:39

5 participants