Repository navigation
Fix(Hive): Fix thread-safety race condition in static extractor - #90474
Conversation
|
Workflow [PR], commit [b0de052] Summary: ❌
|
|
@pamarcos sir, You approved it… but CI didn’t get the memo 😅 |
|
@pareshjoshij yep, the state of our CI these last days has been crazy. I'll make sure this ends up landing in master 👍 |
… in static extractor
… in static extractor
|
Thank you for the review and the merge, @pamarcos! sir 🙌 |
Backport #90474 to 25.10: Fix(Hive): Fix thread-safety race condition in static extractor
Backport #90474 to 25.11: Fix(Hive): Fix thread-safety race condition in static extractor
Why is that? What is the state shared between threads? @pareshjoshij |
Backport #90474 to 25.8: Fix(Hive): Fix thread-safety race condition in static extractor
|
@pamarcos I don't think such race condition or "internal state corruption" exists at all. The extractor does not store any state aside from the The PairWriter (struct responsible for processing & storing the key-value pairs) is re-created at each function invocation and passed down as a parameter, see |
|
Thanks @arthurpassos sir, for checking! Even though the config fields are read-only, the extractor’s internal parsing flow still mutates state per call. With a single static instance, parallel S3/HDFS reads were hitting shared mutable state. |
Can you show some code evidences of that? |
|
@arthurpassos ok sir , I’m a bit short on time to grab new stack traces, but here is a hint to find the logic gap: Please look at Line 126 in CHKeyValuePairExtractor.h (state_handler is a member variable) and check the method signature of extractImpl at Line 38 (it is not const). Since the extractor was static, multiple threads were invoking non-const methods on that shared state_handler member simultaneously. The thread_local change aligns the object lifecycle with the thread scope to prevent this race. |
|
The statement
Is true for pre-C++11. The zero-initialization (8.5) of all block-scope variables with static storage duration (3.7.1) or thread storage In other words, the PR does not make sense to me. Attn @pamarcos |
ok ChatGPT
maybe because you don't have any
StateHandler is a member indeed, but the StateHandler itself does not have any members. Did you read the code in the first place? You would be surprised to learn that marking everything as const builds just fine :) |
|
@arthurpassos Sir, I have been engaging with you politely from the start, but you are resorting to mocking me. I am not here for that kind of argument. You clearly have deep knowledge of C++, likely more than I do. But if a contributor is missing something, the constructive path is to explain it, not aggressively try to pull them down. That is not how we build a community. The fact remains: The static version was crashing in our production environment, and thread_local fixed it completely. I am closing this debate from my side. If you believe you have a superior implementation that is both const-correct and crash-free, please feel free to open a PR. I wish you the best. |
@pareshjoshij do you have some log trace to back that up? ClickHouse logs the stack trace when crashing |
|
To me
means that the problem is not really fixed and can reappear anytime. So logs and any additional information how to reproduce the issue is very welcomed. |
|
I'm reverting this. Please @pareshjoshij provide some logs and evidence that the root of the crashes were due to what you thought and we'll re-evaluate. |
|
Hi @pareshjoshij — thanks for your effort. I’m a bit concerned about the nature of your recent contributions. Without accompanying logs, crash reports or other reproducible evidence, the changes feel more like speculative patches than solid fixes or improvements. In effect, it is hard to evaluate their real value to the project. If you’d like to help the project genuinely — maybe start with existing open issues that have reproduceable problems, and provide concrete data when submitting a PR. Automating patches or relying solely on AI-generated suggestions without real-world verification can feel risky for a large project like this. I appreciate initiative — but for this kind of work, concrete evidence and reproducibility matter more than quantity of changes. |
|
Hi, @filimonov sir thank you for the honest feedback and guidance. I really appreciate it. As a beginner, I realize you are right—I should focus on concrete, existing issues rather than speculative fixes. I’ll make sure to work on reproducible problems and verify everything properly moving forward |
|
@pamarcos . I agree with the revert. Apologies for wasting your time |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a race condition in Hive partitioning where a static
KeyValuePairExtractorcaused data corruption or crashes during concurrent file reads.Documentation entry for user-facing changes
Details
In
HivePartitioningUtils::parseHivePartitioningKeysAndValues, theextractorwas declared asstatic. TheKeyValuePairExtractoris not thread-safe.When multiple threads process different files simultaneously (which happens frequently during parallel reads from object storage like S3 or HDFS), they access this shared singleton instance concurrently. This leads to race conditions, internal state corruption of the extractor, invalid partition key extraction, or segmentation faults (crashes).
This PR changes the storage duration from
statictothread_local. This ensures that each thread has its own isolated instance of the extractor, preventing data races while maintaining performance by avoiding reconstruction of the extractor on every call.