gpt4 book ai didi

org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 01:20:49 26 4
gpt4 key购买 nike

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher类的一些代码示例,展示了ZooKeeperWatcher类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperWatcher类的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher
类名称:ZooKeeperWatcher

ZooKeeperWatcher介绍

[英]Acts as the single ZooKeeper Watcher. One instance of this is instantiated for each Master, RegionServer, and client process.

This is the only class that implements Watcher. Other internal classes which need to be notified of ZooKeeper events must register with the local instance of this watcher via #registerListener.

This class also holds and manages the connection to ZooKeeper. Code to deal with connection related events and exceptions are handled here.
[中]充当单一的动物园管理员和观察者。为每个主进程、RegionServer和客户端进程实例化一个实例。
这是唯一实现Watcher的类。其他需要通知ZooKeeper事件的内部类必须通过#registerListener向该观察者的本地实例注册。
这个类还保存和管理与ZooKeeper的连接。处理连接相关事件和异常的代码在这里处理。

代码示例

代码示例来源:origin: apache/kylin

private String getHBaseMasterUrl() throws IOException, KeeperException {
  String host = conf.get("hbase.master.info.bindAddress");
  if (host.equals("0.0.0.0")) {
    host = MasterAddressTracker.getMasterAddress(new ZooKeeperWatcher(conf, null, null)).getHostname();
  }
  String port = conf.get("hbase.master.info.port");
  return "http://" + host + ":" + port + "/";
}

代码示例来源:origin: line/armeria

/**
   * Ensure Armeria's dependencies do not cause a trouble with hbase-shaded-client.
   *
   * @see <a href="https://issues.apache.org/jira/browse/HBASE-14963">HBASE-14963</a>
   */
  @Test(expected = NotAllMetaRegionsOnlineException.class)
  public void testGuavaConflict() throws Exception {
    // Make sure Armeria is available in the class path.
    assertThat(Version.identify(Server.class.getClassLoader())).isNotNull();
    // Make sure newer Guava is available in the class path.
    assertThat(Stopwatch.class.getDeclaredConstructor().getModifiers()).is(new Condition<>(
        value -> !Modifier.isPublic(value),
        "Recent Guava Stopwatch should have non-public default constructor."));

    final MetaTableLocator locator = new MetaTableLocator();
    final ZooKeeperWatcher zkw = mock(ZooKeeperWatcher.class);
    final RecoverableZooKeeper zk = mock(RecoverableZooKeeper.class);
    when(zkw.getRecoverableZooKeeper()).thenReturn(zk);
    when(zk.exists(any(), any())).thenReturn(new Stat(0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0));

    locator.waitMetaRegionLocation(zkw, 100);
  }
}

代码示例来源:origin: co.cask.hbase/hbase

this.conf = new Configuration(conf);
this.conf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f);
 conf.get("hbase.master.dns.interface", "default"),
 conf.get("hbase.master.dns.nameserver", "default")));
int port = conf.getInt(HConstants.MASTER_PORT, HConstants.DEFAULT_MASTER_PORT);
this.serverName = new ServerName(this.isa.getHostName(),
 this.isa.getPort(), System.currentTimeMillis());
this.rsFatals = new MemoryBoundedLogMessageBuffer(
ZKUtil.loginClient(this.conf, "hbase.zookeeper.client.keytab.file",
 "hbase.zookeeper.client.kerberos.principal", this.isa.getHostName());
setName(MASTER + "-" + this.serverName.toString());
if (this.conf.get("mapred.task.id") == null) {
 this.conf.set("mapred.task.id", "hb_m_" + this.serverName.toString());
this.zooKeeper = new ZooKeeperWatcher(conf, MASTER + ":" + isa.getPort(), this, true);
this.rpcServer.startThreads();
this.metrics = new MasterMetrics(getServerName().toString());

代码示例来源:origin: harbby/presto-connectors

FSUtils.setupShortCircuitRead(this.conf);
this.conf.setBoolean(HConstants.USE_META_REPLICAS, false);
this.numRetries = this.conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
  HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
this.threadWakeFrequency = conf.getInt(HConstants.THREAD_WAKE_FREQUENCY, 10 * 1000);
this.msgInterval = conf.getInt("hbase.regionserver.msginterval", 3 * 1000);
serverName = ServerName.valueOf(hostName, rpcServices.isa.getPort(), startcode);
ZKUtil.loginClient(this.conf, HConstants.ZK_CLIENT_KEYTAB_FILE,
 HConstants.ZK_CLIENT_KERBEROS_PRINCIPAL, hostName);
 this.conf, this.fs, this.rootDir, !canUpdateTableDescriptor(), false);
service = new ExecutorService(getServerName().toShortString());
spanReceiverHost = SpanReceiverHost.getInstance(getConfiguration());
if (!conf.getBoolean("hbase.testing.nocluster", false)) {
 zooKeeper = new ZooKeeperWatcher(conf, getProcessName() + ":" +
  rpcServices.isa.getPort(), this, canCreateBaseZNode());
putUpWebUI();
this.walRoller = new LogRoller(this, this);
this.choreService = new ChoreService(getServerName().toString(), true);

代码示例来源:origin: co.cask.hbase/hbase

@Override
public void setConf(Configuration config) {
 // If replication is disabled, keep all members null
 if (!config.getBoolean(HConstants.REPLICATION_ENABLE_KEY, false)) {
  return;
 }
 // Make my own Configuration.  Then I'll have my own connection to zk that
 // I can close myself when comes time.
 Configuration conf = new Configuration(config);
 super.setConf(conf);
 try {
  ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "replicationLogCleaner", null);
  this.zkHelper = new ReplicationZookeeper(this, conf, zkw);
 } catch (KeeperException e) {
  LOG.error("Error while configuring " + this.getClass().getName(), e);
 } catch (IOException e) {
  LOG.error("Error while configuring " + this.getClass().getName(), e);
 }
 refreshHLogsAndSearch(null);
}

代码示例来源:origin: co.cask.hbase/hbase

this.serverNameFromMasterPOV = new ServerName(hostnameFromMasterPOV,
    this.isa.getPort(), this.startcode);
   LOG.info("Master passed us hostname to use. Was=" +
    this.isa.getHostName() + ", Now=" +
    this.serverNameFromMasterPOV.getHostname());
   continue;
   LOG.debug("Config from master: " + key + "=" + value);
  this.conf.set(key, value);
 if (this.conf.get("mapred.task.id") == null) {
  this.conf.set("mapred.task.id", "hb_rs_" +
   this.serverNameFromMasterPOV.toString());
  ", RPC listening on " + this.isa +
  ", sessionid=0x" +
  Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()));
 isOnline = true;
} catch (Throwable e) {

代码示例来源:origin: harbby/presto-connectors

this.serverName = ServerName.valueOf(hostnameFromMasterPOV,
   rpcServices.isa.getPort(), this.startcode);
  if (shouldUseThisHostnameInstead() &&
  LOG.info("Config from master: " + key + "=" + value);
 this.conf.set(key, value);
if (this.conf.get("mapreduce.task.attempt.id") == null) {
 this.conf.set("mapreduce.task.attempt.id", "hb_rs_" +
  this.serverName.toString());
 ", RpcServer on " + rpcServices.isa +
 ", sessionid=0x" +
 Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()));

代码示例来源:origin: XiaoMi/themis

TEST_UTIL.shutdownMiniCluster();
conf.set(ThemisRegionObserver.THEMIS_DELETE_THEMIS_DELETED_DATA_WHEN_COMPACT, "true");
TransactionTTL.timestampType = TimestampType.MS;
TransactionTestBase.startMiniCluster(conf);
initEnv();
ZooKeeperWatcher zk = new ZooKeeperWatcher(conf, "test", null, true);
HBaseAdmin admin = new HBaseAdmin(connection);
ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
 Bytes.toBytes(String.valueOf(Long.MIN_VALUE)));
ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
 Bytes.toBytes(String.valueOf(prewriteTs + 5)));
Assert.assertNull(result);
deleteOldDataAndUpdateTs();
conf.set(ThemisRegionObserver.THEMIS_DELETE_THEMIS_DELETED_DATA_WHEN_COMPACT, "false");
zk.close();

代码示例来源:origin: co.cask.hbase/hbase

private static void getReplicationZnodesDump(ZooKeeperWatcher zkw, StringBuilder sb)
  throws KeeperException {
 String replicationZNodeName = zkw.getConfiguration().get("zookeeper.znode.replication",
  "replication");
 String replicationZnode = joinZNode(zkw.baseZNode, replicationZNodeName);
 if (ZKUtil.checkExists(zkw, replicationZnode) == -1)
  return;
 // do a ls -r on this znode
 List<String> stack = new LinkedList<String>();
 stack.add(replicationZnode);
 do {
  String znodeToProcess = stack.remove(stack.size() - 1);
  sb.append("\n").append(znodeToProcess).append(": ")
    .append(Bytes.toString(ZKUtil.getData(zkw, znodeToProcess)));
  for (String zNodeChild : ZKUtil.listChildrenNoWatch(zkw, znodeToProcess)) {
   stack.add(ZKUtil.joinZNode(znodeToProcess, zNodeChild));
  }
 } while (stack.size() > 0);
}
/**

代码示例来源:origin: harbby/presto-connectors

/**
 * Appends replication znodes to the passed StringBuilder.
 * @param zkw
 * @param sb
 * @throws KeeperException
 */
private static void getReplicationZnodesDump(ZooKeeperWatcher zkw, StringBuilder sb)
  throws KeeperException {
 String replicationZNodeName = zkw.getConfiguration().get("zookeeper.znode.replication",
  "replication");
 String replicationZnode = joinZNode(zkw.baseZNode, replicationZNodeName);
 if (ZKUtil.checkExists(zkw, replicationZnode) == -1) return;
 // do a ls -r on this znode
 sb.append("\n").append(replicationZnode).append(": ");
 List<String> children = ZKUtil.listChildrenNoWatch(zkw, replicationZnode);
 for (String child : children) {
  String znode = joinZNode(replicationZnode, child);
  if (child.equals(zkw.getConfiguration().get("zookeeper.znode.replication.peers", "peers"))) {
   appendPeersZnodes(zkw, znode, sb);
  } else if (child.equals(zkw.getConfiguration().
    get("zookeeper.znode.replication.rs", "rs"))) {
   appendRSZnodes(zkw, znode, sb);
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

private static void appendPeerState(ZooKeeperWatcher 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;
  String peerStateZnode = ZKUtil.joinZNode(znodeToProcess, child);
  sb.append("\n").append(peerStateZnode).append(": ");
  byte[] peerStateData;
  try {
   peerStateData = ZKUtil.getData(zkw, peerStateZnode);
   ZooKeeperProtos.ReplicationState.Builder builder =
     ZooKeeperProtos.ReplicationState.newBuilder();
   ProtobufUtil.mergeFrom(builder, peerStateData, pblen, peerStateData.length - pblen);
   sb.append(builder.getState().name());
  } catch (IOException ipbe) {
   LOG.warn("Got Exception while parsing peer: " + znodeToProcess, ipbe);
  } catch (InterruptedException e) {
   zkw.interruptedException(e);
   return;
  }
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-client

public static ArrayList<ACL> createACL(ZooKeeperWatcher zkw, String node,
                    boolean isSecureZooKeeper) {
 if (!node.startsWith(zkw.baseZNode)) {
  return Ids.OPEN_ACL_UNSAFE;
 }
 if (isSecureZooKeeper) {
  String superUser = zkw.getConfiguration().get("hbase.superuser");
  ArrayList<ACL> acls = new ArrayList<ACL>();
  // add permission to hbase supper user
  if (superUser != null) {
   acls.add(new ACL(Perms.ALL, new Id("sasl", superUser)));
  }
  // Certain znodes are accessed directly by the client,
  // so they must be readable by non-authenticated clients
  if (zkw.isClientReadable(node)) {
   acls.addAll(Ids.CREATOR_ALL_ACL);
   acls.addAll(Ids.READ_ACL_UNSAFE);
  } else {
   acls.addAll(Ids.CREATOR_ALL_ACL);
  }
  return acls;
 } else {
  return Ids.OPEN_ACL_UNSAFE;
 }
}

代码示例来源:origin: harbby/presto-connectors

ZooKeeperWatcher zkw = null;
try {
 zkw = new ZooKeeperWatcher(getConf(), "Migrate ZK data to PB.",
  new ZKDataMigratorAbortable());
 if (ZKUtil.checkExists(zkw, zkw.baseZNode) == -1) {
  LOG.info("No hbase related data available in zookeeper. returning..");
  return 0;
 List<String> children = ZKUtil.listChildrenNoWatch(zkw, zkw.baseZNode);
 if (children == null) {
  LOG.info("No child nodes to mirgrate. returning..");
  childPath = ZKUtil.joinZNode(zkw.baseZNode, child);
  if (child.equals(conf.get("zookeeper.znode.rootserver", "root-region-server"))) {
   ZKUtil.deleteNodeRecursively(zkw, childPath);
  } else if (child.equals(conf.get("zookeeper.znode.rs", "rs"))) {
   ZKUtil.deleteNodeRecursively(zkw, childPath);
  } else if (child.equals(conf.get("zookeeper.znode.draining.rs", "draining"))) {
} finally {
 if (zkw != null) {
  zkw.close();

代码示例来源:origin: com.aliyun.hbase/alihbase-client

/**
 * Appends replication znodes to the passed StringBuilder.
 * @param zkw
 * @param sb
 * @throws KeeperException
 */
private static void getReplicationZnodesDump(ZooKeeperWatcher zkw, StringBuilder sb)
  throws KeeperException {
 String replicationZNodeName = zkw.getConfiguration().get("zookeeper.znode.replication",
  "replication");
 String replicationZnode = joinZNode(zkw.baseZNode, replicationZNodeName);
 if (ZKUtil2.checkExists(zkw, replicationZnode) == -1) return;
 // do a ls -r on this znode
 sb.append("\n").append(replicationZnode).append(": ");
 List<String> children = ZKUtil2.listChildrenNoWatch(zkw, replicationZnode);
 for (String child : children) {
  String znode = joinZNode(replicationZnode, child);
  if (child.equals(zkw.getConfiguration().get("zookeeper.znode.replication.peers", "peers"))) {
   appendPeersZnodes(zkw, znode, sb);
  } else if (child.equals(zkw.getConfiguration().
    get("zookeeper.znode.replication.rs", "rs"))) {
   appendRSZnodes(zkw, znode, sb);
  }
 }
}

代码示例来源:origin: com.aliyun.hbase/alihbase-client

private static void appendPeerState(ZooKeeperWatcher 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 : ZKUtil2.listChildrenNoWatch(zkw, znodeToProcess)) {
  if (!child.equals(peerState)) continue;
  String peerStateZnode = ZKUtil2.joinZNode(znodeToProcess, child);
  sb.append("\n").append(peerStateZnode).append(": ");
  byte[] peerStateData;
  try {
   peerStateData = ZKUtil2.getData(zkw, peerStateZnode);
   ZooKeeperProtos.ReplicationState.Builder builder =
     ZooKeeperProtos.ReplicationState.newBuilder();
   ProtobufUtil.mergeFrom(builder, peerStateData, pblen, peerStateData.length - pblen);
   sb.append(builder.getState().name());
  } catch (IOException ipbe) {
   LOG.warn("Got Exception while parsing peer: " + znodeToProcess, ipbe);
  } catch (InterruptedException e) {
   zkw.interruptedException(e);
   return;
  }
 }
}

代码示例来源:origin: XiaoMi/themis

public ZookeeperWorkerRegister(Configuration conf) throws IOException {
 super(conf);
 try {
  clientNameStr = constructClientName();
  clusterName = conf.get("hbase.cluster.name");
  aliveClientParentPath = getAliveClientParentPath();
  aliveClientPath = getAliveClientPath();
  watcher = new ZooKeeperWatcher(conf, clientNameStr, new TimeoutOrDeletedHandler(),
    false);
  clientTracker = new ClientTracker(watcher);
  LOG.info("create ZookeeperWorkerRegister, clientPath=" + aliveClientParentPath);
 } catch (Exception e) {
  LOG.error("init ZookeeperWorkerRegister fail", e);
  throw new IOException(e);
 }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void init() throws IOException {
 this.zkretries = conf.getLong("hbase.splitlog.zk.retries", DEFAULT_ZK_RETRIES);
 this.resubmitThreshold = conf.getLong("hbase.splitlog.max.resubmit", DEFAULT_MAX_RESUBMIT);
 this.timeout = conf.getInt(HConstants.HBASE_SPLITLOG_MANAGER_TIMEOUT, DEFAULT_TIMEOUT);
 setRecoveryMode(true);
 if (this.watcher != null) {
  this.watcher.registerListener(this);
  lookForOrphans();
 }
}

代码示例来源:origin: NGDATA/hbase-indexer

new FifoRpcScheduler(hbaseConf, hbaseConf.getInt("hbase.regionserver.handler.count", 10)));
this.serverName = ServerName.valueOf(hostName, rpcServer.getListenerAddress().getPort(), System.currentTimeMillis());
this.zkWatcher = new ZooKeeperWatcher(hbaseConf, this.serverName.toString(), null);
ZKUtil.loginClient(hbaseConf, "hbase.zookeeper.client.keytab.file",
    "hbase.zookeeper.client.kerberos.principal", hostName);

代码示例来源:origin: co.cask.hbase/hbase

boolean runSequentialOnMultiFailure) throws KeeperException {
if (ops == null) return;
boolean useMulti = zkw.getConfiguration().getBoolean(HConstants.ZOOKEEPER_USEMULTI, false);
  zkOps.add(toZooKeeperOp(zkw, op));
  zkw.getRecoverableZooKeeper().multi(zkOps);
 } catch (KeeperException ke) {
  switch (ke.code()) {
      + "  Attempting to run operations sequentially because"
      + " runSequentialOnMultiFailure is: " + runSequentialOnMultiFailure + ".");
     processSequentially(zkw, ops);
     break;
  zkw.interruptedException(ie);
 processSequentially(zkw, ops);

代码示例来源:origin: XiaoMi/themis

ZooKeeperWatcher zk = new ZooKeeperWatcher(conf, "test", null, true);
HBaseAdmin admin = new HBaseAdmin(connection);
ZKUtil.deleteNodeFailSilent(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk));
admin.flush(TABLENAME);
Assert.assertEquals(6, getRowByScan().size());
ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
 Bytes.toBytes(String.valueOf(Long.MIN_VALUE)));
admin.flush(TABLENAME);
Assert.assertEquals(6, getRowByScan().size());
ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
 Bytes.toBytes(String.valueOf(prewriteTs + 1)));
admin.flush(TABLENAME);
Assert.assertEquals(6, getRowByScan().size());
ZKUtil.createSetData(zk, ThemisMasterObserver.getThemisExpiredTsZNodePath(zk),
 Bytes.toBytes(String.valueOf(prewriteTs + 5)));
admin.flush(TABLENAME);
Result result = getRowByScan();
zk.close();

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com