From 4393934247861b43773b723232fd3e25e143aa75 Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Tue, 6 Feb 2018 14:58:39 +0800 Subject: [PATCH] HBASE-19923 Reset peer state and config when refresh replication source failed --- .../hbase/replication/ReplicationPeerImpl.java | 4 ++-- .../regionserver/PeerProcedureHandlerImpl.java | 24 ++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerImpl.java b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerImpl.java index 604e0bb..d656466 100644 --- a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerImpl.java +++ b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerImpl.java @@ -54,11 +54,11 @@ public class ReplicationPeerImpl implements ReplicationPeer { this.peerConfigListeners = new ArrayList<>(); } - void setPeerState(boolean enabled) { + public void setPeerState(boolean enabled) { this.peerState = enabled ? PeerState.ENABLED : PeerState.DISABLED; } - void setPeerConfig(ReplicationPeerConfig peerConfig) { + public void setPeerConfig(ReplicationPeerConfig peerConfig) { this.peerConfig = peerConfig; peerConfigListeners.forEach(listener -> listener.peerConfigUpdated(peerConfig)); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/PeerProcedureHandlerImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/PeerProcedureHandlerImpl.java index ce8fdae..2cbf47b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/PeerProcedureHandlerImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/PeerProcedureHandlerImpl.java @@ -69,9 +69,15 @@ public class PeerProcedureHandlerImpl implements PeerProcedureHandler { } PeerState oldState = peer.getPeerState(); newState = replicationSourceManager.getReplicationPeers().refreshPeerState(peerId); - // RS need to start work with the new replication state change - if (oldState.equals(PeerState.ENABLED) && newState.equals(PeerState.DISABLED)) { - replicationSourceManager.refreshSources(peerId); + try { + // RS need to start work with the new replication state change + if (oldState.equals(PeerState.ENABLED) && newState.equals(PeerState.DISABLED)) { + replicationSourceManager.refreshSources(peerId); + } + } catch (IOException ioe) { + // Reset peer state if refresh source failed + peer.setPeerState(oldState.equals(PeerState.ENABLED)); + throw ioe; } } finally { peerLock.unlock(); @@ -99,9 +105,15 @@ public class PeerProcedureHandlerImpl implements PeerProcedureHandler { ReplicationPeerConfig oldConfig = peer.getPeerConfig(); ReplicationPeerConfig newConfig = replicationSourceManager.getReplicationPeers().refreshPeerConfig(peerId); - // RS need to start work with the new replication config change - if (!ReplicationUtils.isKeyConfigEqual(oldConfig, newConfig)) { - replicationSourceManager.refreshSources(peerId); + try { + // RS need to start work with the new replication config change + if (!ReplicationUtils.isKeyConfigEqual(oldConfig, newConfig)) { + replicationSourceManager.refreshSources(peerId); + } + } catch (IOException ioe) { + // Reset peer config if refresh source failed + peer.setPeerConfig(oldConfig); + throw ioe; } } finally { peerLock.unlock(); -- 1.9.1