Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D55F11D14 for ; Wed, 6 Aug 2014 18:20:52 +0000 (UTC) Received: (qmail 12962 invoked by uid 500); 6 Aug 2014 18:20:52 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 12930 invoked by uid 500); 6 Aug 2014 18:20:51 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 12921 invoked by uid 99); 6 Aug 2014 18:20:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Aug 2014 18:20:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 99DF59248B0; Wed, 6 Aug 2014 18:20:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jmhsieh@apache.org To: commits@hbase.apache.org Message-Id: <7e247a68f9bd47b2b42ce8239dae69f0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: HBASE-11535 ReplicationPeer map is not thread safe (Virag Kothari) Date: Wed, 6 Aug 2014 18:20:51 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/0.98 e0ede7f4a -> c8812737b HBASE-11535 ReplicationPeer map is not thread safe (Virag Kothari) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c8812737 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c8812737 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c8812737 Branch: refs/heads/0.98 Commit: c8812737bb53016ec18738061b9c2a18ca8c0ad8 Parents: e0ede7f Author: Jonathan M Hsieh Authored: Wed Aug 6 11:18:20 2014 -0700 Committer: Jonathan M Hsieh Committed: Wed Aug 6 11:18:20 2014 -0700 ---------------------------------------------------------------------- .../replication/ReplicationPeersZKImpl.java | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/c8812737/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java ---------------------------------------------------------------------- diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java index b69367a..b7a6447 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java @@ -27,6 +27,8 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -86,7 +88,7 @@ public class ReplicationPeersZKImpl extends ReplicationStateZKBase implements Re Abortable abortable) { super(zk, conf, abortable); this.tableCFsNodeName = conf.get("zookeeper.znode.replication.peers.tableCFs", "tableCFs"); - this.peerClusters = new HashMap(); + this.peerClusters = new ConcurrentHashMap(); } @Override @@ -195,18 +197,20 @@ public class ReplicationPeersZKImpl extends ReplicationStateZKBase implements Re @Override public Map> getTableCFs(String id) throws IllegalArgumentException { - if (!this.peerClusters.containsKey(id)) { + ReplicationPeer replicationPeer = this.peerClusters.get(id); + if (replicationPeer == null) { throw new IllegalArgumentException("Peer with id= " + id + " is not connected"); } - return this.peerClusters.get(id).getTableCFs(); + return replicationPeer.getTableCFs(); } @Override public boolean getStatusOfConnectedPeer(String id) { - if (!this.peerClusters.containsKey(id)) { + ReplicationPeer replicationPeer = this.peerClusters.get(id); + if (replicationPeer == null) { throw new IllegalArgumentException("Peer with id= " + id + " is not connected"); - } - return this.peerClusters.get(id).getPeerEnabled().get(); + } + return replicationPeer.getPeerEnabled().get(); } @Override @@ -246,7 +250,7 @@ public class ReplicationPeersZKImpl extends ReplicationStateZKBase implements Re if (peer == null) { return false; } - this.peerClusters.put(peerId, peer); + ((ConcurrentMap) peerClusters).putIfAbsent(peerId, peer); LOG.info("Added new peer cluster " + peer.getClusterKey()); return true; } @@ -256,7 +260,7 @@ public class ReplicationPeersZKImpl extends ReplicationStateZKBase implements Re ReplicationPeer rp = this.peerClusters.get(peerId); if (rp != null) { rp.getZkw().close(); - this.peerClusters.remove(peerId); + ((ConcurrentMap) peerClusters).remove(peerId, rp); } } @@ -375,10 +379,11 @@ public class ReplicationPeersZKImpl extends ReplicationStateZKBase implements Re @Override public long getTimestampOfLastChangeToPeer(String peerId) { - if (!peerClusters.containsKey(peerId)) { + ReplicationPeer peer = this.peerClusters.get(peerId); + if (peer == null) { throw new IllegalArgumentException("Unknown peer id: " + peerId); } - return peerClusters.get(peerId).getLastRegionserverUpdate(); + return peer.getLastRegionserverUpdate(); } /**