Repository navigation
Fix: possible race condition on EXCHANGE TABLES query - #61135
yakov-olkhovskiy wants to merge 27 commits into
Conversation
|
This is an automated comment for commit d205601 with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page
Successful checks
|
|
Add a test that has a chance to reproduce the problem at least occasionally. |
|
|
||
| using ConstStoragePtr = std::shared_ptr<const IStorage>; | ||
| using StoragePtr = std::shared_ptr<IStorage>; | ||
| using StorageWeakPtr = std::weak_ptr<IStorage>; |
There was a problem hiding this comment.
It's not allowed to use std::weak_ptr<IStorage> because we rely on std::shared_ptr<IStorage>::unique()
There was a problem hiding this comment.
Instead of saving StoragePtr, we can save StorageID with resolved UUID
There was a problem hiding this comment.
it's exactly the point to not keep shared_ptr here - since on HTTP requests session can be preserved it would block database from DROP - making it weak_ptr doesn't block it and we don't need to keep it cached beyond session so it should be safe
| return shared->filesystem_cache_user; | ||
| } | ||
|
|
||
| DatabaseAndTable Context::getOrCacheStorage(const StorageID & id, std::function<DatabaseAndTable()> f, std::optional<Exception> * exception) const |
There was a problem hiding this comment.
We could cache it in Context::resolveStorageID, but a new method is fine too
There was a problem hiding this comment.
I don't think we want to enforce this cache everywhere where we call to Context::resolveStorageID - at least having a query context is a condition we need to use this cache.
There was a problem hiding this comment.
We can check this condition in resolveStorageID
| return storage; | ||
| } | ||
|
|
||
| auto storage = f(); |
| { | ||
| DatabaseAndTable storage = DatabaseCatalog::instance().tryGetByUUID(storage_id->uuid); | ||
| if (exception && !storage.second) | ||
| exception->emplace(Exception(ErrorCodes::UNKNOWN_TABLE, "Table {} does not exist anymore - maybe it was dropped", id.getNameForLogs())); |
There was a problem hiding this comment.
Currently, a query will fail if it requests a table the second time, but the table was dropped after the first get. But we can improve it later
There was a problem hiding this comment.
I don't think we need to improve it - if table was dropped concurrently then query is better to be interrupted than trying to reposes the table from drop queue - at this point we don't even know who is holding it from physical deletion...
There was a problem hiding this comment.
We do know, see addStorageHolder
|
@yakov-olkhovskiy, restarting CI by merging master is pointless. It will not fix the failures. For two reasons: |
|
@tavplubix Mergeable check was failing because build failures like this:
I'm not sure I see anything related... could you point it out please? |
|
Dear @tavplubix, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Dear @tavplubix, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
@tavplubix I don't like this solution involving additional locks - makes it too fragile. I'll think on maybe different solution if possible. But don't close this PR - maybe will continue here |
|
Does a similar race condition exist for ALTER too? The cache in Context would need to contain a StorageSnapshotPtr/StorageMetadataPtr to fix it. And along the way it can also have a TableLockHolder to fix #67646 But also TableNode already has all of these things. I would've assumed that preventing this kind of race condition is already the purpose of TableNode. Was it not the purpose, or is something broken? Did the crash happen with analyzer enabled? @KochetovNicolai , do you know? Tl;dr: #61072 , #67646 - is TableNode intended to prevent these race conditions by doing table lookup+locking+snapshotting at most once per query? |
|
@al13n321 I don't think so - the problem with |
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
1 similar comment
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
2 similar comments
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
3 similar comments
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @yakov-olkhovskiy, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
# Conflicts: # src/Interpreters/Context.cpp # src/Interpreters/Context.h # src/Interpreters/DatabaseCatalog.cpp
…e_tables_race.sh The C++ fix in `Context.cpp` / `Context.h` / `DatabaseCatalog.cpp` was reimplemented with a sharded cache and merged into master via #97411 (#97411). The accompanying test was committed under the new name `03915_exchange_tables_race.sh`, so the original `03007_exchange_tables_race.sh` would be a duplicate. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
fixed in #97411 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed possible race condition when
EXCHANGE TABLESexecuted in parallel.closes #61072