gpt4 book ai didi

org.lilyproject.util.zookeeper.ZkUtil类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 12:48:49 26 4
gpt4 key购买 nike

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

ZkUtil介绍

[英]Various ZooKeeper utility methods.
[中]

代码示例

代码示例来源:origin: NGDATA/lilyproject

public static void createPath(final ZooKeeperItf zk, final String path)
    throws InterruptedException, KeeperException {
  createPath(zk, path, null);
}

代码示例来源:origin: NGDATA/lilyproject

public LilyClient(String zookeeperConnectString, int sessionTimeout, boolean keepAlive) throws IOException, InterruptedException,
    KeeperException, ZkConnectException, NoServersException, RepositoryException {
  this(ZkUtil.connect(zookeeperConnectString, sessionTimeout), keepAlive);
  managedZk = true;
}

代码示例来源:origin: NGDATA/lilyproject

private Server createServer() throws Exception {
  if (this.useSolrCloud) {
    // create path on zookeeper for solr cloud
    ZooKeeperItf zk = ZkUtil.connect("localhost:2181", 10000);
    ZkUtil.createPath(zk, "/solr");
    zk.close();
  }
  Server server = new Server(solrPort);
  WebAppContext ctx = new WebAppContext(solrWarPath, "/solr");
  // The reason to change the classloading behavior was primarily so that the logging libraries would
  // be inherited, and hence that Solr would use the same logging system & conf.
  ctx.setParentLoaderPriority(true);
  server.addHandler(ctx);
  return server;
}

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Void call() throws Exception {
    String bucketId = watcher.getBucket();
    String bucketPath = bucketPath(bucketId);
    Stat stat = new Stat();
    try {
      ZkUtil.getData(zooKeeper, bucketPath, watcher, stat);
      bucketVersions.put(bucketId, stat.getVersion());
    } catch (KeeperException e) {
      if (Thread.currentThread().isInterrupted()) {
        if (log.isDebugEnabled()) {
          log.debug(
              "Failed to put watcher on bucket " + bucketPath + " : thread interrupted");
        }
      } else {
        log.warn("Failed to put watcher on bucket " + bucketPath
            + " - Relying on connection watcher to reinitialize cache", e);
        // Failed to put our watcher.
        // Relying on the ConnectionWatcher to put it again and
        // initialize the caches.
      }
    }
    return null;
  }
});

代码示例来源:origin: NGDATA/lilyproject

/**
 * Sets the cache refresh flag on Zookeeper. This triggers the caches to
 * refresh their data.
 *
 * @param force
 *            if true, it is ignored if cache refreshing is enabled or not.
 */
public void triggerRefresh(byte[] rowKey, boolean force) throws TypeException, InterruptedException {
  if (force || cacheRefreshingEnabled) {
    try {
      if (rowKey == null) {
        if (log.isDebugEnabled()) {
          log.debug("Triggering schema cache refresh for all types.");
        }
        ZkUtil.update(zooKeeper, CACHE_INVALIDATION_PATH, null, -1);
      } else {
        String bucketId = encodeHex(rowKey);
        if (log.isDebugEnabled()) {
          log.debug("Triggering schema cache refresh for bucket: " + bucketId);
        }
        ZkUtil.update(zooKeeper, CACHE_INVALIDATION_PATH + "/" + bucketId, null, -1);
      }
    } catch (KeeperException e) {
      throw new TypeException("Exception while triggering cache refresh", e);
    }
  }
}

代码示例来源:origin: NGDATA/lilyproject

Stat stat = new Stat();
try {
  ZkUtil.getData(zooKeeper, bucketPath, watcher, stat);
  if (stat.getVersion() == bucketVersions.get(bucketId)) {
    continue; // The bucket is up to date

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Void call() throws InterruptedException, KeeperException, RepositoryException {
    for (int j = 0; j < 16; j++) {
      String bucket = "" + DIGITS_LOWER[index] + DIGITS_LOWER[j];
      ZkUtil.createPath(zooKeeper, bucketPath(bucket));
      cacheWatchers.add(new CacheWatcher(bucket));
    }
    return null;
  }
}));

代码示例来源:origin: NGDATA/lilyproject

@Override
public void run() {
  try {
    ZooKeeperItf zk = ZkUtil.connect("localhost:2181,localhost:21812", 5000);
    new LeaderElection(zk, "electiontest", "/lily/electiontest/leaders", new Callback());
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: NGDATA/lilyproject

ZkUtil.getData(zooKeeper, CACHE_INVALIDATION_PATH, parentWatcher, stat);
if (parentVersion == null || (stat.getVersion() != parentVersion)) {
  Stat stat = new Stat();
  try {
    ZkUtil.getData(zooKeeper, bucketPath, watcher, stat);
    Integer oldVersion = bucketVersions.get(bucketId);
    if (oldVersion == null || (oldVersion != stat.getVersion())) {

代码示例来源:origin: NGDATA/lilyproject

@PostConstruct
public void init() throws KeeperException, InterruptedException {
  ZkUtil.createPath(zk, "/lily/repositoryNodes");
  refresh();
}

代码示例来源:origin: NGDATA/lilyproject

/**
 * Factory method for creation of a {@code BulkIngester} that operates on a non-default repository table.
 *
 * @param zkConnString connection string for ZooKeeper
 * @param timeout      ZooKeeper session timeout
 * @param tableName    name of the repository table to write to
 */
public static BulkIngester newBulkIngester(String zkConnString, int timeout, String repositoryName, String tableName,
                      boolean bulkMode) {
  try {
    ZooKeeperItf zk = ZkUtil.connect(zkConnString, timeout);
    // we need a lily client for non bulk access
    LilyClient lilyClient = new LilyClient(zk);
    // we need an HBaseRepository for bulk access
    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", zkConnString);
    HBaseTableFactory hbaseTableFactory = new HBaseTableFactoryImpl(conf);
    HBaseRepository hbaseRepository = createHBaseRepository(repositoryName, tableName, zk, conf, hbaseTableFactory);
    return new BulkIngester(
        lilyClient,
        hbaseRepository,
        LilyHBaseSchema.getRecordTable(hbaseTableFactory, hbaseRepository.getRepositoryName(),
            hbaseRepository.getTableName()),
        bulkMode);
  } catch (Exception e) {
    ExceptionUtil.handleInterrupt(e);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: NGDATA/lilyproject

@PostConstruct
  public void start() throws IOException, InterruptedException, KeeperException {
    // Publish our address
    ZkUtil.createPath(zk, nodesPath);
    final String repoAddressAndPort = hostAddress + ":" + port;
    zk.retryOperation(new ZooKeeperOperation<Object>() {
      @Override
      public Object execute() throws KeeperException, InterruptedException {
        zk.create(nodesPath + "/" + repoAddressAndPort, null, ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL);
        return null;
      }
    });

    // Publish HBase configuration for LilyClient use
    // Translate HBase conf into json
    ObjectNode propertiesNode = JsonNodeFactory.instance.objectNode();
    for (Map.Entry<String, String> propertyEntry : hbaseConf) {
      if (!propertyEntry.getKey().equals(HConstants.HBASE_CLIENT_INSTANCE_ID)) {
        propertiesNode.put(propertyEntry.getKey(), propertyEntry.getValue());
      }
    }
    // TODO we could compare with current state and log a warn if its different
    ZkUtil.createPath(zk, hbaseConfPath, JsonFormat.serializeAsBytes(propertiesNode));
  }
}

代码示例来源:origin: NGDATA/lilyproject

public void setupCore() throws Exception {
  if (coreSetup) {
    return;
  }
  hbaseProxy = new HBaseProxy();
  hbaseProxy.start();
  hadoopConf = hbaseProxy.getConf();
  zk = ZkUtil.connect(hbaseProxy.getZkConnectString(), 10000);
  hbaseTableFactory = new HBaseTableFactoryImpl(hadoopConf);
  repositoryModel = new RepositoryModelImpl(zk);
  repositoryMaster = new RepositoryMaster(zk, repositoryModel, new DummyLilyInfo(),
      Collections.<RepositoryMasterHook>singletonList(new CoreRepositoryMasterHook(hbaseTableFactory, hbaseProxy.getConf())));
  repositoryMaster.start();
  coreSetup = true;
}

代码示例来源:origin: NGDATA/lilyproject

public void start() throws InterruptedException, KeeperException, RepositoryException {
  cacheRefresher.start();
  ZkUtil.createPath(zooKeeper, CACHE_INVALIDATION_PATH);
  final ExecutorService threadPool = Executors.newFixedThreadPool(50);
  final List<Future> futures = new ArrayList<Future>();
  ZkUtil.createPath(zooKeeper, CACHE_REFRESHENABLED_PATH);
  connectionWatcher = new ConnectionWatcher();
  zooKeeper.addDefaultWatcher(connectionWatcher);

代码示例来源:origin: NGDATA/lilyproject

private void proposeAsLeader() throws LeaderElectionSetupException, InterruptedException, KeeperException {
  ZkUtil.createPath(zk, electionPath);
  try {
    // In case of connection loss, a node might have been created for us (we do not know it). Therefore,
    // retrying upon connection loss is important, so that we can continue with watching the leaders.
    // Later on, we do not look at the name of the node we created here, but at the owner.
    zk.retryOperation(new ZooKeeperOperation<String>() {
      @Override
      public String execute() throws KeeperException, InterruptedException {
        return zk.create(electionPath + "/n_", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
      }
    });
  } catch (KeeperException e) {
    throw new LeaderElectionSetupException("Error creating leader election zookeeper node below " +
        electionPath, e);
  }
  watchLeaders();
}

代码示例来源:origin: NGDATA/lilyproject

public void init() throws KeeperException, InterruptedException {
  ZkUtil.createPath(zk, REPOSITORY_COLLECTION_PATH);
  assureDefaultRepositoryExists();
  zkWatcher = new RepositoryZkWatcher();
  zk.addDefaultWatcher(zkWatcher);
  refresh();
}

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