This is an automated email from the ASF dual-hosted git repository.
mdrob pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 0ba4323 SOLR-15918 Avoid repetitive creating parent znodes (#554)
0ba4323 is described below
commit 0ba432371064586a900ae1e66b483f0685d4ef7f
Author: Mike Drob <[email protected]>
AuthorDate: Tue Jan 25 21:39:31 2022 -0600
SOLR-15918 Avoid repetitive creating parent znodes (#554)
---
solr/CHANGES.txt | 2 +-
.../org/apache/solr/common/cloud/SolrZkClient.java | 3 +++
.../solr/common/cloud/ZkMaintenanceUtils.java | 21 ++++++++++++++++++++-
.../solr/common/cloud/TestZkConfigSetService.java | 2 ++
4 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index abbcdbc..59c575ca 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -47,7 +47,7 @@ Optimizations
Bug 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.java
index 24562af..7a45c36 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 race
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 aff7fde..03a74aa 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 negative
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
@Override
public 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.java
index c2c7975..68357b9 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;