| 541 | |
| 542 | |
| 543 | TaskStatus ClusterCopier::tryMoveAllPiecesToDestinationTable(const TaskTable & task_table, const String & partition_name) |
| 544 | { |
| 545 | bool inject_fault = false; |
| 546 | if (move_fault_probability > 0) |
| 547 | { |
| 548 | double value = std::uniform_real_distribution<>(0, 1)(task_table.task_cluster.random_engine); |
| 549 | inject_fault = value < move_fault_probability; |
| 550 | } |
| 551 | |
| 552 | LOG_INFO(log, "Try to move {} to destination table", partition_name); |
| 553 | |
| 554 | auto zookeeper = getContext()->getZooKeeper(); |
| 555 | |
| 556 | const auto current_partition_attach_is_active = task_table.getPartitionAttachIsActivePath(partition_name); |
| 557 | const auto current_partition_attach_is_done = task_table.getPartitionAttachIsDonePath(partition_name); |
| 558 | |
| 559 | /// Create ephemeral node to mark that we are active and process the partition |
| 560 | zookeeper->createAncestors(current_partition_attach_is_active); |
| 561 | zkutil::EphemeralNodeHolderPtr partition_attach_node_holder; |
| 562 | try |
| 563 | { |
| 564 | partition_attach_node_holder = zkutil::EphemeralNodeHolder::create(current_partition_attach_is_active, *zookeeper, host_id); |
| 565 | } |
| 566 | catch (const Coordination::Exception & e) |
| 567 | { |
| 568 | if (e.code == Coordination::Error::ZNODEEXISTS) |
| 569 | { |
| 570 | LOG_INFO(log, "Someone is already moving pieces {}", current_partition_attach_is_active); |
| 571 | return TaskStatus::Active; |
| 572 | } |
| 573 | |
| 574 | throw; |
| 575 | } |
| 576 | |
| 577 | |
| 578 | /// Exit if task has been already processed; |
| 579 | /// create blocking node to signal cleaning up if it is abandoned |
| 580 | { |
| 581 | String status_data; |
| 582 | if (zookeeper->tryGet(current_partition_attach_is_done, status_data)) |
| 583 | { |
| 584 | TaskStateWithOwner status = TaskStateWithOwner::fromString(status_data); |
| 585 | if (status.state == TaskState::Finished) |
| 586 | { |
| 587 | LOG_INFO(log, "All pieces for partition from this task {} has been successfully moved to destination table by {}", current_partition_attach_is_active, status.owner); |
| 588 | return TaskStatus::Finished; |
| 589 | } |
| 590 | |
| 591 | /// Task is abandoned, because previously we created ephemeral node, possibly in other copier's process. |
| 592 | /// Initialize DROP PARTITION |
| 593 | LOG_INFO(log, "Moving piece for partition {} has not been successfully finished by {}. Will try to move by myself.", current_partition_attach_is_active, status.owner); |
| 594 | |
| 595 | /// Remove is_done marker. |
| 596 | zookeeper->remove(current_partition_attach_is_done); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 |
nothing calls this directly
no test coverage detected