diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java index 41a4e7b0e174..ee423e0acf61 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSource.java @@ -555,7 +555,12 @@ public void terminate(String reason, Exception cause) { terminate(reason, cause, true); } - public void terminate(String reason, Exception cause, boolean join) { + @Override + public void terminate(String reason, Exception cause, boolean clearMetrics) { + terminate(reason, cause, clearMetrics, true); + } + + public void terminate(String reason, Exception cause, boolean clearMetrics, boolean join) { if (cause == null) { LOG.info("{} Closing source {} because: {}", logPeerId(), this.queueId, reason); } else { @@ -616,7 +621,9 @@ public void terminate(String reason, Exception cause, boolean join) { } } } - this.metrics.clear(); + if (clearMetrics) { + this.metrics.clear(); + } } @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceInterface.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceInterface.java index 91497a46a442..d287acb9a6b8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceInterface.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceInterface.java @@ -91,6 +91,14 @@ void addHFileRefs(TableName tableName, byte[] family, List> pai */ void terminate(String reason, Exception cause); + /** + * End the replication + * @param reason why it's terminating + * @param cause the error that's causing it + * @param clearMetrics removes all metrics about this Source + */ + void terminate(String reason, Exception cause, boolean clearMetrics); + /** * Get the current log that's replicated * @return the current log diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java index bc5b10568914..60c49edacab1 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java @@ -380,7 +380,8 @@ public void refreshSources(String peerId) throws IOException { ReplicationSourceInterface toRemove = this.sources.put(peerId, src); if (toRemove != null) { LOG.info("Terminate replication source for " + toRemove.getPeerId()); - toRemove.terminate(terminateMessage); + // Do not clear metrics + toRemove.terminate(terminateMessage, null, false); } for (SortedSet walsByGroup : walsById.get(peerId).values()) { walsByGroup.forEach(wal -> { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/ReplicationSourceDummy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/ReplicationSourceDummy.java index ec6ec96e1a56..305a818c9181 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/ReplicationSourceDummy.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/ReplicationSourceDummy.java @@ -85,7 +85,14 @@ public void terminate(String reason) { @Override public void terminate(String reason, Exception e) { - this.metrics.clear(); + terminate(reason, e, true); + } + + @Override + public void terminate(String reason, Exception e, boolean clearMetrics) { + if (clearMetrics) { + this.metrics.clear(); + } } @Override