Skip to content

Fix/codec registry thread safety - #699

Open
alex268 wants to merge 2 commits into
ydb-platform:masterfrom
alex268:fix/codec-registry-thread-safety
Open

Fix/codec registry thread safety#699
alex268 wants to merge 2 commits into
ydb-platform:masterfrom
alex268:fix/codec-registry-thread-safety

Conversation

@alex268

@alex268 alex268 commented Aug 12, 2026

Copy link
Copy Markdown
Member

No description provided.

Igor Melnichenko and others added 2 commits August 6, 2026 00:36
One CodecRegistry instance is shared by every reader and writer created
from a TopicClient. getCodec is called from the compression threads
(WriterQueue), from the decompression threads (MessageDecoder via
Encoder.decode) and from gRPC callbacks, while registerCodec is public
API that may be called at any time. Backing that with a plain HashMap
means concurrent puts can lose entries or corrupt the table.

Use a ConcurrentHashMap. The new test loses codecs on every run with the
old implementation.

@robot-vibe-db robot-vibe-db Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI Review Summary

Verdict: ✅ No critical issues found

Critical issues

No critical issues found.

Other findings

  • Major | High: The concurrent regression test registerCustomCodecIsSafeForConcurrentUse was added in the first commit to validate the HashMap→ConcurrentHashMap fix, but removed in the second commit. This is the only test that proves the thread-safety fix works and would catch future regressions (e.g., someone reverting to HashMap). — topic/src/test/java/tech/ydb/topic/impl/CodecRegistryTest.java

This review was generated automatically. Critical issues require attention; other findings are advisory.
If this comment was useful, please give it a 👍 — it helps us improve the review bot.

final Map<Integer, Codec> customCodecMap;
// registerCodec may be called at any moment, while getCodec is used by the compression and the
// decompression threads of every reader and writer created from the same TopicClient
private final Map<Integer, Codec> customCodecMap = new ConcurrentHashMap<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: Major
Confidence: High

The concurrent test registerCustomCodecIsSafeForConcurrentUse — added in the first commit (87390cb) specifically to validate this HashMap→ConcurrentHashMap change — was removed in the second commit (a4a67f1). The first commit's message states: "The new test loses codecs on every run with the old implementation."

This test is the only automated validation that the thread-safety fix works. Without it, there is no regression test to catch future changes that might reintroduce the race (e.g., someone refactoring back to a plain HashMap, or introducing a compound read-then-write operation that ConcurrentHashMap alone doesn't make atomic).

Suggested fix: restore the registerCustomCodecIsSafeForConcurrentUse test. It uses 4 writer threads + 1 reader thread with a CountDownLatch to stress-test concurrent registrations, and asserts that no codecs are lost — this is exactly the kind of test that should stay as a regression guard.

@robot-vibe-db

robot-vibe-db Bot commented Aug 12, 2026

Copy link
Copy Markdown

Full analysis log

Analysis performed by claude, claude-opus-4-6.

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.97%. Comparing base (d876581) to head (a4a67f1).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #699      +/-   ##
============================================
+ Coverage     71.91%   71.97%   +0.06%     
- Complexity     3474     3493      +19     
============================================
  Files           390      391       +1     
  Lines         16220    16277      +57     
  Branches       1698     1705       +7     
============================================
+ Hits          11664    11716      +52     
- Misses         3904     3908       +4     
- Partials        652      653       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant