MCPcopy Create free account
hub / github.com/ByConity/ByConity / restoreReplica

Method restoreReplica

src/Interpreters/InterpreterSystemQuery.cpp:922–957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

920}
921
922void 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
959StoragePtr InterpreterSystemQuery::tryRestartReplica(const StorageID & replica, ContextMutablePtr system_context, bool need_ddl_guard)
960{

Callers

nothing calls this directly

Calls 12

getReplicaNameMethod · 0.80
ExceptionClass · 0.70
checkAccessMethod · 0.45
getZooKeeperMethod · 0.45
expiredMethod · 0.45
getTableMethod · 0.45
getMethod · 0.45
dataMethod · 0.45
getNameForLogsMethod · 0.45
getStatusMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected