Apache Solr open-source search software
SOLR-15918 Avoid repetitive creating parent znodes (#554)
Mike Drob0ba432371064
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex abbcdbc55ca..59c575ca5ce 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -47,7 +47,7 @@ OptimizationsBug Fixes----------------------(No changes)+* SOLR-15918: Skip repetitive parent znode creation on config set upload (Mike Drob)Other Changes---------------------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.javaindex 24562af79ff..7a45c369e1f 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@@ -543,6 +543,9 @@ public class SolrZkClient implements Closeable {throw e;}} catch (NodeExistsException e) {+ if (log.isDebugEnabled()) {+ log.debug("Node exists: {}", e.getPath());+ }if (!failOnExists && i == paths.length - 1) {// TODO: version ? for now, don't worry about racediff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.javaindex aff7fdeb2fd..03a74aa1d94 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@@ -35,6 +35,7 @@ import java.util.regex.Pattern;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.common.StringUtils;+import org.apache.zookeeper.CreateMode;import org.apache.zookeeper.KeeperException;import org.apache.zookeeper.data.Stat;import org.slf4j.Logger;@@ -283,6 +284,7 @@ public class ZkMaintenanceUtils {if (!Files.exists(rootPath))throw new IOException("Path " + rootPath + " does not exist");+ int partsOffset = Path.of(zkPath).getNameCount() - rootPath.getNameCount() - 1; // will be negativeFiles.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {@Overridepublic FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {@@ -297,7 +299,9 @@ public class ZkMaintenanceUtils {if (file.toFile().getName().equals(ZKNODE_DATA_FILE) && zkClient.exists(zkNode, true)) {zkClient.setData(zkNode, file, true);} else {- zkClient.makePath(zkNode, file, false, true);+ // Skip path parts here because they should have been created during preVisitDirectory+ int pathParts = file.getNameCount() + partsOffset;+ zkClient.makePath(zkNode, Files.readAllBytes(file), CreateMode.PERSISTENT, null, false, true, pathParts);}} catch (KeeperException | InterruptedException e) {throw new IOException("Error uploading file " + file + " to zookeeper path " + zkNode,@@ -310,6 +314,21 @@ public class ZkMaintenanceUtils {public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {if (dir.getFileName().toString().startsWith(".")) return FileVisitResult.SKIP_SUBTREE;+ String zkNode = createZkNodeName(zkPath, rootPath, dir);+ try {+ if (dir.equals(rootPath)) {+ // Make sure the root path exists, including potential parents+ zkClient.makePath(zkNode, false, 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);+ }+ } catch (KeeperException | InterruptedException e) {+ throw new IOException("Error creating intermediate directory " + dir,+ SolrZkClient.checkInterrupted(e));+ }+return FileVisitResult.CONTINUE;}});diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.javaindex c2c79753802..68357b95549 100644--- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java@@ -24,6 +24,7 @@ import org.apache.solr.cloud.ZkConfigSetService;import org.apache.solr.cloud.ZkTestServer;import org.apache.solr.core.ConfigSetService;import org.apache.solr.core.CoreContainer;+import org.apache.solr.util.LogLevel;import org.apache.zookeeper.KeeperException;import org.apache.zookeeper.ZooDefs;import org.apache.zookeeper.data.ACL;@@ -44,6 +45,7 @@ import java.util.Collection;import java.util.List;import java.util.Properties;+@LogLevel("org.apache.solr.common.cloud=DEBUG")public class TestZkConfigSetService extends SolrTestCaseJ4 {private static ZkTestServer zkServer;