Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15918 Fix test failures (#568)

Mike Drobdfef340534c5
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
index 7a45c369e1f..1006dca3ba8 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
@@ -499,6 +499,8 @@ public class SolrZkClient implements Closeable {
*
* Note: retryOnConnLoss is only respected for the final node - nodes
* before that are always retried on connection loss.
+ *
+ * Note: if failOnExists == false then we will always overwrite the existing data with the given data
*/
public void makePath(String path, byte[] data, CreateMode createMode,
Watcher watcher, boolean failOnExists, boolean retryOnConnLoss, int skipPathParts) throws KeeperException, InterruptedException {
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
index 03a74aa1d94..decb8319bd7 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
@@ -298,6 +298,9 @@ public class ZkMaintenanceUtils {
// 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, true);
+ } else if (file == rootPath) {
+ // We are only uploading a single file, preVisitDirectory was never called
+ zkClient.makePath(zkNode, file, false, true);
} else {
// Skip path parts here because they should have been created during preVisitDirectory
int pathParts = file.getNameCount() + partsOffset;
@@ -318,12 +321,16 @@ public class ZkMaintenanceUtils {
try {
if (dir.equals(rootPath)) {
// Make sure the root path exists, including potential parents
- zkClient.makePath(zkNode, false, true);
+ zkClient.makePath(zkNode, true);
} else {
// Skip path parts here because they should have been created during previous visits
int pathParts = dir.getNameCount() + partsOffset;
- zkClient.makePath(zkNode, null, CreateMode.PERSISTENT, null, false, true, pathParts);
+ zkClient.makePath(zkNode, null, CreateMode.PERSISTENT, null, true, true, pathParts);
}
+ } catch (KeeperException.NodeExistsException ignored) {
+ // Using fail-on-exists == false has side effect of makePath attempting to setData on the leaf of the path
+ // We prefer that if the parent directory already exists, we do not modify it
+ // Particularly relevant for marking config sets as trusted
} catch (KeeperException | InterruptedException e) {
throw new IOException("Error creating intermediate directory " + dir,
SolrZkClient.checkInterrupted(e));