/** * Write data to ZooKeeper. */ public Stat setData(String path, byte[] data, boolean retryOnConnLoss) throws KeeperException, InterruptedException { return setData(path, data, -1, retryOnConnLoss); }
/** * Write data to ZooKeeper. */ public Stat setData(String path, byte[] data, boolean retryOnConnLoss) throws KeeperException, InterruptedException { return setData(path, data, -1, retryOnConnLoss); }
/** * Write file to ZooKeeper - default system encoding used. * * @param path path to upload file to e.g. /solr/conf/solrconfig.xml * @param file path to file to be uploaded */ public Stat setData(String path, File file, boolean retryOnConnLoss) throws IOException, KeeperException, InterruptedException { log.debug("Write to ZooKeeper: {} to {}", file.getAbsolutePath(), path); byte[] data = FileUtils.readFileToByteArray(file); return setData(path, data, retryOnConnLoss); }
/** * Write file to ZooKeeper - default system encoding used. * * @param path path to upload file to e.g. /solr/conf/solrconfig.xml * @param file path to file to be uploaded */ public Stat setData(String path, File file, boolean retryOnConnLoss) throws IOException, KeeperException, InterruptedException { if (log.isInfoEnabled()) { log.info("Write to ZooKeepeer " + file.getAbsolutePath() + " to " + path); } byte[] data = FileUtils.readFileToByteArray(file); return setData(path, data, retryOnConnLoss); }
@Override public void setData(String path, byte[] data, int version) throws BadVersionException, NoSuchElementException, IOException, KeeperException, InterruptedException { try { zkClient.setData(path, data, version, true); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.BadVersionException e) { throw new BadVersionException(version, path); } catch (InterruptedException e) { throw e; } }
@Override public void visit(String path) throws InterruptedException, KeeperException { String finalDestination = dest; if (path.equals(source) == false) finalDestination += "/" + path.substring(source.length() + 1); zkClient.makePath(finalDestination, false, true); zkClient.setData(finalDestination, zkClient.getData(path, null, null, true), true); } }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String filename = file.getFileName().toString(); if (filenameExclusions != null && filenameExclusions.matcher(filename).matches()) { log.info("uploadToZK skipping '{}' due to filenameExclusions '{}'", filename, filenameExclusions); return FileVisitResult.CONTINUE; } String zkNode = createZkNodeName(zkPath, rootPath, file); try { // if the path exists (and presumably we're uploading data to it) just set its data if (file.toFile().getName().equals(ZKNODE_DATA_FILE) && zkClient.exists(zkNode, true)) { zkClient.setData(zkNode, file.toFile(), true); } else { zkClient.makePath(zkNode, file.toFile(), false, true); } } catch (KeeperException | InterruptedException e) { throw new IOException("Error uploading file " + file.toString() + " to zookeeper path " + zkNode, SolrZkClient.checkInterrupted(e)); } return FileVisitResult.CONTINUE; }
@Override public void persist(Map<String, Object> propObjs) { Properties existing = mapToProperties(readIndexerProperties()); existing.putAll(mapToProperties(propObjs)); StringWriter output = new StringWriter(); try { existing.store(output, null); byte[] bytes = output.toString().getBytes(StandardCharsets.UTF_8); if (!zkClient.exists(path, false)) { try { zkClient.makePath(path, false); } catch (NodeExistsException e) {} } zkClient.setData(path, bytes, false); } catch (Exception e) { SolrZkClient.checkInterrupted(e); log.warn("Could not persist properties to " + path + " :" + e.getClass(), e); } }
public void atomicUpdate(String path, Function<byte[], byte[]> editor) throws KeeperException, InterruptedException { for (; ; ) { byte[] modified = null; byte[] zkData = null; Stat s = new Stat(); try { if (exists(path, true)) { zkData = getData(path, null, s, true); modified = editor.apply(zkData); if (modified == null) { //no change , no need to persist return; } setData(path, modified, s.getVersion(), true); break; } else { modified = editor.apply(null); if (modified == null) { //no change , no need to persist return; } create(path, modified, CreateMode.PERSISTENT, true); break; } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { continue; } } }
public static void moveZnode(SolrZkClient zkClient, String src, String dst) throws SolrServerException, KeeperException, InterruptedException { String destName = normalizeDest(src, dst, true, true); // Special handling if the source has no children, i.e. copying just a single file. if (zkClient.getChildren(src, null, true).size() == 0) { zkClient.makePath(destName, false, true); zkClient.setData(destName, zkClient.getData(src, null, null, true), true); } else { traverseZkTree(zkClient, src, VISIT_ORDER.VISIT_PRE, new ZkCopier(zkClient, src, destName)); } // Insure all source znodes are present in dest before deleting the source. // throws error if not all there so the source is left intact. Throws error if source and dest don't match. checkAllZnodesThere(zkClient, src, destName); clean(zkClient, src); }
@Override public void distribSetUp() throws Exception { super.distribSetUp(); // ignoreException(".*"); if (sliceCount > 0) { System.setProperty("numShards", Integer.toString(sliceCount)); } else { System.clearProperty("numShards"); } if (isSSLMode()) { System.clearProperty("urlScheme"); try (ZkStateReader zkStateReader = new ZkStateReader(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT)) { try { zkStateReader.getZkClient().create(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(Collections.singletonMap("urlScheme", "https")), CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { ZkNodeProps props = ZkNodeProps.load(zkStateReader.getZkClient().getData(ZkStateReader.CLUSTER_PROPS, null, null, true)); zkStateReader.getZkClient().setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus("urlScheme", "https")), true); } } } if (useTlogReplicas()) { log.info("Will use {} replicas unless explicitly asked otherwise", Replica.Type.TLOG); } else { log.info("Will use {} replicas unless explicitly asked otherwise", Replica.Type.NRT); } }
final Stat stat = getZkClient().setData(ALIASES, modAliasesJson, curAliases.getZNodeVersion(), true); setIfNewer(Aliases.fromJSON(modAliasesJson, stat.getVersion())); return;
zkStateReader .getZkClient() .setData("/security.json", securityJson.getBytes(Charset.defaultCharset()), true); String zkAddress = cluster.getZkServer().getZkAddress(); connectionConfiguration =