Skip to content

Commit 28e99a3

Browse files
wchevreuilAmina Dinari
authored andcommitted
CDPD-71667: Add CDPD-34408 and COD-1499 on top of the feature branch (apache#209)
* CDPD-71667: Revert "HBASE-24764: Add support of adding default peer configs via hbase-site.xml for all replication peers. (apache#2284)" This reverts commit 7df1b92. Change-Id: I2b4570a3ab1bca6c573c669a54ef67008438bd95 * CDPD-71667: Revert "HBASE-24743 Reject to add a peer which replicate to itself earlier (apache#2124)" This reverts commit 70ab0dc. Change-Id: I6d508ff3aacf2d48e00f903afe7bca21d34f3247 --------- Co-authored-by: Wellington Ramos Chevreuil <wchevreuil@apache.org>
1 parent ea031c1 commit 28e99a3

File tree

11 files changed

+111
-252
lines changed

11 files changed

+111
-252
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ private void initializeZKBasedSystemTrackers()
803803
this.splitOrMergeStateStore = new SplitOrMergeStateStore(masterRegion, zooKeeper, conf);
804804

805805
this.replicationPeerManager =
806-
ReplicationPeerManager.create(fileSystemManager.getFileSystem(), zooKeeper, conf, clusterId);
806+
ReplicationPeerManager.create(fileSystemManager.getFileSystem(), zooKeeper, conf);
807807
this.configurationManager.registerObserver(replicationPeerManager);
808808
this.replicationPeerModificationStateStore =
809809
new ReplicationPeerModificationStateStore(masterRegion);

hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.commons.lang3.StringUtils;
3232
import org.apache.hadoop.conf.Configuration;
3333
import org.apache.hadoop.fs.FileSystem;
34+
import org.apache.hadoop.fs.FileSystem;
3435
import org.apache.hadoop.hbase.DoNotRetryIOException;
3536
import org.apache.hadoop.hbase.HBaseConfiguration;
3637
import org.apache.hadoop.hbase.ReplicationPeerNotFoundException;
@@ -50,6 +51,7 @@
5051
import org.apache.hadoop.hbase.replication.ReplicationQueueStorage;
5152
import org.apache.hadoop.hbase.replication.ReplicationStorageFactory;
5253
import org.apache.hadoop.hbase.replication.ReplicationUtils;
54+
import org.apache.hadoop.hbase.replication.regionserver.HBaseInterClusterReplicationEndpoint;
5355
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
5456
import org.apache.hadoop.hbase.zookeeper.ZKConfig;
5557
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
@@ -73,25 +75,18 @@ public class ReplicationPeerManager implements ConfigurationObserver {
7375

7476
private final ConcurrentMap<String, ReplicationPeerDescription> peers;
7577

76-
private final String clusterId;
77-
78-
private volatile Configuration conf;
79-
8078
// for dynamic recreating ReplicationPeerStorage.
8179
private final FileSystem fs;
8280

8381
private final ZKWatcher zk;
8482

85-
ReplicationPeerManager(FileSystem fs, ZKWatcher zk, ReplicationPeerStorage peerStorage,
86-
ReplicationQueueStorage queueStorage, ConcurrentMap<String, ReplicationPeerDescription> peers,
87-
Configuration conf, String clusterId) {
88-
this.fs = fs;
89-
this.zk = zk;
83+
ReplicationPeerManager(FileSystem fs, ZKWatcher zk, ReplicationPeerStorage peerStorage, ReplicationQueueStorage queueStorage,
84+
ConcurrentMap<String, ReplicationPeerDescription> peers) {
9085
this.peerStorage = peerStorage;
9186
this.queueStorage = queueStorage;
9287
this.peers = peers;
93-
this.conf = conf;
94-
this.clusterId = clusterId;
88+
this.fs = fs;
89+
this.zk = zk;
9590
}
9691

9792
private void checkQueuesDeleted(String peerId)
@@ -181,12 +176,11 @@ ReplicationPeerDescription preUpdatePeerConfig(String peerId, ReplicationPeerCon
181176
}
182177

183178
public void addPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled)
184-
throws ReplicationException {
179+
throws ReplicationException {
185180
if (peers.containsKey(peerId)) {
186181
// this should be a retry, just return
187182
return;
188183
}
189-
peerConfig = ReplicationPeerConfigUtil.updateReplicationBasePeerConfigs(conf, peerConfig);
190184
ReplicationPeerConfig copiedPeerConfig = ReplicationPeerConfig.newBuilder(peerConfig).build();
191185
peerStorage.addPeer(peerId, copiedPeerConfig, enabled);
192186
peers.put(peerId, new ReplicationPeerDescription(peerId, enabled, copiedPeerConfig));
@@ -281,25 +275,25 @@ void removeAllQueuesAndHFileRefs(String peerId) throws ReplicationException {
281275

282276
private void checkPeerConfig(ReplicationPeerConfig peerConfig) throws DoNotRetryIOException {
283277
String replicationEndpointImpl = peerConfig.getReplicationEndpointImpl();
284-
ReplicationEndpoint endpoint = null;
278+
boolean checkClusterKey = true;
285279
if (!StringUtils.isBlank(replicationEndpointImpl)) {
280+
// try creating a instance
281+
ReplicationEndpoint endpoint;
286282
try {
287-
// try creating a instance
288-
endpoint = Class.forName(replicationEndpointImpl).asSubclass(ReplicationEndpoint.class)
289-
.getDeclaredConstructor().newInstance();
283+
endpoint = Class.forName(replicationEndpointImpl)
284+
.asSubclass(ReplicationEndpoint.class).getDeclaredConstructor().newInstance();
290285
} catch (Throwable e) {
291286
throw new DoNotRetryIOException(
292287
"Can not instantiate configured replication endpoint class=" + replicationEndpointImpl,
293288
e);
294289
}
290+
// do not check cluster key if we are not HBaseInterClusterReplicationEndpoint
291+
if (!(endpoint instanceof HBaseInterClusterReplicationEndpoint)) {
292+
checkClusterKey = false;
293+
}
295294
}
296-
// Endpoints implementing HBaseReplicationEndpoint need to check cluster key
297-
if (endpoint == null || endpoint instanceof HBaseReplicationEndpoint) {
295+
if (checkClusterKey) {
298296
checkClusterKey(peerConfig.getClusterKey());
299-
// Check if endpoint can replicate to the same cluster
300-
if (endpoint == null || !endpoint.canReplicateToSameCluster()) {
301-
checkSameClusterKey(peerConfig.getClusterKey());
302-
}
303297
}
304298

305299
if (peerConfig.replicateAllUserTables()) {
@@ -396,25 +390,6 @@ private void checkClusterKey(String clusterKey) throws DoNotRetryIOException {
396390
}
397391
}
398392

399-
private void checkSameClusterKey(String clusterKey) throws DoNotRetryIOException {
400-
String peerClusterId = "";
401-
try {
402-
// Create the peer cluster config for get peer cluster id
403-
Configuration peerConf = HBaseConfiguration.createClusterConf(conf, clusterKey);
404-
try (ZKWatcher zkWatcher = new ZKWatcher(peerConf, this + "check-peer-cluster-id", null)) {
405-
peerClusterId = ZKClusterId.readClusterIdZNode(zkWatcher);
406-
}
407-
} catch (IOException | KeeperException e) {
408-
throw new DoNotRetryIOException("Can't get peerClusterId for clusterKey=" + clusterKey, e);
409-
}
410-
// In rare case, zookeeper setting may be messed up. That leads to the incorrect
411-
// peerClusterId value, which is the same as the source clusterId
412-
if (clusterId.equals(peerClusterId)) {
413-
throw new DoNotRetryIOException("Invalid cluster key: " + clusterKey
414-
+ ", should not replicate to itself for HBaseInterClusterReplicationEndpoint");
415-
}
416-
}
417-
418393
public List<String> getSerialPeerIdsBelongsTo(TableName tableName) {
419394
return peers.values().stream().filter(p -> p.getPeerConfig().isSerial())
420395
.filter(p -> p.getPeerConfig().needToReplicate(tableName)).map(p -> p.getPeerId())
@@ -425,21 +400,18 @@ public ReplicationQueueStorage getQueueStorage() {
425400
return queueStorage;
426401
}
427402

428-
public static ReplicationPeerManager create(FileSystem fs, ZKWatcher zk, Configuration conf,
429-
String clusterId) throws ReplicationException {
403+
public static ReplicationPeerManager create(FileSystem fs, ZKWatcher zk, Configuration conf)
404+
throws ReplicationException {
430405
ReplicationPeerStorage peerStorage =
431406
ReplicationStorageFactory.getReplicationPeerStorage(fs, zk, conf);
432407
ConcurrentMap<String, ReplicationPeerDescription> peers = new ConcurrentHashMap<>();
433408
for (String peerId : peerStorage.listPeerIds()) {
434409
ReplicationPeerConfig peerConfig = peerStorage.getPeerConfig(peerId);
435-
436-
peerConfig = ReplicationPeerConfigUtil.updateReplicationBasePeerConfigs(conf, peerConfig);
437-
peerStorage.updatePeerConfig(peerId, peerConfig);
438410
boolean enabled = peerStorage.isPeerEnabled(peerId);
439411
peers.put(peerId, new ReplicationPeerDescription(peerId, enabled, peerConfig));
440412
}
441413
return new ReplicationPeerManager(fs, zk, peerStorage,
442-
ReplicationStorageFactory.getReplicationQueueStorage(zk, conf), peers, conf, clusterId);
414+
ReplicationStorageFactory.getReplicationQueueStorage(zk, conf), peers);
443415
}
444416

445417
/**
@@ -455,7 +427,6 @@ private boolean isStringEquals(String s1, String s2) {
455427

456428
@Override
457429
public void onConfigurationChange(Configuration conf) {
458-
this.conf = conf;
459430
this.peerStorage = ReplicationStorageFactory.getReplicationPeerStorage(fs, zk, conf);
460431
}
461432
}

hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,18 @@ private void initialize() {
584584
return;
585585
}
586586

587+
// In rare case, zookeeper setting may be messed up. That leads to the incorrect
588+
// peerClusterId value, which is the same as the source clusterId
589+
if (clusterId.equals(peerClusterId) && !replicationEndpoint.canReplicateToSameCluster()) {
590+
this.terminate("ClusterId " + clusterId + " is replicating to itself: peerClusterId "
591+
+ peerClusterId + " which is not allowed by ReplicationEndpoint:"
592+
+ replicationEndpoint.getClass().getName(), null, false);
593+
this.manager.removeSource(this);
594+
return;
595+
}
596+
LOG.info("{} Source: {}, is now replicating from cluster: {}; to peer cluster: {};",
597+
logPeerId(), this.replicationQueueInfo.getQueueId(), clusterId, peerClusterId);
598+
587599
LOG.info("{} queueId={} (queues={}) is replicating from cluster={} to cluster={}", logPeerId(),
588600
this.replicationQueueInfo.getQueueId(), logQueue.getNumQueues(), clusterId, peerClusterId);
589601
initializeWALEntryFilter(peerClusterId);

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApi.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public class TestAsyncReplicationAdminApi extends TestAsyncAdminBase {
7474
HBaseClassTestRule.forClass(TestAsyncReplicationAdminApi.class);
7575

7676
private final String ID_ONE = "1";
77-
private static String KEY_ONE;
77+
private final String KEY_ONE = "127.0.0.1:2181:/hbase";
7878
private final String ID_TWO = "2";
79-
private static String KEY_TWO;
79+
private final String KEY_TWO = "127.0.0.1:2181:/hbase2";
8080

8181
@BeforeClass
8282
public static void setUpBeforeClass() throws Exception {
@@ -85,8 +85,6 @@ public static void setUpBeforeClass() throws Exception {
8585
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
8686
TEST_UTIL.getConfiguration().setInt(START_LOG_ERRORS_AFTER_COUNT_KEY, 0);
8787
TEST_UTIL.startMiniCluster();
88-
KEY_ONE = TEST_UTIL.getClusterKey() + "-test1";
89-
KEY_TWO = TEST_UTIL.getClusterKey() + "-test2";
9088
ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
9189
}
9290

hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public class TestReplicationAdmin {
7777
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
7878

7979
private final String ID_ONE = "1";
80-
private static String KEY_ONE;
80+
private final String KEY_ONE = "127.0.0.1:2181:/hbase";
8181
private final String ID_SECOND = "2";
82-
private static String KEY_SECOND;
82+
private final String KEY_SECOND = "127.0.0.1:2181:/hbase2";
8383

8484
private static ReplicationAdmin admin;
8585
private static Admin hbaseAdmin;
@@ -96,8 +96,6 @@ public static void setUpBeforeClass() throws Exception {
9696
TEST_UTIL.startMiniCluster();
9797
admin = new ReplicationAdmin(TEST_UTIL.getConfiguration());
9898
hbaseAdmin = TEST_UTIL.getAdmin();
99-
KEY_ONE = TEST_UTIL.getClusterKey() + "-test1";
100-
KEY_SECOND = TEST_UTIL.getClusterKey() + "-test2";
10199
}
102100

103101
@AfterClass

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/SerialReplicationTestBase.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ protected void doStart() {
114114
protected void doStop() {
115115
notifyStopped();
116116
}
117-
118-
@Override
119-
public boolean canReplicateToSameCluster() {
120-
return true;
121-
}
122117
}
123118

124119
@BeforeClass

0 commit comments

Comments
 (0)