Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions solr/core/src/java/org/apache/solr/cli/AuthTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ private void handleBasicAuth(CommandLine cli) throws Exception {
if (!updateIncludeFileOnly) {
echoIfVerbose("Uploading following security.json: " + securityJson);
try (SolrZkClient zkClient = CLIUtils.getSolrZkClient(cli, zkHost)) {
zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8));
zkClient.makePath(
"/security.json", securityJson.getBytes(StandardCharsets.UTF_8), false);
}
}

Expand Down Expand Up @@ -368,7 +369,7 @@ private void clearSecurityJson(CommandLine cli, boolean updateIncludeFileOnly) t
echoIfVerbose("Uploading following security.json: {}");

try (SolrZkClient zkClient = CLIUtils.getSolrZkClient(cli, zkHost)) {
zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8));
zkClient.makePath("/security.json", "{}".getBytes(StandardCharsets.UTF_8), false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.apache.solr.logging.DeprecationLog;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -107,11 +106,7 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
nodeList.remove(node);
}

if (nodeExists) {
zkClient.setData(ZkStateReader.ROLES, Utils.toJSON(roles));
} else {
zkClient.create(ZkStateReader.ROLES, Utils.toJSON(roles), CreateMode.PERSISTENT);
}
zkClient.makePath(ZkStateReader.ROLES, Utils.toJSON(roles), false);
runPrioritizer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ protected ManagedIndexSchema restoreLanguageSpecificObjectsAndFiles(
for (String path : langFilesToRestore) {
String copyToPath = path.replace(origPathDir, replacePathDir);
try {
// Only restore files that are missing -- do not overwrite an existing file with the
// copyFrom version.
if (!zkClient.exists(copyToPath)) {
zkClient.makePath(copyToPath, false);
zkClient.setData(copyToPath, zkClient.getData(path, null, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.apache.solr.packagemanager.SolrPackage.SolrPackageRelease;
import org.apache.solr.pkg.PackageAPI;
import org.apache.solr.pkg.SolrPackageLoader;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -123,16 +122,10 @@ public void addRepository(String repoName, String uri) throws Exception {
@SuppressWarnings({"unchecked"})
List<PackageRepository> repos = getMapper().readValue(existingRepositoriesJson, List.class);
repos.add(new DefaultPackageRepository(repoName, uri));
if (packageManager.zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH) == false) {
packageManager.zkClient.create(
PackageUtils.REPOSITORIES_ZK_PATH,
getMapper().writeValueAsString(repos).getBytes(StandardCharsets.UTF_8),
CreateMode.PERSISTENT);
} else {
packageManager.zkClient.setData(
PackageUtils.REPOSITORIES_ZK_PATH,
getMapper().writeValueAsString(repos).getBytes(StandardCharsets.UTF_8));
}
packageManager.zkClient.makePath(
PackageUtils.REPOSITORIES_ZK_PATH,
getMapper().writeValueAsString(repos).getBytes(StandardCharsets.UTF_8),
false);

try (InputStream is = new URI(uri + "/publickey.der").toURL().openStream()) {
addKey(is.readAllBytes(), repoName + ".der");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,8 @@ public OutputStream openOutputStream(String storedResourceId) throws IOException
public void close() {
byte[] znodeData = toByteArray();
try {
if (zkClient.exists(znodePath)) {
zkClient.setData(znodePath, znodeData);
log.info("Wrote {} bytes to existing znode {}", znodeData.length, znodePath);
} else {
zkClient.makePath(znodePath, znodeData);
log.info("Wrote {} bytes to new znode {}", znodeData.length, znodePath);
}
zkClient.makePath(znodePath, znodeData, false);
log.info("Wrote {} bytes to znode {}", znodeData.length, znodePath);
} catch (Exception e) {
// have to throw a runtimer here as we're in close,
// which doesn't throw IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkMaintenanceUtils;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.NamedList;
Expand Down Expand Up @@ -487,8 +486,7 @@ private void zkUgradeToManagedSchema() {
// First, copy the non-managed schema znode content to the upgraded schema znode
byte[] bytes = zkController.getZkClient().getData(nonManagedSchemaPath, null, null);
final String upgradedSchemaPath = nonManagedSchemaPath + UPGRADED_SCHEMA_EXTENSION;
ZkMaintenanceUtils.ensureExists(upgradedSchemaPath, zkController.getZkClient());
zkController.getZkClient().setData(upgradedSchemaPath, bytes);
zkController.getZkClient().makePath(upgradedSchemaPath, bytes, false);
// Then delete the non-managed schema znode
if (zkController.getZkClient().exists(nonManagedSchemaPath)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ public void makePath(String path, boolean failOnExists)
makePath(path, null, CreateMode.PERSISTENT, null, failOnExists, 0);
}

/**
* Creates the path in ZooKeeper, creating each node as necessary.
*
* @param data to set on the last zkNode
* @param failOnExists if {@code true}, fail if the last zkNode already exists; if {@code false},
* an existing zkNode's data is overwritten instead, making this a safe create-or-update
*/
public void makePath(String path, byte[] data, boolean failOnExists)
throws KeeperException, InterruptedException {
makePath(path, data, CreateMode.PERSISTENT, null, failOnExists, 0);
Expand Down Expand Up @@ -711,7 +718,11 @@ public void ensureExists(
}
}

/** Write data to ZooKeeper. */
/**
* Write data to ZooKeeper. The node at {@code path} must already exist; throws {@link
* NoNodeException} otherwise. Use {@link #makePath(String, byte[], boolean) makePath(path, data,
* false)} instead if the node may not exist yet.
*/
public Stat setData(String path, byte[] data) throws KeeperException, InterruptedException {
return setData(path, data, -1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
zkClient.setData(zkNode, file);
} else if (file.equals(rootPath)) {
// We are only uploading a single file, preVisitDirectory was never called
if (zkClient.exists(zkPath)) {
zkClient.setData(zkPath, file);
} else {
zkClient.makePath(zkPath, Files.readAllBytes(file), false);
}
zkClient.makePath(zkPath, Files.readAllBytes(file), false);
} else {
// Skip path parts here because they should have been created during
// preVisitDirectory
Expand Down
Loading