diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java index d145d0825ac..4e9b34c576a 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ClusterStatusTracker.java @@ -20,11 +20,12 @@ package org.apache.hadoop.hbase.zookeeper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.Abortable; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.zookeeper.KeeperException; + import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos; -import org.apache.zookeeper.KeeperException; /** * Tracker on cluster settings up in zookeeper. @@ -42,8 +43,9 @@ public class ClusterStatusTracker extends ZKNodeTracker { * *

After construction, use {@link #start} to kick off tracking. * - * @param watcher - * @param abortable + * @param watcher reference to the {@link ZKWatcher} which also contains configuration and + * constants + * @param abortable used to abort if a fatal error occurs */ public ClusterStatusTracker(ZKWatcher watcher, Abortable abortable) { super(watcher, watcher.znodePaths.clusterStateZNode, abortable); @@ -52,7 +54,7 @@ public class ClusterStatusTracker extends ZKNodeTracker { /** * Checks if cluster is up. * @return true if the cluster up ('shutdown' is its name up in zk) znode - * exists with data, false if not + * exists with data, false if not */ public boolean isClusterUp() { return super.getData(false) != null; @@ -88,7 +90,7 @@ public class ClusterStatusTracker extends ZKNodeTracker { /** * @return Content of the clusterup znode as a serialized pb with the pb - * magic as prefix. + * magic as prefix. */ static byte [] toByteArray() { ZooKeeperProtos.ClusterUp.Builder builder = diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java index 1ec4f1d03fd..ce6a5feacc0 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/EmptyWatcher.java @@ -25,7 +25,7 @@ import org.apache.zookeeper.Watcher; * An empty ZooKeeper watcher */ @InterfaceAudience.Private -public class EmptyWatcher implements Watcher { +public final class EmptyWatcher implements Watcher { // Used in this package but also by tests so needs to be public public static final EmptyWatcher instance = new EmptyWatcher(); private EmptyWatcher() {} diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java index 93573971582..01935158797 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java @@ -35,11 +35,11 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.HConstants; -import org.apache.yetus.audience.InterfaceAudience; -import org.apache.yetus.audience.InterfaceStability; import org.apache.hadoop.hbase.util.DNS; import org.apache.hadoop.hbase.util.Strings; import org.apache.hadoop.util.StringUtils; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.yetus.audience.InterfaceStability; import org.apache.zookeeper.server.ServerConfig; import org.apache.zookeeper.server.ZooKeeperServerMain; import org.apache.zookeeper.server.quorum.QuorumPeerConfig; @@ -54,7 +54,9 @@ import org.apache.zookeeper.server.quorum.QuorumPeerMain; */ @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS) @InterfaceStability.Evolving -public class HQuorumPeer { +public final class HQuorumPeer { + private HQuorumPeer() { + } /** * Parse ZooKeeper configuration from HBase XML config and run a QuorumPeer. @@ -80,7 +82,8 @@ public class HQuorumPeer { } } - private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException { + private static void runZKServer(QuorumPeerConfig zkConfig) + throws UnknownHostException, IOException { if (zkConfig.isDistributed()) { QuorumPeerMain qp = new QuorumPeerMain(); qp.runFromConfig(zkConfig); @@ -139,8 +142,8 @@ public class HQuorumPeer { } // Set the max session timeout from the provided client-side timeout - properties.setProperty("maxSessionTimeout", - conf.get(HConstants.ZK_SESSION_TIMEOUT, Integer.toString(HConstants.DEFAULT_ZK_SESSION_TIMEOUT))); + properties.setProperty("maxSessionTimeout", conf.get(HConstants.ZK_SESSION_TIMEOUT, + Integer.toString(HConstants.DEFAULT_ZK_SESSION_TIMEOUT))); if (myId == -1) { throw new IOException("Could not find my address: " + myAddress + diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/LoadBalancerTracker.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/LoadBalancerTracker.java index 55dafcb3b20..cddce3319fa 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/LoadBalancerTracker.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/LoadBalancerTracker.java @@ -21,13 +21,14 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.exceptions.DeserializationException; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.zookeeper.KeeperException; + import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.LoadBalancerProtos; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.zookeeper.KeeperException; /** * Tracks the load balancer state up in ZK @@ -57,12 +58,14 @@ public class LoadBalancerTracker extends ZKNodeTracker { } /** - * Set the balancer on/off - * @param balancerOn - * @throws KeeperException + * Set the balancer on/off. + * + * @param balancerOn true if the balancher should be on, false otherwise + * @throws KeeperException if a ZooKeeper operation fails */ public void setBalancerOn(boolean balancerOn) throws KeeperException { - byte [] upData = toByteArray(balancerOn); + byte [] upData = toByteArray(balancerOn); + try { ZKUtil.setData(watcher, watcher.znodePaths.balancerZNode, upData); } catch(KeeperException.NoNodeException nne) { diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java index 85668ad18b7..630eb3e6c05 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java @@ -23,14 +23,15 @@ import java.io.InterruptedIOException; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.exceptions.DeserializationException; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; + +import org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.data.Stat; -import org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException; /** * Manages the location of the current active Master for the RegionServer. @@ -138,12 +139,12 @@ public class MasterAddressTracker extends ZKNodeTracker { * instance of this tracker in your context. * @param zkw ZKWatcher to use * @return ServerName stored in the the master address znode or null if no - * znode present. - * @throws KeeperException - * @throws IOException + * znode present. + * @throws KeeperException if a ZooKeeper operation fails + * @throws IOException if the address of the ZooKeeper master cannot be retrieved */ public static ServerName getMasterAddress(final ZKWatcher zkw) - throws KeeperException, IOException { + throws KeeperException, IOException { byte [] data; try { data = ZKUtil.getData(zkw, zkw.znodePaths.masterAddressZNode); @@ -169,13 +170,12 @@ public class MasterAddressTracker extends ZKNodeTracker { * instance of this tracker in your context. * @param zkw ZKWatcher to use * @return master info port in the the master address znode or null if no - * znode present. - * // TODO can't return null for 'int' return type. non-static verison returns 0 - * @throws KeeperException - * @throws IOException + * znode present. + * // TODO can't return null for 'int' return type. non-static verison returns 0 + * @throws KeeperException if a ZooKeeper operation fails + * @throws IOException if the address of the ZooKeeper master cannot be retrieved */ - public static int getMasterInfoPort(final ZKWatcher zkw) throws KeeperException, - IOException { + public static int getMasterInfoPort(final ZKWatcher zkw) throws KeeperException, IOException { byte[] data; try { data = ZKUtil.getData(zkw, zkw.znodePaths.masterAddressZNode); @@ -201,10 +201,10 @@ public class MasterAddressTracker extends ZKNodeTracker { * path. * @param zkw The ZKWatcher to use. * @param znode Where to create the znode; could be at the top level or it - * could be under backup masters + * could be under backup masters * @param master ServerName of the current master must not be null. * @return true if node created, false if not; a watch is set in both cases - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public static boolean setMasterAddress(final ZKWatcher zkw, final String znode, final ServerName master, int infoPort) @@ -223,7 +223,7 @@ public class MasterAddressTracker extends ZKNodeTracker { /** * @param sn must not be null * @return Content of the master znode as a serialized pb with the pb - * magic as prefix. + * magic as prefix. */ static byte[] toByteArray(final ServerName sn, int infoPort) { ZooKeeperProtos.Master.Builder mbuilder = ZooKeeperProtos.Master.newBuilder(); @@ -240,7 +240,7 @@ public class MasterAddressTracker extends ZKNodeTracker { /** * @param data zookeeper data. may be null * @return pb object of master, null if no active master - * @throws DeserializationException + * @throws DeserializationException if the parsing fails */ public static ZooKeeperProtos.Master parse(byte[] data) throws DeserializationException { if (data == null) { diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java index 43c79357947..6e231886ade 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java @@ -99,9 +99,10 @@ public class MetaTableLocator { } /** + * Gets the meta regions and their locations for the given path and replica ID. * - * @param zkw - * @param replicaId + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param replicaId the ID of the replica * @return meta table regions and their locations. */ public List> getMetaRegionsAndLocations(ZKWatcher zkw, @@ -114,6 +115,8 @@ public class MetaTableLocator { } /** + * Gets the meta regions for the given path with the default replica ID. + * * @param zkw ZooKeeper watcher to be used * @return List of meta regions */ @@ -122,9 +125,10 @@ public class MetaTableLocator { } /** + * Gets the meta regions for the given path and replica ID. * - * @param zkw - * @param replicaId + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param replicaId the ID of the replica * @return List of meta regions */ public List getMetaRegions(ZKWatcher zkw, int replicaId) { @@ -133,9 +137,11 @@ public class MetaTableLocator { return getListOfRegionInfos(result); } - private List getListOfRegionInfos( - final List> pairs) { - if (pairs == null || pairs.isEmpty()) return Collections.EMPTY_LIST; + private List getListOfRegionInfos(final List> pairs) { + if (pairs == null || pairs.isEmpty()) { + return Collections.EMPTY_LIST; + } + List result = new ArrayList<>(pairs.size()); for (Pair pair: pairs) { result.add(pair.getFirst()); @@ -159,8 +165,8 @@ public class MetaTableLocator { /** * Gets the meta region location, if available. Does not block. - * @param zkw - * @param replicaId + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param replicaId the ID of the replica * @return server name */ public ServerName getMetaRegionLocation(final ZKWatcher zkw, int replicaId) { @@ -177,12 +183,13 @@ public class MetaTableLocator { * specified timeout if not immediately available. * Given the zookeeper notification could be delayed, we will try to * get the latest data. - * @param zkw + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param timeout maximum time to wait, in millis * @return server name for server hosting meta region formatted as per * {@link ServerName}, or null if none available * @throws InterruptedException if interrupted while waiting - * @throws NotAllMetaRegionsOnlineException + * @throws NotAllMetaRegionsOnlineException if a meta or root region is not online */ public ServerName waitMetaRegionLocation(ZKWatcher zkw, long timeout) throws InterruptedException, NotAllMetaRegionsOnlineException { @@ -190,17 +197,17 @@ public class MetaTableLocator { } /** - * Gets the meta region location, if available, and waits for up to the - * specified timeout if not immediately available. - * Given the zookeeper notification could be delayed, we will try to + * Gets the meta region location, if available, and waits for up to the specified timeout if not + * immediately available. Given the zookeeper notification could be delayed, we will try to * get the latest data. - * @param zkw - * @param replicaId + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param replicaId the ID of the replica * @param timeout maximum time to wait, in millis * @return server name for server hosting meta region formatted as per * {@link ServerName}, or null if none available - * @throws InterruptedException - * @throws NotAllMetaRegionsOnlineException + * @throws InterruptedException if waiting for the socket operation fails + * @throws NotAllMetaRegionsOnlineException if a meta or root region is not online */ public ServerName waitMetaRegionLocation(ZKWatcher zkw, int replicaId, long timeout) throws InterruptedException, NotAllMetaRegionsOnlineException { @@ -234,7 +241,10 @@ public class MetaTableLocator { long startTime = System.currentTimeMillis(); while (!stopped) { try { - if (waitMetaRegionLocation(zkw, 100) != null) break; + if (waitMetaRegionLocation(zkw, 100) != null) { + break; + } + long sleepTime = System.currentTimeMillis() - startTime; // +1 in case sleepTime=0 if ((sleepTime + 1) % 10000 == 0) { @@ -251,33 +261,33 @@ public class MetaTableLocator { /** * Verify hbase:meta is deployed and accessible. - * @param hConnection - * @param zkw + * + * @param hConnection the connection to use + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param timeout How long to wait on zk for meta address (passed through to - * the internal call to {@link #getMetaServerConnection}. + * the internal call to {@link #getMetaServerConnection}. * @return True if the hbase:meta location is healthy. - * @throws java.io.IOException - * @throws InterruptedException + * @throws IOException if the number of retries for getting the connection is exceeded + * @throws InterruptedException if waiting for the socket operation fails */ - public boolean verifyMetaRegionLocation(ClusterConnection hConnection, - ZKWatcher zkw, final long timeout) - throws InterruptedException, IOException { + public boolean verifyMetaRegionLocation(ClusterConnection hConnection, ZKWatcher zkw, + final long timeout) throws InterruptedException, IOException { return verifyMetaRegionLocation(hConnection, zkw, timeout, RegionInfo.DEFAULT_REPLICA_ID); } /** * Verify hbase:meta is deployed and accessible. - * @param connection - * @param zkw + * + * @param connection the connection to use + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param timeout How long to wait on zk for meta address (passed through to - * @param replicaId + * @param replicaId the ID of the replica * @return True if the hbase:meta location is healthy. - * @throws InterruptedException - * @throws IOException + * @throws InterruptedException if waiting for the socket operation fails + * @throws IOException if the number of retries for getting the connection is exceeded */ - public boolean verifyMetaRegionLocation(ClusterConnection connection, - ZKWatcher zkw, final long timeout, int replicaId) - throws InterruptedException, IOException { + public boolean verifyMetaRegionLocation(ClusterConnection connection, ZKWatcher zkw, + final long timeout, int replicaId) throws InterruptedException, IOException { AdminProtos.AdminService.BlockingInterface service = null; try { service = getMetaServerConnection(connection, zkw, timeout, replicaId); @@ -299,12 +309,10 @@ public class MetaTableLocator { * Verify we can connect to hostingServer and that its carrying * regionName. * @param hostingServer Interface to the server hosting regionName - * @param address The servername that goes with the metaServer - * Interface. Used logging. + * @param address The servername that goes with the metaServer interface. + * Used logging. * @param regionName The regionname we are interested in. - * @return True if we were able to verify the region located at other side of - * the Interface. - * @throws IOException + * @return True if we were able to verify the region located at other side of the interface. */ // TODO: We should be able to get the ServerName from the AdminProtocol // rather than have to pass it in. Its made awkward by the fact that the @@ -312,8 +320,7 @@ public class MetaTableLocator { // to be fixed to go to a local method or to a cache before we can do this. private boolean verifyRegionLocation(final ClusterConnection connection, AdminService.BlockingInterface hostingServer, final ServerName address, - final byte [] regionName) - throws IOException { + final byte [] regionName) { if (hostingServer == null) { LOG.info("Passed hostingServer is null"); return false; @@ -347,34 +354,33 @@ public class MetaTableLocator { } /** - * Gets a connection to the server hosting meta, as reported by ZooKeeper, - * waiting up to the specified timeout for availability. + * Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the + * specified timeout for availability. + * *

WARNING: Does not retry. Use an {@link org.apache.hadoop.hbase.client.HTable} instead. - * @param connection - * @param zkw + * + * @param connection the connection to use + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param timeout How long to wait on meta location - * @param replicaId + * @param replicaId the ID of the replica * @return connection to server hosting meta - * @throws InterruptedException - * @throws NotAllMetaRegionsOnlineException if timed out waiting - * @throws IOException + * @throws InterruptedException if waiting for the socket operation fails + * @throws IOException if the number of retries for getting the connection is exceeded */ private AdminService.BlockingInterface getMetaServerConnection(ClusterConnection connection, - ZKWatcher zkw, long timeout, int replicaId) - throws InterruptedException, NotAllMetaRegionsOnlineException, IOException { + ZKWatcher zkw, long timeout, int replicaId) throws InterruptedException, IOException { return getCachedConnection(connection, waitMetaRegionLocation(zkw, replicaId, timeout)); } /** * @param sn ServerName to get a connection against. * @return The AdminProtocol we got when we connected to sn - * May have come from cache, may not be good, may have been setup by this - * invocation, or may be null. - * @throws IOException + * May have come from cache, may not be good, may have been setup by this invocation, or + * may be null. + * @throws IOException if the number of retries for getting the connection is exceeded */ private static AdminService.BlockingInterface getCachedConnection(ClusterConnection connection, - ServerName sn) - throws IOException { + ServerName sn) throws IOException { if (sn == null) { return null; } @@ -430,16 +436,16 @@ public class MetaTableLocator { } /** - * Sets the location of hbase:meta in ZooKeeper to the - * specified server address. - * @param zookeeper - * @param serverName - * @param replicaId - * @param state - * @throws KeeperException + * Sets the location of hbase:meta in ZooKeeper to the specified server address. + * @param zookeeper reference to the {@link ZKWatcher} which also contains configuration and + * operation + * @param serverName the name of the server + * @param replicaId the ID of the replica + * @param state the state of the region + * @throws KeeperException if a ZooKeeper operation fails */ - public static void setMetaLocation(ZKWatcher zookeeper, - ServerName serverName, int replicaId, RegionState.State state) throws KeeperException { + public static void setMetaLocation(ZKWatcher zookeeper, ServerName serverName, int replicaId, + RegionState.State state) throws KeeperException { if (serverName == null) { LOG.warn("Tried to set null ServerName in hbase:meta; skipping -- ServerName required"); return; @@ -476,13 +482,14 @@ public class MetaTableLocator { /** * Load the meta region state from the meta server ZNode. - * @param zkw - * @param replicaId + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param replicaId the ID of the replica * @return regionstate - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public static RegionState getMetaRegionState(ZKWatcher zkw, int replicaId) - throws KeeperException { + throws KeeperException { RegionState.State state = RegionState.State.OPEN; ServerName serverName = null; try { @@ -491,8 +498,8 @@ public class MetaTableLocator { try { int prefixLen = ProtobufUtil.lengthOfPBMagic(); ZooKeeperProtos.MetaRegionServer rl = - ZooKeeperProtos.MetaRegionServer.PARSER.parseFrom - (data, prefixLen, data.length - prefixLen); + ZooKeeperProtos.MetaRegionServer.PARSER.parseFrom(data, prefixLen, + data.length - prefixLen); if (rl.hasState()) { state = RegionState.State.convert(rl.getState()); } @@ -545,24 +552,28 @@ public class MetaTableLocator { } } /** - * Wait until the primary meta region is available. Get the secondary - * locations as well but don't block for those. - * @param zkw - * @param timeout - * @param conf + * Wait until the primary meta region is available. Get the secondary locations as well but don't + * block for those. + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param timeout maximum time to wait in millis + * @param conf the {@link Configuration} to use * @return ServerName or null if we timed out. - * @throws InterruptedException + * @throws InterruptedException if waiting for the socket operation fails */ - public List blockUntilAvailable(final ZKWatcher zkw, - final long timeout, Configuration conf) - throws InterruptedException { + public List blockUntilAvailable(final ZKWatcher zkw, final long timeout, + Configuration conf) throws InterruptedException { int numReplicasConfigured = 1; List servers = new ArrayList<>(); // Make the blocking call first so that we do the wait to know // the znodes are all in place or timeout. ServerName server = blockUntilAvailable(zkw, timeout); - if (server == null) return null; + + if (server == null) { + return null; + } + servers.add(server); try { @@ -583,27 +594,32 @@ public class MetaTableLocator { * @param zkw zookeeper connection to use * @param timeout maximum time to wait, in millis * @return ServerName or null if we timed out. - * @throws InterruptedException + * @throws InterruptedException if waiting for the socket operation fails */ - public ServerName blockUntilAvailable(final ZKWatcher zkw, - final long timeout) - throws InterruptedException { + public ServerName blockUntilAvailable(final ZKWatcher zkw, final long timeout) + throws InterruptedException { return blockUntilAvailable(zkw, RegionInfo.DEFAULT_REPLICA_ID, timeout); } /** * Wait until the meta region is available and is not in transition. - * @param zkw - * @param replicaId - * @param timeout + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and constants + * @param replicaId the ID of the replica + * @param timeout maximum time to wait in millis * @return ServerName or null if we timed out. - * @throws InterruptedException + * @throws InterruptedException if waiting for the socket operation fails */ - public ServerName blockUntilAvailable(final ZKWatcher zkw, int replicaId, - final long timeout) - throws InterruptedException { - if (timeout < 0) throw new IllegalArgumentException(); - if (zkw == null) throw new IllegalArgumentException(); + public ServerName blockUntilAvailable(final ZKWatcher zkw, int replicaId, final long timeout) + throws InterruptedException { + if (timeout < 0) { + throw new IllegalArgumentException(); + } + + if (zkw == null) { + throw new IllegalArgumentException(); + } + long startTime = System.currentTimeMillis(); ServerName sn = null; while (true) { diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MiniZooKeeperCluster.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MiniZooKeeperCluster.java index cb8681c826e..a4acda2c2da 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MiniZooKeeperCluster.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MiniZooKeeperCluster.java @@ -20,9 +20,9 @@ package org.apache.hadoop.hbase.zookeeper; import java.io.BufferedReader; import java.io.File; -import java.io.InterruptedIOException; import java.io.IOException; import java.io.InputStreamReader; +import java.io.InterruptedIOException; import java.io.OutputStream; import java.io.Reader; import java.net.BindException; @@ -34,9 +34,9 @@ import java.util.Random; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.server.NIOServerCnxnFactory; import org.apache.zookeeper.server.ZooKeeperServer; import org.apache.zookeeper.server.persistence.FileTxnLog; @@ -187,17 +187,18 @@ public class MiniZooKeeperCluster { } /** - * @param baseDir - * @param numZooKeeperServers - * @return ClientPort server bound to, -1 if there was a - * binding problem and we couldn't pick another port. - * @throws IOException - * @throws InterruptedException + * @param baseDir the base directory to use + * @param numZooKeeperServers the number of ZooKeeper servers + * @return ClientPort server bound to, -1 if there was a binding problem and we couldn't pick + * another port. + * @throws IOException if an operation fails during the startup + * @throws InterruptedException if the startup fails */ public int startup(File baseDir, int numZooKeeperServers) throws IOException, - InterruptedException { - if (numZooKeeperServers <= 0) + InterruptedException { + if (numZooKeeperServers <= 0) { return -1; + } setupTestEnv(); shutdown(); @@ -226,15 +227,18 @@ public class MiniZooKeeperCluster { ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTimeToUse); // Setting {min,max}SessionTimeout defaults to be the same as in Zookeeper - server.setMinSessionTimeout(configuration.getInt("hbase.zookeeper.property.minSessionTimeout", -1)); - server.setMaxSessionTimeout(configuration.getInt("hbase.zookeeper.property.maxSessionTimeout", -1)); + server.setMinSessionTimeout(configuration.getInt( + "hbase.zookeeper.property.minSessionTimeout", -1)); + server.setMaxSessionTimeout(configuration.getInt( + "hbase.zookeeper.property.maxSessionTimeout", -1)); NIOServerCnxnFactory standaloneServerFactory; while (true) { try { standaloneServerFactory = new NIOServerCnxnFactory(); standaloneServerFactory.configure( new InetSocketAddress(currentClientPort), - configuration.getInt(HConstants.ZOOKEEPER_MAX_CLIENT_CNXNS, HConstants.DEFAULT_ZOOKEPER_MAX_CLIENT_CNXNS)); + configuration.getInt(HConstants.ZOOKEEPER_MAX_CLIENT_CNXNS, + HConstants.DEFAULT_ZOOKEPER_MAX_CLIENT_CNXNS)); } catch (BindException e) { LOG.debug("Failed binding ZK Server to client port: " + currentClientPort, e); @@ -290,7 +294,7 @@ public class MiniZooKeeperCluster { } /** - * @throws IOException + * @throws IOException if waiting for the shutdown of a server fails */ public void shutdown() throws IOException { // shut down all the zk servers @@ -321,13 +325,12 @@ public class MiniZooKeeperCluster { } } - /**@return clientPort return clientPort if there is another ZK backup can run + /** + * @return clientPort return clientPort if there is another ZK backup can run * when killing the current active; return -1, if there is no backups. - * @throws IOException - * @throws InterruptedException + * @throws IOException if waiting for the shutdown of a server fails */ - public int killCurrentActiveZooKeeperServer() throws IOException, - InterruptedException { + public int killCurrentActiveZooKeeperServer() throws IOException, InterruptedException { if (!started || activeZKServerIndex < 0) { return -1; } @@ -363,14 +366,12 @@ public class MiniZooKeeperCluster { } /** - * Kill one back up ZK servers - * @throws IOException - * @throws InterruptedException + * Kill one back up ZK servers. + * + * @throws IOException if waiting for the shutdown of a server fails */ - public void killOneBackupZooKeeperServer() throws IOException, - InterruptedException { - if (!started || activeZKServerIndex < 0 || - standaloneServerFactoryList.size() <= 1) { + public void killOneBackupZooKeeperServer() throws IOException, InterruptedException { + if (!started || activeZKServerIndex < 0 || standaloneServerFactoryList.size() <= 1) { return ; } diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java index d6c11af7576..4b88a5de079 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java @@ -26,13 +26,13 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.trace.TraceUtil; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.RetryCounter; import org.apache.hadoop.hbase.util.RetryCounterFactory; -import org.apache.yetus.audience.InterfaceAudience; -import org.apache.hadoop.hbase.trace.TraceUtil; import org.apache.htrace.core.TraceScope; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.AsyncCallback; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -113,14 +113,19 @@ public class RecoverableZooKeeper { this.sessionTimeout = sessionTimeout; this.quorumServers = quorumServers; this.metrics = new ZKMetrics(); - try {checkZk();} catch (Exception x) {/* ignore */} + + try { + checkZk(); + } catch (Exception x) { + /* ignore */ + } } /** * Try to create a ZooKeeper connection. Turns any exception encountered into a * KeeperException.OperationTimeoutException so it can retried. * @return The created ZooKeeper connection object - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ protected synchronized ZooKeeper checkZk() throws KeeperException { if (this.zk == null) { @@ -161,7 +166,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); checkZk().delete(path, version); - this.metrics.registerWriteOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerWriteOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -205,7 +211,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); Stat nodeStat = checkZk().exists(path, watcher); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return nodeStat; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -239,7 +246,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); Stat nodeStat = checkZk().exists(path, watch); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return nodeStat; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -285,7 +293,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); List children = checkZk().getChildren(path, watcher); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return children; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -320,7 +329,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); List children = checkZk().getChildren(path, watch); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return children; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -355,7 +365,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); byte[] revData = checkZk().getData(path, watcher, stat); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return ZKMetadata.removeMetaData(revData); } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -390,7 +401,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); byte[] revData = checkZk().getData(path, watch, stat); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return ZKMetadata.removeMetaData(revData); } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -430,7 +442,8 @@ public class RecoverableZooKeeper { try { startTime = EnvironmentEdgeManager.currentTime(); Stat nodeStat = checkZk().setData(path, newData, version); - this.metrics.registerWriteOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerWriteOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return nodeStat; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -450,7 +463,8 @@ public class RecoverableZooKeeper { Stat stat = new Stat(); startTime = EnvironmentEdgeManager.currentTime(); byte[] revData = checkZk().getData(path, false, stat); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); if(Bytes.compareTo(revData, newData) == 0) { // the bad version is caused by previous successful setData return stat; @@ -484,7 +498,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); List nodeACL = checkZk().getACL(path, stat); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return nodeACL; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -519,7 +534,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); Stat nodeStat = checkZk().setACL(path, acls, version); - this.metrics.registerWriteOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerWriteOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return nodeStat; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -587,7 +603,8 @@ public class RecoverableZooKeeper { try { startTime = EnvironmentEdgeManager.currentTime(); String nodePath = checkZk().create(path, data, acl, createMode); - this.metrics.registerWriteOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerWriteOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return nodePath; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -599,7 +616,8 @@ public class RecoverableZooKeeper { // so we read the node and compare. startTime = EnvironmentEdgeManager.currentTime(); byte[] currentData = checkZk().getData(path, false, null); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); if (currentData != null && Bytes.compareTo(currentData, data) == 0) { // We successfully created a non-sequential node @@ -649,7 +667,8 @@ public class RecoverableZooKeeper { first = false; long startTime = EnvironmentEdgeManager.currentTime(); String nodePath = checkZk().create(newPath, data, acl, createMode); - this.metrics.registerWriteOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerWriteOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return nodePath; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -674,9 +693,10 @@ public class RecoverableZooKeeper { * Convert Iterable of {@link org.apache.zookeeper.Op} we got into the ZooKeeper.Op * instances to actually pass to multi (need to do this in order to appendMetaData). */ - private Iterable prepareZKMulti(Iterable ops) - throws UnsupportedOperationException { - if(ops == null) return null; + private Iterable prepareZKMulti(Iterable ops) throws UnsupportedOperationException { + if(ops == null) { + return null; + } List preparedOps = new LinkedList<>(); for (Op op : ops) { @@ -689,8 +709,8 @@ public class RecoverableZooKeeper { preparedOps.add(op); } else if (op.getType() == ZooDefs.OpCode.setData) { SetDataRequest setData = (SetDataRequest)op.toRequestRecord(); - preparedOps.add(Op.setData(setData.getPath(), ZKMetadata.appendMetaData(id, setData.getData()), - setData.getVersion())); + preparedOps.add(Op.setData(setData.getPath(), + ZKMetadata.appendMetaData(id, setData.getData()), setData.getVersion())); } else { throw new UnsupportedOperationException("Unexpected ZKOp type: " + op.getClass().getName()); } @@ -710,7 +730,8 @@ public class RecoverableZooKeeper { try { long startTime = EnvironmentEdgeManager.currentTime(); List opResults = checkZk().multi(multiOps); - this.metrics.registerWriteOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerWriteOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); return opResults; } catch (KeeperException e) { this.metrics.registerFailedZKCall(); @@ -741,13 +762,15 @@ public class RecoverableZooKeeper { String nodePrefix = path.substring(lastSlashIdx+1); long startTime = EnvironmentEdgeManager.currentTime(); List nodes = checkZk().getChildren(parent, false); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); List matching = filterByPrefix(nodes, nodePrefix); for (String node : matching) { String nodePath = parent + "/" + node; startTime = EnvironmentEdgeManager.currentTime(); Stat stat = checkZk().exists(nodePath, false); - this.metrics.registerReadOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerReadOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); if (stat != null) { return nodePath; } @@ -760,7 +783,9 @@ public class RecoverableZooKeeper { } public synchronized void close() throws InterruptedException { - if (zk != null) zk.close(); + if (zk != null) { + zk.close(); + } } public synchronized States getState() { @@ -778,7 +803,8 @@ public class RecoverableZooKeeper { public void sync(String path, AsyncCallback.VoidCallback cb, Object ctx) throws KeeperException { long startTime = EnvironmentEdgeManager.currentTime(); checkZk().sync(path, cb, null); - this.metrics.registerSyncOperationLatency(Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); + this.metrics.registerSyncOperationLatency( + Math.min(EnvironmentEdgeManager.currentTime() - startTime, 1)); } /** diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionNormalizerTracker.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionNormalizerTracker.java index 93545ee74fc..58d405d5576 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionNormalizerTracker.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RegionNormalizerTracker.java @@ -18,16 +18,17 @@ package org.apache.hadoop.hbase.zookeeper; +import java.io.IOException; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.exceptions.DeserializationException; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; -import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionNormalizerProtos; import org.apache.hadoop.hbase.util.Bytes; import org.apache.zookeeper.KeeperException; -import java.io.IOException; +import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionNormalizerProtos; /** * Tracks region normalizer state up in ZK @@ -35,8 +36,7 @@ import java.io.IOException; public class RegionNormalizerTracker extends ZKNodeTracker { private static final Log LOG = LogFactory.getLog(RegionNormalizerTracker.class); - public RegionNormalizerTracker(ZKWatcher watcher, - Abortable abortable) { + public RegionNormalizerTracker(ZKWatcher watcher, Abortable abortable) { super(watcher, watcher.znodePaths.regionNormalizerZNode, abortable); } @@ -59,7 +59,7 @@ public class RegionNormalizerTracker extends ZKNodeTracker { /** * Set region normalizer on/off * @param normalizerOn whether normalizer should be on or off - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public void setNormalizerOn(boolean normalizerOn) throws KeeperException { byte [] upData = toByteArray(normalizerOn); diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAclReset.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAclReset.java index 4150f5483fa..c0f33e588b8 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAclReset.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKAclReset.java @@ -26,9 +26,9 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooKeeper; diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKClusterId.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKClusterId.java index 2f2b0364985..be2529b054f 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKClusterId.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKClusterId.java @@ -23,8 +23,8 @@ import java.util.UUID; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.ClusterId; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.exceptions.DeserializationException; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.KeeperException; /** @@ -90,7 +90,7 @@ public class ZKClusterId { * Get the UUID for the provided ZK watcher. Doesn't handle any ZK exceptions * @param zkw watcher connected to an ensemble * @return the UUID read from zookeeper - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public static UUID getUUIDForCluster(ZKWatcher zkw) throws KeeperException { String uuid = readClusterIdZNode(zkw); diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKLeaderManager.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKLeaderManager.java index 9ae3e1cba6b..25310bd50cd 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKLeaderManager.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKLeaderManager.java @@ -23,8 +23,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.Stoppable; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.KeeperException; /** diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java index 2db83eb615a..934476b43da 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java @@ -76,22 +76,26 @@ public class ZKMainServer { } /** - * @param args + * @param args the arguments to check * @return True if argument strings have a '-server' in them. */ - private static boolean hasServer(final String args[]) { + private static boolean hasServer(final String[] args) { return args.length > 0 && args[0].equals(SERVER_ARG); } /** - * @param args + * @param args the arguments to check for command-line arguments * @return True if command-line arguments were passed. */ - private static boolean hasCommandLineArguments(final String args[]) { + private static boolean hasCommandLineArguments(final String[] args) { if (hasServer(args)) { - if (args.length < 2) throw new IllegalStateException("-server param but no value"); + if (args.length < 2) { + throw new IllegalStateException("-server param but no value"); + } + return args.length > 2; } + return args.length > 0; } @@ -99,7 +103,7 @@ public class ZKMainServer { * Run the tool. * @param args Command line arguments. First arg is path to zookeepers file. */ - public static void main(String args[]) throws Exception { + public static void main(String[] args) throws Exception { String [] newArgs = args; if (!hasServer(args)) { // Add the zk ensemble from configuration if none passed on command-line. diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKNodeTracker.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKNodeTracker.java index 8ce41e3a508..2dd5df5080a 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKNodeTracker.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKNodeTracker.java @@ -53,9 +53,10 @@ public abstract class ZKNodeTracker extends ZKListener { * *

After construction, use {@link #start} to kick off tracking. * - * @param watcher - * @param node - * @param abortable + * @param watcher reference to the {@link ZKWatcher} which also contains configuration and + * constants + * @param node path of the node being tracked + * @param abortable used to abort if a fatal error occurs */ public ZKNodeTracker(ZKWatcher watcher, String node, Abortable abortable) { @@ -109,14 +110,17 @@ public abstract class ZKNodeTracker extends ZKListener { * Gets the data of the node, blocking until the node is available or the * specified timeout has elapsed. * - * @param timeout maximum time to wait for the node data to be available, - * n milliseconds. Pass 0 for no timeout. + * @param timeout maximum time to wait for the node data to be available, n milliseconds. Pass 0 + * for no timeout. * @return data of the node * @throws InterruptedException if the waiting thread is interrupted */ public synchronized byte [] blockUntilAvailable(long timeout, boolean refresh) - throws InterruptedException { - if (timeout < 0) throw new IllegalArgumentException(); + throws InterruptedException { + if (timeout < 0) { + throw new IllegalArgumentException(); + } + boolean notimeout = timeout == 0; long startTime = System.currentTimeMillis(); long remaining = timeout; @@ -137,9 +141,8 @@ public abstract class ZKNodeTracker extends ZKListener { try { nodeExistsChecked = (ZKUtil.checkExists(watcher, node) != -1); } catch (KeeperException e) { - LOG.warn( - "Got exception while trying to check existence in ZooKeeper" + - " of the node: "+node+", retrying if timeout not reached",e ); + LOG.warn("Got exception while trying to check existence in ZooKeeper" + + " of the node: " + node + ", retrying if timeout not reached", e); } // It did not exists, and now it does. @@ -188,7 +191,10 @@ public abstract class ZKNodeTracker extends ZKListener { @Override public synchronized void nodeCreated(String path) { - if (!path.equals(node)) return; + if (!path.equals(node)) { + return; + } + try { byte [] data = ZKUtil.getDataAndWatch(watcher, node); if (data != null) { diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKServerTool.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKServerTool.java index 8116c2366f2..dd71dee5b8c 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKServerTool.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKServerTool.java @@ -19,6 +19,9 @@ package org.apache.hadoop.hbase.zookeeper; +import java.util.LinkedList; +import java.util.List; + import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseInterfaceAudience; @@ -26,15 +29,15 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; import org.apache.yetus.audience.InterfaceAudience; -import java.util.LinkedList; -import java.util.List; - /** * Tool for reading ZooKeeper servers from HBase XML configuration and producing * a line-by-line list for use by bash scripts. */ @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS) -public class ZKServerTool { +public final class ZKServerTool { + private ZKServerTool() { + } + public static ServerName[] readZKNodes(Configuration conf) { List hosts = new LinkedList<>(); String quorum = conf.get(HConstants.ZOOKEEPER_QUORUM, HConstants.LOCALHOST); @@ -56,7 +59,7 @@ public class ZKServerTool { * Run the tool. * @param args Command line arguments. */ - public static void main(String args[]) { + public static void main(String[] args) { for(ServerName server: readZKNodes(HBaseConfiguration.create())) { // bin/zookeeper.sh relies on the "ZK host" string for grepping which is case sensitive. System.out.println("ZK host: " + server.getHostname()); diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKSplitLog.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKSplitLog.java index 33cc43eab1f..da45f9dc92e 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKSplitLog.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKSplitLog.java @@ -30,12 +30,16 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.yetus.audience.InterfaceAudience; /** - * Common methods and attributes used by SplitLogManager and SplitLogWorker running distributed splitting of WAL logs. + * Common methods and attributes used by SplitLogManager and SplitLogWorker running distributed + * splitting of WAL logs. */ @InterfaceAudience.Private -public class ZKSplitLog { +public final class ZKSplitLog { private static final Log LOG = LogFactory.getLog(ZKSplitLog.class); + private ZKSplitLog() { + } + /** * Gets the full path node name for the log file being split. * This method will url encode the filename. @@ -80,7 +84,9 @@ public class ZKSplitLog { } /** - * @param zkw + * Checks if the given path represents a rescan node. + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and constants * @param path the absolute path, starts with '/' * @return whether the path represents a rescan node */ diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 859ab48dbfd..a4edbb3507e 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -45,12 +45,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.AuthUtil; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.security.Superusers; -import org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; -import org.apache.hadoop.hbase.shaded.protobuf.generated.ReplicationProtos; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp.CreateAndFailSilent; @@ -59,6 +55,7 @@ import org.apache.hadoop.hbase.zookeeper.ZKUtil.ZKUtilOp.SetData; import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.util.KerberosUtil; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.AsyncCallback; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -77,6 +74,10 @@ import org.apache.zookeeper.proto.DeleteRequest; import org.apache.zookeeper.proto.SetDataRequest; import org.apache.zookeeper.server.ZooKeeperSaslServer; +import org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException; +import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.shaded.protobuf.generated.ReplicationProtos; + /** * Internal HBase utility class for ZooKeeper. * @@ -87,11 +88,14 @@ import org.apache.zookeeper.server.ZooKeeperSaslServer; * If ZK is required for the operation, the server will need to be aborted. */ @InterfaceAudience.Private -public class ZKUtil { +public final class ZKUtil { private static final Log LOG = LogFactory.getLog(ZKUtil.class); private static int zkDumpConnectionTimeOut; + private ZKUtil() { + } + /** * Creates a new connection to ZooKeeper, pulling settings and ensemble config * from the specified configuration object using methods from {@link ZKConfig}. @@ -198,13 +202,15 @@ public class ZKUtil { String userNameKey, String hostname, String loginContextProperty, String loginContextName) throws IOException { - if (!isSecureZooKeeper(conf)) + if (!isSecureZooKeeper(conf)) { return; + } // User has specified a jaas.conf, keep this one as the good one. // HBASE_OPTS="-Djava.security.auth.login.config=jaas.conf" - if (System.getProperty("java.security.auth.login.config") != null) + if (System.getProperty("java.security.auth.login.config") != null) { return; + } // No keytab specified, no auth String keytabFilename = conf.get(keytabFileKey); @@ -295,7 +301,11 @@ public class ZKUtil { KEYTAB_KERBEROS_OPTIONS.put("useTicketCache", useTicketCache ? "true" : "false"); return KEYTAB_KERBEROS_CONF; } - if (baseConfig != null) return baseConfig.getAppConfigurationEntry(appName); + + if (baseConfig != null) { + return baseConfig.getAppConfigurationEntry(appName); + } + return(null); } } @@ -454,7 +464,7 @@ public class ZKUtil { * @param zkw zookeeper reference * @param znode node to get children of and watch * @return list of znode names, null if the node doesn't exist - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public static List listChildrenAndWatchThem(ZKWatcher zkw, String znode) throws KeeperException { @@ -544,8 +554,8 @@ public class ZKUtil { try { return !zkw.getRecoverableZooKeeper().getChildren(znode, null).isEmpty(); } catch(KeeperException.NoNodeException ke) { - LOG.debug(zkw.prefix("Unable to list children of znode " + znode + " " + - "because node does not exist (not an error)")); + LOG.debug(zkw.prefix("Unable to list children of znode " + znode + + " because node does not exist (not an error)")); return false; } catch (KeeperException e) { LOG.warn(zkw.prefix("Unable to list children of znode " + znode), e); @@ -591,8 +601,8 @@ public class ZKUtil { /** * Get znode data. Does not set a watcher. - * @return ZNode data, null if the node does not exist or if there is an - * error. + * + * @return ZNode data, null if the node does not exist or if there is an error. */ public static byte [] getData(ZKWatcher zkw, String znode) throws KeeperException, InterruptedException { @@ -748,17 +758,16 @@ public class ZKUtil { * Sets no watches under any conditions. * * @param zkw zk reference - * @param znode - * @param data - * @param expectedVersion + * @param znode the path to the ZNode + * @param data the data to store in ZooKeeper + * @param expectedVersion the expected version * @throws KeeperException if unexpected zookeeper exception * @throws KeeperException.BadVersionException if version mismatch * @deprecated Unused */ @Deprecated - public static void updateExistingNodeData(ZKWatcher zkw, String znode, - byte [] data, int expectedVersion) - throws KeeperException { + public static void updateExistingNodeData(ZKWatcher zkw, String znode, byte[] data, + int expectedVersion) throws KeeperException { try { zkw.getRecoverableZooKeeper().setData(znode, data, expectedVersion); } catch(InterruptedException ie) { @@ -808,11 +817,10 @@ public class ZKUtil { * @param zkw zk reference * @param znode path of node * @param data data to set for node - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ - public static void createSetData(final ZKWatcher zkw, final String znode, - final byte [] data) - throws KeeperException { + public static void createSetData(final ZKWatcher zkw, final String znode, final byte [] data) + throws KeeperException { if (checkExists(zkw, znode) == -1) { ZKUtil.createWithParents(zkw, znode, data); } else { @@ -1025,9 +1033,8 @@ public class ZKUtil { * @return true name of the newly created znode or null * @throws KeeperException if unexpected zookeeper exception */ - public static String createNodeIfNotExistsNoWatch(ZKWatcher zkw, String znode, - byte[] data, CreateMode createMode) throws KeeperException { - + public static String createNodeIfNotExistsNoWatch(ZKWatcher zkw, String znode, byte[] data, + CreateMode createMode) throws KeeperException { String createdZNode = null; try { createdZNode = zkw.getRecoverableZooKeeper().create(znode, data, @@ -1069,7 +1076,8 @@ public class ZKUtil { throw KeeperException.create(KeeperException.Code.SYSTEMERROR, "ZK.exists returned null (i.e.: znode does not exist) for znode=" + znode); } - return stat.getVersion(); + + return stat.getVersion(); } catch (InterruptedException e) { zkw.interruptedException(e); return -1; @@ -1086,8 +1094,8 @@ public class ZKUtil { * @param zkw zk reference * @param znode path of node to create * @param data data of node to create - * @param cb - * @param ctx + * @param cb the callback to use for the creation + * @param ctx the context to use for the creation */ public static void asyncCreate(ZKWatcher zkw, String znode, byte [] data, final AsyncCallback.StringCallback cb, @@ -1232,9 +1240,10 @@ public class ZKUtil { /** * Deletes the specified node. Fails silent if the node does not exist. - * @param zkw - * @param node - * @throws KeeperException + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param node the node to delete + * @throws KeeperException if a ZooKeeper operation fails */ public static void deleteNodeFailSilent(ZKWatcher zkw, String node) throws KeeperException { @@ -1273,7 +1282,7 @@ public class ZKUtil { * Sets no watches. Throws all exceptions besides dealing with deletion of * children. * - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public static void deleteChildrenRecursively(ZKWatcher zkw, String node) throws KeeperException { @@ -1506,7 +1515,7 @@ public class ZKUtil { * ZKUtilOp representing createAndFailSilent in ZooKeeper * (attempt to create node, ignore error if already exists) */ - public static class CreateAndFailSilent extends ZKUtilOp { + public static final class CreateAndFailSilent extends ZKUtilOp { private byte [] data; private CreateAndFailSilent(String path, byte [] data) { @@ -1520,8 +1529,12 @@ public class ZKUtil { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CreateAndFailSilent)) return false; + if (this == o) { + return true; + } + if (!(o instanceof CreateAndFailSilent)) { + return false; + } CreateAndFailSilent op = (CreateAndFailSilent) o; return getPath().equals(op.getPath()) && Arrays.equals(data, op.data); @@ -1538,15 +1551,19 @@ public class ZKUtil { * ZKUtilOp representing deleteNodeFailSilent in ZooKeeper * (attempt to delete node, ignore error if node doesn't exist) */ - public static class DeleteNodeFailSilent extends ZKUtilOp { + public static final class DeleteNodeFailSilent extends ZKUtilOp { private DeleteNodeFailSilent(String path) { super(path); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DeleteNodeFailSilent)) return false; + if (this == o) { + return true; + } + if (!(o instanceof DeleteNodeFailSilent)) { + return false; + } return super.equals(o); } @@ -1560,7 +1577,7 @@ public class ZKUtil { /** * ZKUtilOp representing setData in ZooKeeper */ - public static class SetData extends ZKUtilOp { + public static final class SetData extends ZKUtilOp { private byte [] data; private SetData(String path, byte [] data) { @@ -1574,8 +1591,12 @@ public class ZKUtil { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof SetData)) return false; + if (this == o) { + return true; + } + if (!(o instanceof SetData)) { + return false; + } SetData op = (SetData) o; return getPath().equals(op.getPath()) && Arrays.equals(data, op.data); @@ -1592,9 +1613,10 @@ public class ZKUtil { /** * Convert from ZKUtilOp to ZKOp */ - private static Op toZooKeeperOp(ZKWatcher zkw, ZKUtilOp op) - throws UnsupportedOperationException { - if(op == null) return null; + private static Op toZooKeeperOp(ZKWatcher zkw, ZKUtilOp op) throws UnsupportedOperationException { + if(op == null) { + return null; + } if (op instanceof CreateAndFailSilent) { CreateAndFailSilent cafs = (CreateAndFailSilent)op; @@ -1629,14 +1651,16 @@ public class ZKUtil { * In this case, if the previous conditions hold, the commands are run sequentially, which should * result in the correct final state, but means that the operations will not run atomically. * - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public static void multiOrSequential(ZKWatcher zkw, List ops, boolean runSequentialOnMultiFailure) throws KeeperException { if (zkw.getConfiguration().get("hbase.zookeeper.useMulti") != null) { LOG.warn("hbase.zookeeper.useMulti is deprecated. Default to true always."); } - if (ops == null) return; + if (ops == null) { + return; + } List zkOps = new LinkedList<>(); for (ZKUtilOp op : ops) { @@ -1646,21 +1670,21 @@ public class ZKUtil { zkw.getRecoverableZooKeeper().multi(zkOps); } catch (KeeperException ke) { switch (ke.code()) { - case NODEEXISTS: - case NONODE: - case BADVERSION: - case NOAUTH: - // if we get an exception that could be solved by running sequentially - // (and the client asked us to), then break out and run sequentially - if (runSequentialOnMultiFailure) { - LOG.info("On call to ZK.multi, received exception: " + ke.toString() + "." - + " Attempting to run operations sequentially because" - + " runSequentialOnMultiFailure is: " + runSequentialOnMultiFailure + "."); - processSequentially(zkw, ops); - break; - } - default: - throw ke; + case NODEEXISTS: + case NONODE: + case BADVERSION: + case NOAUTH: + // if we get an exception that could be solved by running sequentially + // (and the client asked us to), then break out and run sequentially + if (runSequentialOnMultiFailure) { + LOG.info("On call to ZK.multi, received exception: " + ke.toString() + "." + + " Attempting to run operations sequentially because" + + " runSequentialOnMultiFailure is: " + runSequentialOnMultiFailure + "."); + processSequentially(zkw, ops); + break; + } + default: + throw ke; } } catch (InterruptedException ie) { zkw.interruptedException(ie); @@ -1748,14 +1772,19 @@ public class ZKUtil { /** * Appends replication znodes to the passed StringBuilder. - * @param zkw - * @param sb - * @throws KeeperException + * + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation + * @param sb the {@link StringBuilder} to append to + * @throws KeeperException if a ZooKeeper operation fails */ private static void getReplicationZnodesDump(ZKWatcher zkw, StringBuilder sb) throws KeeperException { String replicationZnode = zkw.znodePaths.replicationZNode; - if (ZKUtil.checkExists(zkw, replicationZnode) == -1) return; + + if (ZKUtil.checkExists(zkw, replicationZnode) == -1) { + return; + } + // do a ls -r on this znode sb.append("\n").append(replicationZnode).append(": "); List children = ZKUtil.listChildrenNoWatch(zkw, replicationZnode); @@ -1790,7 +1819,7 @@ public class ZKUtil { /** * Returns a string with replication znodes and position of the replication log - * @param zkw + * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @return aq string of replication znodes and log positions */ public static String getReplicationZnodesDump(ZKWatcher zkw) throws KeeperException { @@ -1858,13 +1887,16 @@ public class ZKUtil { } } - private static void appendPeerState(ZKWatcher zkw, String znodeToProcess, - StringBuilder sb) throws KeeperException, InvalidProtocolBufferException { + private static void appendPeerState(ZKWatcher zkw, String znodeToProcess, StringBuilder sb) + throws KeeperException, InvalidProtocolBufferException { String peerState = zkw.getConfiguration().get("zookeeper.znode.replication.peers.state", "peer-state"); int pblen = ProtobufUtil.lengthOfPBMagic(); for (String child : ZKUtil.listChildrenNoWatch(zkw, znodeToProcess)) { - if (!child.equals(peerState)) continue; + if (!child.equals(peerState)) { + continue; + } + String peerStateZnode = ZNodePaths.joinZNode(znodeToProcess, child); sb.append("\n").append(peerStateZnode).append(": "); byte[] peerStateData; @@ -1929,7 +1961,10 @@ public class ZKUtil { private static void logRetrievedMsg(final ZKWatcher zkw, final String znode, final byte [] data, final boolean watcherSet) { - if (!LOG.isTraceEnabled()) return; + if (!LOG.isTraceEnabled()) { + return; + } + LOG.trace(zkw.prefix("Retrieved " + ((data == null)? 0: data.length) + " byte(s) of data from znode " + znode + (watcherSet? " and set watcher; ": "; data=") + @@ -2008,7 +2043,10 @@ public class ZKUtil { * @param root name of the root directory in zk to print */ public static void logZKTree(ZKWatcher zkw, String root) { - if (!LOG.isDebugEnabled()) return; + if (!LOG.isDebugEnabled()) { + return; + } + LOG.debug("Current zk system:"); String prefix = "|-"; LOG.debug(prefix + root); @@ -2027,7 +2065,11 @@ public class ZKUtil { protected static void logZKTree(ZKWatcher zkw, String root, String prefix) throws KeeperException { List children = ZKUtil.listChildrenNoWatch(zkw, root); - if (children == null) return; + + if (children == null) { + return; + } + for (String child : children) { LOG.debug(prefix + child); String node = ZNodePaths.joinZNode(root.equals("/") ? "" : root, child); @@ -2036,7 +2078,7 @@ public class ZKUtil { } /** - * @param position + * @param position the position to serialize * @return Serialized protobuf of position with pb magic prefix prepended suitable * for use as content of an wal position in a replication queue. */ @@ -2049,7 +2091,7 @@ public class ZKUtil { /** * @param bytes - Content of a WAL position znode. * @return long - The current WAL position. - * @throws DeserializationException + * @throws DeserializationException if the WAL position cannot be parsed */ public static long parseWALPositionFrom(final byte[] bytes) throws DeserializationException { if (bytes == null) { diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java index d0b0081d712..5d48117bf1b 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java @@ -33,9 +33,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.AuthUtil; import org.apache.hadoop.hbase.ZooKeeperConnectionException; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.security.Superusers; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.yetus.audience.InterfaceAudience; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; @@ -85,8 +85,6 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { // negotiation to complete public CountDownLatch saslLatch = new CountDownLatch(1); - - private final Configuration conf; /* A pattern that matches a Kerberos name, borrowed from Hadoop's KerberosName */ @@ -95,8 +93,8 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { /** * Instantiate a ZooKeeper connection and watcher. * @param identifier string that is passed to RecoverableZookeeper to be used as - * identifier for this instance. Use null for default. - * @throws IOException + * identifier for this instance. Use null for default. + * @throws IOException if the connection to ZooKeeper fails * @throws ZooKeeperConnectionException */ public ZKWatcher(Configuration conf, String identifier, @@ -106,13 +104,13 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { /** * Instantiate a ZooKeeper connection and watcher. - * @param conf + * @param conf the configuration to use * @param identifier string that is passed to RecoverableZookeeper to be used as identifier for * this instance. Use null for default. * @param abortable Can be null if there is on error there is no host to abort: e.g. client * context. - * @param canCreateBaseZNode - * @throws IOException + * @param canCreateBaseZNode true if a base ZNode can be created + * @throws IOException if the connection to ZooKeeper fails * @throws ZooKeeperConnectionException */ public ZKWatcher(Configuration conf, String identifier, @@ -211,7 +209,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { /** * Set the znode perms recursively. This will do post-order recursion, so that baseZnode ACLs * will be set last in case the master fails in between. - * @param znode + * @param znode the ZNode to set the permissions for */ private void setZnodeAclsRecursive(String znode) throws KeeperException, InterruptedException { List children = recoverableZooKeeper.getChildren(znode, false); @@ -228,7 +226,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { * Checks whether the ACLs returned from the base znode (/hbase) is set for secure setup. * @param acls acls from zookeeper * @return whether ACLs are set for the base znode - * @throws IOException + * @throws IOException if getting the current user fails */ private boolean isBaseZnodeAclSetup(List acls) throws IOException { if (LOG.isDebugEnabled()) { @@ -355,7 +353,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { * Adds this instance's identifier as a prefix to the passed str * @param str String to amend. * @return A new string with this instance's identifier as prefix: e.g. - * if passed 'hello world', the returned string could be + * if passed 'hello world', the returned string could be */ public String prefix(final String str) { return this.toString() + " " + str; @@ -364,7 +362,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { /** * Get the znodes corresponding to the meta replicas from ZK * @return list of znodes - * @throws KeeperException + * @throws KeeperException if a ZooKeeper operation fails */ public List getMetaReplicaNodes() throws KeeperException { List childrenOfBaseNode = ZKUtil.listChildrenNoWatch(this, znodePaths.baseZNode); @@ -372,7 +370,9 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { if (childrenOfBaseNode != null) { String pattern = conf.get("zookeeper.znode.metaserver","meta-region-server"); for (String child : childrenOfBaseNode) { - if (child.startsWith(pattern)) metaReplicaNodes.add(child); + if (child.startsWith(pattern)) { + metaReplicaNodes.add(child); + } } } return metaReplicaNodes; @@ -380,7 +380,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { /** * Register the specified listener to receive ZooKeeper events. - * @param listener + * @param listener the listener to register */ public void registerListener(ZKListener listener) { listeners.add(listener); @@ -389,7 +389,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { /** * Register the specified listener to receive ZooKeeper events and add it as * the first in the list of current listeners. - * @param listener + * @param listener the listener to register */ public void registerListenerFirst(ZKListener listener) { listeners.add(0, listener); @@ -512,7 +512,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { * call, it's possible for the Abortable to catch it and try to create a new * session with ZooKeeper. This is what the client does in HCM. *

- * @param event + * @param event the connection-related event */ private void connectionEvent(WatchedEvent event) { switch(event.getState()) { @@ -571,11 +571,10 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { *

* TODO: Currently this method rethrows the exception to let the caller handle *

- * @param ke - * @throws KeeperException + * @param ke the exception to rethrow + * @throws KeeperException if a ZooKeeper operation fails */ - public void keeperException(KeeperException ke) - throws KeeperException { + public void keeperException(KeeperException ke) throws KeeperException { LOG.error(prefix("Received unexpected KeeperException, re-throwing exception"), ke); throw ke; } @@ -623,8 +622,11 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { @Override public void abort(String why, Throwable e) { - if (this.abortable != null) this.abortable.abort(why, e); - else this.aborted = true; + if (this.abortable != null) { + this.abortable.abort(why, e); + } else { + this.aborted = true; + } } @Override