Repository navigation
Fix "Part <...> does not contain in snapshot of previous virtual parts. (PART_IS_TEMPORARILY_LOCKED)" during DETACH PART - #76039
Conversation
|
Unrelated failures : Stateless tests (tsan, 3/3) - 00156_max_execution_speed_sample_merge - Fixed in #77346 |
|
It can be easily covered with a test create table test1 (p Date, k Int) engine=ReplicatedMergeTree('/tables/t1', 'r1') order by (p) partition by k;
system stop pulling replication log test1;
INSERT INTO test1 SELECT toDate('2023-01-01') + toIntervalDay(number), number + 1000 from system.numbers limit 20;
system start pulling replication log test1;
ALTER TABLE test1 DETACH PART '1019_0_0_0';
-- Code: 384. DB::Exception: Received from localhost:9000. DB::Exception: Part 1019_0_0_0 does not contain in snapshot of previous virtual parts. (PART_IS_TEMPORARILY_LOCKED)
ALTER TABLE test1 DETACH PART '1019_0_0_0';
-- Ok@aalexfvk let's commit this test (maybe with some cleanup) |
| /// in the list of virtual parts during pulling queue. | ||
| /// The second call to pullLogsToQueue() below is used for preserving the invariant, | ||
| /// see DistributedMergePredicate | ||
| queue_.pullLogsToQueue(zookeeper, {}, ReplicatedMergeTreeQueue::MERGE_PREDICATE); |
There was a problem hiding this comment.
Looks like pulling queue 2x time for every merge should be OK (since the queue should not be big), but maybe @tavplubix see some problems here?
There was a problem hiding this comment.
We want to ensure that the predicate uses the most recent state of the queue
Actually we do not really want this and it's fine to use a slightly outdated set of virtual parts here, at least for merges, which is the main usecase for merge predicate. And for DROP PART, the error is retriable, so it's a minor issue. If we still want to avoid this error, it would be better to pull logs before constructing merge pred in dropPartImpl, so we will not have to think about potential overhead for merges. Yes, the overhead is not big, but looks like we can easily avoid it for merges
There was a problem hiding this comment.
Looks reasonable, upload the new version concerning only dropPartImpl()
Head branch was pushed to by a user without write access
|
|
@azat Are we waiting for solving issues you linked to ? Or should I focus on some of them |
|
Fixing something that failed on CI is always welcome! But, it is not a requirement for this PR to be merged. From my side looks good now (after the pulling has been removed from generic code). |
…redicate A part inserted on a replica enters that replica's `queue.virtual_parts` only when the replica pulls the part's own GET_PART log entry, which the background `queueUpdatingTask` does asynchronously. `movePartitionToShard` builds a `ReplicatedMergeTreeZooKeeperMergePredicate`, whose constructor snapshots `virtual_parts` into `prev_virtual_parts` before it pulls the log, and `canUsePartInMerges` rejects a part missing from that snapshot. So `ALTER TABLE ... MOVE PART ... TO SHARD` issued right after an INSERT on the same replica fails with "Part ... does not contain in snapshot of previous virtual parts. (PART_IS_TEMPORARILY_LOCKED)" while the background pull is still in flight. On the macOS Fast test runner the client round trips are short enough to hit this window, which makes 05495_part_moves_between_shards_step_retry time out. `dropPartImpl` got the same fix in ClickHouse#76039 (pull the log with MERGE_PREDICATE before `getMergePredicate`); `movePartitionToShard`, whose check block is a copy of `dropPart`'s, never did. Port that call. The new test stops log pulling, inserts, then restarts pulling and moves the part in one client call, so the insert's entry is not in the queue when the MOVE starts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The race condition leading to the error below can be easily reproduced for the test lines:
By adding sleep in any place of
ReplicatedMergeTreeQueue::pullLogsToQueue()before this line.Error:
Failure report
Race condition takes place between creating of merge predicate (actually saving
prev_virtual_parts) and the pulling of new log entries to queue with subsequent updatingqueue.virtual_parts.I implemented the simplest fix without conditional logic for now.
Alternatives would be pulling preliminary only for some checking (for example, for
dropPart) or usevirtual_partsinstead ofprev_virtual_partswhile workingDistributedMergePredicate::CanUsePartInMerges() -> checkCanMergePartsPreconditions()linkChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix "Part <...> does not contain in snapshot of previous virtual parts. (PART_IS_TEMPORARILY_LOCKED)" during DETACH PART
Documentation entry for user-facing changes