| 920 | } |
| 921 | |
| 922 | void InterpreterSystemQuery::restoreReplica() |
| 923 | { |
| 924 | getContext()->checkAccess(AccessType::SYSTEM_RESTORE_REPLICA, table_id); |
| 925 | |
| 926 | const zkutil::ZooKeeperPtr& zookeeper = getContext()->getZooKeeper(); |
| 927 | |
| 928 | if (zookeeper->expired()) |
| 929 | throw Exception(ErrorCodes::NO_ZOOKEEPER, |
| 930 | "Cannot restore table metadata because ZooKeeper session has expired"); |
| 931 | |
| 932 | const StoragePtr table_ptr = DatabaseCatalog::instance().getTable(table_id, getContext()); |
| 933 | |
| 934 | auto * const table_replicated_ptr = dynamic_cast<StorageReplicatedMergeTree *>(table_ptr.get()); |
| 935 | |
| 936 | if (table_replicated_ptr == nullptr) |
| 937 | throw Exception(ErrorCodes::BAD_ARGUMENTS, table_is_not_replicated.data(), table_id.getNameForLogs()); |
| 938 | |
| 939 | auto & table_replicated = *table_replicated_ptr; |
| 940 | |
| 941 | StorageReplicatedMergeTree::Status status; |
| 942 | table_replicated.getStatus(status); |
| 943 | |
| 944 | if (!status.is_readonly) |
| 945 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "Replica must be readonly"); |
| 946 | |
| 947 | const String replica_name = table_replicated.getReplicaName(); |
| 948 | const String& zk_root_path = status.zookeeper_path; |
| 949 | |
| 950 | if (String replica_path = zk_root_path + "replicas/" + replica_name; zookeeper->exists(replica_path)) |
| 951 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 952 | "Replica path is present at {} -- nothing to restore. " |
| 953 | "If you are sure that metadata it lost and replica path contain some garbage, " |
| 954 | "then use SYSTEM DROP REPLICA query first.", replica_path); |
| 955 | |
| 956 | table_replicated.restoreMetadataInZooKeeper(); |
| 957 | } |
| 958 | |
| 959 | StoragePtr InterpreterSystemQuery::tryRestartReplica(const StorageID & replica, ContextMutablePtr system_context, bool need_ddl_guard) |
| 960 | { |
nothing calls this directly
no test coverage detected