| 907 | } |
| 908 | |
| 909 | bool ClusterCopier::tryProcessTable(const ConnectionTimeouts & timeouts, TaskTable & task_table) |
| 910 | { |
| 911 | /// Create destination table |
| 912 | TaskStatus task_status = TaskStatus::Error; |
| 913 | |
| 914 | task_status = tryCreateDestinationTable(timeouts, task_table); |
| 915 | /// Exit if success |
| 916 | if (task_status != TaskStatus::Finished) |
| 917 | { |
| 918 | LOG_WARNING(log, "Create destination Tale Failed "); |
| 919 | return false; |
| 920 | } |
| 921 | |
| 922 | /// Set all_partitions_count for table in Zookeeper |
| 923 | auto zookeeper = getContext()->getZooKeeper(); |
| 924 | while (true) |
| 925 | { |
| 926 | Coordination::Stat stat; |
| 927 | auto status_json = zookeeper->get(task_zookeeper_path + "/status", &stat); |
| 928 | auto statuses = StatusAccumulator::fromJSON(status_json); |
| 929 | |
| 930 | /// Exit if someone already set the initial value for this table. |
| 931 | if (statuses->find(task_table.name_in_config) != statuses->end()) |
| 932 | break; |
| 933 | (*statuses)[task_table.name_in_config] = StatusAccumulator::TableStatus |
| 934 | { |
| 935 | /*all_partitions_count=*/task_table.ordered_partition_names.size(), |
| 936 | /*processed_partition_count=*/0 |
| 937 | }; |
| 938 | |
| 939 | auto statuses_to_commit = StatusAccumulator::serializeToJSON(statuses); |
| 940 | auto error = zookeeper->trySet(task_zookeeper_path + "/status", statuses_to_commit, stat.version); |
| 941 | if (error == Coordination::Error::ZOK) |
| 942 | break; |
| 943 | } |
| 944 | |
| 945 | |
| 946 | /// An heuristic: if previous shard is already done, then check next one without sleeps due to max_workers constraint |
| 947 | bool previous_shard_is_instantly_finished = false; |
| 948 | |
| 949 | /// Process each partition that is present in cluster |
| 950 | for (const String & partition_name : task_table.ordered_partition_names) |
| 951 | { |
| 952 | if (!task_table.cluster_partitions.count(partition_name)) |
| 953 | throw Exception("There are no expected partition " + partition_name + ". It is a bug", ErrorCodes::LOGICAL_ERROR); |
| 954 | |
| 955 | ClusterPartition & cluster_partition = task_table.cluster_partitions[partition_name]; |
| 956 | |
| 957 | Stopwatch watch; |
| 958 | /// We will check all the shards of the table and check if they contain current partition. |
| 959 | TasksShard expected_shards; |
| 960 | UInt64 num_failed_shards = 0; |
| 961 | |
| 962 | ++cluster_partition.total_tries; |
| 963 | |
| 964 | LOG_INFO(log, "Processing partition {} for the whole cluster", partition_name); |
| 965 | |
| 966 | /// Process each source shard having current partition and copy current partition |
nothing calls this directly
no test coverage detected