HBASE-20597 Serialize access to a shared reference to ZooKeeperWatcher in HBaseReplicationEndpoint

This commit is contained in:
Andrew Purtell 2018-05-25 10:25:29 -07:00
parent 807c905f90
commit 06611256ee
1 changed files with 4 additions and 6 deletions

View File

@ -43,19 +43,17 @@ import org.slf4j.LoggerFactory;
* target cluster is an HBase cluster. * target cluster is an HBase cluster.
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="MT_CORRECTNESS",
justification="Thinks zkw needs to be synchronized access but should be fine as is.")
public abstract class HBaseReplicationEndpoint extends BaseReplicationEndpoint public abstract class HBaseReplicationEndpoint extends BaseReplicationEndpoint
implements Abortable { implements Abortable {
private static final Logger LOG = LoggerFactory.getLogger(HBaseReplicationEndpoint.class); private static final Logger LOG = LoggerFactory.getLogger(HBaseReplicationEndpoint.class);
private ZKWatcher zkw = null; // FindBugs: MT_CORRECTNESS private ZKWatcher zkw = null;
private List<ServerName> regionServers = new ArrayList<>(0); private List<ServerName> regionServers = new ArrayList<>(0);
private long lastRegionServerUpdate; private long lastRegionServerUpdate;
protected void disconnect() { protected synchronized void disconnect() {
if (zkw != null) { if (zkw != null) {
zkw.close(); zkw.close();
} }
@ -123,7 +121,7 @@ public abstract class HBaseReplicationEndpoint extends BaseReplicationEndpoint
* Get the ZK connection to this peer * Get the ZK connection to this peer
* @return zk connection * @return zk connection
*/ */
protected ZKWatcher getZkw() { protected synchronized ZKWatcher getZkw() {
return zkw; return zkw;
} }
@ -131,7 +129,7 @@ public abstract class HBaseReplicationEndpoint extends BaseReplicationEndpoint
* Closes the current ZKW (if not null) and creates a new one * Closes the current ZKW (if not null) and creates a new one
* @throws IOException If anything goes wrong connecting * @throws IOException If anything goes wrong connecting
*/ */
void reloadZkWatcher() throws IOException { synchronized void reloadZkWatcher() throws IOException {
if (zkw != null) zkw.close(); if (zkw != null) zkw.close();
zkw = new ZKWatcher(ctx.getConfiguration(), zkw = new ZKWatcher(ctx.getConfiguration(),
"connection to cluster: " + ctx.getPeerId(), this); "connection to cluster: " + ctx.getPeerId(), this);