org.apache.hadoop.hbase.zookeeper.ZKWatcher Java Examples

The following examples show how to use org.apache.hadoop.hbase.zookeeper.ZKWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMetaTableLocator.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws IOException {
  this.abortable = new Abortable() {
    @Override
    public void abort(String why, Throwable e) {
      LOG.info(why, e);
    }

    @Override
    public boolean isAborted() {
      return false;
    }
  };
  this.watcher =
    new ZKWatcher(UTIL.getConfiguration(), this.getClass().getSimpleName(), this.abortable, true);
}
 
Example #2
Source File: TestAdmin4.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecommissionAndStopRegionServers() throws Exception {
  List<ServerName> decommissionedRegionServers = ADMIN.listDecommissionedRegionServers();
  assertTrue(decommissionedRegionServers.isEmpty());

  ArrayList<ServerName> clusterRegionServers =
    new ArrayList<>(ADMIN.getRegionServers(true));

  List<ServerName> serversToDecommission = new ArrayList<ServerName>();
  serversToDecommission.add(clusterRegionServers.get(0));

  // Decommission
  ADMIN.decommissionRegionServers(serversToDecommission, true);
  assertEquals(1, ADMIN.listDecommissionedRegionServers().size());

  // Stop decommissioned region server and verify it is removed from draining znode
  ServerName serverName = serversToDecommission.get(0);
  ADMIN.stopRegionServer(serverName.getHostname()+":"+serverName.getPort());
  assertNotEquals("RS not removed from decommissioned list", -1,
    TEST_UTIL.waitFor(10000, () -> ADMIN.listDecommissionedRegionServers().isEmpty()));
  ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
  assertEquals(-1, ZKUtil.checkExists(zkw,
    ZNodePaths.joinZNode(zkw.getZNodePaths().drainingZNode, serverName.getServerName())));
}
 
Example #3
Source File: TestMetaWithReplicasBasic.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testZookeeperNodesForReplicas() throws Exception {
  // Checks all the znodes exist when meta's replicas are enabled
  ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
  Configuration conf = TEST_UTIL.getConfiguration();
  String baseZNode =
    conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
  String primaryMetaZnode =
    ZNodePaths.joinZNode(baseZNode, conf.get("zookeeper.znode.metaserver", "meta-region-server"));
  // check that the data in the znode is parseable (this would also mean the znode exists)
  byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
  ProtobufUtil.toServerName(data);
  for (int i = 1; i < 3; i++) {
    String secZnode = ZNodePaths.joinZNode(baseZNode,
      conf.get("zookeeper.znode.metaserver", "meta-region-server") + "-" + i);
    String str = zkw.getZNodePaths().getZNodeForReplica(i);
    assertTrue(str.equals(secZnode));
    // check that the data in the znode is parseable (this would also mean the znode exists)
    data = ZKUtil.getData(zkw, secZnode);
    ProtobufUtil.toServerName(data);
  }
}
 
Example #4
Source File: IntegrationTestZKAndFSPermissions.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void testZNodeACLs() throws IOException, KeeperException, InterruptedException {

    ZKWatcher watcher = new ZKWatcher(conf, "IntegrationTestZnodeACLs", null);
    RecoverableZooKeeper zk = ZKUtil.connect(this.conf, watcher);

    String baseZNode = watcher.getZNodePaths().baseZNode;

    LOG.info("");
    LOG.info("***********************************************************************************");
    LOG.info("Checking ZK permissions, root znode: " + baseZNode);
    LOG.info("***********************************************************************************");
    LOG.info("");

    checkZnodePermsRecursive(watcher, zk, baseZNode);

    LOG.info("Checking ZK permissions: SUCCESS");
  }
 
Example #5
Source File: IntegrationTestMetaReplicas.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // Set up the integration test util
  if (util == null) {
    util = new IntegrationTestingUtility();
  }
  util.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3);
  util.getConfiguration().setInt(
      StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 1000);
  // Make sure there are three servers.
  util.initializeCluster(3);
  ZKWatcher zkw = util.getZooKeeperWatcher();
  Configuration conf = util.getConfiguration();
  String baseZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
      HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
  String primaryMetaZnode = ZNodePaths.joinZNode(baseZNode,
      conf.get("zookeeper.znode.metaserver", "meta-region-server"));
  // check that the data in the znode is parseable (this would also mean the znode exists)
  byte[] data = ZKUtil.getData(zkw, primaryMetaZnode);
  ProtobufUtil.toServerName(data);
  waitUntilZnodeAvailable(1);
  waitUntilZnodeAvailable(2);
}
 
Example #6
Source File: RegionServerFlushTableProcedureManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize this region server flush procedure manager
 * Uses a zookeeper based member controller.
 * @param rss region server
 * @throws KeeperException if the zookeeper cannot be reached
 */
@Override
public void initialize(RegionServerServices rss) throws KeeperException {
  this.rss = rss;
  ZKWatcher zkw = rss.getZooKeeper();
  this.memberRpcs = new ZKProcedureMemberRpcs(zkw,
    MasterFlushTableProcedureManager.FLUSH_TABLE_PROCEDURE_SIGNATURE);

  Configuration conf = rss.getConfiguration();
  long keepAlive = conf.getLong(FLUSH_TIMEOUT_MILLIS_KEY, FLUSH_TIMEOUT_MILLIS_DEFAULT);
  int opThreads = conf.getInt(FLUSH_REQUEST_THREADS_KEY, FLUSH_REQUEST_THREADS_DEFAULT);

  // create the actual flush table procedure member
  ThreadPoolExecutor pool = ProcedureMember.defaultPool(rss.getServerName().toString(),
    opThreads, keepAlive);
  this.member = new ProcedureMember(memberRpcs, pool, new FlushTableSubprocedureBuilder());
}
 
Example #7
Source File: ZKProcedureUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Top-level watcher/controller for procedures across the cluster.
 * <p>
 * On instantiation, this ensures the procedure znodes exist.  This however requires the passed in
 *  watcher has been started.
 * @param watcher watcher for the cluster ZK. Owned by <tt>this</tt> and closed via
 *          {@link #close()}
 * @param procDescription name of the znode describing the procedure to run
 * @throws KeeperException when the procedure znodes cannot be created
 */
public ZKProcedureUtil(ZKWatcher watcher, String procDescription)
    throws KeeperException {
  super(watcher);
  // make sure we are listening for events
  watcher.registerListener(this);
  // setup paths for the zknodes used in procedures
  this.baseZNode = ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, procDescription);
  acquiredZnode = ZNodePaths.joinZNode(baseZNode, ACQUIRED_BARRIER_ZNODE_DEFAULT);
  reachedZnode = ZNodePaths.joinZNode(baseZNode, REACHED_BARRIER_ZNODE_DEFAULT);
  abortZnode = ZNodePaths.joinZNode(baseZNode, ABORT_ZNODE_DEFAULT);

  // first make sure all the ZK nodes exist
  // make sure all the parents exist (sometimes not the case in tests)
  ZKUtil.createWithParents(watcher, acquiredZnode);
  // regular create because all the parents exist
  ZKUtil.createAndFailSilent(watcher, reachedZnode);
  ZKUtil.createAndFailSilent(watcher, abortZnode);
}
 
Example #8
Source File: TestZKPermissionWatcher.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  // setup configuration
  Configuration conf = UTIL.getConfiguration();
  SecureTestUtil.enableSecurity(conf);

  // start minicluster
  UTIL.startMiniCluster();
  AUTH_A = new AuthManager(conf);
  AUTH_B = new AuthManager(conf);
  WATCHER_A = new ZKPermissionWatcher(
      new ZKWatcher(conf, "TestZKPermissionsWatcher_1", ABORTABLE), AUTH_A, conf);
  WATCHER_B = new ZKPermissionWatcher(
      new ZKWatcher(conf, "TestZKPermissionsWatcher_2", ABORTABLE), AUTH_B, conf);
  WATCHER_A.start();
  WATCHER_B.start();
}
 
Example #9
Source File: RegionServerSnapshotManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create a default snapshot handler - uses a zookeeper based member controller.
 * @param rss region server running the handler
 * @throws KeeperException if the zookeeper cluster cannot be reached
 */
@Override
public void initialize(RegionServerServices rss) throws KeeperException {
  this.rss = rss;
  ZKWatcher zkw = rss.getZooKeeper();
  this.memberRpcs = new ZKProcedureMemberRpcs(zkw,
      SnapshotManager.ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION);

  // read in the snapshot request configuration properties
  Configuration conf = rss.getConfiguration();
  long keepAlive = conf.getLong(SNAPSHOT_TIMEOUT_MILLIS_KEY, SNAPSHOT_TIMEOUT_MILLIS_DEFAULT);
  int opThreads = conf.getInt(SNAPSHOT_REQUEST_THREADS_KEY, SNAPSHOT_REQUEST_THREADS_DEFAULT);

  // create the actual snapshot procedure member
  ThreadPoolExecutor pool = ProcedureMember.defaultPool(rss.getServerName().toString(),
    opThreads, keepAlive);
  this.member = new ProcedureMember(memberRpcs, pool, new SnapshotSubprocedureBuilder());
}
 
Example #10
Source File: TestSplitLogWorker.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  TEST_UTIL.startMiniZKCluster();
  Configuration conf = TEST_UTIL.getConfiguration();
  zkw = new ZKWatcher(TEST_UTIL.getConfiguration(),
      "split-log-worker-tests", null);
  ds = new DummyServer(zkw, conf);
  ZKUtil.deleteChildrenRecursively(zkw, zkw.getZNodePaths().baseZNode);
  ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().baseZNode);
  assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode), not(is(-1)));
  LOG.debug(zkw.getZNodePaths().baseZNode + " created");
  ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().splitLogZNode);
  assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().splitLogZNode), not(is(-1)));

  LOG.debug(zkw.getZNodePaths().splitLogZNode + " created");
  ZKUtil.createAndFailSilent(zkw, zkw.getZNodePaths().rsZNode);
  assertThat(ZKUtil.checkExists(zkw, zkw.getZNodePaths().rsZNode), not(is(-1)));

  SplitLogCounters.resetCounters();
  executorService = new ExecutorService("TestSplitLogWorker");
  executorService.startExecutorService(ExecutorType.RS_LOG_REPLAY_OPS, 10);
}
 
Example #11
Source File: TestZKProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static ZKWatcher newZooKeeperWatcher() throws IOException {
  return new ZKWatcher(UTIL.getConfiguration(), "testing utility", new Abortable() {
    @Override
    public void abort(String why, Throwable e) {
      throw new RuntimeException(
          "Unexpected abort in distributed three phase commit test:" + why, e);
    }

    @Override
    public boolean isAborted() {
      return false;
    }
  });
}
 
Example #12
Source File: TableHFileArchiveTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
private TableHFileArchiveTracker(ZKWatcher watcher, HFileArchiveTableMonitor monitor) {
  super(watcher);
  watcher.registerListener(this);
  this.monitor = monitor;
  this.archiveHFileZNode = ZKTableArchiveClient.getArchiveZNode(watcher.getConfiguration(),
    watcher);
}
 
Example #13
Source File: TestRegionServerHostname.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegionServerHostname() throws Exception {
  Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
  while (netInterfaceList.hasMoreElements()) {
    NetworkInterface ni = netInterfaceList.nextElement();
    Enumeration<InetAddress> addrList = ni.getInetAddresses();
    // iterate through host addresses and use each as hostname
    while (addrList.hasMoreElements()) {
      InetAddress addr = addrList.nextElement();
      if (addr.isLoopbackAddress() || addr.isLinkLocalAddress() || addr.isMulticastAddress() ||
          !addr.isSiteLocalAddress()) {
        continue;
      }
      String hostName = addr.getHostName();
      LOG.info("Found " + hostName + " on " + ni + ", addr=" + addr);

      TEST_UTIL.getConfiguration().set(DNS.MASTER_HOSTNAME_KEY, hostName);
      TEST_UTIL.getConfiguration().set(DNS.RS_HOSTNAME_KEY, hostName);
      StartMiniClusterOption option = StartMiniClusterOption.builder()
          .numMasters(NUM_MASTERS).numRegionServers(NUM_RS).numDataNodes(NUM_RS).build();
      TEST_UTIL.startMiniCluster(option);
      try {
        ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
        List<String> servers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode);
        // there would be NUM_RS+1 children - one for the master
        assertTrue(servers.size() ==
          NUM_RS + (LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration())? 1: 0));
        for (String server : servers) {
          assertTrue("From zookeeper: " + server + " hostname: " + hostName,
            server.startsWith(hostName.toLowerCase(Locale.ROOT)+","));
        }
        zkw.close();
      } finally {
        TEST_UTIL.shutdownMiniCluster();
      }
    }
  }
}
 
Example #14
Source File: SpliceZooKeeperManager.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public void initialize(SConfiguration configuration){
    try{
        ZKWatcher watcher=new ZKWatcher((Configuration) configuration.getConfigSource().unwrapDelegate(), "spliceconnection", this);
        rzk=watcher.getRecoverableZooKeeper();
    }catch(Exception e){
        LOG.error(e);
        throw new RuntimeException(e);
    }
}
 
Example #15
Source File: SimpleRSProcedureManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(RegionServerServices rss) throws KeeperException {
  this.rss = rss;
  ZKWatcher zkw = rss.getZooKeeper();
  this.memberRpcs = new ZKProcedureMemberRpcs(zkw, getProcedureSignature());

  ThreadPoolExecutor pool =
      ProcedureMember.defaultPool(rss.getServerName().toString(), 1);
  this.member = new ProcedureMember(memberRpcs, pool, new SimleSubprocedureBuilder());
  LOG.info("Initialized: " + rss.getServerName().toString());
}
 
Example #16
Source File: ZKDataMigrator.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Method for table states migration.
 * Used when upgrading from pre-2.0 to 2.0
 * Reading state from zk, applying them to internal state
 * and delete.
 * Used by master to clean migration from zk based states to
 * table descriptor based states.
 * @deprecated Since 2.0.0. To be removed in hbase-3.0.0.
 */
@Deprecated
public static Map<TableName, TableState.State> queryForTableStates(ZKWatcher zkw)
    throws KeeperException, InterruptedException {
  Map<TableName, TableState.State> rv = new HashMap<>();
  List<String> children = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().tableZNode);
  if (children == null)
    return rv;
  for (String child: children) {
    TableName tableName = TableName.valueOf(child);
    ZooKeeperProtos.DeprecatedTableState.State state = getTableState(zkw, tableName);
    TableState.State newState = TableState.State.ENABLED;
    if (state != null) {
      switch (state) {
      case ENABLED:
        newState = TableState.State.ENABLED;
        break;
      case DISABLED:
        newState = TableState.State.DISABLED;
        break;
      case DISABLING:
        newState = TableState.State.DISABLING;
        break;
      case ENABLING:
        newState = TableState.State.ENABLING;
        break;
      default:
      }
    }
    rv.put(tableName, newState);
  }
  return rv;
}
 
Example #17
Source File: MockRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @param sn Name of this mock regionserver
 * @throws IOException
 * @throws org.apache.hadoop.hbase.ZooKeeperConnectionException
 */
MockRegionServer(final Configuration conf, final ServerName sn)
throws ZooKeeperConnectionException, IOException {
  this.sn = sn;
  this.conf = conf;
  this.zkw = new ZKWatcher(conf, sn.toString(), this, true);
}
 
Example #18
Source File: ReplicationMonitorChore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setNewMasterTimestamp(String newMasterClusterKey,
                                   long ts) throws IOException, KeeperException, InterruptedException{
    Configuration conf = ReplicationUtils.createConfiguration(newMasterClusterKey);

    try (ZKWatcher masterZkw = new ZKWatcher(conf, "replication monitor", null, false)) {
        RecoverableZooKeeper rzk = masterZkw.getRecoverableZooKeeper();
        String rootNode = HConfiguration.getConfiguration().getSpliceRootPath();
        String node = rootNode + HConfiguration.MAX_RESERVED_TIMESTAMP_PATH;
        rzk.setData(node, Bytes.toBytes(ts), -1);
    }
}
 
Example #19
Source File: TestMasterReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the replication scenario 0 -> 0. By default
 * {@link BaseReplicationEndpoint#canReplicateToSameCluster()} returns false, so the
 * ReplicationSource should terminate, and no further logs should get enqueued
 */
@Test
public void testLoopedReplication() throws Exception {
  LOG.info("testLoopedReplication");
  startMiniClusters(1);
  createTableOnClusters(table);
  addPeer("1", 0, 0);
  Thread.sleep(SLEEP_TIME);

  // wait for source to terminate
  final ServerName rsName = utilities[0].getHBaseCluster().getRegionServer(0).getServerName();
  Waiter.waitFor(baseConfiguration, 10000, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      ClusterMetrics clusterStatus = utilities[0].getAdmin()
          .getClusterMetrics(EnumSet.of(ClusterMetrics.Option.LIVE_SERVERS));
      ServerMetrics serverLoad = clusterStatus.getLiveServerMetrics().get(rsName);
      List<ReplicationLoadSource> replicationLoadSourceList =
          serverLoad.getReplicationLoadSourceList();
      return replicationLoadSourceList.isEmpty();
    }
  });

  Table[] htables = getHTablesOnClusters(tableName);
  putAndWait(row, famName, htables[0], htables[0]);
  rollWALAndWait(utilities[0], table.getTableName(), row);
  ZKWatcher zkw = utilities[0].getZooKeeperWatcher();
  String queuesZnode = ZNodePaths.joinZNode(zkw.getZNodePaths().baseZNode,
    ZNodePaths.joinZNode("replication", "rs"));
  List<String> listChildrenNoWatch =
      ZKUtil.listChildrenNoWatch(zkw, ZNodePaths.joinZNode(queuesZnode, rsName.toString()));
  assertEquals(0, listChildrenNoWatch.size());
}
 
Example #20
Source File: ReplicationMonitorChore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private void init() throws SQLException, IOException, KeeperException, InterruptedException {
    conf = ReplicationUtils.createConfiguration(replicationMonitorQuorum);
    zkWatcher = new ZKWatcher(conf, "replication monitor", null, false);
    rzk = zkWatcher.getRecoverableZooKeeper();
    if (thisCluster != null) {
        SpliceLogUtils.info(LOG, "register as a replication monitor");
        String path = replicationMonitorPath + "/monitors/" + thisCluster;
        try {
            if (rzk.exists(path, false) != null) {
                SpliceLogUtils.info(LOG, "remove znode %s created by previous monitor instance", path);
                ZkUtils.safeDelete(path, -1, rzk);
            }
        }
        catch (KeeperException e) {
            SpliceLogUtils.warn(LOG, "Encountered an error when trying to delete znode %s", path, e);
        }
        ZkUtils.recursiveSafeCreate(path, new byte[]{}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, rzk);
        if (rzk.exists(path, false) != null) {
            SpliceLogUtils.info(LOG, "created znode %s", path);
        }
        else {
            SpliceLogUtils.info(LOG, "znode %s Not created?!", path);
        }
        determineLeadership();
    }
    else {
        SpliceLogUtils.info(LOG, "thisCluster = null");
    }
}
 
Example #21
Source File: ReplicationMonitorChore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean isMasterReachable() {
    String masterClusterKey = getClusterKey(masterCluster);
    Configuration conf = ReplicationUtils.createConfiguration(masterClusterKey);

    try (ZKWatcher masterZkw = new ZKWatcher(conf, "replication monitor", null, false)) {
        String[] s = masterClusterKey.split(":");
        RecoverableZooKeeper rzk = masterZkw.getRecoverableZooKeeper();
        List<String> children = rzk.getChildren(s[2], false);
        return true;
    }
    catch (Exception e) {
        return false;
    }
}
 
Example #22
Source File: IntegrationTestZKAndFSPermissions.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void assertZnodePerms(RecoverableZooKeeper zk, String znode,
    boolean expectedWorldReadable) throws KeeperException, InterruptedException {
  Stat stat = new Stat();
  List<ACL> acls;
  try {
    acls = zk.getZooKeeper().getACL(znode, stat);
  } catch (NoNodeException ex) {
    LOG.debug("Caught exception for missing znode", ex);
    // the znode is deleted. Probably it was a temporary znode (like RIT).
    return;
  }
  String[] superUsers = superUser == null ? null : superUser.split(",");

  LOG.info("Checking ACLs for znode znode:" + znode + " acls:" + acls);

  for (ACL acl : acls) {
    int perms = acl.getPerms();
    Id id = acl.getId();
    // We should only set at most 3 possible ACL for 3 Ids. One for everyone, one for superuser
    // and one for the hbase user
    if (Ids.ANYONE_ID_UNSAFE.equals(id)) {
      // everyone should be set only if we are expecting this znode to be world readable
      assertTrue(expectedWorldReadable);
      // assert that anyone can only read
      assertEquals(perms, Perms.READ);
    } else if (superUsers != null && ZKWatcher.isSuperUserId(superUsers, id)) {
      // assert that super user has all the permissions
      assertEquals(perms, Perms.ALL);
    } else if (new Id("sasl", masterPrincipal).equals(id)) {
      // hbase.master.kerberos.principal?
      assertEquals(perms, Perms.ALL);
    } else {
      fail("An ACL is found which is not expected for the znode:" + znode + " , ACL:" + acl);
    }
  }
}
 
Example #23
Source File: TestLogsCleaner.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * When zk is working both files should be returned
 * @throws Exception from ZK watcher
 */
@Test
public void testZooKeeperNormal() throws Exception {
  ReplicationLogCleaner cleaner = new ReplicationLogCleaner();

  // Subtract 1000 from current time so modtime is for sure older
  // than 'now'.
  long modTime = System.currentTimeMillis() - 1000;
  List<FileStatus> dummyFiles = Arrays.asList(
      new FileStatus(100, false, 3, 100, modTime, new Path("log1")),
      new FileStatus(100, false, 3, 100, modTime, new Path("log2"))
  );

  ZKWatcher zkw = new ZKWatcher(conf, "testZooKeeperAbort-normal", null);
  try {
    cleaner.setConf(conf, zkw);
    cleaner.preClean();
    Iterable<FileStatus> filesToDelete = cleaner.getDeletableFiles(dummyFiles);
    Iterator<FileStatus> iter = filesToDelete.iterator();
    assertTrue(iter.hasNext());
    assertEquals(new Path("log1"), iter.next().getPath());
    assertTrue(iter.hasNext());
    assertEquals(new Path("log2"), iter.next().getPath());
    assertFalse(iter.hasNext());
  } finally {
    zkw.close();
  }
}
 
Example #24
Source File: ZKReplicationQueueStorage.java    From hbase with Apache License 2.0 5 votes vote down vote up
public ZKReplicationQueueStorage(ZKWatcher zookeeper, Configuration conf) {
  super(zookeeper, conf);

  String queuesZNodeName = conf.get("zookeeper.znode.replication.rs", "rs");
  String hfileRefsZNodeName = conf.get(ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_KEY,
    ZOOKEEPER_ZNODE_REPLICATION_HFILE_REFS_DEFAULT);
  this.queuesZNode = ZNodePaths.joinZNode(replicationZNode, queuesZNodeName);
  this.hfileRefsZNode = ZNodePaths.joinZNode(replicationZNode, hfileRefsZNodeName);
  this.regionsZNode = ZNodePaths.joinZNode(replicationZNode, conf
      .get(ZOOKEEPER_ZNODE_REPLICATION_REGIONS_KEY, ZOOKEEPER_ZNODE_REPLICATION_REGIONS_DEFAULT));
}
 
Example #25
Source File: TestZKProcedureControllers.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Verify that the prepare, commit and abort nodes for the operation are removed from zookeeper
 */
private void verifyZooKeeperClean(String operationName, ZKWatcher watcher,
    ZKProcedureUtil controller) throws Exception {
  String prepare = ZKProcedureUtil.getAcquireBarrierNode(controller, operationName);
  String commit = ZKProcedureUtil.getReachedBarrierNode(controller, operationName);
  String abort = ZKProcedureUtil.getAbortNode(controller, operationName);
  assertEquals("Didn't delete prepare node", -1, ZKUtil.checkExists(watcher, prepare));
  assertEquals("Didn't delete commit node", -1, ZKUtil.checkExists(watcher, commit));
  assertEquals("Didn't delete abort node", -1, ZKUtil.checkExists(watcher, abort));
}
 
Example #26
Source File: HFileArchiveManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
public HFileArchiveManager(Connection connection, Configuration conf)
    throws ZooKeeperConnectionException, IOException {
  this.zooKeeper = new ZKWatcher(conf, "hfileArchiveManager-on-" + connection.toString(),
      connection);
  this.archiveZnode = ZKTableArchiveClient.getArchiveZNode(this.zooKeeper.getConfiguration(),
    this.zooKeeper);
}
 
Example #27
Source File: RegionServerTracker.java    From hbase with Apache License 2.0 5 votes vote down vote up
public RegionServerTracker(ZKWatcher watcher, MasterServices server,
    ServerManager serverManager) {
  super(watcher);
  this.server = server;
  this.serverManager = serverManager;
  this.executor = Executors.newSingleThreadExecutor(
    new ThreadFactoryBuilder().setDaemon(true).setNameFormat("RegionServerTracker-%d").build());
}
 
Example #28
Source File: TestRSStatusServlet.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Before
public void setupBasicMocks() throws IOException, ServiceException {
  rs = Mockito.mock(HRegionServer.class);
  rpcServices = Mockito.mock(RSRpcServices.class);
  rpcServer = Mockito.mock(RpcServerInterface.class);
  Mockito.doReturn(HBaseConfiguration.create()).when(rs).getConfiguration();
  Mockito.doReturn(rpcServices).when(rs).getRSRpcServices();
  Mockito.doReturn(rpcServer).when(rs).getRpcServer();
  Mockito.doReturn(fakeResponse).when(rpcServices).getServerInfo(Mockito.any(), Mockito.any());
  // Fake ZKW
  ZKWatcher zkw = Mockito.mock(ZKWatcher.class);
  Mockito.doReturn("fakequorum").when(zkw).getQuorum();
  Mockito.doReturn(zkw).when(rs).getZooKeeper();

  // Fake BlockCache
  LOG.warn("The " + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " is set to 0");
  Mockito.doReturn(Optional.empty()).when(rs).getBlockCache();

  // Fake MasterAddressTracker
  MasterAddressTracker mat = Mockito.mock(MasterAddressTracker.class);
  Mockito.doReturn(fakeMasterAddress).when(mat).getMasterAddress();
  Mockito.doReturn(mat).when(rs).getMasterAddressTracker();

  MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class);
  Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper();
  Mockito.doReturn(rms).when(rs).getMetrics();

  MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class);
  Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper();
  Mockito.doReturn(ms).when(rpcServer).getMetrics();
  Mockito.doReturn(ByteBuffAllocator.HEAP).when(rpcServer).getByteBuffAllocator();
}
 
Example #29
Source File: ReplicationMonitorChore.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private long getMasterTimestamp() throws IOException, KeeperException, InterruptedException {
    String masterClusterKey = getClusterKey(masterCluster);
    Configuration conf = ReplicationUtils.createConfiguration(masterClusterKey);

    try (ZKWatcher masterZkw = new ZKWatcher(conf, "replication monitor", null, false)) {
        RecoverableZooKeeper rzk = masterZkw.getRecoverableZooKeeper();
        String rootNode = HConfiguration.getConfiguration().getSpliceRootPath();
        String node = rootNode + HConfiguration.MAX_RESERVED_TIMESTAMP_PATH;
        byte[] data = rzk.getData(node, false, null);
        long ts = Bytes.toLong(data);
        return ts;
    }
}
 
Example #30
Source File: AssignmentManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void start() throws IOException, KeeperException {
  if (!running.compareAndSet(false, true)) {
    return;
  }

  LOG.trace("Starting assignment manager");

  // Start the Assignment Thread
  startAssignmentThread();

  // load meta region state
  ZKWatcher zkw = master.getZooKeeper();
  // it could be null in some tests
  if (zkw != null) {
    // here we are still in the early steps of active master startup. There is only one thread(us)
    // can access AssignmentManager and create region node, so here we do not need to lock the
    // region node.
    RegionState regionState = MetaTableLocator.getMetaRegionState(zkw);
    RegionStateNode regionNode =
      regionStates.getOrCreateRegionStateNode(RegionInfoBuilder.FIRST_META_REGIONINFO);
    regionNode.setRegionLocation(regionState.getServerName());
    regionNode.setState(regionState.getState());
    if (regionNode.getProcedure() != null) {
      regionNode.getProcedure().stateLoaded(this, regionNode);
    }
    if (regionState.getServerName() != null) {
      regionStates.addRegionToServer(regionNode);
    }
    setMetaAssigned(regionState.getRegion(), regionState.getState() == State.OPEN);
  }
}