public void ensureExists(String path, final byte[] data, final SolrZkClient zkClient) throws KeeperException, InterruptedException { ensureExists(path, data, CreateMode.PERSISTENT, zkClient, 0); }
/** * Perform the given operation, retrying if the connection fails */ @SuppressWarnings("unchecked") public <T> T retryOperation(ZkOperation operation) throws KeeperException, InterruptedException { KeeperException exception = null; for (int i = 0; i < retryCount; i++) { try { return (T) operation.execute(); } catch (KeeperException.ConnectionLossException e) { if (exception == null) { exception = e; } if (Thread.currentThread().isInterrupted()) { Thread.currentThread().interrupt(); throw new InterruptedException(); } if (i != retryCount -1) { retryDelay(i); } } } throw exception; }
public List<OpResult> multi(final Iterable<Op> ops, boolean retryOnConnLoss) throws InterruptedException, KeeperException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(new ZkOperation() { @Override public List<OpResult> execute() throws KeeperException, InterruptedException { return keeper.multi(ops); } }); } else { return keeper.multi(ops); } }
public ZkStateReader(SolrZkClient zkClient, Runnable securityNodeListener) { this.zkClient = zkClient; this.cmdExecutor = new ZkCmdExecutor(zkClient.getZkClientTimeout()); this.configManager = new ZkConfigManager(zkClient); this.closeClient = false; this.securityNodeListener = securityNodeListener; }
public ZkStateReader(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout) { this.zkClient = new SolrZkClient(zkServerAddress, zkClientTimeout, zkClientConnectTimeout, // on reconnect, reload cloud info new OnReconnect() { @Override public void command() { try { ZkStateReader.this.createClusterStateWatchersAndUpdate(); } catch (KeeperException e) { log.error("", e); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } catch (InterruptedException e) { // Restore the interrupted status Thread.currentThread().interrupt(); log.error("", e); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } } }); this.cmdExecutor = new ZkCmdExecutor(zkClientTimeout); this.configManager = new ZkConfigManager(zkClient); this.closeClient = true; this.securityNodeListener = null; }
public void delete(final String path, final int version, boolean retryOnConnLoss) throws InterruptedException, KeeperException { if (retryOnConnLoss) { zkCmdExecutor.retryOperation(new ZkOperation() { @Override public Stat execute() throws KeeperException, InterruptedException { keeper.delete(path, version); return null; } }); } else { keeper.delete(path, version); } }
public void ensureExists(String path, final SolrZkClient zkClient) throws KeeperException, InterruptedException { ensureExists(path, null, CreateMode.PERSISTENT, zkClient); }
zkCmdExecutor = new ZkCmdExecutor(zkClientTimeout); connManager = new ConnectionManager("ZooKeeperConnection Watcher:" + zkServerAddress, this, zkServerAddress, strat, onReconnect, beforeReconnect);
/** * Returns true if path exists */ public Boolean exists(final String path, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(new ZkOperation() { @Override public Boolean execute() throws KeeperException, InterruptedException { return keeper.exists(path, null) != null; } }); } else { return keeper.exists(path, null) != null; } }
public void ensureExists(String path, final SolrZkClient zkClient) throws KeeperException, InterruptedException { ensureExists(path, null, CreateMode.PERSISTENT, zkClient, 0); }
zkCmdExecutor = new ZkCmdExecutor(zkClientTimeout); connManager = new ConnectionManager("ZooKeeperConnection Watcher:" + zkServerAddress, this, zkServerAddress, strat, onReconnect, beforeReconnect);
/** * Returns node's state */ public Stat setData(final String path, final byte data[], final int version, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(new ZkOperation() { @Override public Stat execute() throws KeeperException, InterruptedException { return keeper.setData(path, data, version); } }); } else { return keeper.setData(path, data, version); } }
public void ensureExists(String path, final byte[] data, CreateMode createMode, final SolrZkClient zkClient) throws KeeperException, InterruptedException { ensureExists(path, data, createMode, zkClient, 0); }
/** * Returns node's state */ public Stat setData(final String path, final byte data[], final int version, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(() -> keeper.setData(path, data, version)); } else { return keeper.setData(path, data, version); } }
synchronized (getUpdateLock()) { cmdExecutor.ensureExists(fullpath, zkClient); log.info("Updating collection state at {} from ZooKeeper... ", fullpath);
public List<OpResult> multi(final Iterable<Op> ops, boolean retryOnConnLoss) throws InterruptedException, KeeperException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(() -> keeper.multi(ops)); } else { return keeper.multi(ops); } }
/** * Returns true if path exists */ public Boolean exists(final String path, boolean retryOnConnLoss) throws KeeperException, InterruptedException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(() -> keeper.exists(path, null) != null); } else { return keeper.exists(path, null) != null; } }
public void delete(final String path, final int version, boolean retryOnConnLoss) throws InterruptedException, KeeperException { if (retryOnConnLoss) { zkCmdExecutor.retryOperation(() -> { keeper.delete(path, version); return null; }); } else { keeper.delete(path, version); } }
/** * Set the ACL on a single node in ZooKeeper. This will replace all existing ACL on that node. * * @param path path to set ACL on e.g. /solr/conf/solrconfig.xml * @param acls a list of {@link ACL}s to be applied * @param retryOnConnLoss true if the command should be retried on connection loss */ public Stat setACL(String path, List<ACL> acls, boolean retryOnConnLoss) throws InterruptedException, KeeperException { if (retryOnConnLoss) { return zkCmdExecutor.retryOperation(() -> keeper.setACL(path, acls, -1)); } else { return keeper.setACL(path, acls, -1); } }