From 44399c710f639350c8c635bb3458024699a9c0a5 Mon Sep 17 00:00:00 2001 From: Kevin Risden Date: Wed, 11 Oct 2023 15:16:08 -0400 Subject: [PATCH] revert retryOnConnLoss changes --- .../java/org/apache/solr/cli/AuthTool.java | 11 +- .../java/org/apache/solr/cli/CreateTool.java | 4 +- .../java/org/apache/solr/cli/ZkRmTool.java | 2 +- .../java/org/apache/solr/cloud/CloudUtil.java | 4 +- .../cloud/DistributedApiAsyncTracker.java | 16 ++- .../cloud/DistributedClusterStateUpdater.java | 10 +- .../org/apache/solr/cloud/DistributedMap.java | 20 +-- .../apache/solr/cloud/ElectionContext.java | 2 +- .../org/apache/solr/cloud/LeaderElector.java | 26 ++-- .../java/org/apache/solr/cloud/Overseer.java | 8 +- .../solr/cloud/OverseerElectionContext.java | 2 +- .../solr/cloud/OverseerNodePrioritizer.java | 5 +- .../solr/cloud/OverseerTaskProcessor.java | 10 +- .../apache/solr/cloud/OverseerTaskQueue.java | 22 +-- .../solr/cloud/RefreshCollectionMessage.java | 2 +- .../cloud/ShardLeaderElectionContext.java | 2 +- .../solr/cloud/SizeLimitedDistributedMap.java | 4 +- .../src/java/org/apache/solr/cloud/ZkCLI.java | 19 ++- .../apache/solr/cloud/ZkConfigSetService.java | 25 ++-- .../org/apache/solr/cloud/ZkController.java | 56 ++++---- .../apache/solr/cloud/ZkDistributedLock.java | 9 +- .../solr/cloud/ZkDistributedLockFactory.java | 4 +- .../apache/solr/cloud/ZkDistributedQueue.java | 20 +-- .../org/apache/solr/cloud/ZkShardTerms.java | 8 +- .../solr/cloud/ZkSolrResourceLoader.java | 4 +- .../api/collections/CreateCollectionCmd.java | 6 +- .../api/collections/DeleteCollectionCmd.java | 4 +- .../api/collections/OverseerRoleCmd.java | 8 +- .../api/collections/OverseerStatusCmd.java | 6 +- .../cloud/api/collections/SplitShardCmd.java | 9 +- .../solr/cloud/overseer/ZkStateWriter.java | 6 +- .../java/org/apache/solr/core/NodeConfig.java | 4 +- .../org/apache/solr/core/RequestParams.java | 3 +- .../java/org/apache/solr/core/SolrCore.java | 2 +- .../solr/core/backup/BackupManager.java | 6 +- .../core/snapshots/SolrSnapshotManager.java | 18 +-- .../solr/filestore/DistribPackageStore.java | 18 ++- .../solr/filestore/PackageStoreAPI.java | 8 +- .../solr/handler/admin/ClusterStatus.java | 7 +- .../handler/admin/ContainerPluginsApi.java | 2 +- .../handler/admin/SecurityConfHandlerZk.java | 3 +- .../handler/admin/ShowFileRequestHandler.java | 9 +- .../handler/admin/ZookeeperInfoHandler.java | 8 +- .../solr/handler/admin/ZookeeperReadAPI.java | 10 +- .../handler/designer/SchemaDesignerAPI.java | 10 +- .../SchemaDesignerConfigSetHelper.java | 10 +- .../designer/SchemaDesignerSettingsDAO.java | 2 +- .../solr/packagemanager/PackageManager.java | 8 +- .../packagemanager/RepositoryManager.java | 13 +- .../java/org/apache/solr/pkg/PackageAPI.java | 11 +- .../solr/rest/ManagedResourceStorage.java | 22 +-- .../solr/schema/ManagedIndexSchema.java | 4 +- .../schema/ManagedIndexSchemaFactory.java | 18 +-- .../org/apache/solr/schema/SchemaManager.java | 4 +- .../solr/schema/ZkIndexSchemaReader.java | 4 +- .../org/apache/solr/servlet/HttpSolrCall.java | 2 +- .../apache/solr/servlet/QueryRateLimiter.java | 2 +- .../solr/cloud/AliasIntegrationTest.java | 2 +- .../AssignBackwardCompatibilityTest.java | 4 +- .../solr/cloud/CollectionPropsTest.java | 5 +- .../solr/cloud/CollectionStateZnodeTest.java | 6 +- .../solr/cloud/DistributedQueueTest.java | 6 +- .../cloud/LeaderElectionContextKeyTest.java | 3 +- .../apache/solr/cloud/LeaderElectionTest.java | 7 +- .../solr/cloud/LeaderVoteWaitTimeoutTest.java | 2 +- ...OfBoxZkACLAndCredentialsProvidersTest.java | 20 +-- ...iddenZkACLAndCredentialsProvidersTest.java | 22 ++- ...rseerCollectionConfigSetProcessorTest.java | 10 +- .../org/apache/solr/cloud/OverseerTest.java | 24 ++-- .../apache/solr/cloud/SolrCLIZkUtilsTest.java | 48 ++++--- .../apache/solr/cloud/SolrXmlInZkTest.java | 2 +- .../apache/solr/cloud/TestConfigSetsAPI.java | 60 +++++---- .../cloud/TestConfigSetsAPIExclusivity.java | 3 +- .../cloud/TestConfigSetsAPIZkFailure.java | 3 +- .../apache/solr/cloud/TestDistributedMap.java | 23 ++-- .../solr/cloud/TestLazySolrCluster.java | 9 +- .../apache/solr/cloud/TestPullReplica.java | 4 +- .../cloud/TestQueryingOnDownCollection.java | 5 +- .../solr/cloud/TestRebalanceLeaders.java | 3 +- .../cloud/TestSizeLimitedDistributedMap.java | 2 +- .../solr/cloud/TestStressLiveNodes.java | 4 +- .../apache/solr/cloud/TestTlogReplica.java | 4 +- .../test/org/apache/solr/cloud/ZkCLITest.java | 39 +++--- .../apache/solr/cloud/ZkControllerTest.java | 29 ++-- .../apache/solr/cloud/ZkSolrClientTest.java | 71 +++++----- .../cloud/api/collections/ShardSplitTest.java | 6 +- .../SimpleCollectionCreateDeleteTest.java | 35 +++-- .../api/collections/TestCollectionAPI.java | 4 +- .../TestLocalFSCloudBackupRestore.java | 4 +- .../cloud/overseer/ZkStateReaderTest.java | 8 +- .../cloud/overseer/ZkStateWriterTest.java | 22 +-- .../apache/solr/handler/TestConfigReload.java | 8 +- .../handler/admin/ZookeeperReadAPITest.java | 6 +- .../designer/TestSchemaDesignerAPI.java | 4 +- .../TestSchemaDesignerConfigSetHelper.java | 6 +- .../org/apache/solr/pkg/TestPackages.java | 6 +- .../solr/schema/TestCloudManagedSchema.java | 6 +- .../schema/TestManagedSchemaThreadSafety.java | 6 +- .../security/BasicAuthIntegrationTest.java | 2 +- .../security/BasicAuthOnSingleNodeTest.java | 2 +- .../security/TestAuthorizationFramework.java | 3 +- .../TimeRoutedAliasUpdateProcessorTest.java | 10 +- .../hadoop/DelegationTokenKerberosFilter.java | 3 +- .../security/hadoop/HadoopAuthFilter.java | 3 +- .../hadoop/SaslZkACLProviderTest.java | 22 ++- .../hadoop/TestDelegationWithHadoopAuth.java | 4 +- .../TestSolrCloudWithDelegationTokens.java | 4 +- .../TestHdfsCloudBackupRestore.java | 3 +- .../impl/ZkClientClusterStateProvider.java | 2 +- .../solrj/impl/ZkDistribStateManager.java | 16 +-- .../apache/solr/common/LazySolrCluster.java | 2 +- .../org/apache/solr/common/SimpleZkMap.java | 7 +- .../solr/common/cloud/ClusterProperties.java | 14 +- .../common/cloud/CollectionProperties.java | 13 +- .../common/cloud/PerReplicaStatesOps.java | 6 +- .../common/cloud/SecurityNodeWatcher.java | 13 +- .../solr/common/cloud/SolrZkClient.java | 125 +++++++++++------- .../solr/common/cloud/ZkMaintenanceUtils.java | 69 ++++++---- .../solr/common/cloud/ZkStateReader.java | 31 ++--- .../solr/common/cloud/SolrZkClientTest.java | 18 ++- .../common/cloud/TestPerReplicaStates.java | 6 +- .../common/cloud/TestZkConfigSetService.java | 2 +- .../common/cloud/TestZkMaintenanceUtils.java | 21 +-- .../solrj/impl/HttpClusterStateSSLTest.java | 4 +- .../impl/TestCloudSolrClientConnections.java | 2 +- .../PerReplicaStatesIntegrationTest.java | 10 +- .../cloud/SolrZkClientCompressedDataTest.java | 4 +- .../java/org/apache/solr/SolrTestCaseJ4.java | 2 +- .../AbstractBasicDistributedZk2TestBase.java | 2 +- ...tZkACLAndCredentialsProvidersTestBase.java | 43 +++--- .../solr/cloud/AbstractDistribZkTestBase.java | 1 - .../cloud/AbstractFullDistribZkTestBase.java | 10 +- .../solr/cloud/MiniSolrCloudCluster.java | 15 ++- .../apache/solr/cloud/MockSolrZkClient.java | 6 +- .../org/apache/solr/cloud/ZkTestServer.java | 8 +- ...ctCollectionsAPIDistributedZkTestBase.java | 12 +- 136 files changed, 919 insertions(+), 684 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cli/AuthTool.java b/solr/core/src/java/org/apache/solr/cli/AuthTool.java index 1f2fc2ac0dd..2afd71706b6 100644 --- a/solr/core/src/java/org/apache/solr/cli/AuthTool.java +++ b/solr/core/src/java/org/apache/solr/cli/AuthTool.java @@ -217,7 +217,8 @@ private int handleKerberos(CommandLine cli) throws Exception { .withTimeout( SolrZkClientTimeout.DEFAULT_ZK_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); + zkClient.setData( + "/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true); } catch (Exception ex) { CLIO.out( "Unable to access ZooKeeper. Please add the following security.json to ZooKeeper (in case of SolrCloud):\n" @@ -383,7 +384,7 @@ private int handleBasicAuth(CommandLine cli) throws Exception { .withUrl(zkHost) .withTimeout(SolrZkClientTimeout.DEFAULT_ZK_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); + zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true); } } @@ -451,8 +452,8 @@ private int handleBasicAuth(CommandLine cli) throws Exception { private void checkSecurityJsonExists(SolrZkClient zkClient) throws KeeperException, InterruptedException { - if (zkClient.exists("/security.json")) { - byte[] oldSecurityBytes = zkClient.getData("/security.json", null, null); + if (zkClient.exists("/security.json", true)) { + byte[] oldSecurityBytes = zkClient.getData("/security.json", null, null, true); if (!"{}".equals(new String(oldSecurityBytes, StandardCharsets.UTF_8).trim())) { CLIO.out( "Security is already enabled. You can disable it with 'bin/solr auth disable'. Existing security.json: \n" @@ -478,7 +479,7 @@ private void clearSecurityJson(CommandLine cli, boolean updateIncludeFileOnly) t .withUrl(zkHost) .withTimeout(SolrZkClientTimeout.DEFAULT_ZK_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8)); + zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8), true); } } } diff --git a/solr/core/src/java/org/apache/solr/cli/CreateTool.java b/solr/core/src/java/org/apache/solr/cli/CreateTool.java index 64f8a9ceaca..e62c42d185a 100644 --- a/solr/core/src/java/org/apache/solr/cli/CreateTool.java +++ b/solr/core/src/java/org/apache/solr/cli/CreateTool.java @@ -243,7 +243,9 @@ protected void createCollection(CloudSolrClient cloudSolrClient, CommandLine cli boolean configExistsInZk = confName != null && !confName.trim().isEmpty() - && ZkStateReader.from(cloudSolrClient).getZkClient().exists("/configs/" + confName); + && ZkStateReader.from(cloudSolrClient) + .getZkClient() + .exists("/configs/" + confName, true); if (CollectionAdminParams.SYSTEM_COLL.equals(collectionName)) { // do nothing diff --git a/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java b/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java index 4b106a540b5..dad5bdbbe94 100644 --- a/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java +++ b/solr/core/src/java/org/apache/solr/cli/ZkRmTool.java @@ -87,7 +87,7 @@ public void runImpl(CommandLine cli) throws Exception { .withUrl(zkHost) .withTimeout(SolrZkClientTimeout.DEFAULT_ZK_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - if (!recurse && zkClient.getChildren(znode, null).size() != 0) { + if (!recurse && zkClient.getChildren(znode, null, true).size() != 0) { throw new SolrServerException( "ZooKeeper node " + znode + " has children and recurse has NOT been specified."); } diff --git a/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java b/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java index fc3d7239202..de9181e505c 100644 --- a/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java +++ b/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java @@ -140,10 +140,10 @@ public static String unifiedResourcePath(SolrResourceLoader loader) { public static Map getTrustedKeys(SolrZkClient zk, String dir) { Map result = new HashMap<>(); try { - List children = zk.getChildren("/keys/" + dir, null); + List children = zk.getChildren("/keys/" + dir, null, true); for (String key : children) { if (key.endsWith(".der")) - result.put(key, zk.getData("/keys/" + dir + "/" + key, null, null)); + result.put(key, zk.getData("/keys/" + dir + "/" + key, null, null, true)); } } catch (KeeperException.NoNodeException e) { log.info("Error fetching key names"); diff --git a/solr/core/src/java/org/apache/solr/cloud/DistributedApiAsyncTracker.java b/solr/core/src/java/org/apache/solr/cloud/DistributedApiAsyncTracker.java index 6120d8ad6b2..8ebdb2ae287 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedApiAsyncTracker.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedApiAsyncTracker.java @@ -311,8 +311,8 @@ enum State { this.rootNodePath = rootNodePath; try { - if (!zkClient.exists(rootNodePath)) { - zkClient.makePath(rootNodePath, new byte[0], CreateMode.PERSISTENT); + if (!zkClient.exists(rootNodePath, true)) { + zkClient.makePath(rootNodePath, new byte[0], CreateMode.PERSISTENT, true); } } catch (KeeperException.NodeExistsException nee) { // Some other thread (on this or another JVM) beat us to create the node, that's ok, the @@ -329,25 +329,27 @@ void createNewInFlightTask(String asyncId) throws KeeperException, InterruptedEx zkClient.create( getPath(asyncId), State.SUBMITTED.shorthand.getBytes(StandardCharsets.UTF_8), - CreateMode.EPHEMERAL); + CreateMode.EPHEMERAL, + true); } void setTaskRunning(String asyncId) throws KeeperException, InterruptedException { - zkClient.setData(getPath(asyncId), State.RUNNING.shorthand.getBytes(StandardCharsets.UTF_8)); + zkClient.setData( + getPath(asyncId), State.RUNNING.shorthand.getBytes(StandardCharsets.UTF_8), true); } void deleteInFlightTask(String asyncId) throws KeeperException, InterruptedException { - zkClient.delete(getPath(asyncId), -1); + zkClient.delete(getPath(asyncId), -1, true); } State getInFlightState(String asyncId) throws KeeperException, InterruptedException { - if (!zkClient.exists(getPath(asyncId))) { + if (!zkClient.exists(getPath(asyncId), true)) { return State.NOT_FOUND; } final byte[] bytes; try { - bytes = zkClient.getData(getPath(asyncId), null, null); + bytes = zkClient.getData(getPath(asyncId), null, null, true); } catch (KeeperException.NoNodeException nne) { // Unlikely race, but not impossible... if (log.isInfoEnabled()) { diff --git a/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java b/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java index 02543e51e40..bc565ad97e8 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java @@ -598,7 +598,7 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState) if (updater.isCollectionCreation()) { // The state.json file does not exist yet (more precisely it is assumed not to exist) log.debug("going to create collection {}", jsonPath); - zkStateReader.getZkClient().create(jsonPath, stateJson, CreateMode.PERSISTENT); + zkStateReader.getZkClient().create(jsonPath, stateJson, CreateMode.PERSISTENT, true); } else { // We're updating an existing state.json if (log.isDebugEnabled()) { @@ -607,7 +607,9 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState) jsonPath, collection.getZNodeVersion()); } - zkStateReader.getZkClient().setData(jsonPath, stateJson, collection.getZNodeVersion()); + zkStateReader + .getZkClient() + .setData(jsonPath, stateJson, collection.getZNodeVersion(), true); } } } @@ -621,7 +623,7 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState) private ClusterState fetchStateForCollection() throws KeeperException, InterruptedException { String collectionStatePath = DocCollection.getCollectionPath(updater.getCollectionName()); Stat stat = new Stat(); - byte[] data = zkStateReader.getZkClient().getData(collectionStatePath, null, stat); + byte[] data = zkStateReader.getZkClient().getData(collectionStatePath, null, stat, true); // This factory method can detect a missing configName and supply it by reading it from the // old ZK location. @@ -931,7 +933,7 @@ public static void executeNodeDownStateUpdate(String nodeName, ZkStateReader zkS try { final List collectionNames = - zkStateReader.getZkClient().getChildren(COLLECTIONS_ZKNODE, null); + zkStateReader.getZkClient().getChildren(COLLECTIONS_ZKNODE, null, true); // Collections are totally independent of each other. Multiple threads could share the load // here (need a ZK connection for each though). diff --git a/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java b/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java index 532a782825b..fb2347c3e82 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java @@ -68,7 +68,8 @@ private void assertKeyFormat(String trackingId) { public void put(String trackingId, byte[] data) throws KeeperException, InterruptedException { assertKeyFormat(trackingId); - zookeeper.makePath(dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, false); + zookeeper.makePath( + dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, false, true); } /** @@ -80,7 +81,8 @@ public boolean putIfAbsent(String trackingId, byte[] data) throws KeeperException, InterruptedException { assertKeyFormat(trackingId); try { - zookeeper.makePath(dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, true); + zookeeper.makePath( + dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, true, true); return true; } catch (NodeExistsException e) { return false; @@ -88,16 +90,16 @@ public boolean putIfAbsent(String trackingId, byte[] data) } public byte[] get(String trackingId) throws KeeperException, InterruptedException { - return zookeeper.getData(dir + "/" + PREFIX + trackingId, null, null); + return zookeeper.getData(dir + "/" + PREFIX + trackingId, null, null, true); } public boolean contains(String trackingId) throws KeeperException, InterruptedException { - return zookeeper.exists(dir + "/" + PREFIX + trackingId); + return zookeeper.exists(dir + "/" + PREFIX + trackingId, true); } public int size() throws KeeperException, InterruptedException { Stat stat = new Stat(); - zookeeper.getData(dir, null, stat); + zookeeper.getData(dir, null, stat, true); return stat.getNumChildren(); } @@ -108,7 +110,7 @@ public int size() throws KeeperException, InterruptedException { public boolean remove(String trackingId) throws KeeperException, InterruptedException { final var path = dir + "/" + PREFIX + trackingId; try { - zookeeper.delete(path, -1); + zookeeper.delete(path, -1, true); } catch (KeeperException.NoNodeException e) { return false; } catch (KeeperException.NotEmptyException hack) { @@ -121,15 +123,15 @@ public boolean remove(String trackingId) throws KeeperException, InterruptedExce /** Helper method to clear all child nodes for a parent node. */ public void clear() throws KeeperException, InterruptedException { - List childNames = zookeeper.getChildren(dir, null); + List childNames = zookeeper.getChildren(dir, null, true); for (String childName : childNames) { - zookeeper.delete(dir + "/" + childName, -1); + zookeeper.delete(dir + "/" + childName, -1, true); } } /** Returns the keys of all the elements in the map */ public Collection keys() throws KeeperException, InterruptedException { - List childs = zookeeper.getChildren(dir, null); + List childs = zookeeper.getChildren(dir, null, true); final List ids = new ArrayList<>(childs.size()); childs.stream().forEach((child) -> ids.add(child.substring(PREFIX.length()))); return ids; diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java index e41546f24da..1ace066447c 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java @@ -55,7 +55,7 @@ public void cancelElection() throws InterruptedException, KeeperException { if (leaderSeqPath != null) { try { log.debug("Canceling election {}", leaderSeqPath); - zkClient.delete(leaderSeqPath, -1); + zkClient.delete(leaderSeqPath, -1, true); } catch (NoNodeException e) { // fine log.debug("cancelElection did not find election node to remove {}", leaderSeqPath); diff --git a/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java b/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java index 760d6ae04ab..1b13d470240 100644 --- a/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java +++ b/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java @@ -94,7 +94,7 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement context.checkIfIamLeaderFired(); // get all other numbers... final String holdElectionPath = context.electionPath + ELECTION_NODE; - List seqs = zkClient.getChildren(holdElectionPath, null); + List seqs = zkClient.getChildren(holdElectionPath, null, true); sortSeqs(seqs); String leaderSeqNodeName = @@ -114,7 +114,7 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement try { String toDelete = holdElectionPath + "/" + elec; log.warn("Deleting duplicate registration: {}", toDelete); - zkClient.delete(toDelete, -1); + zkClient.delete(toDelete, -1, true); } catch (KeeperException.NoNodeException e) { // ignore } @@ -148,7 +148,8 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement watcher = new ElectionWatcher( context.leaderSeqPath, watchedNode, getSeq(context.leaderSeqPath), context), - null); + null, + true); log.debug("Watching path {} to know if I could be the leader", watchedNode); } catch (KeeperException.SessionExpiredException e) { throw e; @@ -239,7 +240,10 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo if (nodes.size() < 2) { leaderSeqPath = zkClient.create( - shardsElectZkPath + "/" + id + "-n_", null, CreateMode.EPHEMERAL_SEQUENTIAL); + shardsElectZkPath + "/" + id + "-n_", + null, + CreateMode.EPHEMERAL_SEQUENTIAL, + false); } else { String firstInLine = nodes.get(1); log.debug("The current head: {}", firstInLine); @@ -248,12 +252,15 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo throw new IllegalStateException("Could not find regex match in:" + firstInLine); } leaderSeqPath = shardsElectZkPath + "/" + id + "-n_" + m.group(1); - zkClient.create(leaderSeqPath, null, CreateMode.EPHEMERAL); + zkClient.create(leaderSeqPath, null, CreateMode.EPHEMERAL, false); } } else { leaderSeqPath = zkClient.create( - shardsElectZkPath + "/" + id + "-n_", null, CreateMode.EPHEMERAL_SEQUENTIAL); + shardsElectZkPath + "/" + id + "-n_", + null, + CreateMode.EPHEMERAL_SEQUENTIAL, + false); } log.debug("Joined leadership election with path: {}", leaderSeqPath); @@ -261,7 +268,7 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo cont = false; } catch (ConnectionLossException e) { // we don't know if we made our node or not... - List entries = zkClient.getChildren(shardsElectZkPath, null); + List entries = zkClient.getChildren(shardsElectZkPath, null, true); boolean foundId = false; for (String entry : entries) { @@ -329,7 +336,7 @@ public void process(WatchedEvent event) { if (canceled) { log.debug("This watcher is not active anymore {}", myNode); try { - zkClient.delete(myNode, -1); + zkClient.delete(myNode, -1, true); } catch (KeeperException.NoNodeException nne) { // expected . don't do anything } catch (Exception e) { @@ -357,7 +364,8 @@ public void setup(final ElectionContext context) throws InterruptedException, Ke ZkMaintenanceUtils.ensureExists(electZKPath, zkClient); } else { // we use 2 param so that replica won't create /collection/{collection} if it doesn't exist - ZkMaintenanceUtils.ensureExists(electZKPath, null, CreateMode.PERSISTENT, zkClient, 2); + ZkMaintenanceUtils.ensureExists( + electZKPath, (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); } this.context = context; diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.java index b37453948d5..b81673423d1 100644 --- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java +++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java @@ -479,7 +479,7 @@ private void checkIfIamStillLeader() { final String path = OVERSEER_ELECT + "/leader"; byte[] data; try { - data = zkClient.getData(path, null, stat); + data = zkClient.getData(path, null, stat, true); } catch (IllegalStateException e) { return; } catch (Exception e) { @@ -494,7 +494,7 @@ private void checkIfIamStillLeader() { log.warn( "I (id={}) am exiting, but I'm still the leader", overseerCollectionConfigSetProcessor.getId()); - zkClient.delete(path, stat.getVersion()); + zkClient.delete(path, stat.getVersion(), true); } catch (KeeperException.BadVersionException e) { // no problem ignore it some other Overseer has already taken over } catch (Exception e) { @@ -616,7 +616,7 @@ private LeaderStatus amILeader() { String propsId = null; try { ZkNodeProps props = - ZkNodeProps.load(zkClient.getData(OVERSEER_ELECT + "/leader", null, null)); + ZkNodeProps.load(zkClient.getData(OVERSEER_ELECT + "/leader", null, null, true)); propsId = props.getStr(ID); if (myId.equals(propsId)) { return LeaderStatus.YES; @@ -1184,7 +1184,7 @@ OverseerTaskQueue getConfigSetQueue(final SolrZkClient zkClient, Stats zkStats) private void createOverseerNode(final SolrZkClient zkClient) { try { - zkClient.create("/overseer", new byte[0], CreateMode.PERSISTENT); + zkClient.create("/overseer", new byte[0], CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { // ok } catch (InterruptedException e) { diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java index 270d746bc4e..8eb8a6d1386 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java @@ -62,7 +62,7 @@ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStartMs) final String id = leaderSeqPath.substring(leaderSeqPath.lastIndexOf('/') + 1); ZkNodeProps myProps = new ZkNodeProps(ID, id); - zkClient.makePath(leaderPath, Utils.toJSON(myProps), CreateMode.EPHEMERAL); + zkClient.makePath(leaderPath, Utils.toJSON(myProps), CreateMode.EPHEMERAL, true); if (pauseBeforeStartMs > 0) { try { Thread.sleep(pauseBeforeStartMs); diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java b/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java index 0e1a0acd58e..63dca3f1c61 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java @@ -67,8 +67,9 @@ public OverseerNodePrioritizer( public synchronized void prioritizeOverseerNodes(String overseerId) throws Exception { SolrZkClient zk = zkStateReader.getZkClient(); List overseerDesignates = new ArrayList<>(); - if (zk.exists(ZkStateReader.ROLES)) { - Map m = (Map) Utils.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat())); + if (zk.exists(ZkStateReader.ROLES, true)) { + Map m = + (Map) Utils.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat(), true)); @SuppressWarnings("unchecked") List l = (List) m.get("overseer"); if (l != null) { diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java index 9ebe8644626..b63afbcf0c4 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java @@ -431,7 +431,7 @@ public static List getSortedOverseerNodeNames(SolrZkClient zk) throws KeeperException, InterruptedException { List children = null; try { - children = zk.getChildren(Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE, null); + children = zk.getChildren(Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE, null, true); } catch (Exception e) { log.warn("error ", e); return new ArrayList<>(); @@ -446,7 +446,7 @@ public static List getSortedElectionNodes(SolrZkClient zk, String path) throws KeeperException, InterruptedException { List children = null; try { - children = zk.getChildren(path, null); + children = zk.getChildren(path, null, true); LeaderElector.sortSeqs(children); return children; } catch (Exception e) { @@ -464,7 +464,7 @@ public static String getLeaderId(SolrZkClient zkClient) throws KeeperException, InterruptedException { byte[] data = null; try { - data = zkClient.getData(Overseer.OVERSEER_ELECT + "/leader", null, new Stat()); + data = zkClient.getData(Overseer.OVERSEER_ELECT + "/leader", null, new Stat(), true); } catch (KeeperException.NoNodeException e) { return null; } @@ -480,7 +480,9 @@ protected LeaderStatus amILeader() { try { ZkNodeProps props = ZkNodeProps.load( - zkStateReader.getZkClient().getData(Overseer.OVERSEER_ELECT + "/leader", null, null)); + zkStateReader + .getZkClient() + .getData(Overseer.OVERSEER_ELECT + "/leader", null, null, true)); propsId = props.getStr(ID); if (myId.equals(propsId)) { return LeaderStatus.YES; diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java index a7b81e2889e..3092dce185e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java @@ -77,12 +77,12 @@ public void allowOverseerPendingTasksToComplete() { public boolean containsTaskWithRequestId(String requestIdKey, String requestId) throws KeeperException, InterruptedException { - List childNames = zookeeper.getChildren(dir, null); + List childNames = zookeeper.getChildren(dir, null, true); stats.setQueueLength(childNames.size()); for (String childName : childNames) { if (childName != null && childName.startsWith(PREFIX)) { try { - byte[] data = zookeeper.getData(dir + "/" + childName, null, null); + byte[] data = zookeeper.getData(dir + "/" + childName, null, null, true); if (data != null) { ZkNodeProps message = ZkNodeProps.load(data); if (message.containsKey(requestIdKey)) { @@ -109,7 +109,7 @@ public void remove(QueueEvent event) throws KeeperException, InterruptedExceptio String responsePath = dir + "/" + RESPONSE_PREFIX + path.substring(path.lastIndexOf('-') + 1); try { - zookeeper.setData(responsePath, event.getBytes()); + zookeeper.setData(responsePath, event.getBytes(), true); } catch (KeeperException.NoNodeException ignored) { // we must handle the race case where the node no longer exists log.info( @@ -117,7 +117,7 @@ public void remove(QueueEvent event) throws KeeperException, InterruptedExceptio responsePath); } try { - zookeeper.delete(path, -1); + zookeeper.delete(path, -1, true); } catch (KeeperException.NoNodeException ignored) { } } finally { @@ -196,10 +196,10 @@ private String createData(String path, byte[] data, CreateMode mode) throws KeeperException, InterruptedException { for (; ; ) { try { - return zookeeper.create(path, data, mode); + return zookeeper.create(path, data, mode, true); } catch (KeeperException.NoNodeException e) { try { - zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT); + zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException ne) { // someone created it } @@ -221,7 +221,7 @@ public QueueEvent offer(byte[] data, long timeout) throws KeeperException, Inter String watchID = createResponseNode(); LatchWatcher watcher = new LatchWatcher(); - Stat stat = zookeeper.exists(watchID, watcher); + Stat stat = zookeeper.exists(watchID, watcher, true); // create the request node createRequestNode(data, watchID); @@ -230,11 +230,11 @@ public QueueEvent offer(byte[] data, long timeout) throws KeeperException, Inter pendingResponses.incrementAndGet(); watcher.await(timeout); } - byte[] bytes = zookeeper.getData(watchID, null, null); + byte[] bytes = zookeeper.getData(watchID, null, null, true); // create the event before deleting the node, otherwise we can get the deleted // event from the watcher. QueueEvent event = new QueueEvent(watchID, bytes, watcher.getWatchedEvent()); - zookeeper.delete(watchID, -1); + zookeeper.delete(watchID, -1, true); return event; } finally { time.stop(); @@ -295,7 +295,9 @@ public String getTailId() throws KeeperException, InterruptedException { try { QueueEvent queueEvent = new QueueEvent( - dir + "/" + headNode, zookeeper.getData(dir + "/" + headNode, null, null), null); + dir + "/" + headNode, + zookeeper.getData(dir + "/" + headNode, null, null, true), + null); return queueEvent.getId(); } catch (KeeperException.NoNodeException e) { // Another client removed the node first, try next diff --git a/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java b/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java index c09a38d418c..fee0d32bf50 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java +++ b/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java @@ -40,7 +40,7 @@ public ClusterState run(ClusterState clusterState, Overseer overseer, ZkStateWri overseer .getZkStateReader() .getZkClient() - .exists(DocCollection.getCollectionPath(collection), null); + .exists(DocCollection.getCollectionPath(collection), null, true); if (stat == null) { // collection does not exist return clusterState.copyWith(collection, null); diff --git a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java index 743f10a4524..c57a43980b1 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java @@ -443,7 +443,7 @@ private boolean waitForReplicasToComeUp(int timeoutms) throws InterruptedExcepti if (slices != null) { int found = 0; try { - found = zkClient.getChildren(shardsElectZkPath, null).size(); + found = zkClient.getChildren(shardsElectZkPath, null, true).size(); } catch (KeeperException e) { if (e instanceof KeeperException.SessionExpiredException) { // if the session has expired, then another election will be launched, so diff --git a/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java b/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java index 510c0f1c1f5..c4c8923b218 100644 --- a/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java +++ b/solr/core/src/java/org/apache/solr/cloud/SizeLimitedDistributedMap.java @@ -65,7 +65,7 @@ public boolean putIfAbsent(String trackingId, byte[] data) private void shrinkIfNeeded() throws KeeperException, InterruptedException { if (this.size() >= maxSize) { // Bring down the size - List children = zookeeper.getChildren(dir, null); + List children = zookeeper.getChildren(dir, null, true); int cleanupSize = maxSize / 10; @@ -79,7 +79,7 @@ protected boolean lessThan(Long a, Long b) { Map childToModificationZxid = CollectionUtil.newHashMap(children.size()); for (String child : children) { - Stat stat = zookeeper.exists(dir + "/" + child, null); + Stat stat = zookeeper.exists(dir + "/" + child, null, true); if (stat != null) { priorityQueue.insertWithOverflow(stat.getMzxid()); childToModificationZxid.put(child, stat.getMzxid()); diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java index 45e7895cc63..8e058a32a9a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java @@ -398,7 +398,7 @@ public static void main(String[] args) stdout.println("-" + MAKEPATH + " requires one arg - the path to make"); System.exit(1); } - zkClient.makePath(arglist.get(0)); + zkClient.makePath(arglist.get(0), true); } else if (line.getOptionValue(CMD).equalsIgnoreCase(PUT)) { List arglist = line.getArgList(); if (arglist.size() != 2) { @@ -406,17 +406,16 @@ public static void main(String[] args) "-" + PUT + " requires two args - the path to create and the data string"); System.exit(1); } - String path = arglist.get(0); byte[] data = arglist.get(1).getBytes(StandardCharsets.UTF_8); if (shouldCompressData(data, path, minStateByteLenForCompression)) { // state.json should be compressed before being put to ZK data = compressor.compressBytes(data, data.length / 10); } - if (zkClient.exists(path)) { - zkClient.setData(path, data); + if (zkClient.exists(path, true)) { + zkClient.setData(path, data, true); } else { - zkClient.makePath(path, data, CreateMode.PERSISTENT); + zkClient.makePath(path, data, CreateMode.PERSISTENT, true); } } else if (line.getOptionValue(CMD).equalsIgnoreCase(PUT_FILE)) { List arglist = line.getArgList(); @@ -434,10 +433,10 @@ public static void main(String[] args) // state.json should be compressed before being put to ZK data = compressor.compressBytes(data, data.length / 10); } - if (zkClient.exists(path)) { - zkClient.setData(path, data); + if (zkClient.exists(path, true)) { + zkClient.setData(path, data, true); } else { - zkClient.makePath(path, data, CreateMode.PERSISTENT); + zkClient.makePath(path, data, CreateMode.PERSISTENT, true); } } else if (line.getOptionValue(CMD).equalsIgnoreCase(GET)) { List arglist = line.getArgList(); @@ -445,7 +444,7 @@ public static void main(String[] args) stdout.println("-" + GET + " requires one arg - the path to get"); System.exit(1); } - byte[] data = zkClient.getData(arglist.get(0), null, null); + byte[] data = zkClient.getData(arglist.get(0), null, null, true); stdout.println(new String(data, StandardCharsets.UTF_8)); } else if (line.getOptionValue(CMD).equalsIgnoreCase(GET_FILE)) { List arglist = line.getArgList(); @@ -454,7 +453,7 @@ public static void main(String[] args) "-" + GET_FILE + "requires two args - the path to get and the file to save it to"); System.exit(1); } - byte[] data = zkClient.getData(arglist.get(0), null, null); + byte[] data = zkClient.getData(arglist.get(0), null, null, true); Files.write(Path.of(arglist.get(1)), data); } else if (line.getOptionValue(CMD).equals(UPDATEACLS)) { List arglist = line.getArgList(); diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java b/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java index fa3f1b4037b..1718edbf56a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java @@ -72,7 +72,7 @@ public SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd) { // For back compat with cores that can create collections without the collections API try { - if (!zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + colName)) { + if (!zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + colName, true)) { // TODO remove this functionality or maybe move to a CLI mechanism log.warn( "Auto-creating collection (in ZK) from core descriptor (on disk). This feature may go away!"); @@ -117,7 +117,7 @@ protected Long getCurrentSchemaModificationVersion( String zkPath = CONFIGS_ZKNODE + "/" + configSet + "/" + schemaFile; Stat stat; try { - stat = zkClient.exists(zkPath, null); + stat = zkClient.exists(zkPath, null, true); } catch (KeeperException e) { log.warn("Unexpected exception when getting modification time of {}", zkPath, e); return null; // debatable; we'll see an error soon if there's a real problem @@ -139,7 +139,7 @@ public String configSetName(CoreDescriptor cd) { @Override public boolean checkConfigExists(String configName) throws IOException { try { - return zkClient.exists(CONFIGS_ZKNODE + "/" + configName); + return zkClient.exists(CONFIGS_ZKNODE + "/" + configName, true); } catch (KeeperException | InterruptedException e) { throw new IOException( "Error checking whether config exists", SolrZkClient.checkInterrupted(e)); @@ -200,7 +200,7 @@ public void uploadFileToConfig( log.warn("Not including uploading file to config, as it is a forbidden type: {}", fileName); } else { // if overwriteOnExists is true then zkClient#makePath failOnExists is set to false - zkClient.makePath(filePath, data, CreateMode.PERSISTENT, null, !overwriteOnExists); + zkClient.makePath(filePath, data, CreateMode.PERSISTENT, null, !overwriteOnExists, true); } } catch (KeeperException.NodeExistsException nodeExistsException) { throw new SolrException( @@ -224,7 +224,8 @@ public void setConfigMetadata(String configName, Map data) throw Utils.toJSON(data), CreateMode.PERSISTENT, null, - false); + false, + true); } catch (KeeperException | InterruptedException e) { throw new IOException("Error setting config metadata", SolrZkClient.checkInterrupted(e)); } @@ -236,7 +237,7 @@ public Map getConfigMetadata(String configName) throws IOExcepti @SuppressWarnings("unchecked") Map data = (Map) - Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null)); + Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null, true)); return data; } catch (KeeperException | InterruptedException e) { throw new IOException("Error getting config metadata", SolrZkClient.checkInterrupted(e)); @@ -251,7 +252,7 @@ public void downloadConfig(String configName, Path dir) throws IOException { @Override public byte[] downloadFileFromConfig(String configName, String filePath) throws IOException { try { - return zkClient.getData(CONFIGS_ZKNODE + "/" + configName + "/" + filePath, null, null); + return zkClient.getData(CONFIGS_ZKNODE + "/" + configName + "/" + filePath, null, null, true); } catch (KeeperException.NoNodeException e) { return null; } catch (KeeperException | InterruptedException e) { @@ -262,7 +263,7 @@ public byte[] downloadFileFromConfig(String configName, String filePath) throws @Override public List listConfigs() throws IOException { try { - return zkClient.getChildren(CONFIGS_ZKNODE, null); + return zkClient.getChildren(CONFIGS_ZKNODE, null, true); } catch (KeeperException.NoNodeException e) { return Collections.emptyList(); } catch (KeeperException | InterruptedException e) { @@ -309,9 +310,9 @@ public List getAllConfigFiles(String configName) throws IOException { private void copyConfigDirFromZk(String fromZkPath, String toZkPath) throws IOException { try { - List files = zkClient.getChildren(fromZkPath, null); + List files = zkClient.getChildren(fromZkPath, null, true); for (String file : files) { - List children = zkClient.getChildren(fromZkPath + "/" + file, null); + List children = zkClient.getChildren(fromZkPath + "/" + file, null, true); if (children.size() == 0) { copyData(fromZkPath + "/" + file, toZkPath + "/" + file); } else { @@ -337,8 +338,8 @@ private void copyData(String fromZkFilePath, String toZkFilePath) toZkFilePath); } else { log.debug("Copying zk node {} to {}", fromZkFilePath, toZkFilePath); - byte[] data = zkClient.getData(fromZkFilePath, null, null); - zkClient.makePath(toZkFilePath, data); + byte[] data = zkClient.getData(fromZkFilePath, null, null, true); + zkClient.makePath(toZkFilePath, data, true); } } diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java index 44e72a76d84..1770f2df748 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -526,17 +526,18 @@ private void onReconnect(Supplier> descriptorsSupplier) { */ private void checkNoOldClusterstate(final SolrZkClient zkClient) throws InterruptedException { try { - if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE)) { + if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, true)) { return; } - final byte[] data = zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null); + final byte[] data = + zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null, true); if (Arrays.equals("{}".getBytes(StandardCharsets.UTF_8), data)) { // Empty json. This log will only occur once. log.warn( "{} no longer supported starting with Solr 9. Found empty file on Zookeeper, deleting it.", ZkStateReader.UNSUPPORTED_CLUSTER_STATE); - zkClient.delete(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, -1); + zkClient.delete(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, -1, true); } else { // /clusterstate.json not empty: refuse to start but do not automatically delete. A bit of a // pain but user shouldn't have older collections at this stage anyway. @@ -600,7 +601,8 @@ private void registerAllCoresAsDown( + "/leader_elect/" + slice + "/election", - null) + null, + true) .size(); if (children == 0) { log.debug( @@ -922,7 +924,7 @@ public static void createClusterZkNodes(SolrZkClient zkClient) private static void repairSecurityJson(SolrZkClient zkClient) throws KeeperException, InterruptedException { - List securityConfAcl = zkClient.getACL(ZkStateReader.SOLR_SECURITY_CONF_PATH, null); + List securityConfAcl = zkClient.getACL(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, true); ACLProvider aclProvider = zkClient.getZkACLProvider(); boolean tryUpdate = false; @@ -989,7 +991,7 @@ private void init() { } } - Stat stat = zkClient.exists(ZkStateReader.LIVE_NODES_ZKNODE, null); + Stat stat = zkClient.exists(ZkStateReader.LIVE_NODES_ZKNODE, null, true); if (stat != null && stat.getNumChildren() > 0) { publishAndWaitForDownStates(); } @@ -1018,7 +1020,7 @@ private void checkForExistingEphemeralNode() throws KeeperException, Interrupted String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; - if (!zkClient.exists(nodePath)) { + if (!zkClient.exists(nodePath, true)) { return; } @@ -1033,7 +1035,8 @@ private void checkForExistingEphemeralNode() throws KeeperException, Interrupted if (Watcher.Event.EventType.NodeDeleted.equals(event.getType())) { deletedLatch.countDown(); } - }); + }, + true); if (stat == null) { // znode suddenly disappeared but that's okay @@ -1147,10 +1150,10 @@ public static boolean checkChrootPath(String zkHost, boolean create) .withTimeout(SolrZkClientTimeout.DEFAULT_ZK_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS) .withConnTimeOut(SolrZkClientTimeout.DEFAULT_ZK_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS) .build(); - boolean exists = tmpClient.exists(chrootPath); + boolean exists = tmpClient.exists(chrootPath, true); if (!exists && create) { log.info("creating chroot {}", chrootPath); - tmpClient.makePath(chrootPath, false); + tmpClient.makePath(chrootPath, false, true); exists = true; } tmpClient.close(); @@ -1193,7 +1196,7 @@ public void removeEphemeralLiveNode() throws KeeperException, InterruptedExcepti String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; log.info("Remove node as live in ZooKeeper:{}", nodePath); try { - zkClient.delete(nodePath, -1); + zkClient.delete(nodePath, -1, true); } catch (NoNodeException e) { } @@ -1205,7 +1208,7 @@ public String getNodeName() { /** Returns true if the path exists */ public boolean pathExists(String path) throws KeeperException, InterruptedException { - return zkClient.exists(path); + return zkClient.exists(path, true); } /** @@ -1520,7 +1523,8 @@ public ZkCoreNodeProps getLeaderProps( while (iterCount-- > 0) { try { byte[] data = - zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null); + zkClient.getData( + ZkStateReader.getShardLeadersPath(collection, slice), null, null, true); ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data)); return leaderProps; } catch (InterruptedException e) { @@ -2186,14 +2190,14 @@ public static void linkConfSet(SolrZkClient zkClient, String collection, String log.debug("Load collection config from:{}", path); byte[] data; try { - data = zkClient.getData(path, null, null); + data = zkClient.getData(path, null, null, true); } catch (NoNodeException e) { // if there is no node, we will try and create it // first try to make in case we are pre configuring ZkNodeProps props = new ZkNodeProps(CONFIGNAME_PROP, confSetName); try { - zkClient.makePath(path, Utils.toJSON(props), CreateMode.PERSISTENT); + zkClient.makePath(path, Utils.toJSON(props), CreateMode.PERSISTENT, null, true); } catch (KeeperException e2) { // it's okay if the node already exists if (e2.code() != KeeperException.Code.NODEEXISTS) { @@ -2201,7 +2205,7 @@ public static void linkConfSet(SolrZkClient zkClient, String collection, String } // if we fail creating, setdata // TODO: we should consider using version - zkClient.setData(path, Utils.toJSON(props)); + zkClient.setData(path, Utils.toJSON(props), true); } return; } @@ -2217,7 +2221,7 @@ public static void linkConfSet(SolrZkClient zkClient, String collection, String } // TODO: we should consider using version - zkClient.setData(path, Utils.toJSON(props)); + zkClient.setData(path, Utils.toJSON(props), true); } public ZkDistributedQueue getOverseerJobQueue() { @@ -2323,7 +2327,9 @@ public void rejoinOverseerElection(String electionNode, boolean joinAtHead) { if (electionNode.startsWith(getNodeName())) { try { zkClient.delete( - Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE + "/" + electionNode, -1); + Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE + "/" + electionNode, + -1, + true); } catch (NoNodeException e) { // no problem } catch (InterruptedException e) { @@ -2411,7 +2417,7 @@ public void rejoinShardLeaderElection(SolrParams params) { public void checkOverseerDesignate() { try { - byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat()); + byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true); if (data == null) return; Map roles = (Map) Utils.fromJSON(data); if (roles == null) return; @@ -2517,7 +2523,7 @@ public static int persistConfigResourceToZooKeeper( String errMsg = "Failed to persist resource at {0} - old {1}"; try { try { - Stat stat = zkClient.setData(resourceLocation, content, znodeVersion); + Stat stat = zkClient.setData(resourceLocation, content, znodeVersion, true); // if the set succeeded, it should have incremented the version by one always latestVersion = stat.getVersion(); log.info("Persisted config data to node {} ", resourceLocation); @@ -2525,12 +2531,12 @@ public static int persistConfigResourceToZooKeeper( } catch (NoNodeException e) { if (createIfNotExists) { try { - zkClient.create(resourceLocation, content, CreateMode.PERSISTENT); + zkClient.create(resourceLocation, content, CreateMode.PERSISTENT, true); latestVersion = 0; // just created so version must be zero touchConfDir(zkLoader); } catch (KeeperException.NodeExistsException nee) { try { - Stat stat = zkClient.exists(resourceLocation, null); + Stat stat = zkClient.exists(resourceLocation, null, true); if (log.isDebugEnabled()) { log.debug( "failed to set data version in zk is {} and expected version is {} ", @@ -2553,7 +2559,7 @@ public static int persistConfigResourceToZooKeeper( } catch (KeeperException.BadVersionException bve) { try { - zkClient.exists(resourceLocation, null); + zkClient.exists(resourceLocation, null, true); } catch (Exception e) { log.error("Exception during ZooKeeper node checking ", e); } @@ -2677,7 +2683,7 @@ public void process(WatchedEvent event) { Stat stat = null; try { - stat = zkClient.exists(zkDir, null); + stat = zkClient.exists(zkDir, null, true); } catch (KeeperException e) { // ignore , it is not a big deal } catch (InterruptedException e) { @@ -2731,7 +2737,7 @@ private boolean fireEventListeners(String zkDir) { private void setConfWatcher(String zkDir, Watcher watcher, Stat stat) { try { - Stat newStat = zkClient.exists(zkDir, watcher); + Stat newStat = zkClient.exists(zkDir, watcher, true); if (stat != null && newStat.getVersion() > stat.getVersion()) { // a race condition where a we missed an event fired // so fire the event listeners diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java index 469986960d6..ca29d53e9d7 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java @@ -92,7 +92,8 @@ protected ZkDistributedLock(SolrZkClient zkClient, String lockDir, String lockNo + DistributedCollectionConfigSetCommandRunner.ZK_PATH_SEPARATOR + lockNodePrefix, null, - CreateMode.EPHEMERAL_SEQUENTIAL); + CreateMode.EPHEMERAL_SEQUENTIAL, + false); sequence = getSequenceFromNodename(lockNode); } @@ -140,7 +141,7 @@ public void waitUntilAcquired() { String nodeToWatch = nodeToWatch(); while (nodeToWatch != null) { final DeletedNodeWatcher watcher = new DeletedNodeWatcher(nodeToWatch); - if (zkClient.exists(nodeToWatch, watcher) != null) { + if (zkClient.exists(nodeToWatch, watcher, true) != null) { watcher.await(); } nodeToWatch = nodeToWatch(); @@ -156,7 +157,7 @@ public void waitUntilAcquired() { @Override public void release() { try { - zkClient.delete(lockNode, -1); + zkClient.delete(lockNode, -1, true); released = true; } catch (KeeperException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); @@ -187,7 +188,7 @@ public boolean isAcquired() { * {@code null} if the lock is ours. */ String nodeToWatch() throws KeeperException, InterruptedException { - List locks = zkClient.getChildren(lockDir, null); + List locks = zkClient.getChildren(lockDir, null, true); boolean foundSelf = false; // For finding bugs or ZK bad behavior // We deviate from the ZK recipe here: we do not sort the list of nodes, and we stop waiting on // the first one we find that blocks us. This is done in O(n), whereas sorting is more diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLockFactory.java b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLockFactory.java index 76696dc3942..54434c8e6bc 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLockFactory.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLockFactory.java @@ -59,8 +59,8 @@ protected StringBuilder getPathPrefix() { private void makeLockPath(String lockNodePath) throws KeeperException, InterruptedException { try { - if (!zkClient.exists(lockNodePath)) { - zkClient.makePath(lockNodePath, new byte[0], CreateMode.PERSISTENT); + if (!zkClient.exists(lockNodePath, true)) { + zkClient.makePath(lockNodePath, new byte[0], CreateMode.PERSISTENT, true); } } catch (KeeperException.NodeExistsException nee) { // Some other thread (on this or another JVM) beat us to create the node, that's ok. diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java index c8bc80615f0..174b782c226 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java @@ -257,7 +257,7 @@ public void remove(Collection paths) throws KeeperException, Interrupted for (CuratorTransactionResult result : results) { if (result.getError() != 0) { try { - zookeeper.delete(result.getForPath(), -1); + zookeeper.delete(result.getForPath(), -1, true); } catch (KeeperException.NoNodeException ignored) { } } @@ -314,7 +314,7 @@ public void offer(byte[] data) throws KeeperException, InterruptedException { if (maxQueueSize > 0) { if (offerPermits.get() <= 0 || offerPermits.getAndDecrement() <= 0) { // If a max queue size is set, check it before creating a new queue item. - Stat stat = zookeeper.exists(dir, null); + Stat stat = zookeeper.exists(dir, null, true); if (stat == null) { // jump to the code below, which tries to create dir if it doesn't exist throw new KeeperException.NoNodeException(); @@ -332,12 +332,12 @@ public void offer(byte[] data) throws KeeperException, InterruptedException { // Explicitly set isDirty here so that synchronous same-thread calls behave as expected. // This will get set again when the watcher actually fires, but that's ok. - zookeeper.create(dir + "/" + PREFIX, data, CreateMode.PERSISTENT_SEQUENTIAL); + zookeeper.create(dir + "/" + PREFIX, data, CreateMode.PERSISTENT_SEQUENTIAL, true); isDirty = true; return; } catch (KeeperException.NoNodeException e) { try { - zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT); + zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException ne) { // someone created it } @@ -424,7 +424,7 @@ TreeSet fetchZkChildren(Watcher watcher) throws InterruptedException, Ke try { TreeSet orderedChildren = new TreeSet<>(); - List childNames = zookeeper.getChildren(dir, watcher); + List childNames = zookeeper.getChildren(dir, watcher, true); stats.setQueueLength(childNames.size()); for (String childName : childNames) { // Check format @@ -436,7 +436,7 @@ TreeSet fetchZkChildren(Watcher watcher) throws InterruptedException, Ke } return orderedChildren; } catch (KeeperException.NoNodeException e) { - zookeeper.makePath(dir, false); + zookeeper.makePath(dir, false, true); // go back to the loop and try again } } @@ -499,7 +499,7 @@ public Collection> peekElements( break; } try { - byte[] data = zookeeper.getData(dir + "/" + child, null, null); + byte[] data = zookeeper.getData(dir + "/" + child, null, null, true); result.add(new Pair<>(child, data)); } catch (KeeperException.NoNodeException e) { // Another client deleted the node first, remove the in-memory and continue. @@ -526,7 +526,7 @@ private byte[] firstElement() throws KeeperException, InterruptedException { return null; } try { - return zookeeper.getData(dir + "/" + firstChild, null, null); + return zookeeper.getData(dir + "/" + firstChild, null, null, true); } catch (KeeperException.NoNodeException e) { // Another client deleted the node first, remove the in-memory and retry. updateLock.lockInterruptibly(); @@ -549,8 +549,8 @@ private byte[] removeFirst() throws KeeperException, InterruptedException { } try { String path = dir + "/" + firstChild; - byte[] result = zookeeper.getData(path, null, null); - zookeeper.delete(path, -1); + byte[] result = zookeeper.getData(path, null, null, true); + zookeeper.delete(path, -1, true); stats.setQueueLength(knownChildren.size()); return result; } catch (KeeperException.NoNodeException e) { diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java b/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java index 1c856b1a5d2..74f1993dd0f 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java @@ -321,7 +321,7 @@ private boolean saveTerms(ShardTerms newTerms, String action) throws KeeperException.NoNodeException { byte[] znodeData = Utils.toJSON(newTerms); try { - Stat stat = zkClient.setData(znodePath, znodeData, newTerms.getVersion()); + Stat stat = zkClient.setData(znodePath, znodeData, newTerms.getVersion(), true); setNewTerms(new ShardTerms(newTerms, stat.getVersion())); log.info("Successful update of terms at {} to {} for {}", znodePath, newTerms, action); return true; @@ -348,7 +348,7 @@ private void ensureTermNodeExist() { try { Map initialTerms = new HashMap<>(); - zkClient.makePath(path, Utils.toJSON(initialTerms), CreateMode.PERSISTENT); + zkClient.makePath(path, Utils.toJSON(initialTerms), CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { // it's okay if another beats us creating the node } @@ -368,7 +368,7 @@ public void refreshTerms() { ShardTerms newTerms; try { Stat stat = new Stat(); - byte[] data = zkClient.getData(znodePath, null, stat); + byte[] data = zkClient.getData(znodePath, null, stat, true); newTerms = new ShardTerms((Map) Utils.fromJSON(data), stat.getVersion()); } catch (KeeperException | InterruptedException e) { Throwable cause = SolrZkClient.checkInterrupted(e); @@ -415,7 +415,7 @@ private void registerWatcher() throws KeeperException { }; try { // exists operation is faster than getData operation - zkClient.exists(znodePath, watcher); + zkClient.exists(znodePath, watcher, true); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SolrException( diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java b/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java index 0d9ef1c8338..4aa5990e0ea 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java @@ -58,7 +58,7 @@ public ZkSolrResourceLoader( public Pair getZkResourceInfo(String resource) { String file = (".".equals(resource)) ? configSetZkPath : configSetZkPath + "/" + resource; try { - Stat stat = zkController.getZkClient().exists(file, null); + Stat stat = zkController.getZkClient().exists(file, null, true); if (stat != null) { return new Pair<>(file, stat.getVersion()); } else { @@ -87,7 +87,7 @@ public InputStream openResource(String resource) throws IOException { try { if (zkController.pathExists(file)) { Stat stat = new Stat(); - byte[] bytes = zkController.getZkClient().getData(file, null, stat); + byte[] bytes = zkController.getZkClient().getData(file, null, stat, true); return new ZkByteArrayInputStream(bytes, file, stat); } else { // Path does not exists. We only retry for session expired exceptions. diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java index 59db03a4c73..9accbf4dc69 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java @@ -190,7 +190,9 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList resu if (zkStateReader.getClusterState().getCollectionOrNull(collection) == null) { if (zkStateReader .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection)) { + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true)) { // if the collection is not in the clusterstate, but is listed in zk, do nothing, it will // just be removed in the finally - we cannot continue, because the below code will error // if the collection is not in the clusterstate @@ -209,7 +209,7 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu try { String collectionPath = DocCollection.getCollectionPathRoot(collection); - if (zkStateReader.getZkClient().exists(collectionPath)) { + if (zkStateReader.getZkClient().exists(collectionPath, true)) { if (removeCounterNode) { zkStateReader.getZkClient().clean(collectionPath); } else { diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerRoleCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerRoleCmd.java index fc400ffb26a..d8e7a3dea64 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerRoleCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerRoleCmd.java @@ -75,12 +75,12 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu } String roleName = message.getStr("role"); - boolean nodeExists = zkClient.exists(ZkStateReader.ROLES); + boolean nodeExists = zkClient.exists(ZkStateReader.ROLES, true); if (nodeExists) { @SuppressWarnings("unchecked") Map> tmp = (Map>) - Utils.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat())); + Utils.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true)); roles = tmp; } else { roles = CollectionUtil.newLinkedHashMap(1); @@ -96,9 +96,9 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu } if (nodeExists) { - zkClient.setData(ZkStateReader.ROLES, Utils.toJSON(roles)); + zkClient.setData(ZkStateReader.ROLES, Utils.toJSON(roles), true); } else { - zkClient.create(ZkStateReader.ROLES, Utils.toJSON(roles), CreateMode.PERSISTENT); + zkClient.create(ZkStateReader.ROLES, Utils.toJSON(roles), CreateMode.PERSISTENT, true); } runPrioritizer(); } diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerStatusCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerStatusCmd.java index d7fad3f776f..0b841fe8790 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerStatusCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerStatusCmd.java @@ -175,13 +175,13 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu String leaderNode = OverseerTaskProcessor.getLeaderNode(zkStateReader.getZkClient()); results.add("leader", leaderNode); Stat stat = new Stat(); - zkStateReader.getZkClient().getData("/overseer/queue", null, stat); + zkStateReader.getZkClient().getData("/overseer/queue", null, stat, true); results.add("overseer_queue_size", stat.getNumChildren()); stat = new Stat(); - zkStateReader.getZkClient().getData("/overseer/queue-work", null, stat); + zkStateReader.getZkClient().getData("/overseer/queue-work", null, stat, true); results.add("overseer_work_queue_size", stat.getNumChildren()); stat = new Stat(); - zkStateReader.getZkClient().getData("/overseer/collection-queue-work", null, stat); + zkStateReader.getZkClient().getData("/overseer/collection-queue-work", null, stat, true); results.add("overseer_collection_queue_size", stat.getNumChildren()); NamedList overseerStats = new NamedList<>(); diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java index f849ab24d92..0060eb676af 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/SplitShardCmd.java @@ -212,7 +212,10 @@ public boolean split(ClusterState clusterState, ZkNodeProps message, NamedList -1) return true; return false; diff --git a/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java index 968b2186a93..be6a1a83c2f 100644 --- a/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java +++ b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java @@ -294,7 +294,7 @@ public void uploadCollectionProperties(String collectionName) throws IOException repository.openInput(sourceDir, ZkStateReader.COLLECTION_PROPS_ZKNODE, IOContext.DEFAULT)) { byte[] arr = new byte[(int) is.length()]; is.readBytes(arr, 0, (int) is.length()); - zkStateReader.getZkClient().create(zkPath, arr, CreateMode.PERSISTENT); + zkStateReader.getZkClient().create(zkPath, arr, CreateMode.PERSISTENT, true); } catch (KeeperException | InterruptedException e) { throw new IOException( "Error uploading file to zookeeper path " + source.toString() + " to " + zkPath, @@ -312,13 +312,13 @@ public void downloadCollectionProperties(String collectionName) throws IOExcepti + ZkStateReader.COLLECTION_PROPS_ZKNODE; try { - if (!zkStateReader.getZkClient().exists(zkPath)) { + if (!zkStateReader.getZkClient().exists(zkPath, true)) { // Nothing to back up return; } try (OutputStream os = repository.createOutput(dest)) { - byte[] data = zkStateReader.getZkClient().getData(zkPath, null, null); + byte[] data = zkStateReader.getZkClient().getData(zkPath, null, null, true); os.write(data); } } catch (KeeperException | InterruptedException e) { diff --git a/solr/core/src/java/org/apache/solr/core/snapshots/SolrSnapshotManager.java b/solr/core/src/java/org/apache/solr/core/snapshots/SolrSnapshotManager.java index db83b2e6d11..acdbd722717 100644 --- a/solr/core/src/java/org/apache/solr/core/snapshots/SolrSnapshotManager.java +++ b/solr/core/src/java/org/apache/solr/core/snapshots/SolrSnapshotManager.java @@ -74,7 +74,7 @@ public static boolean snapshotExists( SolrZkClient zkClient, String collectionName, String commitName) throws KeeperException, InterruptedException { String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.ofNullable(commitName)); - return zkClient.exists(zkPath); + return zkClient.exists(zkPath, true); } /** @@ -90,7 +90,7 @@ public static void createCollectionLevelSnapshot( SolrZkClient zkClient, String collectionName, CollectionSnapshotMetaData meta) throws KeeperException, InterruptedException { String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.of(meta.getName())); - zkClient.makePath(zkPath, Utils.toJSON(meta), CreateMode.PERSISTENT); + zkClient.makePath(zkPath, Utils.toJSON(meta), CreateMode.PERSISTENT, true); } /** @@ -106,7 +106,7 @@ public static void updateCollectionLevelSnapshot( SolrZkClient zkClient, String collectionName, CollectionSnapshotMetaData meta) throws KeeperException, InterruptedException { String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.of(meta.getName())); - zkClient.setData(zkPath, Utils.toJSON(meta), -1); + zkClient.setData(zkPath, Utils.toJSON(meta), -1, true); } /** @@ -122,7 +122,7 @@ public static void deleteCollectionLevelSnapshot( SolrZkClient zkClient, String collectionName, String commitName) throws InterruptedException, KeeperException { String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.of(commitName)); - zkClient.delete(zkPath, -1); + zkClient.delete(zkPath, -1, true); } /** @@ -138,11 +138,11 @@ public static void cleanupCollectionLevelSnapshots(SolrZkClient zkClient, String String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.empty()); try { // Delete the meta-data for each snapshot. - Collection snapshots = zkClient.getChildren(zkPath, null); + Collection snapshots = zkClient.getChildren(zkPath, null, true); for (String snapshot : snapshots) { String path = getSnapshotMetaDataZkPath(collectionName, Optional.of(snapshot)); try { - zkClient.delete(path, -1); + zkClient.delete(path, -1, true); } catch (KeeperException ex) { // Gracefully handle the case when the zk node doesn't exist if (ex.code() != KeeperException.Code.NONODE) { @@ -152,7 +152,7 @@ public static void cleanupCollectionLevelSnapshots(SolrZkClient zkClient, String } // Delete the parent node. - zkClient.delete(zkPath, -1); + zkClient.delete(zkPath, -1, true); } catch (KeeperException ex) { // Gracefully handle the case when the zk node doesn't exist (e.g. if no snapshots were // created for this collection). @@ -180,7 +180,7 @@ public static Optional getCollectionLevelSnapshot( try { @SuppressWarnings({"unchecked"}) Map data = - (Map) Utils.fromJSON(zkClient.getData(zkPath, null, null)); + (Map) Utils.fromJSON(zkClient.getData(zkPath, null, null, true)); return Optional.of(new CollectionSnapshotMetaData(data)); } catch (KeeperException ex) { // Gracefully handle the case when the zk node for a specific @@ -208,7 +208,7 @@ public static Collection listSnapshots( String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.empty()); try { - Collection snapshots = zkClient.getChildren(zkPath, null); + Collection snapshots = zkClient.getChildren(zkPath, null, true); for (String snapshot : snapshots) { Optional s = getCollectionLevelSnapshot(zkClient, collectionName, snapshot); diff --git a/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java b/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java index c301f0d297b..8bd0f2c71ea 100644 --- a/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java +++ b/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java @@ -337,14 +337,18 @@ public void put(FileEntry entry) throws IOException { private void distribute(FileInfo info) { try { String dirName = info.path.substring(0, info.path.lastIndexOf('/')); - coreContainer.getZkController().getZkClient().makePath(ZK_PACKAGESTORE + dirName, false); + coreContainer + .getZkController() + .getZkClient() + .makePath(ZK_PACKAGESTORE + dirName, false, true); coreContainer .getZkController() .getZkClient() .create( ZK_PACKAGESTORE + info.path, info.getDetails().getMetaData().sha512.getBytes(UTF_8), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + true); } catch (Exception e) { throw new SolrException(SERVER_ERROR, "Unable to create an entry in ZK", e); } @@ -508,7 +512,7 @@ public void delete(String path) { private void checkInZk(String path) { try { // fail if file exists - if (coreContainer.getZkController().getZkClient().exists(ZK_PACKAGESTORE + path)) { + if (coreContainer.getZkController().getZkClient().exists(ZK_PACKAGESTORE + path, true)) { throw new SolrException(BAD_REQUEST, "The path exist ZK, delete and retry"); } @@ -532,7 +536,11 @@ public void refresh(String path) { @SuppressWarnings({"rawtypes"}) List l = null; try { - l = coreContainer.getZkController().getZkClient().getChildren(ZK_PACKAGESTORE + path, null); + l = + coreContainer + .getZkController() + .getZkClient() + .getChildren(ZK_PACKAGESTORE + path, null, true); } catch (KeeperException.NoNodeException e) { // does not matter } @@ -639,7 +647,7 @@ private static Map _getKeys(Path solrHome) throws IOException { public static void deleteZKFileEntry(SolrZkClient client, String path) { try { - client.delete(ZK_PACKAGESTORE + path, -1); + client.delete(ZK_PACKAGESTORE + path, -1, true); } catch (KeeperException | InterruptedException e) { log.error("", e); } diff --git a/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java b/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java index ffa7f7dced4..eb87c1a8e29 100644 --- a/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java +++ b/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java @@ -140,7 +140,7 @@ public void delete(SolrQueryRequest req, SolrQueryResponse rsp) { coreContainer .getZkController() .getZkClient() - .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL); + .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL, true); String path = req.getPathTemplateValues().get("*"); validateName(path, true); if (coreContainer.getPackageLoader().getPackageAPI().isJarInuse(path)) { @@ -159,7 +159,7 @@ public void delete(SolrQueryRequest req, SolrQueryResponse rsp) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); } finally { try { - coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1); + coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1, true); } catch (Exception e) { log.error("Unexpected error ", e); } @@ -188,7 +188,7 @@ public void upload(SolrQueryRequest req, SolrQueryResponse rsp) { coreContainer .getZkController() .getZkClient() - .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL); + .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL, true); Iterable streams = req.getContentStreams(); if (streams == null) @@ -239,7 +239,7 @@ public void upload(SolrQueryRequest req, SolrQueryResponse rsp) { log.error("Unexpected error", e); } finally { try { - coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1); + coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1, true); } catch (Exception e) { log.error("Unexpected error ", e); } diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java b/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java index b3aea417df9..9130fcc317a 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java @@ -113,10 +113,11 @@ public void getClusterStatus(NamedList results) } Map roles = null; - if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES)) { + if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES, true)) { roles = (Map) - Utils.fromJSON(zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null)); + Utils.fromJSON( + zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null, true)); } ClusterState clusterState = zkStateReader.getClusterState(); @@ -196,7 +197,7 @@ public void getClusterStatus(NamedList results) } List liveNodes = - zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null); + zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true); // now we need to walk the collectionProps tree to cross-check replica state with live nodes crossCheckReplicaStateWithLiveNodes(liveNodes, collectionProps); diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java b/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java index 290185c7b07..117334b6d4b 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/ContainerPluginsApi.java @@ -174,7 +174,7 @@ public static Map plugins(Supplier zkClientSupplie try { Map clusterPropsJson = (Map) - Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); + Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true)); return (Map) clusterPropsJson.computeIfAbsent(PLUGIN, o -> new LinkedHashMap<>()); } catch (KeeperException.NoNodeException e) { diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java b/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java index 09d8cbcddf6..a0978c02759 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java @@ -79,7 +79,8 @@ protected boolean persistConf(SecurityConfig securityConfig) throws IOException .setData( SOLR_SECURITY_CONF_PATH, Utils.toJSON(securityConfig.getData()), - securityConfig.getVersion()); + securityConfig.getVersion(), + true); log.debug("Persisted security.json to {}", SOLR_SECURITY_CONF_PATH); return true; } catch (KeeperException.BadVersionException bdve) { diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java index 71b2127f790..e2d8b7715b8 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java @@ -156,7 +156,7 @@ private void showFromZooKeeper( } // Show a directory listing - List children = zkClient.getChildren(adminFile, null); + List children = zkClient.getChildren(adminFile, null, true); if (children.size() > 0) { NamedList> files = new SimpleOrderedMap<>(); @@ -167,7 +167,7 @@ private void showFromZooKeeper( SimpleOrderedMap fileInfo = new SimpleOrderedMap<>(); files.add(f, fileInfo); - List fchildren = zkClient.getChildren(adminFile + "/" + f, null); + List fchildren = zkClient.getChildren(adminFile + "/" + f, null, true); if (fchildren.size() > 0) { fileInfo.add("directory", true); } else { @@ -185,7 +185,8 @@ private void showFromZooKeeper( params.set(CommonParams.WT, "raw"); req.setParams(params); ContentStreamBase content = - new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null), adminFile); + new ContentStreamBase.ByteArrayStream( + zkClient.getData(adminFile, null, null, true), adminFile); content.setContentType(getSafeContentType(req.getParams().get(USE_CONTENT_TYPE))); rsp.add(RawResponseWriter.CONTENT, content); @@ -341,7 +342,7 @@ public static String getAdminFileFromZooKeeper( } // Make sure the file exists, is readable and is not a hidden file - if (!zkClient.exists(adminFile)) { + if (!zkClient.exists(adminFile, true)) { log.error("Can not find: {}", adminFile); rsp.setException( new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can not find: " + adminFile)); diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java index ce1616ff901..b5a8234a321 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperInfoHandler.java @@ -282,7 +282,7 @@ private synchronized List getCollections(SolrZkClient zkClient) // cache is stale, rebuild the full list ... cachedCollections = new ArrayList(); - List fromZk = zkClient.getChildren("/collections", this); + List fromZk = zkClient.getChildren("/collections", this, true); if (fromZk != null) cachedCollections.addAll(fromZk); // sort the final merged set of collections @@ -623,7 +623,7 @@ boolean printTree(JSONWriter json, String path) throws IOException { Stat stat = new Stat(); try { // Trickily, the call to zkClient.getData fills in the stat variable - byte[] data = zkClient.getData(path, null, stat); + byte[] data = zkClient.getData(path, null, stat, true); if (stat.getEphemeralOwner() != 0) { writeKeyValue(json, "ephemeral", true, false); @@ -656,7 +656,7 @@ boolean printTree(JSONWriter json, String path) throws IOException { json.startArray(); try { - List children = zkClient.getChildren(path, null); + List children = zkClient.getChildren(path, null, true); java.util.Collections.sort(children); boolean first = true; @@ -711,7 +711,7 @@ boolean printZnode(JSONWriter json, String path) throws IOException { String dataStrErr = null; Stat stat = new Stat(); // Trickily, the call to zkClient.getData fills in the stat variable - byte[] data = zkClient.getData(path, null, stat); + byte[] data = zkClient.getData(path, null, stat, true); if (null != data) { try { dataStr = (new BytesRef(data)).utf8ToString(); diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.java index 4e958192c7a..c2f244e93d8 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/ZookeeperReadAPI.java @@ -121,18 +121,20 @@ public ListZkChildrenResponse listNodes( zkPath = sanitizeZkPath(zkPath); try { - Stat stat = coreContainer.getZkController().getZkClient().exists(zkPath, null); + Stat stat = coreContainer.getZkController().getZkClient().exists(zkPath, null, true); listResponse.stat = new AnnotatedStat(stat); if (includeChildren != null && !includeChildren.booleanValue()) { return listResponse; } - List l = coreContainer.getZkController().getZkClient().getChildren(zkPath, null); + List l = + coreContainer.getZkController().getZkClient().getChildren(zkPath, null, false); String prefix = zkPath.endsWith("/") ? zkPath : zkPath + "/"; Map stats = new LinkedHashMap<>(); for (String s : l) { try { - stats.put(s, coreContainer.getZkController().getZkClient().exists(prefix + s, null)); + stats.put( + s, coreContainer.getZkController().getZkClient().exists(prefix + s, null, false)); } catch (Exception e) { throw new RuntimeException(e); } @@ -182,7 +184,7 @@ private ZooKeeperFileResponse readNodeAndAddToResponse(String zkPath) { private byte[] readPathFromZookeeper(String path) { byte[] d; try { - d = coreContainer.getZkController().getZkClient().getData(path, null, null); + d = coreContainer.getZkController().getZkClient().getData(path, null, null, false); } catch (KeeperException.NoNodeException e) { throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No such node: " + path); } catch (Exception e) { diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.java index 644a48eae12..a8a4b5091d4 100644 --- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.java +++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.java @@ -218,7 +218,7 @@ public void getFileContents(SolrQueryRequest req, SolrQueryResponse rsp) throws String filePath = getConfigSetZkPath(getMutableId(configSet), file); byte[] data; try { - data = zkStateReader().getZkClient().getData(filePath, null, null); + data = zkStateReader().getZkClient().getData(filePath, null, null, true); } catch (KeeperException | InterruptedException e) { throw new IOException("Error reading file: " + filePath, SolrZkClient.checkInterrupted(e)); } @@ -273,7 +273,7 @@ public void updateFileContents(SolrQueryRequest req, SolrQueryResponse rsp) // apply the update and reload the temp collection / re-index sample docs SolrZkClient zkClient = zkStateReader().getZkClient(); try { - zkClient.setData(zkPath, data); + zkClient.setData(zkPath, data, true); } catch (KeeperException | InterruptedException e) { throw new IOException( "Failed to save data in ZK at path: " + zkPath, SolrZkClient.checkInterrupted(e)); @@ -402,8 +402,8 @@ public void downloadConfig(SolrQueryRequest req, SolrQueryResponse rsp) throws I SolrZkClient zkClient = zkStateReader().getZkClient(); String configId = mutableId; try { - if (!zkClient.exists(getConfigSetZkPath(mutableId, null))) { - if (zkClient.exists(getConfigSetZkPath(configSet, null))) { + if (!zkClient.exists(getConfigSetZkPath(mutableId, null), true)) { + if (zkClient.exists(getConfigSetZkPath(configSet, null), true)) { configId = configSet; } else { throw new SolrException( @@ -1363,7 +1363,7 @@ private void validateNewConfigSetName(String configSet) { private boolean pathExistsInZk(final String zkPath) throws IOException { SolrZkClient zkClient = zkStateReader().getZkClient(); try { - return zkClient.exists(zkPath); + return zkClient.exists(zkPath, true); } catch (KeeperException | InterruptedException e) { throw new IOException( "Failed to check if path exists: " + zkPath, SolrZkClient.checkInterrupted(e)); diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java index 8c726f288ca..db35a805c51 100644 --- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java +++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java @@ -705,7 +705,7 @@ int getCurrentSchemaVersion(final String configSet) throws IOException { int currentVersion = -1; final String path = getManagedSchemaZkPath(configSet); try { - Stat stat = cc.getZkController().getZkClient().exists(path, null); + Stat stat = cc.getZkController().getZkClient().exists(path, null, true); if (stat != null) { currentVersion = stat.getVersion(); } @@ -927,7 +927,7 @@ protected ManagedIndexSchema removeLanguageSpecificObjectsAndFiles( for (String path : toRemoveFiles) { try { - zkClient.delete(path, -1); + zkClient.delete(path, -1, false); } catch (KeeperException.NoNodeException nne) { // no-op } catch (KeeperException | InterruptedException e) { @@ -993,9 +993,9 @@ protected ManagedIndexSchema restoreLanguageSpecificObjectsAndFiles( for (String path : langFilesToRestore) { String copyToPath = path.replace(origPathDir, replacePathDir); try { - if (!zkClient.exists(copyToPath)) { - zkClient.makePath(copyToPath, false); - zkClient.setData(copyToPath, zkClient.getData(path, null, null)); + if (!zkClient.exists(copyToPath, true)) { + zkClient.makePath(copyToPath, false, true); + zkClient.setData(copyToPath, zkClient.getData(path, null, null, true), true); } } catch (KeeperException | InterruptedException e) { throw new IOException( diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java index a824e70381d..bf8e3d26e93 100644 --- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java +++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerSettingsDAO.java @@ -130,7 +130,7 @@ private ConfigOverlay getConfigOverlay(String config) throws IOException { byte[] data = null; Stat stat = new Stat(); try { - data = cc.getZkController().getZkStateReader().getZkClient().getData(path, null, stat); + data = cc.getZkController().getZkStateReader().getZkClient().getData(path, null, stat, true); } catch (KeeperException.NoNodeException nne) { // ignore } catch (KeeperException | InterruptedException e) { diff --git a/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java b/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java index f518499c934..79b9fa1c9c3 100644 --- a/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java +++ b/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java @@ -182,14 +182,14 @@ public List fetchInstalledPackageInstances() throws SolrExc List ret = new ArrayList<>(); packages = new HashMap<>(); try { - if (zkClient.exists(ZkStateReader.SOLR_PKGS_PATH)) { + if (zkClient.exists(ZkStateReader.SOLR_PKGS_PATH, true)) { @SuppressWarnings("unchecked") Map>> packagesZnodeMap = (Map>>) getMapper() .readValue( new String( - zkClient.getData(ZkStateReader.SOLR_PKGS_PATH, null, null), + zkClient.getData(ZkStateReader.SOLR_PKGS_PATH, null, null, true), StandardCharsets.UTF_8), Map.class) .get("packages"); @@ -322,7 +322,7 @@ public Map getPackagesDeployedAsClusterLevelPlugins private void ensureCollectionsExist(List collections) { try { - List existingCollections = zkClient.getChildren("/collections", null); + List existingCollections = zkClient.getChildren("/collections", null, true); Set nonExistent = new HashSet<>(collections); nonExistent.removeAll(existingCollections); if (!nonExistent.isEmpty()) { @@ -1080,7 +1080,7 @@ public void undeploy( public Map getDeployedCollections(String packageName) { List allCollections; try { - allCollections = zkClient.getChildren(ZkStateReader.COLLECTIONS_ZKNODE, null); + allCollections = zkClient.getChildren(ZkStateReader.COLLECTIONS_ZKNODE, null, true); } catch (KeeperException | InterruptedException e) { throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, e); } diff --git a/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java b/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java index 9ee18360c31..8ef29ba5552 100644 --- a/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java +++ b/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java @@ -119,15 +119,17 @@ public void addRepository(String repoName, String uri) throws Exception { @SuppressWarnings({"unchecked"}) List repos = getMapper().readValue(existingRepositoriesJson, List.class); repos.add(new DefaultPackageRepository(repoName, uri)); - if (packageManager.zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH) == false) { + if (packageManager.zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH, true) == false) { packageManager.zkClient.create( PackageUtils.REPOSITORIES_ZK_PATH, getMapper().writeValueAsString(repos).getBytes("UTF-8"), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + true); } else { packageManager.zkClient.setData( PackageUtils.REPOSITORIES_ZK_PATH, - getMapper().writeValueAsString(repos).getBytes("UTF-8")); + getMapper().writeValueAsString(repos).getBytes("UTF-8"), + true); } try (InputStream is = new URL(uri + "/publickey.der").openStream()) { @@ -151,8 +153,9 @@ public void addKey(byte[] key, String destinationKeyFilename) throws Exception { private String getRepositoriesJson(SolrZkClient zkClient) throws UnsupportedEncodingException, KeeperException, InterruptedException { - if (zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH)) { - return new String(zkClient.getData(PackageUtils.REPOSITORIES_ZK_PATH, null, null), "UTF-8"); + if (zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH, true)) { + return new String( + zkClient.getData(PackageUtils.REPOSITORIES_ZK_PATH, null, null, true), "UTF-8"); } return "[]"; } diff --git a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java index 3bb8f6578d0..0f9a8d50845 100644 --- a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java +++ b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java @@ -113,14 +113,18 @@ public void process(WatchedEvent event) { refreshPackages(thisWatch); } } - }); + }, + true); } public void refreshPackages(Watcher watcher) { final Stat stat = new Stat(); try { final byte[] data = - coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, watcher, stat); + coreContainer + .getZkController() + .getZkClient() + .getData(SOLR_PKGS_PATH, watcher, stat, true); pkgs = readPkgsFromZk(data, stat); packageLoader.refreshPackageConf(); } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) { @@ -140,7 +144,8 @@ private Packages readPkgsFromZk(byte[] data, Stat stat) if (data == null || stat == null) { stat = new Stat(); - data = coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, null, stat); + data = + coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, null, stat, true); } Packages packages = null; if (data == null || data.length == 0) { diff --git a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java index d6f84216c6c..b28f4f57c36 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java @@ -239,8 +239,8 @@ public void configure(SolrResourceLoader loader, NamedList initArgs) throws SolrException { // validate connectivity and the configured znode base try { - if (!zkClient.exists(znodeBase)) { - zkClient.makePath(znodeBase); + if (!zkClient.exists(znodeBase, retryOnConnLoss)) { + zkClient.makePath(znodeBase, retryOnConnLoss); } } catch (Exception exc) { String errMsg = @@ -257,7 +257,7 @@ public void configure(SolrResourceLoader loader, NamedList initArgs) public boolean exists(String storedResourceId) throws IOException { final String znodePath = getZnodeForResource(storedResourceId); try { - return zkClient.exists(znodePath); + return zkClient.exists(znodePath, retryOnConnLoss); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; @@ -272,8 +272,8 @@ public InputStream openInputStream(String storedResourceId) throws IOException { final String znodePath = getZnodeForResource(storedResourceId); byte[] znodeData = null; try { - if (zkClient.exists(znodePath)) { - znodeData = zkClient.getData(znodePath, null, null); + if (zkClient.exists(znodePath, retryOnConnLoss)) { + znodeData = zkClient.getData(znodePath, null, null, retryOnConnLoss); } } catch (Exception e) { if (e instanceof IOException) { @@ -303,11 +303,11 @@ public OutputStream openOutputStream(String storedResourceId) throws IOException public void close() { byte[] znodeData = toByteArray(); try { - if (zkClient.exists(znodePath)) { - zkClient.setData(znodePath, znodeData); + if (zkClient.exists(znodePath, retryOnConnLoss)) { + zkClient.setData(znodePath, znodeData, retryOnConnLoss); log.info("Wrote {} bytes to existing znode {}", znodeData.length, znodePath); } else { - zkClient.makePath(znodePath, znodeData); + zkClient.makePath(znodePath, znodeData, retryOnConnLoss); log.info("Wrote {} bytes to new znode {}", znodeData.length, znodePath); } } catch (Exception e) { @@ -339,10 +339,10 @@ public boolean delete(String storedResourceId) throws IOException { // this might be overkill for a delete operation try { - if (zkClient.exists(znodePath)) { + if (zkClient.exists(znodePath, retryOnConnLoss)) { log.debug("Attempting to delete znode {}", znodePath); - zkClient.delete(znodePath, -1); - wasDeleted = zkClient.exists(znodePath); + zkClient.delete(znodePath, -1, retryOnConnLoss); + wasDeleted = zkClient.exists(znodePath, retryOnConnLoss); if (wasDeleted) { log.info("Deleted znode {}", znodePath); diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java index cc6e2e01277..0bcfda95823 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java @@ -187,7 +187,7 @@ boolean persistManagedSchemaToZooKeeper(boolean createOnly) { final byte[] data = writer.toString().getBytes(StandardCharsets.UTF_8); if (createOnly) { try { - zkClient.create(managedSchemaPath, data, CreateMode.PERSISTENT); + zkClient.create(managedSchemaPath, data, CreateMode.PERSISTENT, true); schemaZkVersion = 0; log.info("Created and persisted managed schema znode at {}", managedSchemaPath); } catch (KeeperException.NodeExistsException e) { @@ -199,7 +199,7 @@ boolean persistManagedSchemaToZooKeeper(boolean createOnly) { } else { try { // Assumption: the path exists - Stat stat = zkClient.setData(managedSchemaPath, data, schemaZkVersion); + Stat stat = zkClient.setData(managedSchemaPath, data, schemaZkVersion, true); schemaZkVersion = stat.getVersion(); log.info( "Persisted managed schema version {} at {}", schemaZkVersion, managedSchemaPath); diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java index 8bf2f3d1668..73187383bd8 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java @@ -125,7 +125,7 @@ public String lookupZKManagedSchemaPath() { + ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME; try { // check if we are using the legacy managed-schema file name. - if (zkClient.exists(legacyManagedSchemaPath)) { + if (zkClient.exists(legacyManagedSchemaPath, true)) { log.debug( "Legacy managed schema resource {} found - loading legacy managed schema instead of {} file.", ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME, @@ -221,7 +221,7 @@ public ManagedIndexSchema create( Stat stat = new Stat(); try { // Attempt to load the managed schema - byte[] data = zkClient.getData(managedSchemaPath, null, stat); + byte[] data = zkClient.getData(managedSchemaPath, null, stat, true); schemaZkVersion = stat.getVersion(); schemaInputStream = new ZkSolrResourceLoader.ZkByteArrayInputStream(data, managedSchemaPath, stat); @@ -250,7 +250,7 @@ public ManagedIndexSchema create( } catch (IOException e) { try { // Retry to load the managed schema, in case it was created since the first attempt - byte[] data = zkClient.getData(managedSchemaPath, null, stat); + byte[] data = zkClient.getData(managedSchemaPath, null, stat, true); schemaZkVersion = stat.getVersion(); schemaInputStream = new ByteArrayInputStream(data); loadedResource = managedSchemaPath; @@ -470,7 +470,7 @@ private void zkUgradeToManagedSchema() { boolean locked = false; try { try { - zkClient.makePath(lockPath, null, CreateMode.EPHEMERAL, null, true); + zkClient.makePath(lockPath, null, CreateMode.EPHEMERAL, null, true, true); locked = true; } catch (Exception e) { // some other node already started the upgrade, or an error occurred - bail out @@ -487,14 +487,14 @@ private void zkUgradeToManagedSchema() { try { if (zkController.pathExists(nonManagedSchemaPath)) { // First, copy the non-managed schema znode content to the upgraded schema znode - byte[] bytes = zkController.getZkClient().getData(nonManagedSchemaPath, null, null); + byte[] bytes = zkController.getZkClient().getData(nonManagedSchemaPath, null, null, true); final String upgradedSchemaPath = nonManagedSchemaPath + UPGRADED_SCHEMA_EXTENSION; ZkMaintenanceUtils.ensureExists(upgradedSchemaPath, zkController.getZkClient()); - zkController.getZkClient().setData(upgradedSchemaPath, bytes); + zkController.getZkClient().setData(upgradedSchemaPath, bytes, true); // Then delete the non-managed schema znode - if (zkController.getZkClient().exists(nonManagedSchemaPath)) { + if (zkController.getZkClient().exists(nonManagedSchemaPath, true)) { try { - zkController.getZkClient().delete(nonManagedSchemaPath, -1); + zkController.getZkClient().delete(nonManagedSchemaPath, -1, true); } catch (KeeperException.NoNodeException ex) { // ignore - someone beat us to it } @@ -524,7 +524,7 @@ private void zkUgradeToManagedSchema() { if (locked) { // unlock try { - zkClient.delete(lockPath, -1); + zkClient.delete(lockPath, -1, true); } catch (KeeperException.NoNodeException nne) { // ignore - someone else deleted it } catch (Exception e) { diff --git a/solr/core/src/java/org/apache/solr/schema/SchemaManager.java b/solr/core/src/java/org/apache/solr/schema/SchemaManager.java index e99270078a1..801863fa882 100644 --- a/solr/core/src/java/org/apache/solr/schema/SchemaManager.java +++ b/solr/core/src/java/org/apache/solr/schema/SchemaManager.java @@ -490,10 +490,10 @@ private ManagedIndexSchema getFreshManagedSchema(SolrCore core) SolrZkClient zkClient = zkLoader.getZkController().getZkClient(); String managedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + schemaResourceName; try { - if (!zkClient.exists(managedSchemaPath)) { + if (!zkClient.exists(managedSchemaPath, true)) { String backupName = schemaResourceName + ManagedIndexSchemaFactory.UPGRADED_SCHEMA_EXTENSION; - if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + backupName)) { + if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + backupName, true)) { log.warn( "Unable to retrieve fresh managed schema, neither {} nor {} exist.", schemaResourceName, diff --git a/solr/core/src/java/org/apache/solr/schema/ZkIndexSchemaReader.java b/solr/core/src/java/org/apache/solr/schema/ZkIndexSchemaReader.java index 40be270e09e..d37e812a891 100644 --- a/solr/core/src/java/org/apache/solr/schema/ZkIndexSchemaReader.java +++ b/solr/core/src/java/org/apache/solr/schema/ZkIndexSchemaReader.java @@ -101,7 +101,7 @@ public SchemaWatcher createSchemaWatcher() { SchemaWatcher watcher = new SchemaWatcher(this); try { - zkClient.exists(managedSchemaPath, watcher); + zkClient.exists(managedSchemaPath, watcher, true); } catch (KeeperException e) { final String msg = "Error creating ZooKeeper watch for the managed schema"; log.error(msg, e); @@ -173,7 +173,7 @@ void updateSchema(Watcher watcher, int expectedZkVersion) synchronized (getSchemaUpdateLock()) { final ManagedIndexSchema oldSchema = managedIndexSchemaFactory.getSchema(); if (expectedZkVersion == -1 || oldSchema.schemaZkVersion < expectedZkVersion) { - byte[] data = zkClient.getData(managedSchemaPath, watcher, stat); + byte[] data = zkClient.getData(managedSchemaPath, watcher, stat, true); if (stat.getVersion() != oldSchema.schemaZkVersion) { if (log.isInfoEnabled()) { log.info("Retrieved schema version {} from Zookeeper", stat.getVersion()); diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java index 3dfd33ee6b9..ce9b1f8e6be 100644 --- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java +++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java @@ -471,7 +471,7 @@ protected void extractRemotePath(String collectionName, String origCorename) .getZkController() .zkStateReader .getZkClient() - .exists(DocCollection.getCollectionPath(collectionName))) { + .exists(DocCollection.getCollectionPath(collectionName), true)) { // no change and such a collection does not exist. go back return; } diff --git a/solr/core/src/java/org/apache/solr/servlet/QueryRateLimiter.java b/solr/core/src/java/org/apache/solr/servlet/QueryRateLimiter.java index 5b57617fa83..6b54ce450cd 100644 --- a/solr/core/src/java/org/apache/solr/servlet/QueryRateLimiter.java +++ b/solr/core/src/java/org/apache/solr/servlet/QueryRateLimiter.java @@ -69,7 +69,7 @@ private static RateLimiterConfig constructQueryRateLimiterConfig(SolrZkClient zk new RateLimiterConfig(SolrRequest.SolrRequestType.QUERY); Map clusterPropsJson = (Map) - Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); + Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true)); byte[] configInput = Utils.toJSON(clusterPropsJson.get(RL_CONFIG_KEY)); if (configInput.length == 0) { diff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java index 5b4fb191dad..970f4d8478f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java @@ -124,7 +124,7 @@ public void testProperties() throws Exception { assertEquals("collection1meta", aliases.get(0)); assertEquals("collection2meta", aliases.get(1)); // ensure we have the back-compat format in ZK: - final byte[] rawBytes = zkStateReader.getZkClient().getData(ALIASES, null, null); + final byte[] rawBytes = zkStateReader.getZkClient().getData(ALIASES, null, null, true); assertTrue( ((Map>) Utils.fromJSON(rawBytes)).get("collection").get("meta1") instanceof String); diff --git a/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java b/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java index 7275293c6de..0587fada196 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java @@ -73,7 +73,7 @@ public void test() if (random().nextBoolean() && i > 5 && !clearedCounter) { log.info("Clear collection counter"); // clear counter - cluster.getZkClient().delete("/collections/" + COLLECTION + "/counter", -1); + cluster.getZkClient().delete("/collections/" + COLLECTION + "/counter", -1, true); clearedCounter = true; } if (deleteReplica) { @@ -115,7 +115,7 @@ private int getCounter() throws InterruptedException { byte[] data = cluster .getZkClient() - .getData("/collections/" + COLLECTION + "/counter", null, new Stat()); + .getData("/collections/" + COLLECTION + "/counter", null, new Stat(), true); int count = NumberUtils.bytesToInt(data); if (count < 0) throw new AssertionError("Found negative collection counter " + count); return count; diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java index 87f71cc0570..7d963ee6b9a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java @@ -171,7 +171,8 @@ private void waitForValue(String propertyName, String expectedValue) throws Inte new String( cluster .getZkClient() - .getData("/collections/" + collectionName + "/collectionprops.json", null, null), + .getData( + "/collections/" + collectionName + "/collectionprops.json", null, null, true), StandardCharsets.UTF_8); } catch (Exception e) { collectionpropsInZk = "Could not get file from ZooKeeper: " + e.getMessage(); @@ -221,7 +222,7 @@ public void testWatcher() throws KeeperException, InterruptedException, IOExcept log.info("deleting props"); zkStateReader .getZkClient() - .delete("/collections/" + collectionName + "/collectionprops.json", -1); + .delete("/collections/" + collectionName + "/collectionprops.json", -1, true); assertEquals(1, watcher.waitForTrigger()); final Map props = watcher.getProps(); assertTrue(props.toString(), props.isEmpty()); diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionStateZnodeTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionStateZnodeTest.java index 05eb9e5c71b..0c43b93ea80 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionStateZnodeTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionStateZnodeTest.java @@ -50,10 +50,10 @@ public void testZkNodeLocation() throws Exception { (n, c) -> DocCollection.isFullyActive(n, c, 2, 2)); assertTrue( "Collection path does not exist", - zkClient().exists(DocCollection.getCollectionPath(collectionName))); + zkClient().exists(DocCollection.getCollectionPath(collectionName), true)); Stat stat = new Stat(); - zkClient().getData(DocCollection.getCollectionPath(collectionName), null, stat); + zkClient().getData(DocCollection.getCollectionPath(collectionName), null, stat, true); DocCollection c = getCollectionState(collectionName); @@ -68,6 +68,6 @@ public void testZkNodeLocation() throws Exception { assertFalse( "collection state should not exist", - zkClient().exists(DocCollection.getCollectionPath(collectionName))); + zkClient().exists(DocCollection.getCollectionPath(collectionName), true)); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java b/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java index 7a5836391c8..2ed48c9e7bd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java @@ -334,9 +334,9 @@ public void run() { } protected String setupNewDistributedQueueZNode(String znodePath) throws Exception { - if (!zkClient.exists("/")) zkClient.makePath("/", false); - if (zkClient.exists(znodePath)) zkClient.clean(znodePath); - zkClient.makePath(znodePath, false); + if (!zkClient.exists("/", true)) zkClient.makePath("/", false, true); + if (zkClient.exists(znodePath, true)) zkClient.clean(znodePath); + zkClient.makePath(znodePath, false, true); return znodePath; } diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java index 6e0860023fd..0fd64f1306c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java @@ -130,6 +130,7 @@ private List getElectionNodes(String collection, String shard, SolrZkCli throws KeeperException, InterruptedException { return client.getChildren( "/collections/" + collection + "/leader_elect/" + shard + LeaderElector.ELECTION_NODE, - null); + null, + true); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java index 6446a7ced54..d4a61abcc60 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java @@ -72,8 +72,8 @@ public void setUp() throws Exception { .build(); zkStateReader = new ZkStateReader(zkClient); seqToThread = Collections.synchronizedMap(new HashMap()); - zkClient.makePath("/collections/collection1"); - zkClient.makePath("/collections/collection2"); + zkClient.makePath("/collections/collection1", true); + zkClient.makePath("/collections/collection2", true); } static class TestLeaderElectionContext extends ShardLeaderElectionContextBase { @@ -292,7 +292,8 @@ private String getLeaderUrl(final String collection, final String slice) while (iterCount-- > 0) { try { byte[] data = - zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null); + zkClient.getData( + ZkStateReader.getShardLeadersPath(collection, slice), null, null, true); ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data)); return leaderProps.getCoreUrl(); } catch (NoNodeException | SessionExpiredException e) { diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java index 064a9e5ae3c..146a05388e8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java @@ -279,7 +279,7 @@ public void testMostInSyncReplicasCanWinElection() throws Exception { List children = zkClient() .getChildren( - "/collections/" + collectionName + "/leader_elect/shard1/election", null); + "/collections/" + collectionName + "/leader_elect/shard1/election", null, true); log.info("{} election nodes:{}", collectionName, children); throw e; } diff --git a/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java b/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java index b211096aae3..b0188069562 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java @@ -76,7 +76,7 @@ public void setUp() throws Exception { .withUrl(zkServer.getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); - zkClient.makePath("/solr", false); + zkClient.makePath("/solr", false, true); zkClient.close(); zkClient = @@ -85,17 +85,21 @@ public void setUp() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath( - "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + false); zkClient.close(); if (log.isInfoEnabled()) { @@ -148,7 +152,7 @@ public void testOpenACLUnsafeAllover() throws Exception { protected void assertOpenACLUnsafeAllover( SolrZkClient zkClient, String path, List verifiedList) throws Exception { - List acls = zkClient.getACL(path, new Stat()); + List acls = zkClient.getACL(path, new Stat(), true); if (log.isInfoEnabled()) { log.info("Verifying {}", path); } @@ -165,7 +169,7 @@ protected void assertOpenACLUnsafeAllover( "Path " + path + " does not have OPEN_ACL_UNSAFE", ZooDefs.Ids.OPEN_ACL_UNSAFE, acls); } verifiedList.add(path); - List children = zkClient.getChildren(path, null); + List children = zkClient.getChildren(path, null, false); for (String child : children) { assertOpenACLUnsafeAllover( zkClient, path + ((path.endsWith("/")) ? "" : "/") + child, verifiedList); diff --git a/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java b/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java index cc593562d4e..5810c50fe17 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java @@ -89,7 +89,7 @@ public void setUp() throws Exception { "readonlyACLUsername", "readonlyACLPassword") .getSolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { - zkClient.makePath("/solr", false); + zkClient.makePath("/solr", false, true); } try (SolrZkClient zkClient = @@ -100,13 +100,17 @@ public void setUp() throws Exception { "readonlyACLPassword") .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + false); } try (SolrZkClient zkClient = @@ -119,9 +123,15 @@ public void setUp() throws Exception { ("connectAndAllACLUsername:connectAndAllACLPassword") .getBytes(DATA_ENCODING)))) { zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedCreateNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); zkClient.makePath( - "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); } if (log.isInfoEnabled()) { diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java index a64e35a7753..ac3df8b4373 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java @@ -401,7 +401,7 @@ protected Set commonMocks(int liveNodesCount, boolean distributedCluster when(clusterStateMock.getLiveNodes()).thenReturn(liveNodes); - when(solrZkClientMock.setData(anyString(), any(), anyInt())) + when(solrZkClientMock.setData(anyString(), any(), anyInt(), anyBoolean())) .then( invocation -> { System.out.println( @@ -414,7 +414,7 @@ protected Set commonMocks(int liveNodesCount, boolean distributedCluster return null; }); - when(solrZkClientMock.getData(anyString(), any(), any())) + when(solrZkClientMock.getData(anyString(), any(), any(), anyBoolean())) .thenAnswer( invocation -> { byte[] data = zkClientData.get(invocation.getArgument(0)); @@ -424,14 +424,14 @@ protected Set commonMocks(int liveNodesCount, boolean distributedCluster return data; }); - when(solrZkClientMock.create(any(), any(), any())) + when(solrZkClientMock.create(any(), any(), any(), anyBoolean())) .thenAnswer( invocation -> { zkClientData.put(invocation.getArgument(0), invocation.getArgument(1)); return invocation.getArgument(0); }); - when(solrZkClientMock.exists(any(String.class))) + when(solrZkClientMock.exists(any(String.class), anyBoolean())) .thenAnswer( invocation -> { String key = invocation.getArgument(0); @@ -519,7 +519,7 @@ public Void answer(InvocationOnMock invocation) { .when(distribStateManagerMock) .makePath(anyString()); - when(solrZkClientMock.exists(any(String.class), isNull())) + when(solrZkClientMock.exists(any(String.class), isNull(), anyBoolean())) .thenAnswer( invocation -> { String key = invocation.getArgument(0); diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java index 573a7d0191c..1324ae8d6dd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java @@ -155,13 +155,13 @@ public MockZKController(String zkAddress, String nodeName, List overse // live node final String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; - zkClient.makePath(nodePath, CreateMode.EPHEMERAL); + zkClient.makePath(nodePath, CreateMode.EPHEMERAL, true); } private void deleteNode(final String path) { try { - zkClient.delete(path, -1); + zkClient.delete(path, -1, true); } catch (NoNodeException e) { // fine log.warn("cancelElection did not find election node to remove"); @@ -192,7 +192,7 @@ public void close() { public void createCollection(String collection, int numShards) throws Exception { // Create collection znode before having ClusterStateUpdater create state.json below, or it // will fail. - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true); ZkNodeProps m = new ZkNodeProps( @@ -287,7 +287,7 @@ public String publishState( try { zkClient.makePath( - "/collections/" + collection + "/leader_elect/" + shardId + "/election"); + "/collections/" + collection + "/leader_elect/" + shardId + "/election", true); } catch (NodeExistsException nee) { } ZkNodeProps props = @@ -448,7 +448,7 @@ public void tearDown() throws Exception { private void createCollection(String collection, int numShards) throws Exception { // Create collection znode before having ClusterStateUpdater create state.json below, or it // will fail. - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true); ZkNodeProps m = new ZkNodeProps( @@ -1203,7 +1203,7 @@ public void testShardLeaderChange() throws Exception { // Create collection znode before repeatedly trying to enqueue the cluster state update // message - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION, true); for (int i = 0; i < atLeast(4); i++) { killCounter.incrementAndGet(); // for each round allow 1 kill @@ -1452,7 +1452,7 @@ public void testPerformance() throws Exception { final int MAX_COLLECTIONS = 10, MAX_CORES = 10, MAX_STATE_CHANGES = 20000; for (int i = 0; i < MAX_COLLECTIONS; i++) { - zkClient.makePath("/collections/perf" + i); + zkClient.makePath("/collections/perf" + i, true); ZkNodeProps m = new ZkNodeProps( Overseer.QUEUE_OPERATION, @@ -1573,7 +1573,7 @@ public void testReplay() throws Exception { // state DistributedQueue queue = Overseer.getInternalWorkQueue(zkClient, new Stats()); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION, true); ZkNodeProps m = new ZkNodeProps( @@ -1751,7 +1751,7 @@ public void testExternalClusterStateChangeBehavior() throws Exception { q.offer(m); final String testCollectionName = "test"; - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + testCollectionName); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + testCollectionName, true); m = new ZkNodeProps( Overseer.QUEUE_OPERATION, @@ -1769,9 +1769,9 @@ public void testExternalClusterStateChangeBehavior() throws Exception { final String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + testCollectionName + "/state.json"; - byte[] data = zkClient.getData(path, null, null); + byte[] data = zkClient.getData(path, null, null, true); // Simulate an external modification of state.json - zkClient.setData(path, data); + zkClient.setData(path, data, true); m = new ZkNodeProps( @@ -1973,7 +1973,7 @@ public void testRemovalOfLastReplica() throws Exception { // create collection { - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION, true); ZkNodeProps m = new ZkNodeProps( Overseer.QUEUE_OPERATION, diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java index a5439a1c2e0..38f6a674dd3 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java @@ -124,7 +124,8 @@ public void testUpconfig() throws Exception { String content = new String( - zkClient.getData("/configs/upconfig2/schema.xml", null, null), StandardCharsets.UTF_8); + zkClient.getData("/configs/upconfig2/schema.xml", null, null, true), + StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); } @@ -353,7 +354,7 @@ public void testCp() throws Exception { assertEquals("Copy up to intermediate file should have succeeded.", 0, res); assertTrue( "Should have created an intermediate node on ZK", - zkClient.exists("/powerup/solrconfig.xml")); + zkClient.exists("/powerup/solrconfig.xml", true)); // copy individual file up // src and cp3 are valid @@ -373,7 +374,8 @@ public void testCp() throws Exception { cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args)); assertEquals("Copy up to named file should have succeeded.", 0, res); assertTrue( - "Should NOT have created an intermediate node on ZK", zkClient.exists("/copyUpFile.xml")); + "Should NOT have created an intermediate node on ZK", + zkClient.exists("/copyUpFile.xml", true)); // copy individual file down // src and cp3 are valid @@ -420,7 +422,8 @@ public void testCp() throws Exception { res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args)); assertEquals("Copy from somewhere in ZK to ZK root should have succeeded.", 0, res); - assertTrue("Should have found znode /solrconfig.xml: ", zkClient.exists("/solrconfig.xml")); + assertTrue( + "Should have found znode /solrconfig.xml: ", zkClient.exists("/solrconfig.xml", true)); // Check that the form path/ works for copying files up. Should append the last bit of the // source path to the dst @@ -465,7 +468,8 @@ public void testCp() throws Exception { assertEquals("Copy should have succeeded.", 0, res); String content = - new String(zkClient.getData("/cp7/conf/stopwords", null, null), StandardCharsets.UTF_8); + new String( + zkClient.getData("/cp7/conf/stopwords", null, null, true), StandardCharsets.UTF_8); assertTrue("There should be content in the node! ", content.contains("{Some Arbitrary Data}")); res = @@ -510,7 +514,8 @@ public void testCp() throws Exception { assertEquals("Copy should have succeeded.", 0, res); content = - new String(zkClient.getData("/cp9/conf/stopwords", null, null), StandardCharsets.UTF_8); + new String( + zkClient.getData("/cp9/conf/stopwords", null, null, true), StandardCharsets.UTF_8); assertTrue("There should be content in the node! ", content.contains("{Some Arbitrary Data}")); // Copy an individual empty file up and back down and insure it's still a file @@ -618,7 +623,7 @@ public void testMv() throws Exception { // Now does the moved directory match the original on disk? verifyZkLocalPathsMatch(srcPathCheck, "/mv2"); // And are we sure the old path is gone? - assertFalse("/configs/mv1 Znode should not be there: ", zkClient.exists("/configs/mv1")); + assertFalse("/configs/mv1 Znode should not be there: ", zkClient.exists("/configs/mv1", true)); // Files are in mv2 // Now fail if we specify "file:". Everything should still be in /mv2 @@ -644,7 +649,7 @@ public void testMv() throws Exception { mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool.getName(), mvTool.getOptions(), args)); assertEquals("Move should have succeeded.", 0, res); - assertFalse("Znode /mv3 really should be gone", zkClient.exists("/mv3")); + assertFalse("Znode /mv3 really should be gone", zkClient.exists("/mv3", true)); // Now does the moved directory match the original on disk? verifyZkLocalPathsMatch(srcPathCheck, "/mv4"); @@ -660,9 +665,10 @@ public void testMv() throws Exception { mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool.getName(), mvTool.getOptions(), args)); assertEquals("Move should have succeeded.", 0, res); assertTrue( - "Should be able to move a single file", zkClient.exists("/testmvsingle/solrconfig.xml")); + "Should be able to move a single file", + zkClient.exists("/testmvsingle/solrconfig.xml", true)); - zkClient.makePath("/parentNode"); + zkClient.makePath("/parentNode", true); // what happens if the destination ends with a slash? args = @@ -677,9 +683,10 @@ public void testMv() throws Exception { assertEquals("Move should have succeeded.", 0, res); assertTrue( "Should be able to move a single file to a parent znode", - zkClient.exists("/parentnode/schema.xml")); + zkClient.exists("/parentnode/schema.xml", true)); String content = - new String(zkClient.getData("/parentnode/schema.xml", null, null), StandardCharsets.UTF_8); + new String( + zkClient.getData("/parentnode/schema.xml", null, null, true), StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); } @@ -825,7 +832,8 @@ public void testRm() throws Exception { res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args)); assertEquals("Should have removed node /configs/rm1", res, 0); - assertFalse("Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1")); + assertFalse( + "Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1", true)); // Check that zk prefix also works. args = @@ -837,7 +845,8 @@ public void testRm() throws Exception { res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args)); assertEquals("Should have removed node /configs/rm2", res, 0); - assertFalse("Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2")); + assertFalse( + "Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2", true)); // This should silently just refuse to do anything to the / or /zookeeper args = @@ -860,14 +869,14 @@ private void verifyZkLocalPathsMatch(Path fileRoot, String zkRoot) } private static boolean isEphemeral(String zkPath) throws KeeperException, InterruptedException { - Stat znodeStat = zkClient.exists(zkPath, null); + Stat znodeStat = zkClient.exists(zkPath, null, true); return znodeStat.getEphemeralOwner() != 0; } void verifyAllZNodesAreFiles(Path fileRoot, String zkRoot) throws KeeperException, InterruptedException { - for (String child : zkClient.getChildren(zkRoot, null)) { + for (String child : zkClient.getChildren(zkRoot, null, true)) { // Skip ephemeral nodes if (zkRoot.endsWith("/") == false) zkRoot += "/"; if (isEphemeral(zkRoot + child)) continue; @@ -887,7 +896,8 @@ void verifyAllFilesAreZNodes(Path fileRoot, String zkRoot) throws IOException { void checkPathOnZk(Path path) { String znode = ZkMaintenanceUtils.createZkNodeName(zkRoot, fileRoot, path); try { // It's easier to catch this exception and fail than catch it everywhere else. - assertTrue("Should have found " + znode + " on Zookeeper", zkClient.exists(znode)); + assertTrue( + "Should have found " + znode + " on Zookeeper", zkClient.exists(znode, true)); } catch (Exception e) { fail( "Caught unexpected exception " @@ -923,10 +933,10 @@ private void verifyZnodesMatch(String first, String second) // Note, no fuss here with Windows path names. private void verifyFirstZNodesInSecond(String first, String second) throws KeeperException, InterruptedException { - for (String node : zkClient.getChildren(first, null)) { + for (String node : zkClient.getChildren(first, null, true)) { String fNode = first + "/" + node; String sNode = second + "/" + node; - assertTrue("Node " + sNode + " not found. Exists on " + fNode, zkClient.exists(sNode)); + assertTrue("Node " + sNode + " not found. Exists on " + fNode, zkClient.exists(sNode, true)); verifyFirstZNodesInSecond(fNode, sNode); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java index 3dd6948fc3f..868cd91e62a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java @@ -69,7 +69,7 @@ private void setUpZkAndDiskXml(boolean toZk, boolean leaveOnLocal) throws Except .build(); if (toZk) { - zkClient.makePath("solr.xml", XML_FOR_ZK.getBytes(StandardCharsets.UTF_8)); + zkClient.makePath("solr.xml", XML_FOR_ZK.getBytes(StandardCharsets.UTF_8), true); } zkClient.close(); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java index 0272ac5f806..1da60d85ff9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -354,7 +354,7 @@ private NamedList getConfigSetPropertiesFromZk(SolrZkClient zkClient, St throws Exception { byte[] oldPropsData = null; try { - oldPropsData = zkClient.getData(path, null, null); + oldPropsData = zkClient.getData(path, null, null, true); } catch (KeeperException.NoNodeException e) { // okay, properties just don't exist } @@ -444,15 +444,17 @@ public void testUploadErrors() throws Exception { .build(); // Create dummy config files in zookeeper - zkClient.makePath("/configs/myconf"); + zkClient.makePath("/configs/myconf", true); zkClient.create( "/configs/myconf/firstDummyFile", "first dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + true); zkClient.create( "/configs/myconf/anotherDummyFile", "second dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + true); // Checking error when configuration name specified already exists ignoreException("already exists"); @@ -470,10 +472,10 @@ public void testUploadErrors() throws Exception { assertEquals(400l, statusCode); assertTrue( "Expected file doesnt exist in zk. It's possibly overwritten", - zkClient.exists("/configs/myconf/firstDummyFile")); + zkClient.exists("/configs/myconf/firstDummyFile", true)); assertTrue( "Expected file doesnt exist in zk. It's possibly overwritten", - zkClient.exists("/configs/myconf/anotherDummyFile")); + zkClient.exists("/configs/myconf/anotherDummyFile", true)); zkClient.close(); solrClient.close(); @@ -531,7 +533,7 @@ public void testUploadLegacyManagedSchemaFile() throws Exception { assertTrue( "managed-schema file should have been uploaded", - zkClient.exists("/configs/" + configSetName + "/managed-schema")); + zkClient.exists("/configs/" + configSetName + "/managed-schema", true)); } finally { zkClient.close(); } @@ -633,19 +635,20 @@ public void testOverwriteWithCleanup(boolean v2) throws Exception { configPath + "/foo2/1", configPath + "/foo2/2"); for (String f : extraFiles) { - zkClient.makePath(f); + zkClient.makePath(f, true); } assertEquals( 0, uploadConfigSet(configsetName, configsetSuffix, null, true, false, v2, false)); for (String f : extraFiles) { assertTrue( - "Expecting file " + f + " to exist in ConfigSet but it's gone", zkClient.exists(f)); + "Expecting file " + f + " to exist in ConfigSet but it's gone", + zkClient.exists(f, true)); } assertEquals(0, uploadConfigSet(configsetName, configsetSuffix, null, true, true, v2, false)); for (String f : extraFiles) { assertFalse( "Expecting file " + f + " to be deleted from ConfigSet but it wasn't", - zkClient.exists(f)); + zkClient.exists(f, true)); } assertConfigsetFiles(configsetName, configsetSuffix, zkClient); } @@ -677,7 +680,7 @@ public void testOverwriteWithForbiddenFiles(boolean v2) throws Exception { String f = configPath + "/test." + fileEnding; assertFalse( "Expecting file " + f + " to not exist, because it has a forbidden file type", - zkClient.exists(f)); + zkClient.exists(f, true)); } } } @@ -986,7 +989,8 @@ public void testSingleWithCleanup(boolean v2) throws Exception { assertFalse( "New file should not exist, since the trust check did not succeed.", zkClient.exists( - "/configs/" + configsetName + configsetSuffix + "/test/upload/path/solrconfig.xml")); + "/configs/" + configsetName + configsetSuffix + "/test/upload/path/solrconfig.xml", + true)); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("ConfigSet uploads do not allow cleanup=true when filePath is used."); } @@ -1047,10 +1051,8 @@ public void testSingleFileTrusted(boolean v2) throws Exception { assertFalse( "New file should not exist, since the trust check did not succeed.", zkClient.exists( - "/configs/" - + configsetName - + configsetSuffix - + "/test/different/path/solrconfig.xml")); + "/configs/" + configsetName + configsetSuffix + "/test/different/path/solrconfig.xml", + true)); assertTrue(isTrusted(zkClient, configsetName, configsetSuffix)); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("Trying to make an unstrusted ConfigSet update on a trusted configSet"); @@ -1123,7 +1125,8 @@ public void testSingleFileForbiddenType(boolean v2) throws Exception { + configsetName + configsetSuffix + "/test/different/path/solrconfig." - + fileType)); + + fileType, + true)); unIgnoreException("is forbidden for use in configSets"); } } @@ -1306,7 +1309,8 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { List children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixTrusted), - null); + null, + true); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); @@ -1331,7 +1335,8 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixUntrusted), - null); + null, + true); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); } @@ -1341,7 +1346,7 @@ private boolean isTrusted(SolrZkClient zkClient, String configsetName, String co throws KeeperException, InterruptedException { String configSetZkPath = String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffix); - byte[] configSetNodeContent = zkClient.getData(configSetZkPath, null, null); + byte[] configSetNodeContent = zkClient.getData(configSetZkPath, null, null, true); ; @SuppressWarnings("unchecked") @@ -1356,7 +1361,8 @@ private int getConfigZNodeVersion( zkClient.getData( String.format(Locale.ROOT, "/configs/%s%s/%s", configsetName, configsetSuffix, configFile), null, - stat); + stat, + true); return stat.getVersion(); } @@ -1482,20 +1488,22 @@ private void assertConfigsetFiles(String configSetName, String suffix, SolrZkCli throws KeeperException, InterruptedException, IOException { assertTrue( "managed-schema.xml file should have been uploaded", - zkClient.exists("/configs/" + configSetName + suffix + "/managed-schema.xml")); + zkClient.exists("/configs/" + configSetName + suffix + "/managed-schema.xml", true)); assertArrayEquals( "managed-schema.xml file contents on zookeeper are not exactly same as that of the file uploaded in config", - zkClient.getData("/configs/" + configSetName + suffix + "/managed-schema.xml", null, null), + zkClient.getData( + "/configs/" + configSetName + suffix + "/managed-schema.xml", null, null, true), readFile("solr/configsets/upload/" + configSetName + "/managed-schema.xml")); assertTrue( "solrconfig.xml file should have been uploaded", - zkClient.exists("/configs/" + configSetName + suffix + "/solrconfig.xml")); - byte data[] = zkClient.getData("/configs/" + configSetName + suffix, null, null); + zkClient.exists("/configs/" + configSetName + suffix + "/solrconfig.xml", true)); + byte data[] = zkClient.getData("/configs/" + configSetName + suffix, null, null, true); // assertEquals("{\"trusted\": false}", new String(data, StandardCharsets.UTF_8)); assertArrayEquals( "solrconfig.xml file contents on zookeeper are not exactly same as that of the file uploaded in config", - zkClient.getData("/configs/" + configSetName + suffix + "/solrconfig.xml", null, null), + zkClient.getData( + "/configs/" + configSetName + suffix + "/solrconfig.xml", null, null, true), readFile("solr/configsets/upload/" + configSetName + "/solrconfig.xml")); } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java index 4c30011b7be..2920e4ece52 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java @@ -96,7 +96,8 @@ private void setupBaseConfigSet(String baseConfigSetName) throws Exception { .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8)); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8), + true); } private Exception getFirstExceptionOrNull(List list) { diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java index 94b7b3585d0..2ba85cfa437 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java @@ -156,7 +156,8 @@ private void setupBaseConfigSet(String baseConfigSetName, Map ol .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8)); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8), + true); } private StringBuilder getConfigSetProps(Map map) { diff --git a/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java b/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java index 7a5c12a1278..aa5915f007b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java @@ -64,9 +64,9 @@ public void testPut() throws KeeperException, InterruptedException { .build()) { String path = getAndMakeInitialPath(zkClient); DistributedMap map = createMap(zkClient, path); - assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); + assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); map.put("foo", new byte[0]); - assertTrue(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); + assertTrue(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); } } @@ -79,7 +79,12 @@ public void testGet() throws KeeperException, InterruptedException { String path = getAndMakeInitialPath(zkClient); byte[] data = "data".getBytes(Charset.defaultCharset()); zkClient.makePath( - path + "/" + DistributedMap.PREFIX + "foo", data, CreateMode.PERSISTENT, null, false); + path + "/" + DistributedMap.PREFIX + "foo", + data, + CreateMode.PERSISTENT, + null, + false, + true); DistributedMap map = createMap(zkClient, path); assertArrayEquals(data, map.get("foo")); } @@ -99,7 +104,8 @@ public void testContains() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false); + false, + true); assertTrue(map.contains("foo")); } } @@ -118,10 +124,11 @@ public void testRemove() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false); + false, + true); assertTrue(map.remove("foo")); assertFalse(map.contains("foo")); - assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); + assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); } } @@ -233,7 +240,7 @@ public void testRemoveMalformed() throws InterruptedException, KeeperException { String path = getAndMakeInitialPath(zkClient); // Add a "legacy" / malformed key final var key = "slash/test/0"; - zkClient.makePath(path + "/" + DistributedMap.PREFIX + key, new byte[0]); + zkClient.makePath(path + "/" + DistributedMap.PREFIX + key, new byte[0], true); DistributedMap map = createMap(zkClient, path); assertEquals(1, map.size()); @@ -249,7 +256,7 @@ protected DistributedMap createMap(SolrZkClient zkClient, String path) { protected String getAndMakeInitialPath(SolrZkClient zkClient) throws KeeperException, InterruptedException { String path = String.format(Locale.ROOT, "/%s/%s", getClass().getName(), getSaferTestName()); - zkClient.makePath(path, false); + zkClient.makePath(path, false, true); return path; } } diff --git a/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java b/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java index 9fa4f473d07..7d7f7024953 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java @@ -71,11 +71,14 @@ public void test() throws Exception { assertEquals(5, solrCluster.nodes().size()); SolrZkClient zkClient = ZkStateReader.from(cloudClient).getZkClient(); - zkClient.create(ZkStateReader.CONFIGS_ZKNODE + "/conf1/a", null, CreateMode.PERSISTENT); + zkClient.create(ZkStateReader.CONFIGS_ZKNODE + "/conf1/a", null, CreateMode.PERSISTENT, true); zkClient.create( - ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa1", new byte[1024], CreateMode.PERSISTENT); + ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa1", new byte[1024], CreateMode.PERSISTENT, true); zkClient.create( - ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa2", new byte[1024 * 2], CreateMode.PERSISTENT); + ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa2", + new byte[1024 * 2], + CreateMode.PERSISTENT, + true); List allFiles = new ArrayList<>(); byte[] buf = new byte[3 * 1024]; diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java index 96ef9151720..a5b0ee21781 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java @@ -192,7 +192,9 @@ public void testCreateDelete() throws Exception { cluster .getZkClient() .getChildren( - ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null); + ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), + null, + true); assertEquals( "Unexpected election nodes for Shard: " + s.getName() diff --git a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java index 9fe42b53af0..78f165613f2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java @@ -123,7 +123,7 @@ private void downAllReplicas() throws Exception { byte[] collectionState = cluster .getZkClient() - .getData("/collections/" + COLLECTION_NAME + "/state.json", null, null); + .getData("/collections/" + COLLECTION_NAME + "/state.json", null, null, true); Map> infectedState = (Map>) Utils.fromJSON(collectionState); @@ -139,7 +139,8 @@ private void downAllReplicas() throws Exception { cluster .getZkClient() - .setData("/collections/" + COLLECTION_NAME + "/state.json", Utils.toJSON(infectedState)); + .setData( + "/collections/" + COLLECTION_NAME + "/state.json", Utils.toJSON(infectedState), true); } protected static final String STD_CONF = diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java index e891e567136..bf870ad0eb2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java @@ -275,7 +275,8 @@ private void checkOneQueue(DocCollection coll, Slice slice, Set liveRep + "/leader_elect/" + slice.getName() + "/election", - null); + null, + true); if (leaderQueue.size() != liveReplicas.size()) { diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java b/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java index 385c39c26d2..a534e2e2a30 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestSizeLimitedDistributedMap.java @@ -149,7 +149,7 @@ public void testCleanupForKeysWithSlashes() throws InterruptedException, KeeperE String path = getAndMakeInitialPath(zkClient); // Add a "legacy" / malformed key - zkClient.makePath(path + "/" + DistributedMap.PREFIX + "slash/test/0", new byte[0]); + zkClient.makePath(path + "/" + DistributedMap.PREFIX + "slash/test/0", new byte[0], true); AtomicInteger overFlowCounter = new AtomicInteger(); DistributedMap map = diff --git a/solr/core/src/test/org/apache/solr/cloud/TestStressLiveNodes.java b/solr/core/src/test/org/apache/solr/cloud/TestStressLiveNodes.java index 3865d665e20..eb3bf597e4b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestStressLiveNodes.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestStressLiveNodes.java @@ -93,7 +93,7 @@ private static List getTrueLiveNodesFromZk() throws Exception { SolrZkClient client = newSolrZkClient(); try { ArrayList result = - new ArrayList<>(client.getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null)); + new ArrayList<>(client.getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true)); Collections.sort(result); return result; } finally { @@ -254,7 +254,7 @@ public Integer call() { for (int i = 0; running && i < numNodesToAdd; i++) { final String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/thrasher-" + id + "-" + i; try { - client.makePath(nodePath, CreateMode.EPHEMERAL); + client.makePath(nodePath, CreateMode.EPHEMERAL, true); numAdded++; } catch (Exception e) { log.error("failed to create: {}", nodePath, e); diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java index d2b772b44f7..937b8f1fe17 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -222,7 +222,9 @@ public void testCreateDelete() throws Exception { cluster .getZkClient() .getChildren( - ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null); + ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), + null, + true); assertEquals( "Unexpected election nodes for Shard: " + s.getName() diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java index 95ca8d13ac0..11d9cc99711 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java @@ -99,7 +99,7 @@ public void setUp() throws Exception { .withUrl(zkServer.getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); - zkClient.makePath("/solr", false); + zkClient.makePath("/solr", false, true); zkClient.close(); this.zkClient = @@ -124,7 +124,7 @@ public void testCmdConstants() { @Test public void testBootstrapWithChroot() throws Exception { String chroot = "/foo/bar"; - assertFalse(zkClient.exists(chroot)); + assertFalse(zkClient.exists(chroot, true)); String[] args = new String[] { @@ -138,7 +138,7 @@ public void testBootstrapWithChroot() throws Exception { ZkCLI.main(args); - assertTrue(zkClient.exists(chroot + ZkConfigSetService.CONFIGS_ZKNODE + "/collection1")); + assertTrue(zkClient.exists(chroot + ZkConfigSetService.CONFIGS_ZKNODE + "/collection1", true)); } @Test @@ -148,7 +148,7 @@ public void testMakePath() throws Exception { new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "makepath", "/path/mynewpath"}; ZkCLI.main(args); - assertTrue(zkClient.exists("/path/mynewpath")); + assertTrue(zkClient.exists("/path/mynewpath", true)); } @Test @@ -159,17 +159,17 @@ public void testPut() throws Exception { new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "put", "/data.txt", data}; ZkCLI.main(args); - zkClient.getData("/data.txt", null, null); + zkClient.getData("/data.txt", null, null, true); assertArrayEquals( - zkClient.getData("/data.txt", null, null), data.getBytes(StandardCharsets.UTF_8)); + zkClient.getData("/data.txt", null, null, true), data.getBytes(StandardCharsets.UTF_8)); // test re-put to existing data = "my data deux"; args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "put", "/data.txt", data}; ZkCLI.main(args); assertArrayEquals( - zkClient.getData("/data.txt", null, null), data.getBytes(StandardCharsets.UTF_8)); + zkClient.getData("/data.txt", null, null, true), data.getBytes(StandardCharsets.UTF_8)); } @Test @@ -216,7 +216,8 @@ public void testPutFile() throws Exception { }; ZkCLI.main(args); - String fromZk = new String(zkClient.getData("/solr.xml", null, null), StandardCharsets.UTF_8); + String fromZk = + new String(zkClient.getData("/solr.xml", null, null, true), StandardCharsets.UTF_8); Path locFile = Path.of(SOLR_HOME, "solr-stress-new.xml"); String fromLoc = Files.readString(locFile); assertEquals("Should get back what we put in ZK", fromZk, fromLoc); @@ -265,7 +266,7 @@ public void testPutFileNotExists() { @Test public void testList() throws Exception { - zkClient.makePath("/test"); + zkClient.makePath("/test", true); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "list"}; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); @@ -281,7 +282,7 @@ public void testList() throws Exception { @Test public void testLs() throws Exception { - zkClient.makePath("/test/path"); + zkClient.makePath("/test/path", true); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "ls", "/test"}; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); @@ -334,7 +335,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { } ZkCLI.main(upconfigArgs); - assertTrue(zkClient.exists(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname)); + assertTrue(zkClient.exists(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, true)); // print help // ZkCLI.main(new String[0]); @@ -355,7 +356,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { ZkNodeProps collectionProps = ZkNodeProps.load( - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null)); + zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null, true)); assertTrue(collectionProps.containsKey("configName")); assertEquals(confsetname, collectionProps.getStr("configName")); @@ -380,7 +381,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { File[] files = confDir.listFiles(); List zkFiles = - zkClient.getChildren(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, null); + zkClient.getChildren(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, null, true); assertEquals(files.length, zkFiles.size()); File sourceConfDir = new File(ExternalPaths.TECHPRODUCTS_CONFIGSET); @@ -420,7 +421,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "clear", "/"}; ZkCLI.main(args); - assertEquals(0, zkClient.getChildren("/", null).size()); + assertEquals(0, zkClient.getChildren("/", null, true).size()); } @Test @@ -428,7 +429,7 @@ public void testGet() throws Exception { String getNode = "/getNode"; byte[] data = "getNode-data".getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream systemOut = new ByteArrayOutputStream(); - this.zkClient.create(getNode, data, CreateMode.PERSISTENT); + this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "get", getNode}; ZkCLI.setStdout(new PrintStream(systemOut, true, StandardCharsets.UTF_8)); ZkCLI.main(args); @@ -453,7 +454,7 @@ public void testGetCompressed() throws Exception { random().nextBoolean() ? zLibCompressor.compressBytes(data) : zLibCompressor.compressBytes(data, data.length / 10); - this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT); + this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT, true); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "get", getNode}; ZkCLI.setStdout(new PrintStream(systemOut, true, StandardCharsets.UTF_8)); ZkCLI.main(args); @@ -471,7 +472,7 @@ public void testGetFile() throws Exception { String getNode = "/getFileNode"; byte[] data = "getFileNode-data".getBytes(StandardCharsets.UTF_8); - this.zkClient.create(getNode, data, CreateMode.PERSISTENT); + this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true); Path file = tmpDir.resolve("solrtest-getfile-" + this.getClass().getName() + "-" + System.nanoTime()); @@ -500,7 +501,7 @@ public void testGetFileCompressed() throws Exception { random().nextBoolean() ? zLibCompressor.compressBytes(data) : zLibCompressor.compressBytes(data, data.length / 10); - this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT); + this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT, true); Path file = tmpDir.resolve("solrtest-getfile-" + this.getClass().getName() + "-" + System.nanoTime()); @@ -601,7 +602,7 @@ public void testUpdateAcls() throws Exception { .withTimeout( AbstractDistribZkTestBase.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - zkClient.getData("/", null, null); + zkClient.getData("/", null, null, true); } catch (KeeperException.NoAuthException e) { excepted = true; } diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java index a83e5c31b1d..f1df3febab4 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java @@ -233,7 +233,8 @@ public List getCoreDescriptors() { .makePath( DocCollection.getCollectionPathRoot(collectionName), new byte[0], - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + true); ZkNodeProps m = new ZkNodeProps( @@ -339,29 +340,30 @@ public void testTouchConfDir() throws Exception { // touchConfDir doesn't make the znode Stat s = new Stat(); - assertFalse(zkClient.exists(zkpath)); + assertFalse(zkClient.exists(zkpath, true)); zkClient.makePath(zkpath, true); - assertTrue(zkClient.exists(zkpath)); - assertNull(zkClient.getData(zkpath, null, s)); + assertTrue(zkClient.exists(zkpath, true)); + assertNull(zkClient.getData(zkpath, null, s, true)); assertEquals(0, s.getVersion()); // touchConfDir should only set the data to new byte[] {0} ZkController.touchConfDir(loader); - assertTrue(zkClient.exists(zkpath)); - assertArrayEquals(ZkController.TOUCHED_ZNODE_DATA, zkClient.getData(zkpath, null, s)); + assertTrue(zkClient.exists(zkpath, true)); + assertArrayEquals( + ZkController.TOUCHED_ZNODE_DATA, zkClient.getData(zkpath, null, s, true)); assertEquals(1, s.getVersion()); // set new data to check if touchConfDir overwrites later byte[] data = "{\"key\", \"new data\"".getBytes(StandardCharsets.UTF_8); - s = zkClient.setData(zkpath, data); + s = zkClient.setData(zkpath, data, true); assertEquals(2, s.getVersion()); // make sure touchConfDir doesn't overwrite existing data. // touchConfDir should update version. - assertTrue(zkClient.exists(zkpath)); + assertTrue(zkClient.exists(zkpath, true)); ZkController.touchConfDir(loader); - assertTrue(zkClient.exists(zkpath)); - assertArrayEquals(data, zkClient.getData(zkpath, null, s)); + assertTrue(zkClient.exists(zkpath, true)); + assertArrayEquals(data, zkClient.getData(zkpath, null, s, true)); assertEquals(3, s.getVersion()); } } @@ -388,7 +390,10 @@ public void testCheckNoOldClusterstate() throws Exception { server .getZkClient() .create( - "/clusterstate.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); + "/clusterstate.json", + "{}".getBytes(StandardCharsets.UTF_8), + CreateMode.PERSISTENT, + true); AtomicInteger idx = new AtomicInteger(); CountDownLatch latch = new CountDownLatch(nThreads); CountDownLatch done = new CountDownLatch(nThreads); @@ -415,7 +420,7 @@ public void testCheckNoOldClusterstate() throws Exception { }); } done.await(); - assertFalse(server.getZkClient().exists("/clusterstate.json")); + assertFalse(server.getZkClient().exists("/clusterstate.json", true)); assertNull(exception.get()); } finally { ExecutorUtil.shutdownNowAndAwaitTermination(svc); diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java index bf2f1389a30..2ce44a8b65c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java @@ -92,7 +92,7 @@ public void testMakeRootNode() throws Exception { .withUrl(conn.getServer().getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - assertTrue(zkClient.exists("/solr")); + assertTrue(zkClient.exists("/solr", true)); } } } @@ -102,14 +102,14 @@ public void testClean() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/test/path/here"); + zkClient.makePath("/test/path/here", true); - zkClient.makePath("/zz/path/here"); + zkClient.makePath("/zz/path/here", true); zkClient.clean("/"); - assertFalse(zkClient.exists("/test")); - assertFalse(zkClient.exists("/zz")); + assertFalse(zkClient.exists("/test", true)); + assertFalse(zkClient.exists("/zz", true)); } } @@ -125,7 +125,7 @@ public void testReconnect() throws Exception { .build()) { String shardsPath = "/collections/collection1/shards"; - zkClient.makePath(shardsPath, false); + zkClient.makePath(shardsPath, false, true); int zkServerPort = server.getPort(); // this tests disconnect state @@ -138,7 +138,7 @@ public void testReconnect() throws Exception { @Override public void run() { try { - zkClient.makePath("collections/collection2"); + zkClient.makePath("collections/collection2", false); // Assert.fail("Server should be down here"); } catch (KeeperException | InterruptedException e) { @@ -162,7 +162,7 @@ public void run() { public void run() { try { - zkClient.makePath("collections/collection3"); + zkClient.makePath("collections/collection3", true); } catch (KeeperException e) { throw new RuntimeException(e); @@ -178,8 +178,8 @@ public void run() { thread2.join(); - assertNotNull(zkClient.exists("/collections/collection3", null)); - assertNotNull(zkClient.exists("/collections/collection1", null)); + assertNotNull(zkClient.exists("/collections/collection3", null, true)); + assertNotNull(zkClient.exists("/collections/collection1", null, true)); // simulate session expiration @@ -196,7 +196,7 @@ public void run() { for (int i = 0; i < 8; i++) { try { - zkClient.makePath("collections/collection4"); + zkClient.makePath("collections/collection4", true); break; } catch (KeeperException.SessionExpiredException | KeeperException.ConnectionLossException e) { @@ -206,7 +206,8 @@ public void run() { } assertNotNull( - "Node does not exist, but it should", zkClient.exists("/collections/collection4", null)); + "Node does not exist, but it should", + zkClient.exists("/collections/collection4", null, true)); } finally { @@ -221,7 +222,7 @@ public void run() { public void testMultipleWatchesAsync() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/collections"); + zkClient.makePath("/collections", true); final int numColls = random().nextInt(100); final CountDownLatch latch = new CountDownLatch(numColls); @@ -231,7 +232,7 @@ public void testMultipleWatchesAsync() throws Exception { for (int i = 1; i <= numColls; i++) { String collPath = "/collections/collection" + i; - zkClient.makePath(collPath); + zkClient.makePath(collPath, true); zkClient.getChildren( collPath, new Watcher() { @@ -253,12 +254,13 @@ public void process(WatchedEvent event) { } watchesDone.countDown(); } - }); + }, + true); } for (int i = 1; i <= numColls; i++) { String shardsPath = "/collections/collection" + i + "/shards"; - zkClient.makePath(shardsPath); + zkClient.makePath(shardsPath, true); } assertTrue(latch.await(10000, TimeUnit.MILLISECONDS)); @@ -282,7 +284,7 @@ public void testWatchChildren() throws Exception { final AtomicInteger cnt = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); - zkClient.makePath("/collections"); + zkClient.makePath("/collections", true); zkClient.getChildren( "/collections", @@ -293,22 +295,23 @@ public void process(WatchedEvent event) { cnt.incrementAndGet(); // remake watch try { - zkClient.getChildren("/collections", this); + zkClient.getChildren("/collections", this, true); latch.countDown(); } catch (KeeperException | InterruptedException e) { throw new RuntimeException(e); } } - }); + }, + true); - zkClient.makePath("/collections/collection99/shards"); + zkClient.makePath("/collections/collection99/shards", true); latch.await(); // wait until watch has been re-created - zkClient.makePath("collections/collection99/config=collection1"); + zkClient.makePath("collections/collection99/config=collection1", true); - zkClient.makePath("collections/collection99/config=collection3"); + zkClient.makePath("collections/collection99/config=collection3", true); - zkClient.makePath("/collections/collection97/shards"); + zkClient.makePath("/collections/collection97/shards", true); // pause for the watches to fire Thread.sleep(700); @@ -333,7 +336,8 @@ public void testSkipPathPartsOnMakePath() throws Exception { zkClient.makePath("/test", true); // should work - zkClient.makePath("/test/path/here", null, CreateMode.PERSISTENT, null, true, 1); + zkClient.makePath( + "/test/path/here", (byte[]) null, CreateMode.PERSISTENT, (Watcher) null, true, true, 1); zkClient.clean("/"); @@ -343,7 +347,14 @@ public void testSkipPathPartsOnMakePath() throws Exception { KeeperException.NoNodeException.class, "We should not be able to create this path", () -> - zkClient.makePath("/test/path/here", null, CreateMode.PERSISTENT, null, true, 1)); + zkClient.makePath( + "/test/path/here", + (byte[]) null, + CreateMode.PERSISTENT, + (Watcher) null, + true, + true, + 1)); zkClient.clean("/"); @@ -376,14 +387,14 @@ public void testSkipPathPartsOnMakePath() throws Exception { ZkMaintenanceUtils.ensureExists( "/collection/collection", bytes, CreateMode.PERSISTENT, zkClient, 2); - byte[] returnedBytes = zkClient.getData("/collection/collection", null, null); + byte[] returnedBytes = zkClient.getData("/collection/collection", null, null, true); assertNull("We skipped 2 path parts, so data won't be written", returnedBytes); zkClient.makePath("/collection/collection/leader", true); ZkMaintenanceUtils.ensureExists( - "/collection/collection/leader", null, CreateMode.PERSISTENT, zkClient, 2); + "/collection/collection/leader", (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); } } @@ -392,14 +403,14 @@ public void testZkBehavior() throws Exception { configureCluster(4).withJettyConfig(jetty -> jetty.enableV2(true)).configure(); try { SolrZkClient zkClient = cluster.getZkClient(); - zkClient.create("/test-node", null, CreateMode.PERSISTENT); + zkClient.create("/test-node", null, CreateMode.PERSISTENT, true); - Stat stat = zkClient.exists("/test-node", null); + Stat stat = zkClient.exists("/test-node", null, true); int cversion = stat.getCversion(); zkClient.multi( op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/test-node/abc", null), op -> op.delete().withVersion(-1).forPath("/test-node/abc")); - stat = zkClient.exists("/test-node", null); + stat = zkClient.exists("/test-node", null, true); assertTrue(stat.getCversion() >= cversion + 2); } finally { cluster.shutdown(); diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java index 22d3a51b2c1..f252c23e901 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/ShardSplitTest.java @@ -708,7 +708,7 @@ public void testSplitLocking() throws Exception { TimeOut timeOut = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); while (!timeOut.hasTimedOut()) { timeOut.sleep(500); - if (ZkStateReader.from(cloudClient).getZkClient().exists(path)) { + if (ZkStateReader.from(cloudClient).getZkClient().exists(path, true)) { log.info("=== found lock node"); break; } @@ -726,13 +726,13 @@ public void testSplitLocking() throws Exception { // make sure the lock still exists assertTrue( "lock znode expected but missing", - ZkStateReader.from(cloudClient).getZkClient().exists(path)); + ZkStateReader.from(cloudClient).getZkClient().exists(path, true)); // let the first split proceed TestInjection.splitLatch.countDown(); timeOut = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); while (!timeOut.hasTimedOut()) { timeOut.sleep(500); - if (!ZkStateReader.from(cloudClient).getZkClient().exists(path)) { + if (!ZkStateReader.from(cloudClient).getZkClient().exists(path, true)) { break; } } diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/SimpleCollectionCreateDeleteTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/SimpleCollectionCreateDeleteTest.java index 021b93a9812..9d8c18f42d7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/SimpleCollectionCreateDeleteTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/SimpleCollectionCreateDeleteTest.java @@ -65,13 +65,15 @@ public void testCreateAndDeleteThenCreateAgain() throws Exception { NamedList request = create.process(cloudClient).getResponse(); if (request.get("success") != null) { - assertTrue(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + assertTrue( + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName); cloudClient.request(delete); - assertFalse(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + assertFalse( + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); // currently, removing a collection does not wait for cores to be unloaded TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); @@ -117,7 +119,7 @@ public void testPropertiesOfReplica() throws Exception { NamedList request = create.process(cloudClient).getResponse(); assertNotNull(request.get("success")); SolrZkClient.NodeData node = - getZkClient().getNode(DocCollection.getCollectionPath(collectionName), null); + getZkClient().getNode(DocCollection.getCollectionPath(collectionName), null, true); DocCollection c = ClusterState.createFromCollectionMap( @@ -149,25 +151,26 @@ public void testDeleteAlsoDeletesAutocreatedConfigSet() throws Exception { assertTrue( ZkStateReader.from(cloudClient) .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); String configName = cloudClient.getClusterStateProvider().getCollection(collectionName).getConfigName(); // config for this collection is '.AUTOCREATED', and exists globally assertTrue(configName.endsWith(".AUTOCREATED")); - assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); + assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName, true)); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName); cloudClient.request(delete); // collection has been deleted - assertFalse(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + assertFalse( + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); // ... and so has its autocreated config set assertFalse( "The auto-created config set should have been deleted with its collection", - getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName, true)); } } @@ -183,7 +186,8 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception if (requestInitial.get("success") != null) { // collection exists now assertTrue( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); + getZkClient() + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial, false)); String configName = cloudClient @@ -193,7 +197,7 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // config for this collection is '.AUTOCREATED', and exists globally assertTrue(configName.endsWith(".AUTOCREATED")); - assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); + assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName, true)); // create a second collection, sharing the same configSet String collectionNameWithSharedConfig = @@ -209,7 +213,8 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception assertTrue( "The new collection should exist after a successful creation", getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); + .exists( + ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig, false)); String configNameOfSecondCollection = cloudClient @@ -230,11 +235,12 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // initial collection has been deleted assertFalse( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); + getZkClient() + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial, false)); // ... but not its autocreated config set, since it is shared with another collection assertTrue( "The auto-created config set should NOT have been deleted. Another collection is using it.", - getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName, true)); // delete the second collection - the config set should now be deleted, since it is no longer // shared any other collection @@ -245,12 +251,13 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // the collection has been deleted assertFalse( getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); + .exists( + ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig, false)); // ... and the config set is now also deleted - once it doesn't get referenced by any // collection assertFalse( "The auto-created config set should have been deleted now. No collection is referencing it.", - getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName, true)); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java index d37017abda8..29c103cb9a3 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionAPI.java @@ -265,11 +265,11 @@ private void testNoConfigset() throws Exception { private void deleteThemAll(SolrZkClient zkClient, String node) throws KeeperException, InterruptedException { - List kids = zkClient.getChildren(node, null); + List kids = zkClient.getChildren(node, null, true); for (String kid : kids) { deleteThemAll(zkClient, node + "/" + kid); } - zkClient.delete(node, -1); + zkClient.delete(node, -1, true); } private void assertCountsForRepFactorAndNrtReplicas(CloudSolrClient client, String collectionName) diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestLocalFSCloudBackupRestore.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestLocalFSCloudBackupRestore.java index 04e1fff06e7..caa2e5f4c74 100644 --- a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestLocalFSCloudBackupRestore.java +++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestLocalFSCloudBackupRestore.java @@ -76,7 +76,9 @@ public static void setupClass() throws Exception { cluster .getZkClient() .delete( - ZkConfigSetService.CONFIGS_ZKNODE + "/" + "confFaulty" + "/" + "solrconfig.xml", -1); + ZkConfigSetService.CONFIGS_ZKNODE + "/" + "confFaulty" + "/" + "solrconfig.xml", + -1, + true); boolean whitespacesInPath = random().nextBoolean(); if (whitespacesInPath) { diff --git a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java index bb5a5fc0524..3e1ca33963c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateReaderTest.java @@ -178,7 +178,7 @@ public void testCollectionStateWatcherCaching() throws Exception { ZkWriteCommand wc = new ZkWriteCommand("c1", state); writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(wc), null); writer.writePendingUpdates(); - assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true)); reader.waitForState( "c1", 1, TimeUnit.SECONDS, (liveNodes, collectionState) -> collectionState != null); @@ -239,7 +239,7 @@ public void testWatchedCollectionCreation() throws Exception { writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(wc), null); writer.writePendingUpdates(); - assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true)); // reader.forceUpdateCollection("c1"); reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null); @@ -397,7 +397,7 @@ public void testForciblyRefreshAllClusterState() throws Exception { writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(wc), null); writer.writePendingUpdates(); - assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true)); reader.forciblyRefreshAllClusterStateSlow(); ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1"); @@ -480,7 +480,7 @@ public void testForciblyRefreshAllClusterStateCompressed() throws Exception { writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(wc), null); writer.writePendingUpdates(); - assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true)); reader.forciblyRefreshAllClusterStateSlow(); ClusterState.CollectionRef ref = reader.getClusterState().getCollectionRef("c1"); diff --git a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java index 1ef1cb28a0c..a1e76dd6bac 100644 --- a/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java @@ -88,9 +88,9 @@ public void testZkStateWriterBatching() throws Exception { try (ZkStateReader reader = new ZkStateReader(zkClient)) { reader.createClusterStateWatchersAndUpdate(); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2"); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c3"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c3", true); Map props = Collections.singletonMap( @@ -327,7 +327,7 @@ public void testSingleExternalCollection() throws Exception { ZkStateWriter writer = new ZkStateWriter(reader, new Stats(), -1, STATE_COMPRESSION_PROVIDER); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); // create new collection ZkWriteCommand c1 = @@ -348,7 +348,7 @@ public void testSingleExternalCollection() throws Exception { (Map) Utils.fromJSON( zkClient.getData( - ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null)); + ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true)); assertNotNull(map.get("c1")); } } finally { @@ -380,8 +380,8 @@ public void testExternalModification() throws Exception { ZkStateWriter writer = new ZkStateWriter(reader, new Stats(), -1, STATE_COMPRESSION_PROVIDER); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true); ClusterState state = reader.getClusterState(); @@ -402,8 +402,8 @@ public void testExternalModification() throws Exception { int c2Version = state.getCollection("c2").getZNodeVersion(); // Simulate an external modification to /collections/c2/state.json - byte[] data = zkClient.getData(DocCollection.getCollectionPath("c2"), null, null); - zkClient.setData(DocCollection.getCollectionPath("c2"), data); + byte[] data = zkClient.getData(DocCollection.getCollectionPath("c2"), null, null, true); + zkClient.setData(DocCollection.getCollectionPath("c2"), data, true); // get the most up-to-date state reader.forceUpdateCollection("c2"); @@ -500,7 +500,9 @@ public void testSingleExternalCollectionCompressedState() throws Exception { writer.writePendingUpdates(); byte[] data = - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null); + zkClient + .getZooKeeper() + .getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null); Map map = (Map) Utils.fromJSON(data); assertNotNull(map.get("c1")); } diff --git a/solr/core/src/test/org/apache/solr/handler/TestConfigReload.java b/solr/core/src/test/org/apache/solr/handler/TestConfigReload.java index ab806d58829..36ce1c08377 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestConfigReload.java +++ b/solr/core/src/test/org/apache/solr/handler/TestConfigReload.java @@ -77,15 +77,15 @@ private void checkConfReload(SolrZkClient client, String resPath, String name, S Stat stat = new Stat(); byte[] data = null; try { - data = client.getData(resPath, null, stat); + data = client.getData(resPath, null, stat, true); } catch (KeeperException.NoNodeException e) { data = "{}".getBytes(StandardCharsets.UTF_8); log.info("creating_node {}", resPath); - client.create(resPath, data, CreateMode.PERSISTENT); + client.create(resPath, data, CreateMode.PERSISTENT, true); } long startTime = System.nanoTime(); - Stat newStat = client.setData(resPath, data); - client.setData("/configs/conf1", new byte[] {1}); + Stat newStat = client.setData(resPath, data, true); + client.setData("/configs/conf1", new byte[] {1}, true); assertTrue(newStat.getVersion() > stat.getVersion()); if (log.isInfoEnabled()) { log.info("new_version {}", newStat.getVersion()); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.java b/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.java index ee4cf40ed34..109e27d64d9 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/ZookeeperReadAPITest.java @@ -86,7 +86,9 @@ public void testZkread() throws Exception { bytes[i] = (byte) random().nextInt(128); } try { - cluster.getZkClient().create("/configs/_default/testdata", bytes, CreateMode.PERSISTENT); + cluster + .getZkClient() + .create("/configs/_default/testdata", bytes, CreateMode.PERSISTENT, true); Utils.executeGET( client.getHttpClient(), basezk + "/configs/_default/testdata", @@ -99,7 +101,7 @@ public void testZkread() throws Exception { return null; }); } finally { - cluster.getZkClient().delete("/configs/_default/testdata", -1); + cluster.getZkClient().delete("/configs/_default/testdata", -1, true); } } } diff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java index 42b25847d15..57d5a6b47a8 100644 --- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java +++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java @@ -126,7 +126,7 @@ public void testTSV() throws Exception { String mutableId = getMutableId(configSet); assertFalse(cc.getZkController().getClusterState().hasCollection(mutableId)); SolrZkClient zkClient = cc.getZkController().getZkClient(); - assertFalse(zkClient.exists("/configs/" + mutableId)); + assertFalse(zkClient.exists("/configs/" + mutableId, true)); } @Test @@ -681,7 +681,7 @@ public void testBasicUserWorkflow() throws Exception { String mutableId = getMutableId(configSet); assertFalse(cc.getZkController().getClusterState().hasCollection(mutableId)); SolrZkClient zkClient = cc.getZkController().getZkClient(); - assertFalse(zkClient.exists("/configs/" + mutableId)); + assertFalse(zkClient.exists("/configs/" + mutableId, true)); SolrQuery query = new SolrQuery("*:*"); query.setRows(0); diff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java index bcb51f4217d..979ecd9ef0b 100644 --- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java +++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java @@ -180,7 +180,8 @@ public void testEnableDisableOptions() throws Exception { assertTrue( cluster .getZkClient() - .exists(SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); + .exists( + SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"), true)); assertNotNull(schema.getFieldTypeByName("text_fr")); assertNotNull(schema.getFieldOrNull("*_txt_fr")); assertNull(schema.getFieldOrNull("*_txt_ga")); @@ -203,7 +204,8 @@ public void testEnableDisableOptions() throws Exception { assertTrue( cluster .getZkClient() - .exists(SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); + .exists( + SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"), true)); assertNotNull(schema.getFieldTypeByName("text_fr")); assertNotNull(schema.getFieldOrNull("*_txt_fr")); assertNull(schema.getFieldOrNull("*_txt_ga")); diff --git a/solr/core/src/test/org/apache/solr/pkg/TestPackages.java b/solr/core/src/test/org/apache/solr/pkg/TestPackages.java index 7c92be25e5a..3e8fea806e5 100644 --- a/solr/core/src/test/org/apache/solr/pkg/TestPackages.java +++ b/solr/core/src/test/org/apache/solr/pkg/TestPackages.java @@ -623,7 +623,7 @@ public void testAPI() throws Exception { new MapWriterMap( (Map) Utils.fromJSON( - cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat(), true))), Map.of(":packages:test_pkg[0]:version", "0.12", ":packages:test_pkg[0]:files[0]", FILE2)); // post a new jar with a proper signature @@ -647,7 +647,7 @@ public void testAPI() throws Exception { new MapWriterMap( (Map) Utils.fromJSON( - cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat(), true))), Map.of(":packages:test_pkg[1]:version", "0.13", ":packages:test_pkg[1]:files[0]", FILE3)); // Now we will just delete one version @@ -673,7 +673,7 @@ public void testAPI() throws Exception { new MapWriterMap( (Map) Utils.fromJSON( - cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat(), true))), Map.of(":packages:test_pkg[0]:version", "0.13", ":packages:test_pkg[0]:files[0]", FILE3)); // So far we have been verifying the details with ZK directly diff --git a/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java b/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java index 33c0f3e3952..5c0f4f49d22 100644 --- a/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java +++ b/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java @@ -92,16 +92,16 @@ public void test() throws Exception { private String getFileContentFromZooKeeper(SolrZkClient zkClient, String fileName) throws KeeperException, InterruptedException { - return (new String(zkClient.getData(fileName, null, null), StandardCharsets.UTF_8)); + return (new String(zkClient.getData(fileName, null, null, true), StandardCharsets.UTF_8)); } protected final void assertFileNotInZooKeeper( SolrZkClient zkClient, String parent, String fileName) throws Exception { - List kids = zkClient.getChildren(parent, null); + List kids = zkClient.getChildren(parent, null, true); for (String kid : kids) { if (kid.equalsIgnoreCase(fileName)) { String rawContent = - new String(zkClient.getData(fileName, null, null), StandardCharsets.UTF_8); + new String(zkClient.getData(fileName, null, null, true), StandardCharsets.UTF_8); fail( "File '" + fileName diff --git a/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java b/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java index 8e84d5e5728..bd452178f63 100644 --- a/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java +++ b/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java @@ -73,11 +73,11 @@ boolean isSlowpoke() { } @Override - public byte[] getData(String path, Watcher watcher, Stat stat) + public byte[] getData(String path, Watcher watcher, Stat stat, boolean retryOnConnLoss) throws KeeperException, InterruptedException { byte[] data; try { - data = super.getData(path, watcher, stat); + data = super.getData(path, watcher, stat, retryOnConnLoss); } catch (NoNodeException e) { if (isSlowpoke()) { // System.out.println("suspending "+Thread.currentThread()+" on " + path); @@ -161,7 +161,7 @@ private ZkController createZkController(SolrZkClient client) public Boolean answer(InvocationOnMock invocation) throws Throwable { String path = (String) invocation.getArguments()[0]; perhapsExpired(); - Boolean exists = client.exists(path); + Boolean exists = client.exists(path, true); perhapsExpired(); return exists; } diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java index 12352970d2e..3599a4e2ebe 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java @@ -112,7 +112,7 @@ public void testBasicAuth() throws Exception { JettySolrRunner randomJetty = cluster.getRandomJetty(random()); String baseUrl = randomJetty.getBaseUrl().toString(); verifySecurityStatus(cl, baseUrl + authcPrefix, "/errorMessages", null, 20); - zkClient().setData("/security.json", STD_CONF.replace("'", "\"").getBytes(UTF_8)); + zkClient().setData("/security.json", STD_CONF.replace("'", "\"").getBytes(UTF_8), true); verifySecurityStatus( cl, baseUrl + authcPrefix, "authentication/class", "solr.BasicAuthPlugin", 20); diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java index b5d49a9c55f..8b6708fe825 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java @@ -80,7 +80,7 @@ public void testDeleteSecurityJsonZnode() throws Exception { // Deleting security.json will disable security - before SOLR-9679 it would instead cause an // exception - cluster.getZkClient().delete("/security.json", -1); + cluster.getZkClient().delete("/security.json", -1, false); int count = 0; boolean done = false; diff --git a/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java index ee04fcf20ed..3fdda76715d 100644 --- a/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java +++ b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java @@ -53,7 +53,8 @@ public void distribSetUp() throws Exception { new ZkStateReader(zkServer.getZkAddress(), TIMEOUT, TIMEOUT)) { zkStateReader .getZkClient() - .create(ZkStateReader.SOLR_SECURITY_CONF_PATH, SECURITY_JSON, CreateMode.PERSISTENT); + .create( + ZkStateReader.SOLR_SECURITY_CONF_PATH, SECURITY_JSON, CreateMode.PERSISTENT, true); } } diff --git a/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java index efba05bc1ca..9a781215b8e 100644 --- a/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java @@ -214,7 +214,8 @@ public void test() throws Exception { + "/" + COLLECTION_PROPS_ZKNODE, null, - null); + null, + true); assertNotNull(data); assertTrue(data.length > 0); @SuppressWarnings("unchecked") @@ -1047,7 +1048,8 @@ public void process(WatchedEvent watchedEvent) { aliasUpdate.countDown(); } }, - stat); + stat, + true); } /** @@ -1270,7 +1272,7 @@ private void manuallyConstructLegacyTRA() throws Exception { } // now grab the zk data, so we can hack in our legacy collections... - byte[] data = zkStateReader.getZkClient().getData("/aliases.json", null, null); + byte[] data = zkStateReader.getZkClient().getData("/aliases.json", null, null, true); // some tidbits for handling zk data here are swiped from Aliases.json Map aliasMap; @@ -1291,7 +1293,7 @@ private void manuallyConstructLegacyTRA() throws Exception { colAliases.put(alias, String.join(",", legacy24, legacy23)); data = Utils.toJSON(aliasMap); - zkStateReader.getZkClient().setData("/aliases.json", data); + zkStateReader.getZkClient().setData("/aliases.json", data, true); zkStateReader.aliasesManager.update(); // make sure we've updated with the data we just sent diff --git a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/DelegationTokenKerberosFilter.java b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/DelegationTokenKerberosFilter.java index a1c211b05ad..318ad72e7e7 100644 --- a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/DelegationTokenKerberosFilter.java +++ b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/DelegationTokenKerberosFilter.java @@ -158,7 +158,8 @@ protected CuratorFramework getCuratorClient(SolrZkClient zkClient) // path // without the appropriate ACL configuration. This issue is possibly related to HADOOP-11973 try { - zkClient.makePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT); + zkClient.makePath( + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException ex) { // ignore? } diff --git a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthFilter.java b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthFilter.java index 9a5dcff772d..25bd363d3ad 100644 --- a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthFilter.java +++ b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthFilter.java @@ -142,7 +142,8 @@ protected CuratorFramework getCuratorClient(SolrZkClient zkClient) // path // without the appropriate ACL configuration. This issue is possibly related to HADOOP-11973 try { - zkClient.makePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT); + zkClient.makePath( + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException ex) { // ignore? } diff --git a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/SaslZkACLProviderTest.java b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/SaslZkACLProviderTest.java index c06d8ecd420..9cf22f51cfe 100644 --- a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/SaslZkACLProviderTest.java +++ b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/SaslZkACLProviderTest.java @@ -97,7 +97,7 @@ public void setUp() throws Exception { new SolrZkClientWithACLs(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { ZooKeeperSaslClient saslClient = zkClient.getZooKeeper().getSaslClient(); assumeFalse("Could not set up ZK with SASL", saslClient.isFailed()); - zkClient.makePath("/solr", false); + zkClient.makePath("/solr", false, true); } catch (KeeperException e) { // This fails on Linux but passes on Windows and MacOS. Why? assumeNoException("Could not set up ZK chroot, see SOLR-15366.", e); @@ -114,13 +114,17 @@ protected void setupZNodes() throws Exception { new SolrZkClientWithACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + false); } finally { zkClient.close(); } @@ -128,9 +132,15 @@ protected void setupZNodes() throws Exception { zkClient = new SolrZkClientNoACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedCreateNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); zkClient.makePath( - "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); } finally { zkClient.close(); } diff --git a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestDelegationWithHadoopAuth.java b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestDelegationWithHadoopAuth.java index 60fc0e4e145..0fd49a52314 100644 --- a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestDelegationWithHadoopAuth.java +++ b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestDelegationWithHadoopAuth.java @@ -360,8 +360,8 @@ public void testZNodePaths() throws Exception { .withUrl(cluster.getZkServer().getZkAddress()) .withTimeout(1000, TimeUnit.MILLISECONDS) .build()) { - assertTrue(zkClient.exists("/security/zkdtsm")); - assertTrue(zkClient.exists("/security/token")); + assertTrue(zkClient.exists("/security/zkdtsm", true)); + assertTrue(zkClient.exists("/security/token", true)); } } diff --git a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithDelegationTokens.java b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithDelegationTokens.java index 1a99d543af5..30f59222e63 100644 --- a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithDelegationTokens.java +++ b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestSolrCloudWithDelegationTokens.java @@ -399,8 +399,8 @@ public void testZNodePaths() throws Exception { .withUrl(miniCluster.getZkServer().getZkAddress()) .withTimeout(1000, TimeUnit.MILLISECONDS) .build()) { - assertTrue(zkClient.exists("/security/zkdtsm")); - assertTrue(zkClient.exists("/security/token")); + assertTrue(zkClient.exists("/security/zkdtsm", true)); + assertTrue(zkClient.exists("/security/token", true)); } } diff --git a/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/api/collections/TestHdfsCloudBackupRestore.java b/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/api/collections/TestHdfsCloudBackupRestore.java index b1616c20b6f..9cb6c9ec25a 100644 --- a/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/api/collections/TestHdfsCloudBackupRestore.java +++ b/solr/modules/hdfs/src/test/org/apache/solr/hdfs/cloud/api/collections/TestHdfsCloudBackupRestore.java @@ -160,7 +160,8 @@ public static void setupClass() throws Exception { + "confFaulty" + Path.SEPARATOR + "solrconfig.xml", - -1); + -1, + true); } @AfterClass diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkClientClusterStateProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkClientClusterStateProvider.java index 4e74981a661..075c1e4d3de 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkClientClusterStateProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkClientClusterStateProvider.java @@ -100,7 +100,7 @@ public static ClusterState createFromJsonSupportingLegacyConfigName( try { // read configName from collections/collection node String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + coll; - byte[] data = zkClient.getData(path, null, null); + byte[] data = zkClient.getData(path, null, null, true); if (data != null && data.length > 0) { ZkNodeProps configProp = ZkNodeProps.load(data); String configName = configProp.getStr(ZkStateReader.CONFIGNAME_PROP); diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java index 15d3ebc2651..0d9f99f0c6d 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java @@ -66,7 +66,7 @@ public Map getJson(String path) @Override public boolean hasData(String path) throws IOException, KeeperException, InterruptedException { try { - return zkClient.exists(path); + return zkClient.exists(path, true); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new AlreadyClosedException(); @@ -77,7 +77,7 @@ public boolean hasData(String path) throws IOException, KeeperException, Interru public List listData(String path, Watcher watcher) throws NoSuchElementException, IOException, KeeperException, InterruptedException { try { - return zkClient.getChildren(path, watcher); + return zkClient.getChildren(path, watcher, true); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (InterruptedException e) { @@ -97,7 +97,7 @@ public VersionedData getData(String path, Watcher watcher) throws NoSuchElementException, IOException, KeeperException, InterruptedException { Stat stat = new Stat(); try { - byte[] bytes = zkClient.getData(path, watcher, stat); + byte[] bytes = zkClient.getData(path, watcher, stat, true); return new VersionedData( stat.getVersion(), bytes, @@ -115,7 +115,7 @@ public VersionedData getData(String path, Watcher watcher) public void makePath(String path) throws AlreadyExistsException, IOException, KeeperException, InterruptedException { try { - zkClient.makePath(path); + zkClient.makePath(path, true); } catch (KeeperException.NodeExistsException e) { throw new AlreadyExistsException(path); } catch (InterruptedException e) { @@ -128,7 +128,7 @@ public void makePath(String path) public void makePath(String path, byte[] data, CreateMode createMode, boolean failOnExists) throws AlreadyExistsException, IOException, KeeperException, InterruptedException { try { - zkClient.makePath(path, data, createMode, null, failOnExists); + zkClient.makePath(path, data, createMode, null, failOnExists, true); } catch (KeeperException.NodeExistsException e) { throw new AlreadyExistsException(path); } catch (InterruptedException e) { @@ -142,7 +142,7 @@ public String createData(String path, byte[] data, CreateMode mode) throws NoSuchElementException, AlreadyExistsException, IOException, KeeperException, InterruptedException { try { - return zkClient.create(path, data, mode); + return zkClient.create(path, data, mode, true); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.NodeExistsException e) { @@ -158,7 +158,7 @@ public void removeData(String path, int version) throws NoSuchElementException, BadVersionException, NotEmptyException, IOException, KeeperException, InterruptedException { try { - zkClient.delete(path, version); + zkClient.delete(path, version, true); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.NotEmptyException e) { @@ -176,7 +176,7 @@ public void setData(String path, byte[] data, int version) throws BadVersionException, NoSuchElementException, IOException, KeeperException, InterruptedException { try { - zkClient.setData(path, data, version); + zkClient.setData(path, data, version, true); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.BadVersionException e) { diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/LazySolrCluster.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/LazySolrCluster.java index 6baac9554d0..811a0b4e2e8 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/LazySolrCluster.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/LazySolrCluster.java @@ -265,7 +265,7 @@ public String config() { byte[] d = zkStateReader .getZkClient() - .getData(DocCollection.getCollectionPathRoot(coll.getName()), null, null); + .getData(DocCollection.getCollectionPathRoot(coll.getName()), null, null, true); if (d == null || d.length == 0) return null; Map m = (Map) Utils.fromJSON(d); confName = (String) m.get("configName"); diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/SimpleZkMap.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/SimpleZkMap.java index 5848831fd76..39051da857c 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/SimpleZkMap.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/SimpleZkMap.java @@ -54,7 +54,7 @@ public Resource get(String key) { @Override public void abortableForEach(BiFunction fun) { try { - recursiveRead("", zkStateReader.getZkClient().getChildren(basePath, null), fun); + recursiveRead("", zkStateReader.getZkClient().getChildren(basePath, null, true), fun); } catch (KeeperException | InterruptedException e) { throwZkExp(e); } @@ -84,7 +84,8 @@ public String name() { @Override public void get(Consumer consumer) throws SolrException { try { - byte[] data = zkStateReader.getZkClient().getData(basePath + "/" + path, null, null); + byte[] data = + zkStateReader.getZkClient().getData(basePath + "/" + path, null, null, true); if (data != null && data.length > 0) { consumer.read(new ByteArrayInputStream(data)); } else { @@ -108,7 +109,7 @@ private boolean recursiveRead( String relativePath = parent.isEmpty() ? child : parent + "/" + child; if (!fun.apply(relativePath, readZkNode(relativePath))) return false; List l1 = - zkStateReader.getZkClient().getChildren(basePath + "/" + relativePath, null); + zkStateReader.getZkClient().getChildren(basePath + "/" + relativePath, null, true); if (l1 != null && !l1.isEmpty()) { withKids.put(relativePath, l1); } diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java index 9373d8825ae..84e5cf462e4 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ClusterProperties.java @@ -97,7 +97,7 @@ public Map getClusterProperties() throws IOException { try { Map properties = (Map) - Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); + Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true)); return convertCollectionDefaultsToNestedFormat(properties); } catch (KeeperException.NoNodeException e) { return Collections.emptyMap(); @@ -197,21 +197,23 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws for (; ; ) { Stat s = new Stat(); try { - if (client.exists(ZkStateReader.CLUSTER_PROPS)) { + if (client.exists(ZkStateReader.CLUSTER_PROPS, true)) { @SuppressWarnings({"rawtypes"}) Map properties = - (Map) Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, s)); + (Map) Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, s, true)); if (propertyValue == null) { // Don't update ZK unless absolutely necessary. if (properties.get(propertyName) != null) { properties.remove(propertyName); - client.setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion()); + client.setData( + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion(), true); } } else { // Don't update ZK unless absolutely necessary. if (!propertyValue.equals(properties.get(propertyName))) { properties.put(propertyName, propertyValue); - client.setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion()); + client.setData( + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion(), true); } } } else { @@ -219,7 +221,7 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws Map properties = new LinkedHashMap(); properties.put(propertyName, propertyValue); client.makePath( - ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT); + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT, true); } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { // race condition diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionProperties.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionProperties.java index 25b13086267..e036ac76217 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionProperties.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/CollectionProperties.java @@ -67,7 +67,8 @@ public Map getCollectionProperties(String collection) throws IOE try { return (Map) Utils.fromJSON( - client.getData(ZkStateReader.getCollectionPropsPath(collection), null, new Stat())); + client.getData( + ZkStateReader.getCollectionPropsPath(collection), null, new Stat(), true)); } catch (KeeperException.NoNodeException e) { return Collections.emptyMap(); } catch (KeeperException | InterruptedException e) { @@ -93,25 +94,25 @@ public void setCollectionProperty(String collection, String propertyName, String while (true) { Stat s = new Stat(); try { - if (client.exists(znodePath)) { + if (client.exists(znodePath, true)) { Map properties = - (Map) Utils.fromJSON(client.getData(znodePath, null, s)); + (Map) Utils.fromJSON(client.getData(znodePath, null, s, true)); if (propertyValue == null) { if (properties.remove(propertyName) != null) { // Don't update ZK unless absolutely necessary. - client.setData(znodePath, Utils.toJSON(properties), s.getVersion()); + client.setData(znodePath, Utils.toJSON(properties), s.getVersion(), true); } } else { if (!propertyValue.equals( properties.put( propertyName, propertyValue))) { // Don't update ZK unless absolutely necessary. - client.setData(znodePath, Utils.toJSON(properties), s.getVersion()); + client.setData(znodePath, Utils.toJSON(properties), s.getVersion(), true); } } } else { Map properties = new LinkedHashMap<>(); properties.put(propertyName, propertyValue); - client.create(znodePath, Utils.toJSON(properties), CreateMode.PERSISTENT); + client.create(znodePath, Utils.toJSON(properties), CreateMode.PERSISTENT, true); } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { // race condition diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java index 2194defcdde..85fcef00e83 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java @@ -59,12 +59,12 @@ public static PerReplicaStates fetch( assert CommonTestInjection.injectBreakpoint( PerReplicaStatesOps.class.getName() + "/beforePrsFetch"); if (current != null) { - Stat stat = zkClient.exists(current.path, null); + Stat stat = zkClient.exists(current.path, null, true); if (stat == null) return new PerReplicaStates(path, 0, Collections.emptyList()); if (current.cversion == stat.getCversion()) return current; // not modifiedZkStateReaderTest } Stat stat = new Stat(); - List children = zkClient.getChildren(path, null, stat); + List children = zkClient.getChildren(path, null, stat, true); return new PerReplicaStates(path, stat.getCversion(), Collections.unmodifiableList(children)); } catch (KeeperException.NoNodeException e) { throw new PrsZkNodeNotFoundException( @@ -115,7 +115,7 @@ private void persist( try { zkClient.multi(ops); } catch (KeeperException e) { - log.error("Multi-op exception: {}", zkClient.getChildren(znode, null)); + log.error("Multi-op exception: {}", zkClient.getChildren(znode, null, true)); throw e; } } diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityNodeWatcher.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityNodeWatcher.java index 0a35bad37e5..487fa6b427b 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityNodeWatcher.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityNodeWatcher.java @@ -71,9 +71,12 @@ public void process(WatchedEvent event) { new SolrZkClient.NodeData(new Stat(), "{}".getBytes(StandardCharsets.UTF_8)); if (Event.EventType.NodeDeleted.equals(event.getType())) { // Node deleted, just recreate watch without attempting a read - SOLR-9679 - zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); + zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this, true); } else { - data = zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); + data = + zkStateReader + .getZkClient() + .getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, this, true); } try { callback.call(data); @@ -94,7 +97,7 @@ public void process(WatchedEvent event) { } void register() throws InterruptedException, KeeperException { - zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); + zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this, true); securityData = getSecurityProps(true); } @@ -105,9 +108,9 @@ ZkStateReader.ConfigData getSecurityProps(boolean getFresh) { return new ZkStateReader.ConfigData(securityData.data, securityData.version); } try { - if (zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH)) { + if (zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, true)) { SolrZkClient.NodeData d = - zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, null); + zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, true); return d != null && d.data.length > 0 ? new ZkStateReader.ConfigData( (Map) Utils.fromJSON(d.data), d.stat.getVersion()) diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SolrZkClient.java index c87be19e421..64c8b523343 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -328,7 +328,7 @@ public boolean isConnected() { return client.getZookeeperClient().isConnected(); } - public void delete(final String path, final int version) + public void delete(final String path, final int version, boolean retryOnConnLoss) throws InterruptedException, KeeperException { runWithCorrectThrows( "deleting znode", () -> client.delete().withVersion(version).forPath(path)); @@ -338,8 +338,9 @@ public void delete(final String path, final int version) /** * Wraps the watcher so that it doesn't fire off ZK's event queue. In order to guarantee that a * watch object will only be triggered once for a given notification, users need to wrap their - * watcher using this method before calling {@link #exists(String, Watcher)} or {@link - * #getData(String, Watcher, Stat)}. + * watcher using this method before calling {@link #exists(String, org.apache.zookeeper.Watcher, + * boolean)} or {@link #getData(String, org.apache.zookeeper.Watcher, + * org.apache.zookeeper.data.Stat, boolean)}. */ public Watcher wrapWatcher(final Watcher watcher) { if (watcher == null || watcher instanceof ProcessWatchWithExecutor) return watcher; @@ -360,7 +361,7 @@ public Watcher wrapWatcher(final Watcher watcher) { * @throws InterruptedException If the server transaction is interrupted. * @throws IllegalArgumentException if an invalid path is specified */ - public Stat exists(final String path, final Watcher watcher) + public Stat exists(final String path, final Watcher watcher, boolean retryOnConnLoss) throws KeeperException, InterruptedException { Stat result = runWithCorrectThrows( @@ -371,7 +372,8 @@ public Stat exists(final String path, final Watcher watcher) } /** Returns true if path exists */ - public Boolean exists(final String path) throws KeeperException, InterruptedException { + public Boolean exists(final String path, boolean retryOnConnLoss) + throws KeeperException, InterruptedException { Boolean result = runWithCorrectThrows("checking exists", () -> client.checkExists().forPath(path) != null); metrics.existsChecks.increment(); @@ -379,7 +381,7 @@ public Boolean exists(final String path) throws KeeperException, InterruptedExce } /** Returns children of the node at the path */ - public List getChildren(final String path, final Watcher watcher) + public List getChildren(final String path, final Watcher watcher, boolean retryOnConnLoss) throws KeeperException, InterruptedException { List result = runWithCorrectThrows( @@ -394,7 +396,8 @@ public List getChildren(final String path, final Watcher watcher) } /** Returns children of the node at the path */ - public List getChildren(final String path, final Watcher watcher, Stat stat) + public List getChildren( + final String path, final Watcher watcher, Stat stat, boolean retryOnConnLoss) throws KeeperException, InterruptedException { List result = runWithCorrectThrows( @@ -414,7 +417,8 @@ public List getChildren(final String path, final Watcher watcher, Stat s } /** Returns node's data */ - public byte[] getData(final String path, final Watcher watcher, final Stat stat) + public byte[] getData( + final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) throws KeeperException, InterruptedException { byte[] result = runWithCorrectThrows( @@ -444,14 +448,15 @@ public byte[] getData(final String path, final Watcher watcher, final Stat stat) return result; } - public NodeData getNode(final String path, Watcher watcher) + public NodeData getNode(final String path, Watcher watcher, boolean retryOnConnLoss) throws KeeperException, InterruptedException { Stat stat = new Stat(); - return new NodeData(stat, getData(path, watcher, stat)); + return new NodeData(stat, getData(path, watcher, stat, retryOnConnLoss)); } /** Returns node's state */ - public Stat setData(final String path, final byte data[], final int version) + public Stat setData( + final String path, final byte data[], final int version, boolean retryOnConnLoss) throws KeeperException, InterruptedException { Stat result = runWithCorrectThrows( @@ -475,14 +480,14 @@ public void atomicUpdate(String path, BiFunction editor) byte[] zkData = null; Stat s = new Stat(); try { - if (exists(path)) { - zkData = getData(path, null, s); + if (exists(path, true)) { + zkData = getData(path, null, s, true); modified = editor.apply(s, zkData); if (modified == null) { // no change , no need to persist return; } - setData(path, modified, s.getVersion()); + setData(path, modified, s.getVersion(), true); break; } else { modified = editor.apply(s, null); @@ -490,7 +495,7 @@ public void atomicUpdate(String path, BiFunction editor) // no change , no need to persist return; } - create(path, modified, CreateMode.PERSISTENT); + create(path, modified, CreateMode.PERSISTENT, true); break; } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { @@ -500,7 +505,8 @@ public void atomicUpdate(String path, BiFunction editor) } /** Returns path of created node */ - public String create(final String path, final byte[] data, final CreateMode createMode) + public String create( + final String path, final byte[] data, final CreateMode createMode, boolean retryOnConnLoss) throws KeeperException, InterruptedException { String result = runWithCorrectThrows( @@ -518,28 +524,36 @@ public String create(final String path, final byte[] data, final CreateMode crea *

e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, * each will be created. */ - public void makePath(String path) throws KeeperException, InterruptedException { - makePath(path, null, CreateMode.PERSISTENT); + public void makePath(String path, boolean retryOnConnLoss) + throws KeeperException, InterruptedException { + makePath(path, null, CreateMode.PERSISTENT, retryOnConnLoss); } - public void makePath(String path, boolean failOnExists) + public void makePath(String path, boolean failOnExists, boolean retryOnConnLoss) throws KeeperException, InterruptedException { - makePath(path, null, CreateMode.PERSISTENT, null, failOnExists, 0); + makePath(path, null, CreateMode.PERSISTENT, null, failOnExists, retryOnConnLoss, 0); } - public void makePath(String path, Path data, boolean failOnExists) + public void makePath(String path, Path data, boolean failOnExists, boolean retryOnConnLoss) throws IOException, KeeperException, InterruptedException { - makePath(path, Files.readAllBytes(data), CreateMode.PERSISTENT, null, failOnExists, 0); + makePath( + path, + Files.readAllBytes(data), + CreateMode.PERSISTENT, + null, + failOnExists, + retryOnConnLoss, + 0); } - public void makePath(String path, Path data) + public void makePath(String path, Path data, boolean retryOnConnLoss) throws IOException, KeeperException, InterruptedException { - makePath(path, Files.readAllBytes(data)); + makePath(path, Files.readAllBytes(data), retryOnConnLoss); } - public void makePath(String path, CreateMode createMode) + public void makePath(String path, CreateMode createMode, boolean retryOnConnLoss) throws KeeperException, InterruptedException { - makePath(path, null, createMode); + makePath(path, null, createMode, retryOnConnLoss); } /** @@ -547,8 +561,9 @@ public void makePath(String path, CreateMode createMode) * * @param data to set on the last zkNode */ - public void makePath(String path, byte[] data) throws KeeperException, InterruptedException { - makePath(path, data, CreateMode.PERSISTENT); + public void makePath(String path, byte[] data, boolean retryOnConnLoss) + throws KeeperException, InterruptedException { + makePath(path, data, CreateMode.PERSISTENT, retryOnConnLoss); } /** @@ -559,14 +574,9 @@ public void makePath(String path, byte[] data) throws KeeperException, Interrupt * * @param data to set on the last zkNode */ - public void makePath(String path, byte[] data, CreateMode createMode) - throws KeeperException, InterruptedException { - makePath(path, data, createMode, null); - } - - public void makePath(String zkPath, CreateMode createMode, Watcher watcher) + public void makePath(String path, byte[] data, CreateMode createMode, boolean retryOnConnLoss) throws KeeperException, InterruptedException { - makePath(zkPath, null, createMode, watcher, true, 0); + makePath(path, data, createMode, null, retryOnConnLoss); } /** @@ -577,9 +587,10 @@ public void makePath(String zkPath, CreateMode createMode, Watcher watcher) * * @param data to set on the last zkNode */ - public void makePath(String path, byte[] data, CreateMode createMode, Watcher watcher) + public void makePath( + String path, byte[] data, CreateMode createMode, Watcher watcher, boolean retryOnConnLoss) throws KeeperException, InterruptedException { - makePath(path, data, createMode, watcher, true, 0); + makePath(path, data, createMode, watcher, true, retryOnConnLoss, 0); } /** @@ -591,9 +602,14 @@ public void makePath(String path, byte[] data, CreateMode createMode, Watcher wa * @param data to set on the last zkNode */ public void makePath( - String path, byte[] data, CreateMode createMode, Watcher watcher, boolean failOnExists) + String path, + byte[] data, + CreateMode createMode, + Watcher watcher, + boolean failOnExists, + boolean retryOnConnLoss) throws KeeperException, InterruptedException { - makePath(path, data, createMode, watcher, failOnExists, 0); + makePath(path, data, createMode, watcher, failOnExists, retryOnConnLoss, 0); } /** @@ -604,6 +620,8 @@ public void makePath( * *

skipPathParts will force the call to fail if the first skipPathParts do not exist already. * + *

Note: retryOnConnLoss is no longer respected at all and is ignored + * *

Note: if failOnExists == false then we will always overwrite the existing data with the * given data */ @@ -613,6 +631,7 @@ public void makePath( CreateMode createMode, Watcher watcher, boolean failOnExists, + boolean retryOnConnLoss, int skipPathParts) throws KeeperException, InterruptedException { log.debug("makePath: {}", path); @@ -668,6 +687,12 @@ public void makePath( }); } + public void makePath( + String zkPath, CreateMode createMode, Watcher watcher, boolean retryOnConnLoss) + throws KeeperException, InterruptedException { + makePath(zkPath, null, createMode, watcher, retryOnConnLoss); + } + /** * Create a node if it does not exist * @@ -711,7 +736,7 @@ public void ensureExists(final String path, final byte[] data, CreateMode create public void ensureExists( final String path, final byte[] data, CreateMode createMode, int skipPathParts) throws KeeperException, InterruptedException { - if (exists(path)) { + if (exists(path, true)) { return; } try { @@ -724,19 +749,20 @@ public void ensureExists( throw new KeeperException.NoNodeException(path); } String startingPath = path.substring(0, endingIndex); - if (!exists(startingPath)) { + if (!exists(startingPath, true)) { throw new KeeperException.NoNodeException(startingPath); } } - makePath(path, data, createMode, null, true, skipPathParts); + makePath(path, data, createMode, null, true, true, skipPathParts); } catch (KeeperException.NodeExistsException ignored) { // it's okay if another beats us creating the node } } /** Write data to ZooKeeper. */ - public Stat setData(String path, byte[] data) throws KeeperException, InterruptedException { - return setData(path, data, -1); + public Stat setData(String path, byte[] data, boolean retryOnConnLoss) + throws KeeperException, InterruptedException { + return setData(path, data, -1, retryOnConnLoss); } /** @@ -745,12 +771,12 @@ public Stat setData(String path, byte[] data) throws KeeperException, Interrupte * @param path path to upload file to e.g. /solr/conf/solrconfig.xml * @param data a filepath to read data from */ - public Stat setData(String path, Path data) + public Stat setData(String path, Path data, boolean retryOnConnLoss) throws IOException, KeeperException, InterruptedException { if (log.isDebugEnabled()) { log.debug("Write to ZooKeeper: {} to {}", data.toAbsolutePath(), path); } - return setData(path, Files.readAllBytes(data)); + return setData(path, Files.readAllBytes(data), retryOnConnLoss); } @FunctionalInterface @@ -796,8 +822,8 @@ public List multi(final List ops) /** Fills string with printout of current ZooKeeper layout. */ public void printLayout(String path, int indent, StringBuilder string) throws KeeperException, InterruptedException { - byte[] data = getData(path, null, null); - List children = getChildren(path, null); + byte[] data = getData(path, null, null, true); + List children = getChildren(path, null, true); StringBuilder dent = new StringBuilder(); dent.append(" ".repeat(Math.max(0, indent))); string.append(dent).append(path).append(" (").append(children.size()).append(")").append(NEWL); @@ -959,7 +985,8 @@ public ACLProvider getZkACLProvider() { /** * @return the ACLs on a single node in ZooKeeper. */ - public List getACL(String path, Stat stat) throws KeeperException, InterruptedException { + public List getACL(String path, Stat stat, boolean retryOnConnLoss) + throws KeeperException, InterruptedException { return runWithCorrectThrows( "getting acls", () -> client.getACL().storingStatIn(stat).forPath(path)); } diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java index 658281dd09c..34d770c7a12 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java @@ -85,7 +85,7 @@ public static String listZnode(SolrZkClient zkClient, String path, Boolean recur StringBuilder sb = new StringBuilder(); if (recurse == false) { - for (String node : zkClient.getChildren(root, null)) { + for (String node : zkClient.getChildren(root, null, true)) { if (node.equals("zookeeper") == false) { sb.append(node).append(System.lineSeparator()); } @@ -139,7 +139,7 @@ public static void zkTransfer( // Make sure -recurse is specified if the source has children. if (recurse == false) { if (srcIsZk) { - if (zkClient.getChildren(src, null).size() != 0) { + if (zkClient.getChildren(src, null, true).size() != 0) { throw new SolrServerException( "Zookeeper node " + src + " has children and recurse is false"); } @@ -171,7 +171,7 @@ public static void zkTransfer( // Copying individual files from ZK requires special handling since downloadFromZK assumes the // node has children. This is kind of a weak test for the notion of "directory" on Zookeeper. ZK // -> local copy where ZK is a parent node - if (zkClient.getChildren(src, null).size() > 0) { + if (zkClient.getChildren(src, null, true).size() > 0) { downloadFromZK(zkClient, src, Paths.get(dst)); return; } @@ -181,7 +181,7 @@ public static void zkTransfer( if (dst.endsWith(File.separator) == false) dst += File.separator; dst = normalizeDest(src, dst, srcIsZk, dstIsZk); } - byte[] data = zkClient.getData(src, null, null); + byte[] data = zkClient.getData(src, null, null, true); Path filename = Paths.get(dst); Path parentDir = filename.getParent(); if (parentDir != null) { @@ -222,9 +222,9 @@ public static void moveZnode(SolrZkClient zkClient, String src, String dst) 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).size() == 0) { - zkClient.makePath(destName, false); - zkClient.setData(destName, zkClient.getData(src, null, null)); + 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)); } @@ -241,8 +241,8 @@ public static void moveZnode(SolrZkClient zkClient, String src, String dst) private static void checkAllZnodesThere(SolrZkClient zkClient, String src, String dst) throws KeeperException, InterruptedException, SolrServerException { - for (String node : zkClient.getChildren(src, null)) { - if (zkClient.exists(dst + "/" + node) == false) { + for (String node : zkClient.getChildren(src, null, true)) { + if (zkClient.exists(dst + "/" + node, true) == false) { throw new SolrServerException( "mv command did not move node " + dst + "/" + node + " source left intact"); } @@ -261,7 +261,7 @@ public static void clean(SolrZkClient zkClient, String path) try { if (!znode.equals("/")) { try { - zkClient.delete(znode, -1); + zkClient.delete(znode, -1, true); } catch (KeeperException.NotEmptyException e) { clean(zkClient, znode); } @@ -300,7 +300,7 @@ public static void clean(SolrZkClient zkClient, String path, Predicate f for (String subpath : paths) { if (!subpath.equals("/")) { try { - zkClient.delete(subpath, -1); + zkClient.delete(subpath, -1, true); } catch (KeeperException.NotEmptyException | KeeperException.NoNodeException e) { // expected } @@ -324,9 +324,11 @@ public static void uploadToZK( 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<>() { + new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { @@ -348,11 +350,24 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) 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)) { - zkClient.setData(zkNode, file); - } else { + 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); + zkClient.makePath(zkNode, file, false, true); + } else { + // 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( @@ -371,9 +386,11 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) try { if (dir.equals(rootPath)) { // Make sure the root path exists, including potential parents - zkClient.makePath(zkNode); - } else { 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, true, true, pathParts); } } catch (KeeperException.NodeExistsException ignored) { // Using fail-on-exists == false has side effect of makePath attempting to setData on @@ -392,13 +409,13 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) private static boolean isEphemeral(SolrZkClient zkClient, String zkPath) throws KeeperException, InterruptedException { - Stat znodeStat = zkClient.exists(zkPath, null); + Stat znodeStat = zkClient.exists(zkPath, null, true); return znodeStat.getEphemeralOwner() != 0; } private static int copyDataDown(SolrZkClient zkClient, String zkPath, Path file) throws IOException, KeeperException, InterruptedException { - byte[] data = zkClient.getData(zkPath, null, null); + byte[] data = zkClient.getData(zkPath, null, null, true); if (data != null && data.length > 0) { // There are apparently basically empty ZNodes. log.info("Writing file {}", file); Files.write(file, data); @@ -410,7 +427,7 @@ private static int copyDataDown(SolrZkClient zkClient, String zkPath, Path file) public static void downloadFromZK(SolrZkClient zkClient, String zkPath, Path file) throws IOException { try { - List children = zkClient.getChildren(zkPath, null); + List children = zkClient.getChildren(zkPath, null, true); // If it has no children, it's a leaf node, write the associated data from the ZNode. // Otherwise, continue recursing, but write the associated data to a special file if any if (children.size() == 0) { @@ -481,7 +498,7 @@ public static void traverseZkTree( } List children; try { - children = zkClient.getChildren(path, null); + children = zkClient.getChildren(path, null, true); } catch (KeeperException.NoNodeException r) { return; } @@ -622,11 +639,11 @@ public static void ensureExists( int skipPathParts) throws KeeperException, InterruptedException { - if (zkClient.exists(path)) { + if (zkClient.exists(path, true)) { return; } try { - zkClient.makePath(path, data, createMode, null, true, skipPathParts); + zkClient.makePath(path, data, createMode, null, true, true, skipPathParts); } catch (NodeExistsException ignored) { // it's okay if another beats us creating the node } @@ -652,8 +669,8 @@ 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); - zkClient.setData(finalDestination, zkClient.getData(path, null, null)); + zkClient.makePath(finalDestination, false, true); + zkClient.setData(finalDestination, zkClient.getData(path, null, null, true), true); } } } diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java index f16360a34be..604779839fb 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java @@ -660,7 +660,7 @@ private void refreshCollectionList(Watcher watcher) throws KeeperException, Inte synchronized (refreshCollectionListLock) { List children = null; try { - children = zkClient.getChildren(COLLECTIONS_ZKNODE, watcher); + children = zkClient.getChildren(COLLECTIONS_ZKNODE, watcher, true); } catch (KeeperException.NoNodeException e) { log.warn("Error fetching collection names: ", e); // fall through @@ -754,7 +754,7 @@ public synchronized DocCollection get(boolean allowCached) { if (cachedDocCollection != null) { Stat freshStats = null; try { - freshStats = zkClient.exists(DocCollection.getCollectionPath(collName), null); + freshStats = zkClient.exists(DocCollection.getCollectionPath(collName), null, true); } catch (Exception e) { } if (freshStats != null @@ -792,7 +792,7 @@ private void refreshLiveNodes(Watcher watcher) throws KeeperException, Interrupt synchronized (refreshLiveNodesLock) { SortedSet newLiveNodes; try { - List nodeList = zkClient.getChildren(LIVE_NODES_ZKNODE, watcher); + List nodeList = zkClient.getChildren(LIVE_NODES_ZKNODE, watcher, true); newLiveNodes = new TreeSet<>(nodeList); } catch (KeeperException.NoNodeException e) { newLiveNodes = emptySortedSet(); @@ -1144,7 +1144,8 @@ private void loadClusterProperties() { while (true) { try { byte[] data = - zkClient.getData(ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat()); + zkClient.getData( + ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat(), true); @SuppressWarnings("unchecked") Map properties = (Map) Utils.fromJSON(data); this.clusterProperties = @@ -1160,7 +1161,7 @@ private void loadClusterProperties() { log.debug("Loaded empty cluster properties"); // set an exists watch, and if the node has been created since the last call, // read the data again - if (zkClient.exists(ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher) == null) + if (zkClient.exists(ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, true) == null) return; } } @@ -1273,7 +1274,7 @@ private VersionedCollectionProps fetchCollectionProperties(String collection, Wa while (true) { try { Stat stat = new Stat(); - byte[] data = zkClient.getData(znodePath, watcher, stat); + byte[] data = zkClient.getData(znodePath, watcher, stat, true); @SuppressWarnings("unchecked") Map props = (Map) Utils.fromJSON(data); return new VersionedCollectionProps(stat.getVersion(), props); @@ -1285,7 +1286,7 @@ private VersionedCollectionProps fetchCollectionProperties(String collection, Wa } catch (KeeperException.NoNodeException e) { if (watcher != null) { // Leave an exists watch in place in case a collectionprops.json is created later. - Stat exists = zkClient.exists(znodePath, watcher); + Stat exists = zkClient.exists(znodePath, watcher, true); if (exists != null) { // Rare race condition, we tried to fetch the data and couldn't find it, then we found // it exists. Loop and try again. @@ -1392,7 +1393,7 @@ private void refreshAndWatchChildren() throws KeeperException, InterruptedExcept Stat stat = new Stat(); List replicaStates = null; try { - replicaStates = zkClient.getChildren(collectionPath, this, stat); + replicaStates = zkClient.getChildren(collectionPath, this, stat, true); PerReplicaStates newStates = new PerReplicaStates(collectionPath, stat.getCversion(), replicaStates); DocCollection oldState = collectionWatches.getDocCollection(coll); @@ -1607,7 +1608,7 @@ private DocCollection fetchCollectionState(String coll, Watcher watcher) while (true) { try { Stat stat = new Stat(); - byte[] data = zkClient.getData(collectionPath, watcher, stat); + byte[] data = zkClient.getData(collectionPath, watcher, stat, true); // This factory method can detect a missing configName and supply it by reading it from the // old ZK location. @@ -1621,7 +1622,7 @@ private DocCollection fetchCollectionState(String coll, Watcher watcher) } catch (KeeperException.NoNodeException e) { if (watcher != null) { // Leave an exists watch in place in case a state.json is created later. - Stat exists = zkClient.exists(collectionPath, watcher); + Stat exists = zkClient.exists(collectionPath, watcher, true); if (exists != null) { // Rare race condition, we tried to fetch the data and couldn't find it, then we found // it exists. Loop and try again. @@ -1634,7 +1635,7 @@ private DocCollection fetchCollectionState(String coll, Watcher watcher) ZkStateReader.class.getName() + "/exercised", e); // could be a race condition that state.json and PRS entries are deleted between the // state.json fetch and PRS entry fetch - Stat exists = zkClient.exists(collectionPath, watcher); + Stat exists = zkClient.exists(collectionPath, watcher, true); if (exists == null) { log.info( "PRS entry for collection {} not found in ZK. It was probably deleted between state.json read and PRS entry read.", @@ -2141,7 +2142,7 @@ public AliasesManager getAliasesManager() { private void refreshAliases(AliasesManager watcher) throws KeeperException, InterruptedException { synchronized (getUpdateLock()) { constructState(Collections.emptySet()); - zkClient.exists(ALIASES, watcher); + zkClient.exists(ALIASES, watcher, true); } aliasesManager.update(); } @@ -2200,7 +2201,7 @@ public void applyModificationAndExportToZk(UnaryOperator op) { try { try { final Stat stat = - getZkClient().setData(ALIASES, modAliasesJson, curAliases.getZNodeVersion()); + getZkClient().setData(ALIASES, modAliasesJson, curAliases.getZNodeVersion(), true); setIfNewer(new SolrZkClient.NodeData(stat, modAliasesJson)); return; } catch (KeeperException.BadVersionException e) { @@ -2244,7 +2245,7 @@ public boolean update() throws KeeperException, InterruptedException { // Call sync() first to ensure the subsequent read (getData) is up to date. zkClient.runWithCorrectThrows( "syncing aliases", () -> zkClient.getCuratorFramework().sync().forPath(ALIASES)); - return setIfNewer(zkClient.getNode(ALIASES, null)); + return setIfNewer(zkClient.getNode(ALIASES, null, true)); } // ZK Watcher interface @@ -2258,7 +2259,7 @@ public void process(WatchedEvent event) { log.debug("Aliases: updating"); // re-register the watch - setIfNewer(zkClient.getNode(ALIASES, this)); + setIfNewer(zkClient.getNode(ALIASES, this, true)); } catch (NoNodeException e) { // /aliases.json will not always exist } catch (KeeperException.ConnectionLossException diff --git a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java index cb8723c6e68..38f13860389 100644 --- a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java +++ b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java @@ -86,7 +86,7 @@ public void setUp() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { // Set up chroot - client.makePath("/solr", false); + client.makePath("/solr", false, true); } defaultClient = @@ -94,7 +94,7 @@ public void setUp() throws Exception { .withUrl(zkServer.getZkAddress()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); - defaultClient.makePath(PATH); + defaultClient.makePath(PATH, true); aclClient = new SolrZkClient( @@ -216,10 +216,12 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() - .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); + .getData( + "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null, true); ZkStateReader.from(solrClient) .getZkClient() - .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null); + .getData( + "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null, true); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bam") .process(solrClient); @@ -233,10 +235,12 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() - .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); + .getData( + "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null, true); ZkStateReader.from(solrClient) .getZkClient() - .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null); + .getData( + "/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null, true); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bang") .process(solrClient); @@ -253,7 +257,7 @@ public void process(WatchedEvent event) { private static boolean canRead(SolrZkClient zkClient, String path) throws KeeperException, InterruptedException { try { - zkClient.getData(path, null, null); + zkClient.getData(path, null, null, true); return true; } catch (KeeperException.NoAuthException e) { return false; diff --git a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java index 52ee6ff7d7e..ab650bdc608 100644 --- a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java +++ b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java @@ -86,12 +86,12 @@ public void testEntries() { public void testReplicaStateOperations() throws Exception { String root = "/testReplicaStateOperations"; - cluster.getZkClient().create(root, null, CreateMode.PERSISTENT); + cluster.getZkClient().create(root, null, CreateMode.PERSISTENT, true); List states = List.of("R1:2:A", "R1:1:A:L", "R1:0:D", "R3:0:A", "R4:13:A"); for (String state : states) { - cluster.getZkClient().create(root + "/" + state, null, CreateMode.PERSISTENT); + cluster.getZkClient().create(root + "/" + state, null, CreateMode.PERSISTENT, true); } ZkStateReader zkStateReader = cluster.getZkStateReader(); @@ -106,7 +106,7 @@ public void testReplicaStateOperations() throws Exception { rs = PerReplicaStatesOps.fetch(root, zkStateReader.getZkClient(), null); assertEquals(4, rs.states.size()); assertTrue(rs.cversion >= 6); - assertEquals(6, cluster.getZkClient().getChildren(root, null).size()); + assertEquals(6, cluster.getZkClient().getChildren(root, null, true).size()); ops = PerReplicaStatesOps.flipState("R1", State.DOWN, rs); assertEquals(4, ops.ops.size()); diff --git a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java index 50df39f1156..9f726035691 100644 --- a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java +++ b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java @@ -228,7 +228,7 @@ public void testBootstrapConf() throws IOException, KeeperException, Interrupted .withUrl(zkServer.getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); - zkClient.makePath("/solr", false); + zkClient.makePath("/solr", false, true); cc.setCoreConfigService(new ZkConfigSetService(zkClient)); assertFalse(cc.getConfigSetService().checkConfigExists("collection1")); ConfigSetService.bootstrapConf(cc); diff --git a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java index bbdd7de8cf3..89677753f76 100644 --- a/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java +++ b/solr/solrj-zookeeper/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java @@ -81,17 +81,18 @@ public void testClean() throws KeeperException, InterruptedException, SolrServer String data2 = "myStringData2"; String longData = "myLongStringData"; // create zk nodes that have the same path length - zkClient.create("/myPath", null, CreateMode.PERSISTENT); - zkClient.create(path, null, CreateMode.PERSISTENT); + zkClient.create("/myPath", null, CreateMode.PERSISTENT, true); + zkClient.create(path, null, CreateMode.PERSISTENT, true); zkClient.create( - path + "/file1.txt", data1.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); - zkClient.create(path + "/nothing.txt", null, CreateMode.PERSISTENT); + path + "/file1.txt", data1.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); + zkClient.create(path + "/nothing.txt", null, CreateMode.PERSISTENT, true); zkClient.create( - path + "/file2.txt", data2.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); + path + "/file2.txt", data2.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); zkClient.create( path + "/some_longer_file2.txt", longData.getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + true); /* RUN */ // delete all nodes that contain "file" @@ -137,9 +138,9 @@ public void testTraverseZkTree() throws Exception { .withUrl(zkServer.getZkHost()) .withTimeout(10000, TimeUnit.MILLISECONDS) .build()) { - zkClient.makePath("/testTraverseZkTree/1/1", true); - zkClient.makePath("/testTraverseZkTree/1/2", false); - zkClient.makePath("/testTraverseZkTree/2", false); + zkClient.makePath("/testTraverseZkTree/1/1", true, true); + zkClient.makePath("/testTraverseZkTree/1/2", false, true); + zkClient.makePath("/testTraverseZkTree/2", false, true); assertEquals( Arrays.asList( "/testTraverseZkTree", @@ -171,7 +172,7 @@ public void testOneByteFile() throws Exception { .build()) { byte[] oneByte = new byte[1]; oneByte[0] = 0x30; - zkClient.makePath("/test1byte/one", oneByte); + zkClient.makePath("/test1byte/one", oneByte, true); Path tmpDest = Paths.get(createTempDir().toFile().getAbsolutePath(), "MustBeOne"); ZkMaintenanceUtils.downloadFromZK(zkClient, "/test1byte/one", tmpDest); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java index 79398676f3d..db385e26b83 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java @@ -66,7 +66,9 @@ public void testHttpClusterStateWithSSL() throws Exception { // verify the base_url is actually stored with https in it on the server-side byte[] stateJsonBytes = - cluster.getZkClient().getData(DocCollection.getCollectionPath(collectionId), null, null); + cluster + .getZkClient() + .getData(DocCollection.getCollectionPath(collectionId), null, null, true); assertNotNull(stateJsonBytes); Map replicasMap = (Map) diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java index 36ded773992..d678106f873 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java @@ -81,7 +81,7 @@ public void testCloudClientUploads() throws Exception { assertTrue( "List of uploaded configs does not contain 'testconfig'", - cluster.getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + "testconfig")); + cluster.getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + "testconfig", true)); } finally { cluster.shutdown(); diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java index aa9b5427c99..e75100f1a50 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java @@ -306,7 +306,7 @@ public void testZkNodeVersions() throws Exception { Stat stat = null; CollectionAdminRequest.createCollection(NONPRS_COLL, "conf", 10, 1) .process(cluster.getSolrClient()); - stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(NONPRS_COLL), null); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(NONPRS_COLL), null, true); log.info(""); // the actual number can vary depending on batching assertTrue(stat.getVersion() >= 2); @@ -315,7 +315,7 @@ public void testZkNodeVersions() throws Exception { CollectionAdminRequest.createCollection(PRS_COLL, "conf", 10, 1) .setPerReplicaState(Boolean.TRUE) .process(cluster.getSolrClient()); - stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null, true); // +1 after all replica are added with on state.json write to CreateCollectionCmd.setData() assertEquals(1, stat.getVersion()); // For each replica: @@ -330,7 +330,7 @@ public void testZkNodeVersions() throws Exception { CollectionAdminRequest.addReplicaToShard(PRS_COLL, "shard1") .process(cluster.getSolrClient()); cluster.waitForActiveCollection(PRS_COLL, 10, 11); - stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null, true); // For the new replica: // +2 for state.json overseer writes, even though there's no longer PRS updates from // overseer, current code would still do a "TOUCH" on the PRS entry @@ -350,7 +350,7 @@ public void testZkNodeVersions() throws Exception { CollectionAdminRequest.deleteReplica(PRS_COLL, "shard1", addedReplica.getName()) .process(cluster.getSolrClient()); cluster.waitForActiveCollection(PRS_COLL, 10, 10); - stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null, true); // For replica deletion // +1 for ZkController#unregister, which delete the PRS entry from data node // overseer, current code would still do a "TOUCH" on the PRS entry @@ -359,7 +359,7 @@ public void testZkNodeVersions() throws Exception { for (JettySolrRunner j : cluster.getJettySolrRunners()) { j.stop(); j.start(true); - stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null, true); // ensure restart does not update the state.json, after addReplica/deleteReplica, 2 more // updates hence at version 3 on state.json version assertEquals(3, stat.getVersion()); diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientCompressedDataTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientCompressedDataTest.java index 71f95b23c4b..dbdbbc39449 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientCompressedDataTest.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientCompressedDataTest.java @@ -76,10 +76,10 @@ public void getData() throws Exception { byte[] arr = state.getBytes(StandardCharsets.UTF_8); byte[] compressedData = zLibStateCompression.compressBytes(arr); String path = ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"; - zkClient.create(path, compressedData, CreateMode.PERSISTENT); + zkClient.create(path, compressedData, CreateMode.PERSISTENT, true); byte[] data = - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null); + zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true); Map map = (Map) Utils.fromJSON(data); assertEquals(arr.length, data.length); assertNotNull(map.get("c1")); diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java index d7590f6c257..ee3141e412d 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -876,7 +876,7 @@ public static void deleteCore() { CoreContainer cc = h.getCoreContainer(); if (cc.getNumAllCores() > 0 && cc.isZooKeeperAware()) { try { - cc.getZkController().getZkClient().exists("/"); + cc.getZkController().getZkClient().exists("/", false); } catch (KeeperException e) { log.error("Testing connectivity to ZK by checking for root path failed", e); fail("Trying to tear down a ZK aware core container with ZK not reachable"); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java index 9fc1417cdc4..899efc03dcb 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java @@ -269,7 +269,7 @@ private void bringDownShardIndexSomeDocsAndRecover() throws Exception { int oldLiveNodes = ZkStateReader.from(cloudClient) .getZkClient() - .getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null) + .getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true) .size(); assertEquals(5, oldLiveNodes); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDigestZkACLAndCredentialsProvidersTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDigestZkACLAndCredentialsProvidersTestBase.java index 02935f94b96..dbbf308bad1 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDigestZkACLAndCredentialsProvidersTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDigestZkACLAndCredentialsProvidersTestBase.java @@ -102,7 +102,7 @@ public void setUp() throws Exception { .withConnTimeOut(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); - zkClient.makePath("/solr", false); + zkClient.makePath("/solr", false, true); zkClient.close(); zkClient = @@ -111,14 +111,15 @@ public void setUp() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + false); zkClient.close(); clearSecuritySystemProperties(); @@ -137,9 +138,12 @@ public void setUp() throws Exception { .addAuthInfo( "digest", (ALL_USERNAME + ":" + ALL_PASSWORD).getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); zkClient.makePath( - "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + "/unprotectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT, + false); zkClient.close(); setDigestZkSystemProps(); @@ -308,8 +312,8 @@ public void testRepairACL() throws Exception { .getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); - assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); + "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, false); + assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); } setSecuritySystemProperties(); @@ -319,7 +323,7 @@ public void testRepairACL() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { ZkController.createClusterZkNodes(zkClient); - assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); + assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); } useZkCredentialsInjector(ConnectWithReadonlyCredsInjector.class); @@ -330,8 +334,9 @@ public void testRepairACL() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { NoAuthException e = - assertThrows(NoAuthException.class, () -> zkClient.getData("/security.json", null, null)); - assertEquals("/solr/security.json", e.getPath()); + assertThrows( + NoAuthException.class, () -> zkClient.getData("/security.json", null, null, false)); + assertEquals("/security.json", e.getPath()); } } @@ -396,27 +401,27 @@ protected static void doTest( boolean setData, boolean delete) throws Exception { - doTest(getData, () -> zkClient.getData(path, null, null)); - doTest(list, () -> zkClient.getChildren(path, null)); + doTest(getData, () -> zkClient.getData(path, null, null, false)); + doTest(list, () -> zkClient.getChildren(path, null, false)); doTest( create, () -> { - zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT); - zkClient.delete(path + "/subnode", -1); + zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT, false); + zkClient.delete(path + "/subnode", -1, false); }); doTest( create, () -> { zkClient.makePath(path + "/subnode/subsubnode", false); - zkClient.delete(path + "/subnode/subsubnode", -1); - zkClient.delete(path + "/subnode", -1); + zkClient.delete(path + "/subnode/subsubnode", -1, false); + zkClient.delete(path + "/subnode", -1, false); }); - doTest(setData, () -> zkClient.setData(path, (byte[]) null)); + doTest(setData, () -> zkClient.setData(path, (byte[]) null, false)); // Actually about the ACLs on /solr, but that is protected - doTest(delete, () -> zkClient.delete(path, -1)); + doTest(delete, () -> zkClient.delete(path, -1, false)); } interface ExceptingRunnable { diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java index e8b104f9fcf..435a2a931ba 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java @@ -395,7 +395,6 @@ protected void printLayout() throws Exception { protected void restartZk(int pauseMillis) throws Exception { log.info("Restarting ZK with a pause of {}ms in between", pauseMillis); - zkServer.shutdown(); // disconnect enough to test stalling, if things stall, then clientSoTimeout will be hit Thread.sleep(pauseMillis); diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java index c0f4ce77a69..e2f2074873d 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java @@ -262,14 +262,18 @@ public void distribSetUp() throws Exception { .create( ZkStateReader.CLUSTER_PROPS, Utils.toJSON(Collections.singletonMap(URL_SCHEME, HTTPS)), - CreateMode.PERSISTENT); + CreateMode.PERSISTENT, + true); } catch (KeeperException.NodeExistsException e) { ZkNodeProps props = ZkNodeProps.load( - zkStateReader.getZkClient().getData(ZkStateReader.CLUSTER_PROPS, null, null)); + zkStateReader + .getZkClient() + .getData(ZkStateReader.CLUSTER_PROPS, null, null, true)); zkStateReader .getZkClient() - .setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS))); + .setData( + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS)), true); } } } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java index 66ae8b2d301..03b8877e8c0 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java @@ -301,16 +301,17 @@ public MiniSolrCloudCluster( .withUrl(zkServer.getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - if (!zkClient.exists("/solr/solr.xml")) { - zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset())); + if (!zkClient.exists("/solr/solr.xml", true)) { + zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset()), true); if (jettyConfig.sslConfig != null && jettyConfig.sslConfig.isSSLMode()) { zkClient.makePath( "/solr" + ZkStateReader.CLUSTER_PROPS, - "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8)); + "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8), + true); } if (securityJson.isPresent()) { // configure Solr security zkClient.makePath( - "/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset())); + "/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset()), true); } } } @@ -645,7 +646,9 @@ public void deleteAllConfigSets() throws Exception { // cleanup any property before removing the configset getZkClient() .delete( - ZkConfigSetService.CONFIGS_ZKNODE + "/" + configSet + "/" + DEFAULT_FILENAME, -1); + ZkConfigSetService.CONFIGS_ZKNODE + "/" + configSet + "/" + DEFAULT_FILENAME, + -1, + true); } catch (KeeperException.NoNodeException nne) { } new ConfigSetAdminRequest.Delete().setConfigSetName(configSet).process(solrClient); @@ -737,7 +740,7 @@ public SolrZkClient getZkClient() { public void zkSetData(String path, byte[] data, boolean retryOnConnLoss) throws InterruptedException { try { - getZkClient().setData(path, data, -1); + getZkClient().setData(path, data, -1, retryOnConnLoss); } catch (KeeperException e) { throw new SolrException(ErrorCode.UNKNOWN, "Failed writing to Zookeeper", e); } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java b/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java index e9bd640d101..c1c73fb853a 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java @@ -29,13 +29,15 @@ public MockSolrZkClient() { } @Override - public Boolean exists(final String path) throws KeeperException, InterruptedException { + public Boolean exists(final String path, boolean retryOnConnLoss) + throws KeeperException, InterruptedException { return false; } @Override - public byte[] getData(final String path, final Watcher watcher, final Stat stat) + public byte[] getData( + final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) throws KeeperException, InterruptedException { return null; } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java index 2cfd01b67a0..0043b75a236 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java @@ -502,7 +502,7 @@ public void ensurePathExists(String path) throws IOException { .withUrl(getZkHost()) .withTimeout(10000, TimeUnit.MILLISECONDS) .build()) { - client.makePath(path, null, CreateMode.PERSISTENT, null, false); + client.makePath(path, null, CreateMode.PERSISTENT, null, false, true, 0); } catch (InterruptedException | KeeperException e) { log.error("Error checking path {}", path, e); throw new IOException("Error checking path " + path, SolrZkClient.checkInterrupted(e)); @@ -785,7 +785,7 @@ public static void putConfig( if (log.isInfoEnabled()) { log.info("put {} to {}", file.toAbsolutePath(), destPath); } - zkClient.makePath(destPath, file, false); + zkClient.makePath(destPath, file, false, true); } // static to share with distrib test @@ -832,7 +832,7 @@ public void buildZooKeeper(Path solrhome, String config, String schema) throws E } public void makeSolrZkNode() throws Exception { - rootClient.makePath("/solr", false); + rootClient.makePath("/solr", false, true); } public void tryCleanSolrZkNode() throws Exception { @@ -840,7 +840,7 @@ public void tryCleanSolrZkNode() throws Exception { } void tryCleanPath(String path) throws Exception { - if (rootClient.exists(path)) { + if (rootClient.exists(path, true)) { rootClient.clean(path); } } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java index ed51f2ce357..a414eb5fdbe 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java @@ -115,7 +115,9 @@ public void testCreationAndDeletion() throws Exception { CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName)); assertFalse( - cluster.getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + cluster + .getZkClient() + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true)); } @Test @@ -123,7 +125,7 @@ public void deleteCollectionRemovesStaleZkCollectionsNode() throws Exception { String collectionName = "out_of_sync_collection"; // manually create a collections zknode - cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName); + cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true); CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient()); @@ -131,7 +133,9 @@ public void deleteCollectionRemovesStaleZkCollectionsNode() throws Exception { CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName)); assertFalse( - cluster.getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + cluster + .getZkClient() + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true)); } @Test @@ -169,7 +173,7 @@ public void deleteCollectionOnlyInZk() throws Exception { final String collectionName = "onlyinzk"; // create the collections node, but nothing else - cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName); + cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true); // delete via API - should remove collections node CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());