| 630 | } |
| 631 | |
| 632 | std::map<String, String> DatabaseReplicated::tryGetConsistentMetadataSnapshot(const ZooKeeperPtr & zookeeper, UInt32 & max_log_ptr) |
| 633 | { |
| 634 | std::map<String, String> table_name_to_metadata; |
| 635 | constexpr int max_retries = 10; |
| 636 | int iteration = 0; |
| 637 | while (++iteration <= max_retries) |
| 638 | { |
| 639 | table_name_to_metadata.clear(); |
| 640 | LOG_DEBUG(log, "Trying to get consistent metadata snapshot for log pointer {}", max_log_ptr); |
| 641 | Strings table_names = zookeeper->getChildren(zookeeper_path + "/metadata"); |
| 642 | |
| 643 | std::vector<zkutil::ZooKeeper::FutureGet> futures; |
| 644 | futures.reserve(table_names.size()); |
| 645 | for (const auto & table : table_names) |
| 646 | futures.emplace_back(zookeeper->asyncTryGet(zookeeper_path + "/metadata/" + table)); |
| 647 | |
| 648 | for (size_t i = 0; i < table_names.size(); ++i) |
| 649 | { |
| 650 | auto res = futures[i].get(); |
| 651 | if (res.error != Coordination::Error::ZOK) |
| 652 | break; |
| 653 | table_name_to_metadata.emplace(unescapeForFileName(table_names[i]), res.data); |
| 654 | } |
| 655 | |
| 656 | UInt32 new_max_log_ptr = parse<UInt32>(zookeeper->get(zookeeper_path + "/max_log_ptr")); |
| 657 | if (new_max_log_ptr == max_log_ptr && table_names.size() == table_name_to_metadata.size()) |
| 658 | break; |
| 659 | |
| 660 | if (max_log_ptr < new_max_log_ptr) |
| 661 | { |
| 662 | LOG_DEBUG(log, "Log pointer moved from {} to {}, will retry", max_log_ptr, new_max_log_ptr); |
| 663 | max_log_ptr = new_max_log_ptr; |
| 664 | } |
| 665 | else |
| 666 | { |
| 667 | assert(max_log_ptr == new_max_log_ptr); |
| 668 | assert(table_names.size() != table_name_to_metadata.size()); |
| 669 | LOG_DEBUG(log, "Cannot get metadata of some tables due to ZooKeeper error, will retry"); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | if (max_retries < iteration) |
| 674 | throw Exception(ErrorCodes::DATABASE_REPLICATION_FAILED, "Cannot get consistent metadata snapshot"); |
| 675 | |
| 676 | LOG_DEBUG(log, "Got consistent metadata snapshot for log pointer {}", max_log_ptr); |
| 677 | |
| 678 | return table_name_to_metadata; |
| 679 | } |
| 680 | |
| 681 | ASTPtr DatabaseReplicated::parseQueryFromMetadataInZooKeeper(const String & node_name, const String & query, ParserSettingsImpl dt) |
| 682 | { |
nothing calls this directly
no test coverage detected