Apache9 commented on code in PR #5865:
URL: https://github.com/apache/hbase/pull/5865#discussion_r1604734005
##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java:
##########
@@ -402,6 +407,57 @@ public void removeAllQueuesAndHFileRefs(String peerId)
throws ReplicationExcepti
queueStorage.removePeerFromHFileRefs(peerId);
}
+ private void checkClusterKey(String clusterKey, ReplicationEndpoint endpoint)
+ throws DoNotRetryIOException {
+ if (endpoint != null && !(endpoint instanceof HBaseReplicationEndpoint)) {
+ return;
+ }
+ // Endpoints implementing HBaseReplicationEndpoint need to check cluster
key
+ URI connectionUri =
ConnectionRegistryFactory.tryParseAsConnectionURI(clusterKey);
+ try {
+ if (connectionUri != null) {
+ ConnectionRegistryFactory.validate(connectionUri);
+ } else {
+ ZKConfig.validateClusterKey(clusterKey);
+ }
+ } catch (IOException e) {
+ throw new DoNotRetryIOException("Invalid cluster key: " + clusterKey, e);
+ }
+ if (endpoint != null && endpoint.canReplicateToSameCluster()) {
+ return;
+ }
+ // make sure we do not replicate to same cluster
+ String peerClusterId;
+ try {
+ if (connectionUri != null) {
+ // fetch cluster id through standard admin API
+ try (Connection conn =
ConnectionFactory.createConnection(connectionUri, conf);
+ Admin admin = conn.getAdmin()) {
+ peerClusterId =
+
admin.getClusterMetrics(EnumSet.of(ClusterMetrics.Option.CLUSTER_ID)).getClusterId();
+ }
+ } else {
+ // Create the peer cluster config for get peer cluster id
+ Configuration peerConf = HBaseConfiguration.createClusterConf(conf,
clusterKey);
+ try (ZKWatcher zkWatcher = new ZKWatcher(peerConf, this +
"check-peer-cluster-id", null)) {
+ peerClusterId = ZKClusterId.readClusterIdZNode(zkWatcher);
+ }
+ }
+ } catch (IOException | KeeperException e) {
+ // we just want to check whether we will replicate to the same cluster,
so if we get an error
+ // while getting the cluster id of the peer cluster, it means we are not
connecting to
+ // ourselves, as we are still alive. So here we just log the error and
continue
Review Comment:
This is for allowing adding replication peer when the remote side is
completely down. The most safe way is to get the cluster id and compare it with
ours, but this means the remote side must alive, which maybe a pain sometimes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]