Repository navigation
Fix sparseGram tokenizer bug in hasAny/AllTokens and tokens functions - #89665
Conversation
The bug is only limited to the `sparseGram` tokenizer. The sparseGram tokenizer stores an internal state which is modified during the execution. This led an error when the functions are running concurrently, because the internal state of the sparseGram tokenizer is not thread-safe. This change fixes that by cloning the sparseGram tokenizer for each function call to avoid sharing an internal state between runs.
|
Workflow [PR], commit [d153132] Summary: ❌
|
|
I don't know much about this implementation of |
|
Should this PR be backported? |
george-larionov
left a comment
There was a problem hiding this comment.
It LGTM as a temporary fix while we decide how to fix the underlying issue.
@george-larionov that's interesting, it does not show any result with 25.10, but there should a single match. But I managed to reproduce with the However, if I set the concurrency limit to 1, it does not produce the error anymore: https://fiddle.clickhouse.com/9495b543-a1b1-470a-a0ca-c6d536e0c7f8 |
@PedroTadim 25.10 is already released and the full-text index is still an experimental feature. So, I'm not totally sure if we need to patch the release version. Did you have the similar experience with other experimental features? |
…-tokens-sparse-grams
|
Stataless test failed build: #89106 |
|
Thanks for fixing this. The fix copies the internal state once per processed chunk ... which is relatively expensive as SparseGramsImpl is quite large. There are two alternatives:
Long story short, in my view we can keep this PR as is (George mentioned it is a workaround). |
|
If it is possible to do it per/thread and still get correct results, the most efficient approach will be to use a static thread local copy. It will be copied only once per thread and the execution will stay lock-free |
|
Hmm, this will probably cause wrong results (not sure). Anyways, let's not overoptimize as long as we don't see sparseGrams as a hotspot in a CPU profile. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
hasAnyTokens,hasAllTokensandtokensfunctions concurrent executions with thesparseGramstokenizer. Resolves #89605Details
The bug is only limited to the
sparseGramtokenizer. The sparseGram tokenizer stores an internal state which is modified during the execution.This led to an error when the functions are running concurrently, because the internal state of the sparseGram tokenizer is not thread-safe.
This change fixes that by cloning the sparseGram tokenizer for each function call to avoid sharing an internal state between runs.
Fixes #89605