From b4fbc8c8dd6819f3d080b169c970b85caf7ea1f7 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Fri, 18 Mar 2022 16:04:38 -0400 Subject: [PATCH 01/14] Use Curator - Step 1 --- .../java/org/apache/solr/cloud/CloudUtil.java | 4 +- .../cloud/DistributedApiAsyncTracker.java | 16 +- .../cloud/DistributedClusterStateUpdater.java | 8 +- .../org/apache/solr/cloud/DistributedMap.java | 18 +- .../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 | 4 +- .../solr/cloud/OverseerTaskProcessor.java | 8 +- .../apache/solr/cloud/OverseerTaskQueue.java | 20 +- .../solr/cloud/RefreshCollectionMessage.java | 2 +- .../cloud/ShardLeaderElectionContext.java | 4 +- .../cloud/ShardLeaderElectionContextBase.java | 48 +- .../solr/cloud/SizeLimitedDistributedMap.java | 6 +- .../src/java/org/apache/solr/cloud/ZkCLI.java | 22 +- .../apache/solr/cloud/ZkConfigSetService.java | 26 +- .../org/apache/solr/cloud/ZkController.java | 124 ++-- .../apache/solr/cloud/ZkDistributedLock.java | 10 +- .../solr/cloud/ZkDistributedLockFactory.java | 4 +- .../apache/solr/cloud/ZkDistributedQueue.java | 41 +- .../org/apache/solr/cloud/ZkShardTerms.java | 19 +- .../solr/cloud/ZkSolrResourceLoader.java | 2 +- .../api/collections/CreateCollectionCmd.java | 4 +- .../api/collections/DeleteCollectionCmd.java | 4 +- .../api/collections/OverseerRoleCmd.java | 8 +- .../api/collections/OverseerStatusCmd.java | 6 +- .../cloud/api/collections/SplitShardCmd.java | 8 +- .../solr/cloud/overseer/ZkStateWriter.java | 6 +- .../java/org/apache/solr/core/NodeConfig.java | 4 +- .../org/apache/solr/core/RequestParams.java | 2 +- .../java/org/apache/solr/core/SolrCore.java | 2 +- .../solr/core/backup/BackupManager.java | 6 +- .../core/snapshots/SolrSnapshotManager.java | 18 +- .../solr/filestore/DistribPackageStore.java | 12 +- .../solr/filestore/PackageStoreAPI.java | 8 +- .../solr/handler/admin/ClusterStatus.java | 6 +- .../handler/admin/ContainerPluginsApi.java | 2 +- .../handler/admin/SecurityConfHandlerZk.java | 4 +- .../handler/admin/ShowFileRequestHandler.java | 8 +- .../handler/admin/ZookeeperInfoHandler.java | 8 +- .../solr/handler/admin/ZookeeperReadAPI.java | 8 +- .../solr/handler/component/SearchHandler.java | 2 +- .../handler/designer/SchemaDesignerAPI.java | 10 +- .../SchemaDesignerConfigSetHelper.java | 10 +- .../designer/SchemaDesignerSettingsDAO.java | 2 +- .../solr/packagemanager/PackageManager.java | 8 +- .../packagemanager/RepositoryManager.java | 14 +- .../java/org/apache/solr/pkg/PackageAPI.java | 8 +- .../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 +- .../apache/solr/servlet/QueryRateLimiter.java | 2 +- .../DistributedZkUpdateProcessor.java | 2 +- .../java/org/apache/solr/util/SolrCLI.java | 22 +- .../solr/cloud/AliasIntegrationTest.java | 2 +- .../AssignBackwardCompatibilityTest.java | 4 +- .../solr/cloud/CollectionPropsTest.java | 4 +- .../solr/cloud/CollectionStateZnodeTest.java | 6 +- .../solr/cloud/ConnectionManagerTest.java | 3 +- .../solr/cloud/DistributedQueueTest.java | 15 +- .../cloud/LeaderElectionContextKeyTest.java | 4 +- .../cloud/LeaderElectionIntegrationTest.java | 3 +- .../apache/solr/cloud/LeaderElectionTest.java | 8 +- .../solr/cloud/LeaderVoteWaitTimeoutTest.java | 2 +- .../cloud/NestedShardedAtomicUpdateTest.java | 2 +- ...OfBoxZkACLAndCredentialsProvidersTest.java | 20 +- ...iddenZkACLAndCredentialsProvidersTest.java | 88 +-- ...rseerCollectionConfigSetProcessorTest.java | 10 +- .../org/apache/solr/cloud/OverseerTest.java | 24 +- .../apache/solr/cloud/SolrCLIZkUtilsTest.java | 38 +- .../apache/solr/cloud/SolrXmlInZkTest.java | 2 +- .../apache/solr/cloud/TestConfigSetsAPI.java | 56 +- .../cloud/TestConfigSetsAPIExclusivity.java | 4 +- .../cloud/TestConfigSetsAPIZkFailure.java | 4 +- .../apache/solr/cloud/TestDistributedMap.java | 20 +- .../solr/cloud/TestLazySolrCluster.java | 8 +- .../cloud/TestLeaderElectionZkExpiry.java | 2 +- .../apache/solr/cloud/TestPullReplica.java | 4 +- .../cloud/TestQueryingOnDownCollection.java | 4 +- .../solr/cloud/TestRebalanceLeaders.java | 4 +- .../solr/cloud/TestStressLiveNodes.java | 4 +- .../apache/solr/cloud/TestTlogReplica.java | 4 +- .../test/org/apache/solr/cloud/ZkCLITest.java | 34 +- .../apache/solr/cloud/ZkControllerTest.java | 4 +- .../apache/solr/cloud/ZkSolrClientTest.java | 91 ++- .../cloud/api/collections/ShardSplitTest.java | 6 +- .../SimpleCollectionCreateDeleteTest.java | 26 +- .../api/collections/TestCollectionAPI.java | 4 +- .../TestLocalFSCloudBackupRestore.java | 4 +- .../cloud/overseer/ZkStateReaderTest.java | 10 +- .../cloud/overseer/ZkStateWriterTest.java | 18 +- .../apache/solr/handler/TestConfigReload.java | 8 +- .../handler/admin/ZookeeperReadAPITest.java | 2 +- .../designer/TestSchemaDesignerAPI.java | 4 +- .../TestSchemaDesignerConfigSetHelper.java | 4 +- .../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 | 4 +- .../TimeRoutedAliasUpdateProcessorTest.java | 12 +- .../hadoop/DelegationTokenKerberosFilter.java | 102 +-- .../security/hadoop/HadoopAuthFilter.java | 111 +--- .../hadoop/SaslZkACLProviderTest.java | 32 +- .../hadoop/TestDelegationWithHadoopAuth.java | 4 +- .../TestSolrCloudWithDelegationTokens.java | 4 +- .../TestHdfsCloudBackupRestore.java | 4 +- solr/server/solr/solr.xml | 2 +- solr/solrj/build.gradle | 2 + .../solrj/cloud/DistribStateManager.java | 7 +- .../solrj/impl/ZkDistribStateManager.java | 24 +- .../apache/solr/common/LazySolrCluster.java | 2 +- .../org/apache/solr/common/SimpleZkMap.java | 6 +- .../solr/common/cloud/ClusterProperties.java | 12 +- .../solr/common/cloud/ClusterState.java | 2 +- .../common/cloud/CollectionProperties.java | 12 +- .../solr/common/cloud/ConnectionManager.java | 148 ++--- ...LProvider.java => DefaultACLProvider.java} | 19 +- .../cloud/DefaultZkCredentialsProvider.java | 25 +- ...BeforeReconnect.java => OnDisconnect.java} | 13 +- .../apache/solr/common/cloud/OnReconnect.java | 14 +- .../solr/common/cloud/PerReplicaStates.java | 4 +- .../common/cloud/PerReplicaStatesOps.java | 12 +- .../solr/common/cloud/SaslZkACLProvider.java | 4 + .../cloud/SecurityAwareZkACLProvider.java | 22 +- .../solr/common/cloud/SolrZkClient.java | 616 +++++++----------- ...ramsAllAndReadonlyDigestZkACLProvider.java | 9 +- .../solr/common/cloud/ZkACLProvider.java | 9 +- .../cloud/ZkClientConnectionStrategy.java | 1 - .../solr/common/cloud/ZkCmdExecutor.java | 2 +- .../common/cloud/ZkCredentialsProvider.java | 25 +- .../solr/common/cloud/ZkMaintenanceUtils.java | 42 +- .../solr/common/cloud/ZkStateReader.java | 40 +- .../org/apache/solr/common/util/Utils.java | 2 +- .../solrj/impl/HttpClusterStateSSLTest.java | 2 +- .../impl/TestCloudSolrClientConnections.java | 2 +- .../solr/common/cloud/SolrZkClientTest.java | 18 +- .../common/cloud/TestPerReplicaStates.java | 6 +- .../common/cloud/TestZkConfigSetService.java | 6 +- .../common/cloud/TestZkMaintenanceUtils.java | 22 +- .../java/org/apache/solr/SolrTestCaseJ4.java | 2 +- .../AbstractBasicDistributedZk2TestBase.java | 2 +- .../cloud/AbstractFullDistribZkTestBase.java | 8 +- ...sZkACLAndCredentialsProvidersTestBase.java | 42 +- .../org/apache/solr/cloud/ChaosMonkey.java | 2 +- .../solr/cloud/MiniSolrCloudCluster.java | 18 +- .../apache/solr/cloud/MockSolrZkClient.java | 4 +- .../org/apache/solr/cloud/ZkTestServer.java | 54 +- ...ctCollectionsAPIDistributedZkTestBase.java | 8 +- 153 files changed, 1213 insertions(+), 1598 deletions(-) rename solr/solrj/src/java/org/apache/solr/common/cloud/{DefaultZkACLProvider.java => DefaultACLProvider.java} (67%) rename solr/solrj/src/java/org/apache/solr/common/cloud/{BeforeReconnect.java => OnDisconnect.java} (68%) 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 7461d6ef6c1..b82197a50c9 100644 --- a/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java +++ b/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java @@ -146,10 +146,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, true); + List children = zk.getChildren("/keys/" + dir, null); for (String key : children) { if (key.endsWith(".der")) - result.put(key, zk.getData("/keys/" + dir + "/" + key, null, null, true)); + result.put(key, zk.getData("/keys/" + dir + "/" + key, null, null)); } } 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 8ebdb2ae287..5e8d0529ec1 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, true)) { - zkClient.makePath(rootNodePath, new byte[0], CreateMode.PERSISTENT, true); + if (!zkClient.exists(rootNodePath)) { + zkClient.makePath(rootNodePath, new byte[0], CreateMode.PERSISTENT); } } catch (KeeperException.NodeExistsException nee) { // Some other thread (on this or another JVM) beat us to create the node, that's ok, the @@ -329,27 +329,27 @@ void createNewInFlightTask(String asyncId) throws KeeperException, InterruptedEx zkClient.create( getPath(asyncId), State.SUBMITTED.shorthand.getBytes(StandardCharsets.UTF_8), - CreateMode.EPHEMERAL, - true); + CreateMode.EPHEMERAL + ); } void setTaskRunning(String asyncId) throws KeeperException, InterruptedException { zkClient.setData( - getPath(asyncId), State.RUNNING.shorthand.getBytes(StandardCharsets.UTF_8), true); + getPath(asyncId), State.RUNNING.shorthand.getBytes(StandardCharsets.UTF_8)); } void deleteInFlightTask(String asyncId) throws KeeperException, InterruptedException { - zkClient.delete(getPath(asyncId), -1, true); + zkClient.delete(getPath(asyncId), -1); } State getInFlightState(String asyncId) throws KeeperException, InterruptedException { - if (!zkClient.exists(getPath(asyncId), true)) { + if (!zkClient.exists(getPath(asyncId))) { return State.NOT_FOUND; } final byte[] bytes; try { - bytes = zkClient.getData(getPath(asyncId), null, null, true); + bytes = zkClient.getData(getPath(asyncId), null, null); } 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 f76fb1fa474..91c53fa9ee9 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java @@ -578,7 +578,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, true); + zkStateReader.getZkClient().create(jsonPath, stateJson, CreateMode.PERSISTENT); } else { // We're updating an existing state.json if (log.isDebugEnabled()) { @@ -589,7 +589,7 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState) } zkStateReader .getZkClient() - .setData(jsonPath, stateJson, collection.getZNodeVersion(), true); + .setData(jsonPath, stateJson, collection.getZNodeVersion()); } } } @@ -603,7 +603,7 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState) private ClusterState fetchStateForCollection() throws KeeperException, InterruptedException { String collectionStatePath = ZkStateReader.getCollectionPath(updater.getCollectionName()); Stat stat = new Stat(); - byte[] data = zkStateReader.getZkClient().getData(collectionStatePath, null, stat, true); + byte[] data = zkStateReader.getZkClient().getData(collectionStatePath, null, stat); // This factory method can detect a missing configName and supply it by reading it from the // old ZK location. @@ -910,7 +910,7 @@ public static void executeNodeDownStateUpdate(String nodeName, ZkStateReader zkS try { final List collectionNames = - zkStateReader.getZkClient().getChildren(COLLECTIONS_ZKNODE, null, true); + zkStateReader.getZkClient().getChildren(COLLECTIONS_ZKNODE, null); // 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 ece2589310a..543bc2eefa1 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java @@ -57,7 +57,7 @@ public DistributedMap(SolrZkClient zookeeper, String dir) { public void put(String trackingId, byte[] data) throws KeeperException, InterruptedException { zookeeper.makePath( - dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, false, true); + dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, false); } /** @@ -69,7 +69,7 @@ public boolean putIfAbsent(String trackingId, byte[] data) throws KeeperException, InterruptedException { try { zookeeper.makePath( - dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, true, true); + dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, true); return true; } catch (NodeExistsException e) { return false; @@ -77,16 +77,16 @@ public boolean putIfAbsent(String trackingId, byte[] data) } public byte[] get(String trackingId) throws KeeperException, InterruptedException { - return zookeeper.getData(dir + "/" + PREFIX + trackingId, null, null, true); + return zookeeper.getData(dir + "/" + PREFIX + trackingId, null, null); } public boolean contains(String trackingId) throws KeeperException, InterruptedException { - return zookeeper.exists(dir + "/" + PREFIX + trackingId, true); + return zookeeper.exists(dir + "/" + PREFIX + trackingId); } public int size() throws KeeperException, InterruptedException { Stat stat = new Stat(); - zookeeper.getData(dir, null, stat, true); + zookeeper.getData(dir, null, stat); return stat.getNumChildren(); } @@ -96,7 +96,7 @@ public int size() throws KeeperException, InterruptedException { */ public boolean remove(String trackingId) throws KeeperException, InterruptedException { try { - zookeeper.delete(dir + "/" + PREFIX + trackingId, -1, true); + zookeeper.delete(dir + "/" + PREFIX + trackingId, -1); } catch (KeeperException.NoNodeException e) { return false; } @@ -105,15 +105,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, true); + List childNames = zookeeper.getChildren(dir, null); for (String childName : childNames) { - zookeeper.delete(dir + "/" + childName, -1, true); + zookeeper.delete(dir + "/" + childName, -1); } } /** Returns the keys of all the elements in the map */ public Collection keys() throws KeeperException, InterruptedException { - List childs = zookeeper.getChildren(dir, null, true); + List childs = zookeeper.getChildren(dir, null); 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 dd89d4ca2ac..d00ee7d7ce0 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, true); + zkClient.delete(leaderSeqPath, -1); } 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 f5a3eba247e..2023663060d 100644 --- a/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java +++ b/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java @@ -100,7 +100,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, true); + List seqs = zkClient.getChildren(holdElectionPath, null); sortSeqs(seqs); String leaderSeqNodeName = @@ -112,7 +112,7 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement // If any double-registrations exist for me, remove all but this latest one! // TODO: can we even get into this state? - String prefix = zkClient.getSolrZooKeeper().getSessionId() + "-" + context.id + "-"; + String prefix = zkClient.getZkSessionId() + "-" + context.id + "-"; Iterator it = seqs.iterator(); while (it.hasNext()) { String elec = it.next(); @@ -120,7 +120,7 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement try { String toDelete = holdElectionPath + "/" + elec; log.warn("Deleting duplicate registration: {}", toDelete); - zkClient.delete(toDelete, -1, true); + zkClient.delete(toDelete, -1); } catch (KeeperException.NoNodeException e) { // ignore } @@ -154,8 +154,8 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement watcher = new ElectionWatcher( context.leaderSeqPath, watchedNode, getSeq(context.leaderSeqPath), context), - null, - true); + null + ); log.debug("Watching path {} to know if I could be the leader", watchedNode); } catch (KeeperException.SessionExpiredException e) { throw e; @@ -232,7 +232,7 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo final String shardsElectZkPath = context.electionPath + LeaderElector.ELECTION_NODE; - long sessionId = zkClient.getSolrZooKeeper().getSessionId(); + long sessionId = zkClient.getZkSessionId(); String id = sessionId + "-" + context.id; String leaderSeqPath = null; boolean cont = true; @@ -248,8 +248,8 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo zkClient.create( shardsElectZkPath + "/" + id + "-n_", null, - CreateMode.EPHEMERAL_SEQUENTIAL, - false); + CreateMode.EPHEMERAL_SEQUENTIAL + ); } else { String firstInLine = nodes.get(1); log.debug("The current head: {}", firstInLine); @@ -258,15 +258,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, false); + zkClient.create(leaderSeqPath, null, CreateMode.EPHEMERAL); } } else { leaderSeqPath = zkClient.create( shardsElectZkPath + "/" + id + "-n_", null, - CreateMode.EPHEMERAL_SEQUENTIAL, - false); + CreateMode.EPHEMERAL_SEQUENTIAL + ); } log.debug("Joined leadership election with path: {}", leaderSeqPath); @@ -274,7 +274,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, true); + List entries = zkClient.getChildren(shardsElectZkPath, null); boolean foundId = false; for (String entry : entries) { @@ -342,7 +342,7 @@ public void process(WatchedEvent event) { if (canceled) { log.debug("This watcher is not active anymore {}", myNode); try { - zkClient.delete(myNode, -1, true); + zkClient.delete(myNode, -1); } catch (KeeperException.NoNodeException nne) { // expected . don't do anything } catch (Exception e) { 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 9b0ae2f55bd..544131d0b46 100644 --- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java +++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java @@ -461,7 +461,7 @@ private void checkIfIamStillLeader() { final String path = OVERSEER_ELECT + "/leader"; byte[] data; try { - data = zkClient.getData(path, null, stat, true); + data = zkClient.getData(path, null, stat); } catch (AlreadyClosedException e) { return; } catch (Exception e) { @@ -476,7 +476,7 @@ private void checkIfIamStillLeader() { log.warn( "I (id={}) am exiting, but I'm still the leader", overseerCollectionConfigSetProcessor.getId()); - zkClient.delete(path, stat.getVersion(), true); + zkClient.delete(path, stat.getVersion()); } catch (KeeperException.BadVersionException e) { // no problem ignore it some other Overseer has already taken over } catch (Exception e) { @@ -598,7 +598,7 @@ private LeaderStatus amILeader() { String propsId = null; try { ZkNodeProps props = - ZkNodeProps.load(zkClient.getData(OVERSEER_ELECT + "/leader", null, null, true)); + ZkNodeProps.load(zkClient.getData(OVERSEER_ELECT + "/leader", null, null)); propsId = props.getStr(ID); if (myId.equals(propsId)) { return LeaderStatus.YES; @@ -1158,7 +1158,7 @@ OverseerTaskQueue getConfigSetQueue(final SolrZkClient zkClient, Stats zkStats) private void createOverseerNode(final SolrZkClient zkClient) { try { - zkClient.create("/overseer", new byte[0], CreateMode.PERSISTENT, true); + zkClient.create("/overseer", new byte[0], CreateMode.PERSISTENT); } 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 d9a1687d28e..60a30183913 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java @@ -63,7 +63,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, true); + zkClient.makePath(leaderPath, Utils.toJSON(myProps), CreateMode.EPHEMERAL); 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 870372e291f..5076d72b860 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java @@ -65,9 +65,9 @@ public OverseerNodePrioritizer( public synchronized void prioritizeOverseerNodes(String overseerId) throws Exception { SolrZkClient zk = zkStateReader.getZkClient(); List overseerDesignates = new ArrayList<>(); - if (zk.exists(ZkStateReader.ROLES, true)) { + if (zk.exists(ZkStateReader.ROLES)) { Map m = - (Map) Utils.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat(), true)); + (Map) Utils.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat())); @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 e6d6c633dab..48ef7b2a304 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java @@ -433,7 +433,7 @@ public static List getSortedOverseerNodeNames(SolrZkClient zk) throws KeeperException, InterruptedException { List children = null; try { - children = zk.getChildren(Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE, null, true); + children = zk.getChildren(Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE, null); } catch (Exception e) { log.warn("error ", e); return new ArrayList<>(); @@ -448,7 +448,7 @@ public static List getSortedElectionNodes(SolrZkClient zk, String path) throws KeeperException, InterruptedException { List children = null; try { - children = zk.getChildren(path, null, true); + children = zk.getChildren(path, null); LeaderElector.sortSeqs(children); return children; } catch (Exception e) { @@ -466,7 +466,7 @@ public static String getLeaderId(SolrZkClient zkClient) throws KeeperException, InterruptedException { byte[] data = null; try { - data = zkClient.getData(Overseer.OVERSEER_ELECT + "/leader", null, new Stat(), true); + data = zkClient.getData(Overseer.OVERSEER_ELECT + "/leader", null, new Stat()); } catch (KeeperException.NoNodeException e) { return null; } @@ -484,7 +484,7 @@ protected LeaderStatus amILeader() { ZkNodeProps.load( zkStateReader .getZkClient() - .getData(Overseer.OVERSEER_ELECT + "/leader", null, null, true)); + .getData(Overseer.OVERSEER_ELECT + "/leader", null, null)); 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 b14b4834a91..654037eb31c 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java @@ -76,12 +76,12 @@ public void allowOverseerPendingTasksToComplete() { public boolean containsTaskWithRequestId(String requestIdKey, String requestId) throws KeeperException, InterruptedException { - List childNames = zookeeper.getChildren(dir, null, true); + List childNames = zookeeper.getChildren(dir, null); stats.setQueueLength(childNames.size()); for (String childName : childNames) { if (childName != null && childName.startsWith(PREFIX)) { try { - byte[] data = zookeeper.getData(dir + "/" + childName, null, null, true); + byte[] data = zookeeper.getData(dir + "/" + childName, null, null); if (data != null) { ZkNodeProps message = ZkNodeProps.load(data); if (message.containsKey(requestIdKey)) { @@ -108,7 +108,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(), true); + zookeeper.setData(responsePath, event.getBytes()); } catch (KeeperException.NoNodeException ignored) { // we must handle the race case where the node no longer exists log.info( @@ -116,7 +116,7 @@ public void remove(QueueEvent event) throws KeeperException, InterruptedExceptio responsePath); } try { - zookeeper.delete(path, -1, true); + zookeeper.delete(path, -1); } catch (KeeperException.NoNodeException ignored) { } } finally { @@ -195,10 +195,10 @@ private String createData(String path, byte[] data, CreateMode mode) throws KeeperException, InterruptedException { for (; ; ) { try { - return zookeeper.create(path, data, mode, true); + return zookeeper.create(path, data, mode); } catch (KeeperException.NoNodeException e) { try { - zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT, true); + zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException ne) { // someone created it } @@ -220,7 +220,7 @@ public QueueEvent offer(byte[] data, long timeout) throws KeeperException, Inter String watchID = createResponseNode(); LatchWatcher watcher = new LatchWatcher(); - Stat stat = zookeeper.exists(watchID, watcher, true); + Stat stat = zookeeper.exists(watchID, watcher); // create the request node createRequestNode(data, watchID); @@ -229,11 +229,11 @@ public QueueEvent offer(byte[] data, long timeout) throws KeeperException, Inter pendingResponses.incrementAndGet(); watcher.await(timeout); } - byte[] bytes = zookeeper.getData(watchID, null, null, true); + byte[] bytes = zookeeper.getData(watchID, null, null); // 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, true); + zookeeper.delete(watchID, -1); return event; } finally { time.stop(); @@ -295,7 +295,7 @@ public String getTailId() throws KeeperException, InterruptedException { QueueEvent queueEvent = new QueueEvent( dir + "/" + headNode, - zookeeper.getData(dir + "/" + headNode, null, null, true), + zookeeper.getData(dir + "/" + headNode, null, null), null); return queueEvent.getId(); } catch (KeeperException.NoNodeException e) { 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 573bf3bda8f..50474b45d29 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java +++ b/solr/core/src/java/org/apache/solr/cloud/RefreshCollectionMessage.java @@ -35,7 +35,7 @@ public ClusterState run(ClusterState clusterState, Overseer overseer) throws Exc overseer .getZkStateReader() .getZkClient() - .exists(ZkStateReader.getCollectionPath(collection), null, true); + .exists(ZkStateReader.getCollectionPath(collection), null); 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 ab4f1c21007..80f74ba7304 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java @@ -451,7 +451,7 @@ private boolean waitForReplicasToComeUp(int timeoutms) throws InterruptedExcepti if (slices != null) { int found = 0; try { - found = zkClient.getChildren(shardsElectZkPath, null, true).size(); + found = zkClient.getChildren(shardsElectZkPath, null).size(); } catch (KeeperException e) { if (e instanceof KeeperException.SessionExpiredException) { // if the session has expired, then another election will be launched, so @@ -510,7 +510,7 @@ private boolean areAllReplicasParticipating() throws InterruptedException { final Slice slices = docCollection.getSlice(shardId); int found = 0; try { - found = zkClient.getChildren(shardsElectZkPath, null, true).size(); + found = zkClient.getChildren(shardsElectZkPath, null).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/ShardLeaderElectionContextBase.java b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java index 594412be378..a28be615369 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java @@ -21,6 +21,10 @@ import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.List; + +import org.apache.curator.framework.api.transaction.CuratorOp; +import org.apache.curator.framework.api.transaction.CuratorTransactionResult; +import org.apache.curator.framework.api.transaction.OperationType; import org.apache.solr.cloud.overseer.OverseerAction; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -102,12 +106,13 @@ public void cancelElection() throws InterruptedException, KeeperException { "Removing leader registration node on cancel: {} {}", leaderPath, leaderZkNodeParentVersion); - List ops = new ArrayList<>(2); String parent = ZkMaintenanceUtils.getZkParent(leaderPath); - ops.add(Op.check(parent, leaderZkNodeParentVersion)); - ops.add(Op.delete(leaderPath, -1)); - zkClient.multi(ops, true); + zkClient.multi( + op -> op.check().withVersion(leaderZkNodeParentVersion).forPath(parent), + op -> op.delete().withVersion(-1).forPath(leaderPath) + ); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw e; } catch (IllegalArgumentException e) { SolrException.log(log, e); @@ -137,33 +142,24 @@ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStartMs) "Creating leader registration node {} after winning as {}", leaderPath, leaderSeqPath); - List ops = new ArrayList<>(2); // We use a multi operation to get the parent nodes version, which will // be used to make sure we only remove our own leader registration node. // The setData call used to get the parent version is also the trigger to // increment the version. We also do a sanity check that our leaderSeqPath exists. - - ops.add(Op.check(leaderSeqPath, -1)); - ops.add( - Op.create( - leaderPath, - Utils.toJSON(leaderProps), - zkClient.getZkACLProvider().getACLsToAdd(leaderPath), - CreateMode.EPHEMERAL)); - ops.add(Op.setData(parent, null, -1)); - List results; - - results = zkClient.multi(ops, true); - for (OpResult result : results) { - if (result.getType() == ZooDefs.OpCode.setData) { - SetDataResult dresult = (SetDataResult) result; - Stat stat = dresult.getStat(); - leaderZkNodeParentVersion = stat.getVersion(); - return; - } - } - assert leaderZkNodeParentVersion != null; + List results = zkClient.multi( + op -> op.check().withVersion(-1).forPath(leaderSeqPath), + op -> op.create() + .withMode(CreateMode.EPHEMERAL) + .forPath(leaderPath, Utils.toJSON(leaderProps)), + op -> op.setData().withVersion(-1).forPath(parent, null) + ); + leaderZkNodeParentVersion = results.stream() + .filter(CuratorTransactionResult.ofTypeAndPath(OperationType.SET_DATA, parent)) + .findFirst() + .orElseThrow(() -> new RuntimeException("Could not set data for parent path in ZK: " + parent)) + .getResultStat() + .getVersion(); } }); } catch (NoNodeException e) { 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 db57ea4980b..8e5d5a4cbd1 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, true); + List children = zookeeper.getChildren(dir, null); int cleanupSize = maxSize / 10; @@ -79,7 +79,7 @@ protected boolean lessThan(Long a, Long b) { Map childToModificationZxid = Maps.newHashMapWithExpectedSize(children.size()); for (String child : children) { - Stat stat = zookeeper.exists(dir + "/" + child, null, true); + Stat stat = zookeeper.exists(dir + "/" + child, null); if (stat != null) { priorityQueue.insertWithOverflow(stat.getMzxid()); childToModificationZxid.put(child, stat.getMzxid()); @@ -91,7 +91,7 @@ protected boolean lessThan(Long a, Long b) { for (String child : children) { Long id = childToModificationZxid.get(child); if (id != null && id <= topElementMzxId) { - zookeeper.delete(dir + "/" + child, -1, true); + zookeeper.delete(dir + "/" + child, -1); if (onOverflowObserver != null) onOverflowObserver.onChildDelete(child.substring(PREFIX.length())); } 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 2a35c8cf11d..28c3e950c02 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java @@ -257,7 +257,7 @@ public static void main(String[] args) } SolrZkClient zkClient = null; try { - zkClient = new SolrZkClient(zkServerAddress, 30000, 30000, () -> {}); + zkClient = new SolrZkClient(zkServerAddress, 30000, 30000); if (line.getOptionValue(CMD).equalsIgnoreCase(BOOTSTRAP)) { if (!line.hasOption(SOLRHOME)) { @@ -344,7 +344,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).toString(), true); + zkClient.makePath(arglist.get(0).toString()); } else if (line.getOptionValue(CMD).equalsIgnoreCase(PUT)) { List arglist = line.getArgList(); if (arglist.size() != 2) { @@ -353,15 +353,15 @@ public static void main(String[] args) System.exit(1); } String path = arglist.get(0).toString(); - if (zkClient.exists(path, true)) { + if (zkClient.exists(path)) { zkClient.setData( - path, arglist.get(1).toString().getBytes(StandardCharsets.UTF_8), true); + path, arglist.get(1).toString().getBytes(StandardCharsets.UTF_8)); } else { zkClient.create( path, arglist.get(1).toString().getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); } } else if (line.getOptionValue(CMD).equalsIgnoreCase(PUT_FILE)) { List arglist = line.getArgList(); @@ -376,10 +376,10 @@ public static void main(String[] args) String path = arglist.get(0).toString(); InputStream is = new FileInputStream(arglist.get(1).toString()); try { - if (zkClient.exists(path, true)) { - zkClient.setData(path, IOUtils.toByteArray(is), true); + if (zkClient.exists(path)) { + zkClient.setData(path, IOUtils.toByteArray(is)); } else { - zkClient.create(path, IOUtils.toByteArray(is), CreateMode.PERSISTENT, true); + zkClient.create(path, IOUtils.toByteArray(is), CreateMode.PERSISTENT); } } finally { IOUtils.closeQuietly(is); @@ -391,7 +391,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).toString(), null, null, true); + byte[] data = zkClient.getData(arglist.get(0).toString(), null, null); stdout.println(new String(data, StandardCharsets.UTF_8)); } else if (line.getOptionValue(CMD).equalsIgnoreCase(GET_FILE)) { List arglist = line.getArgList(); @@ -400,7 +400,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).toString(), null, null, true); + byte[] data = zkClient.getData(arglist.get(0).toString(), null, null); FileUtils.writeByteArrayToFile(new File(arglist.get(1).toString()), 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 4f2d88fec7f..045efeda3c5 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java @@ -73,7 +73,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, true)) { + if (!zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + colName)) { // 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!"); @@ -118,7 +118,7 @@ protected Long getCurrentSchemaModificationVersion( String zkPath = CONFIGS_ZKNODE + "/" + configSet + "/" + schemaFile; Stat stat; try { - stat = zkClient.exists(zkPath, null, true); + stat = zkClient.exists(zkPath, null); } 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 @@ -141,7 +141,7 @@ public String configSetName(CoreDescriptor cd) { public boolean checkConfigExists(String configName) throws IOException { try { Boolean existsSolrConfigXml = - zkClient.exists(CONFIGS_ZKNODE + "/" + configName + "/solrconfig.xml", true); + zkClient.exists(CONFIGS_ZKNODE + "/" + configName + "/solrconfig.xml"); if (existsSolrConfigXml == null) return false; return existsSolrConfigXml; } catch (KeeperException | InterruptedException e) { @@ -200,7 +200,7 @@ public void uploadFileToConfig( String filePath = CONFIGS_ZKNODE + "/" + configName + "/" + fileName; try { // if createNew is true then zkClient#makePath failOnExists is set to false - zkClient.makePath(filePath, data, CreateMode.PERSISTENT, null, !overwriteOnExists, true); + zkClient.makePath(filePath, data, CreateMode.PERSISTENT, null, !overwriteOnExists); } catch (KeeperException.NodeExistsException nodeExistsException) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, @@ -223,8 +223,8 @@ public void setConfigMetadata(String configName, Map data) throw Utils.toJSON(data), CreateMode.PERSISTENT, null, - false, - true); + false + ); } catch (KeeperException | InterruptedException e) { throw new IOException("Error setting config metadata", SolrZkClient.checkInterrupted(e)); } @@ -236,7 +236,7 @@ public Map getConfigMetadata(String configName) throws IOExcepti @SuppressWarnings("unchecked") Map data = (Map) - Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null, true)); + Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null)); if (data == null) return new HashMap<>(); return data; } catch (KeeperException | InterruptedException e) { @@ -252,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, true); + return zkClient.getData(CONFIGS_ZKNODE + "/" + configName + "/" + filePath, null, null); } catch (KeeperException.NoNodeException e) { return null; } catch (KeeperException | InterruptedException e) { @@ -263,7 +263,7 @@ public byte[] downloadFileFromConfig(String configName, String filePath) throws @Override public List listConfigs() throws IOException { try { - return zkClient.getChildren(CONFIGS_ZKNODE, null, true); + return zkClient.getChildren(CONFIGS_ZKNODE, null); } catch (KeeperException.NoNodeException e) { return Collections.emptyList(); } catch (KeeperException | InterruptedException e) { @@ -310,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, true); + List files = zkClient.getChildren(fromZkPath, null); for (String file : files) { - List children = zkClient.getChildren(fromZkPath + "/" + file, null, true); + List children = zkClient.getChildren(fromZkPath + "/" + file, null); if (children.size() == 0) { copyData(fromZkPath + "/" + file, toZkPath + "/" + file); } else { @@ -329,8 +329,8 @@ private void copyConfigDirFromZk(String fromZkPath, String toZkPath) throws IOEx private void copyData(String fromZkFilePath, String toZkFilePath) throws KeeperException, InterruptedException { log.debug("Copying zk node {} to {}", fromZkFilePath, toZkFilePath); - byte[] data = zkClient.getData(fromZkFilePath, null, null, true); - zkClient.makePath(toZkFilePath, data, true); + byte[] data = zkClient.getData(fromZkFilePath, null, null); + zkClient.makePath(toZkFilePath, data); } public SolrCloudManager getSolrCloudManager() { 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 d2cf4547346..fb8dc106c43 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -59,6 +59,8 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; + +import org.apache.curator.framework.api.ACLProvider; import org.apache.solr.client.solrj.cloud.SolrCloudManager; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient; @@ -100,7 +102,6 @@ import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.NoNodeException; import org.apache.zookeeper.KeeperException.SessionExpiredException; -import org.apache.zookeeper.Op; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.data.ACL; @@ -322,18 +323,15 @@ public ZkController( ZkACLProvider zkACLProvider = null; if (zkACLProviderClass != null && zkACLProviderClass.trim().length() > 0) { zkACLProvider = cc.getResourceLoader().newInstance(zkACLProviderClass, ZkACLProvider.class); - } else { - zkACLProvider = new DefaultZkACLProvider(); } String zkCredentialsProviderClass = cloudConfig.getZkCredentialsProviderClass(); + ZkCredentialsProvider zkCredentialsProvider = null; if (zkCredentialsProviderClass != null && zkCredentialsProviderClass.trim().length() > 0) { - strat.setZkCredentialsToAddAutomatically( - cc.getResourceLoader() - .newInstance(zkCredentialsProviderClass, ZkCredentialsProvider.class)); - } else { - strat.setZkCredentialsToAddAutomatically(new DefaultZkCredentialsProvider()); + zkCredentialsProvider = cc.getResourceLoader() + .newInstance(zkCredentialsProviderClass, ZkCredentialsProvider.class); } + addOnReconnectListener(getConfigDirListener()); zkClient = @@ -341,12 +339,13 @@ public ZkController( zkServerAddress, clientTimeout, zkClientConnectTimeout, - strat, + zkCredentialsProvider, + zkACLProvider, // on reconnect, reload cloud info new OnReconnect() { @Override - public void command() throws SessionExpiredException { + public void command() { log.info( "ZooKeeper session re-connected ... refreshing core states after session expiration."); clearZkCollectionTerms(); @@ -449,15 +448,13 @@ public void command() throws SessionExpiredException { // Restore the interrupted status Thread.currentThread().interrupt(); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); - } catch (SessionExpiredException e) { - throw e; } catch (Exception e) { SolrException.log(log, "", e); throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); } } }, - new BeforeReconnect() { + new OnDisconnect() { @Override public void command() { @@ -470,14 +467,7 @@ public void command() { markAllAsNotLeader(descriptorsSupplier); } }, - zkACLProvider, - new ConnectionManager.IsClosed() { - - @Override - public boolean isClosed() { - return cc.isShutDown(); - } - }); + cc::isShutDown); // Refuse to start if ZK has a non empty /clusterstate.json checkNoOldClusterstate(zkClient); @@ -518,19 +508,19 @@ public boolean isClosed() { */ private void checkNoOldClusterstate(final SolrZkClient zkClient) throws InterruptedException { try { - if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, true)) { + if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE)) { return; } final byte[] data = - zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null, true); + zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null); 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, true); + zkClient.delete(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, -1); } 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. @@ -585,8 +575,8 @@ private void registerAllCoresAsDown( + "/leader_elect/" + slice + "/election", - null, - true) + null + ) .size(); if (children == 0) { log.debug( @@ -683,7 +673,7 @@ public void preClose() { } try { - if (getZkClient().getConnectionManager().isConnected()) { + if (getZkClient().isConnected()) { log.info("Publish this node as DOWN..."); publishNodeAsDown(getNodeName()); } @@ -937,13 +927,13 @@ 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, true); - ZkACLProvider aclProvider = zkClient.getZkACLProvider(); + List securityConfAcl = zkClient.getACL(ZkStateReader.SOLR_SECURITY_CONF_PATH, null); + ACLProvider aclProvider = zkClient.getZkACLProvider(); boolean tryUpdate = false; if (OPEN_ACL_UNSAFE.equals(securityConfAcl)) { - List aclToAdd = aclProvider.getACLsToAdd(ZkStateReader.SOLR_SECURITY_CONF_PATH); + List aclToAdd = aclProvider.getAclForPath(ZkStateReader.SOLR_SECURITY_CONF_PATH); if (OPEN_ACL_UNSAFE.equals(aclToAdd)) { log.warn( "Contents of zookeeper /security.json are world-readable;" @@ -953,7 +943,7 @@ private static void repairSecurityJson(SolrZkClient zkClient) } } else if (aclProvider instanceof SecurityAwareZkACLProvider) { // Use Set to explicitly ignore order - Set nonSecureACL = new HashSet<>(aclProvider.getACLsToAdd(null)); + Set nonSecureACL = new HashSet<>(aclProvider.getDefaultAcl()); // case where security.json was not treated as a secure path if (nonSecureACL.equals(new HashSet<>(securityConfAcl))) { tryUpdate = true; @@ -1004,7 +994,7 @@ private void init() { } } - Stat stat = zkClient.exists(ZkStateReader.LIVE_NODES_ZKNODE, null, true); + Stat stat = zkClient.exists(ZkStateReader.LIVE_NODES_ZKNODE, null); if (stat != null && stat.getNumChildren() > 0) { publishAndWaitForDownStates(); } @@ -1033,7 +1023,7 @@ private void checkForExistingEphemeralNode() throws KeeperException, Interrupted String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; - if (!zkClient.exists(nodePath, true)) { + if (!zkClient.exists(nodePath)) { return; } @@ -1048,8 +1038,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 @@ -1058,7 +1048,7 @@ private void checkForExistingEphemeralNode() throws KeeperException, Interrupted boolean deleted = deletedLatch.await( - zkClient.getSolrZooKeeper().getSessionTimeout() * 2, TimeUnit.MILLISECONDS); + zkClient.getZkSessionTimeout() * 2, TimeUnit.MILLISECONDS); if (!deleted) { throw new SolrException( ErrorCode.SERVER_ERROR, @@ -1160,10 +1150,10 @@ public static boolean checkChrootPath(String zkHost, boolean create) SolrZkClient tmpClient = new SolrZkClient(zkHost.substring(0, zkHost.indexOf("/")), 60000, 30000, null, null, null); - boolean exists = tmpClient.exists(chrootPath, true); + boolean exists = tmpClient.exists(chrootPath); if (!exists && create) { log.info("creating chroot {}", chrootPath); - tmpClient.makePath(chrootPath, false, true); + tmpClient.makePath(chrootPath, false); exists = true; } tmpClient.close(); @@ -1182,13 +1172,12 @@ private void createEphemeralLiveNode() throws KeeperException, InterruptedExcept String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; log.info("Register node as live in ZooKeeper:{}", nodePath); - List ops = new ArrayList<>(2); + List ops = new ArrayList<>(2); ops.add( - Op.create( - nodePath, - null, - zkClient.getZkACLProvider().getACLsToAdd(nodePath), - CreateMode.EPHEMERAL)); + op -> op + .create() + .withMode(CreateMode.EPHEMERAL) + .forPath(nodePath)); // Create the roles node as well cc.nodeRoles @@ -1196,13 +1185,12 @@ private void createEphemeralLiveNode() throws KeeperException, InterruptedExcept .forEach( (role, mode) -> ops.add( - Op.create( - NodeRoles.getZNodeForRoleMode(role, mode) + "/" + nodeName, - null, - zkClient.getZkACLProvider().getACLsToAdd(nodePath), - CreateMode.EPHEMERAL))); + op -> op + .create() + .withMode(CreateMode.EPHEMERAL) + .forPath(NodeRoles.getZNodeForRoleMode(role, mode) + "/" + nodeName))); - zkClient.multi(ops, true); + zkClient.multi(ops); } public void removeEphemeralLiveNode() throws KeeperException, InterruptedException { @@ -1212,11 +1200,9 @@ public void removeEphemeralLiveNode() throws KeeperException, InterruptedExcepti String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; log.info("Remove node as live in ZooKeeper:{}", nodePath); - List ops = new ArrayList<>(2); - ops.add(Op.delete(nodePath, -1)); try { - zkClient.multi(ops, true); + zkClient.delete(nodePath, -1); } catch (NoNodeException e) { } @@ -1228,7 +1214,7 @@ public String getNodeName() { /** Returns true if the path exists */ public boolean pathExists(String path) throws KeeperException, InterruptedException { - return zkClient.exists(path, true); + return zkClient.exists(path); } /** @@ -1544,7 +1530,7 @@ public ZkCoreNodeProps getLeaderProps( try { byte[] data = zkClient.getData( - ZkStateReader.getShardLeadersPath(collection, slice), null, null, true); + ZkStateReader.getShardLeadersPath(collection, slice), null, null); ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data)); return leaderProps; } catch (InterruptedException e) { @@ -2199,14 +2185,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, true); + data = zkClient.getData(path, null, null); } 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, null, true); + zkClient.makePath(path, Utils.toJSON(props), CreateMode.PERSISTENT); } catch (KeeperException e2) { // it's okay if the node already exists if (e2.code() != KeeperException.Code.NODEEXISTS) { @@ -2214,7 +2200,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), true); + zkClient.setData(path, Utils.toJSON(props)); } return; } @@ -2230,7 +2216,7 @@ public static void linkConfSet(SolrZkClient zkClient, String collection, String } // TODO: we should consider using version - zkClient.setData(path, Utils.toJSON(props), true); + zkClient.setData(path, Utils.toJSON(props)); } public ZkDistributedQueue getOverseerJobQueue() { @@ -2364,8 +2350,8 @@ public void rejoinOverseerElection(String electionNode, boolean joinAtHead) { try { zkClient.delete( Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE + "/" + electionNode, - -1, - true); + -1 + ); } catch (NoNodeException e) { // no problem } catch (InterruptedException e) { @@ -2453,7 +2439,7 @@ public void rejoinShardLeaderElection(SolrParams params) { public void checkOverseerDesignate() { try { - byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true); + byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat()); if (data == null) return; Map roles = (Map) Utils.fromJSON(data); if (roles == null) return; @@ -2563,7 +2549,7 @@ public static int persistConfigResourceToZooKeeper( String errMsg = "Failed to persist resource at {0} - old {1}"; try { try { - Stat stat = zkClient.setData(resourceLocation, content, znodeVersion, true); + Stat stat = zkClient.setData(resourceLocation, content, znodeVersion); // if the set succeeded, it should have incremented the version by one always latestVersion = stat.getVersion(); log.info("Persisted config data to node {} ", resourceLocation); @@ -2571,12 +2557,12 @@ public static int persistConfigResourceToZooKeeper( } catch (NoNodeException e) { if (createIfNotExists) { try { - zkClient.create(resourceLocation, content, CreateMode.PERSISTENT, true); + zkClient.create(resourceLocation, content, CreateMode.PERSISTENT); latestVersion = 0; // just created so version must be zero touchConfDir(zkLoader); } catch (KeeperException.NodeExistsException nee) { try { - Stat stat = zkClient.exists(resourceLocation, null, true); + Stat stat = zkClient.exists(resourceLocation, null); if (log.isDebugEnabled()) { log.debug( "failed to set data version in zk is {} and expected version is {} ", @@ -2600,7 +2586,7 @@ public static int persistConfigResourceToZooKeeper( } catch (KeeperException.BadVersionException bve) { int v = -1; try { - Stat stat = zkClient.exists(resourceLocation, null, true); + Stat stat = zkClient.exists(resourceLocation, null); v = stat.getVersion(); } catch (Exception e) { log.error("Exception during ZooKeeper node checking ", e); @@ -2629,7 +2615,7 @@ public static int persistConfigResourceToZooKeeper( public static void touchConfDir(ZkSolrResourceLoader zkLoader) { SolrZkClient zkClient = zkLoader.getZkController().getZkClient(); try { - zkClient.setData(zkLoader.getConfigSetZkPath(), new byte[] {0}, true); + zkClient.setData(zkLoader.getConfigSetZkPath(), new byte[] {0}); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); // Restore the interrupted status @@ -2721,7 +2707,7 @@ public void process(WatchedEvent event) { Stat stat = null; try { - stat = zkClient.exists(zkDir, null, true); + stat = zkClient.exists(zkDir, null); } catch (KeeperException e) { // ignore , it is not a big deal } catch (InterruptedException e) { @@ -2776,7 +2762,7 @@ private boolean fireEventListeners(String zkDir) { private void setConfWatcher(String zkDir, Watcher watcher, Stat stat) { try { - Stat newStat = zkClient.exists(zkDir, watcher, true); + Stat newStat = zkClient.exists(zkDir, watcher); 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 ca29d53e9d7..9c74a67ebab 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java @@ -92,8 +92,8 @@ protected ZkDistributedLock(SolrZkClient zkClient, String lockDir, String lockNo + DistributedCollectionConfigSetCommandRunner.ZK_PATH_SEPARATOR + lockNodePrefix, null, - CreateMode.EPHEMERAL_SEQUENTIAL, - false); + CreateMode.EPHEMERAL_SEQUENTIAL + ); sequence = getSequenceFromNodename(lockNode); } @@ -141,7 +141,7 @@ public void waitUntilAcquired() { String nodeToWatch = nodeToWatch(); while (nodeToWatch != null) { final DeletedNodeWatcher watcher = new DeletedNodeWatcher(nodeToWatch); - if (zkClient.exists(nodeToWatch, watcher, true) != null) { + if (zkClient.exists(nodeToWatch, watcher) != null) { watcher.await(); } nodeToWatch = nodeToWatch(); @@ -157,7 +157,7 @@ public void waitUntilAcquired() { @Override public void release() { try { - zkClient.delete(lockNode, -1, true); + zkClient.delete(lockNode, -1); released = true; } catch (KeeperException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); @@ -188,7 +188,7 @@ public boolean isAcquired() { * {@code null} if the lock is ours. */ String nodeToWatch() throws KeeperException, InterruptedException { - List locks = zkClient.getChildren(lockDir, null, true); + List locks = zkClient.getChildren(lockDir, null); 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 54434c8e6bc..76696dc3942 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, true)) { - zkClient.makePath(lockNodePath, new byte[0], CreateMode.PERSISTENT, true); + if (!zkClient.exists(lockNodePath)) { + zkClient.makePath(lockNodePath, new byte[0], CreateMode.PERSISTENT); } } 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 dcb53a78431..e9b4ea1ba23 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java @@ -33,6 +33,8 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Predicate; + +import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.solr.client.solrj.cloud.DistributedQueue; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -42,7 +44,6 @@ import org.apache.solr.common.util.Pair; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.data.Stat; @@ -247,25 +248,19 @@ public byte[] remove() throws NoSuchElementException, KeeperException, Interrupt public void remove(Collection paths) throws KeeperException, InterruptedException { if (paths.isEmpty()) return; - List ops = new ArrayList<>(); + List ops = new ArrayList<>(); for (String path : paths) { - ops.add(Op.delete(dir + "/" + path, -1)); + ops.add(op -> op.delete().withVersion(-1).forPath(dir + "/" + path)); } for (int from = 0; from < ops.size(); from += 1000) { int to = Math.min(from + 1000, ops.size()); if (from < to) { - try { - zookeeper.multi(ops.subList(from, to), true); - } catch (KeeperException.NoNodeException e) { - // don't know which nodes are not exist, so try to delete one by one node - for (int j = from; j < to; j++) { + Collection results = zookeeper.multi(ops.subList(from, to)); + for (CuratorTransactionResult result : results) { + if (result.getError() != 0) { try { - zookeeper.delete(ops.get(j).getPath(), -1, true); - } catch (KeeperException.NoNodeException e2) { - if (log.isDebugEnabled()) { - log.debug("Can not remove node which is not exist : {}", ops.get(j).getPath()); - } - } + zookeeper.delete(result.getForPath(), -1); + } catch (KeeperException.NoNodeException ignored) { } } } } @@ -320,7 +315,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, true); + Stat stat = zookeeper.exists(dir, null); if (stat == null) { // jump to the code below, which tries to create dir if it doesn't exist throw new KeeperException.NoNodeException(); @@ -338,12 +333,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, true); + zookeeper.create(dir + "/" + PREFIX, data, CreateMode.PERSISTENT_SEQUENTIAL); isDirty = true; return; } catch (KeeperException.NoNodeException e) { try { - zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT, true); + zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException ne) { // someone created it } @@ -429,7 +424,7 @@ TreeSet fetchZkChildren(Watcher watcher) throws InterruptedException, Ke try { TreeSet orderedChildren = new TreeSet<>(); - List childNames = zookeeper.getChildren(dir, watcher, true); + List childNames = zookeeper.getChildren(dir, watcher); stats.setQueueLength(childNames.size()); for (String childName : childNames) { // Check format @@ -441,7 +436,7 @@ TreeSet fetchZkChildren(Watcher watcher) throws InterruptedException, Ke } return orderedChildren; } catch (KeeperException.NoNodeException e) { - zookeeper.makePath(dir, false, true); + zookeeper.makePath(dir, false); // go back to the loop and try again } } @@ -504,7 +499,7 @@ public Collection> peekElements( break; } try { - byte[] data = zookeeper.getData(dir + "/" + child, null, null, true); + byte[] data = zookeeper.getData(dir + "/" + child, null, null); result.add(new Pair<>(child, data)); } catch (KeeperException.NoNodeException e) { // Another client deleted the node first, remove the in-memory and continue. @@ -531,7 +526,7 @@ private byte[] firstElement() throws KeeperException, InterruptedException { return null; } try { - return zookeeper.getData(dir + "/" + firstChild, null, null, true); + return zookeeper.getData(dir + "/" + firstChild, null, null); } catch (KeeperException.NoNodeException e) { // Another client deleted the node first, remove the in-memory and retry. updateLock.lockInterruptibly(); @@ -554,8 +549,8 @@ private byte[] removeFirst() throws KeeperException, InterruptedException { } try { String path = dir + "/" + firstChild; - byte[] result = zookeeper.getData(path, null, null, true); - zookeeper.delete(path, -1, true); + byte[] result = zookeeper.getData(path, null, null); + zookeeper.delete(path, -1); 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 972e0111474..8ade8179013 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; @@ -321,7 +320,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(), true); + Stat stat = zkClient.setData(znodePath, znodeData, newTerms.getVersion()); setNewTerms(new ShardTerms(newTerms, stat.getVersion())); log.info("Successful update of terms at {} to {} for {}", znodePath, newTerms, action); return true; @@ -348,7 +347,7 @@ private void ensureTermNodeExist() { try { Map initialTerms = new HashMap<>(); - zkClient.makePath(path, Utils.toJSON(initialTerms), CreateMode.PERSISTENT, true); + zkClient.makePath(path, Utils.toJSON(initialTerms), CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException e) { // it's okay if another beats us creating the node } @@ -368,7 +367,7 @@ public void refreshTerms() { ShardTerms newTerms; try { Stat stat = new Stat(); - byte[] data = zkClient.getData(znodePath, null, stat, true); + byte[] data = zkClient.getData(znodePath, null, stat); newTerms = new ShardTerms((Map) Utils.fromJSON(data), stat.getVersion()); } catch (KeeperException | InterruptedException e) { Throwable cause = SolrZkClient.checkInterrupted(e); @@ -396,16 +395,6 @@ private void retryRegisterWatcher() { return; } catch (KeeperException e) { log.warn("Failed watching shard term for collection: {}, retrying!", collection, e); - try { - zkClient.getConnectionManager().waitForConnected(zkClient.getZkClientTimeout()); - } catch (TimeoutException te) { - if (Thread.interrupted()) { - throw new SolrException( - SolrException.ErrorCode.SERVER_ERROR, - "Error watching shard term for collection: " + collection, - te); - } - } } } } @@ -425,7 +414,7 @@ private void registerWatcher() throws KeeperException { }; try { // exists operation is faster than getData operation - zkClient.exists(znodePath, watcher, true); + zkClient.exists(znodePath, watcher); } 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 39efaaa06ce..327932ffe60 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java @@ -72,7 +72,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, true); + byte[] bytes = zkController.getZkClient().getData(file, null, stat); 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 fb0f1c65c3d..a359d4876a6 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 @@ -175,7 +175,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList resu if (zkStateReader.getClusterState().getCollectionOrNull(collection) == null) { if (zkStateReader .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true)) { + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection)) { // 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 @@ -210,7 +210,7 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu try { String collectionPath = ZkStateReader.getCollectionPathRoot(collection); - if (zkStateReader.getZkClient().exists(collectionPath, true)) { + if (zkStateReader.getZkClient().exists(collectionPath)) { 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 5e31cc89b7c..52278c93509 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 @@ -76,11 +76,11 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu String roleName = message.getStr("role"); boolean nodeExists = false; - if (nodeExists = zkClient.exists(ZkStateReader.ROLES, true)) { + if (nodeExists = zkClient.exists(ZkStateReader.ROLES)) { @SuppressWarnings("unchecked") Map> tmp = (Map>) - Utils.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true)); + Utils.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat())); roles = tmp; } else { roles = new LinkedHashMap<>(1); @@ -96,9 +96,9 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu } if (nodeExists) { - zkClient.setData(ZkStateReader.ROLES, Utils.toJSON(roles), true); + zkClient.setData(ZkStateReader.ROLES, Utils.toJSON(roles)); } else { - zkClient.create(ZkStateReader.ROLES, Utils.toJSON(roles), CreateMode.PERSISTENT, true); + zkClient.create(ZkStateReader.ROLES, Utils.toJSON(roles), CreateMode.PERSISTENT); } 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 3cfe436878f..9925e9cc82c 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 @@ -176,13 +176,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, true); + zkStateReader.getZkClient().getData("/overseer/queue", null, stat); results.add("overseer_queue_size", stat.getNumChildren()); stat = new Stat(); - zkStateReader.getZkClient().getData("/overseer/queue-work", null, stat, true); + zkStateReader.getZkClient().getData("/overseer/queue-work", null, stat); results.add("overseer_work_queue_size", stat.getNumChildren()); stat = new Stat(); - zkStateReader.getZkClient().getData("/overseer/collection-queue-work", null, stat, true); + zkStateReader.getZkClient().getData("/overseer/collection-queue-work", null, stat); 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 9471565920c..444f485e795 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 @@ -151,8 +151,8 @@ public boolean split(ClusterState clusterState, ZkNodeProps message, NamedList updates) reader.getZkClient().clean(path); } else { byte[] data = Utils.toJSON(singletonMap(c.getName(), c)); - if (reader.getZkClient().exists(path, true)) { + if (reader.getZkClient().exists(path)) { if (log.isDebugEnabled()) { log.debug("going to update_collection {} version: {}", path, c.getZNodeVersion()); } - Stat stat = reader.getZkClient().setData(path, data, c.getZNodeVersion(), true); + Stat stat = reader.getZkClient().setData(path, data, c.getZNodeVersion()); DocCollection newCollection = new DocCollection( name, c.getSlicesMap(), c.getProperties(), c.getRouter(), stat.getVersion()); clusterState = clusterState.copyWith(name, newCollection); } else { log.debug("going to create_collection {}", path); - reader.getZkClient().create(path, data, CreateMode.PERSISTENT, true); + reader.getZkClient().create(path, data, CreateMode.PERSISTENT); DocCollection newCollection = new DocCollection(name, c.getSlicesMap(), c.getProperties(), c.getRouter(), 0); clusterState = clusterState.copyWith(name, newCollection); diff --git a/solr/core/src/java/org/apache/solr/core/NodeConfig.java b/solr/core/src/java/org/apache/solr/core/NodeConfig.java index 757e8b3bf4a..01599082b5e 100644 --- a/solr/core/src/java/org/apache/solr/core/NodeConfig.java +++ b/solr/core/src/java/org/apache/solr/core/NodeConfig.java @@ -211,9 +211,9 @@ public static NodeConfig loadNodeConfig(Path solrHome, Properties nodeProperties int startUpZkTimeOut = Integer.getInteger("waitForZk", 30); startUpZkTimeOut *= 1000; try (SolrZkClient zkClient = new SolrZkClient(zkHost, startUpZkTimeOut, startUpZkTimeOut)) { - if (zkClient.exists("/solr.xml", true)) { + if (zkClient.exists("/solr.xml")) { log.info("solr.xml found in ZooKeeper. Loading..."); - byte[] data = zkClient.getData("/solr.xml", null, null, true); + byte[] data = zkClient.getData("/solr.xml", null, null); return SolrXmlConfig.fromInputStream( solrHome, new ByteArrayInputStream(data), nodeProperties, true); } diff --git a/solr/core/src/java/org/apache/solr/core/RequestParams.java b/solr/core/src/java/org/apache/solr/core/RequestParams.java index 1657e9f11cf..b4b72a5f5a7 100644 --- a/solr/core/src/java/org/apache/solr/core/RequestParams.java +++ b/solr/core/src/java/org/apache/solr/core/RequestParams.java @@ -150,7 +150,7 @@ public static RequestParams getFreshRequestParams( .getZkController() .getZkClient() .exists( - resourceLoader.getConfigSetZkPath() + "/" + RequestParams.RESOURCE, null, true); + resourceLoader.getConfigSetZkPath() + "/" + RequestParams.RESOURCE, null); if (log.isDebugEnabled()) { log.debug( "latest version of {}/{} in ZK is : {}", diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index 11d08a34f28..763717fb7a6 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -3429,7 +3429,7 @@ public void registerInfoBean(String name, SolrInfoBean solrInfoBean) { private static boolean checkStale(SolrZkClient zkClient, String zkPath, int currentVersion) { if (zkPath == null) return false; try { - Stat stat = zkClient.exists(zkPath, null, true); + Stat stat = zkClient.exists(zkPath, null); if (stat == null) { if (currentVersion > -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 647886bca6a..ffd0cfa422e 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 @@ -292,7 +292,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, true); + zkStateReader.getZkClient().create(zkPath, arr, CreateMode.PERSISTENT); } catch (KeeperException | InterruptedException e) { throw new IOException( "Error uploading file to zookeeper path " + source.toString() + " to " + zkPath, @@ -310,13 +310,13 @@ public void downloadCollectionProperties(String collectionName) throws IOExcepti + ZkStateReader.COLLECTION_PROPS_ZKNODE; try { - if (!zkStateReader.getZkClient().exists(zkPath, true)) { + if (!zkStateReader.getZkClient().exists(zkPath)) { // Nothing to back up return; } try (OutputStream os = repository.createOutput(dest)) { - byte[] data = zkStateReader.getZkClient().getData(zkPath, null, null, true); + byte[] data = zkStateReader.getZkClient().getData(zkPath, null, null); 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 dd475b03e6e..56c80b00f12 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 @@ -72,7 +72,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, true); + return zkClient.exists(zkPath); } /** @@ -88,7 +88,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, true); + zkClient.makePath(zkPath, Utils.toJSON(meta), CreateMode.PERSISTENT); } /** @@ -104,7 +104,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, true); + zkClient.setData(zkPath, Utils.toJSON(meta), -1); } /** @@ -120,7 +120,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, true); + zkClient.delete(zkPath, -1); } /** @@ -136,11 +136,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, true); + Collection snapshots = zkClient.getChildren(zkPath, null); for (String snapshot : snapshots) { String path = getSnapshotMetaDataZkPath(collectionName, Optional.of(snapshot)); try { - zkClient.delete(path, -1, true); + zkClient.delete(path, -1); } catch (KeeperException ex) { // Gracefully handle the case when the zk node doesn't exist if (ex.code() != KeeperException.Code.NONODE) { @@ -150,7 +150,7 @@ public static void cleanupCollectionLevelSnapshots(SolrZkClient zkClient, String } // Delete the parent node. - zkClient.delete(zkPath, -1, true); + zkClient.delete(zkPath, -1); } catch (KeeperException ex) { // Gracefully handle the case when the zk node doesn't exist (e.g. if no snapshots were // created for this collection). @@ -178,7 +178,7 @@ public static Optional getCollectionLevelSnapshot( try { @SuppressWarnings({"unchecked"}) Map data = - (Map) Utils.fromJSON(zkClient.getData(zkPath, null, null, true)); + (Map) Utils.fromJSON(zkClient.getData(zkPath, null, null)); return Optional.of(new CollectionSnapshotMetaData(data)); } catch (KeeperException ex) { // Gracefully handle the case when the zk node for a specific @@ -206,7 +206,7 @@ public static Collection listSnapshots( String zkPath = getSnapshotMetaDataZkPath(collectionName, Optional.empty()); try { - Collection snapshots = zkClient.getChildren(zkPath, null, true); + Collection snapshots = zkClient.getChildren(zkPath, null); 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 fca382f2227..2f59a584859 100644 --- a/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java +++ b/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java @@ -341,15 +341,15 @@ private void distribute(FileInfo info) { coreContainer .getZkController() .getZkClient() - .makePath(ZK_PACKAGESTORE + dirName, false, true); + .makePath(ZK_PACKAGESTORE + dirName, false); coreContainer .getZkController() .getZkClient() .create( ZK_PACKAGESTORE + info.path, info.getDetails().getMetaData().sha512.getBytes(UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); } catch (Exception e) { throw new SolrException(SERVER_ERROR, "Unable to create an entry in ZK", e); } @@ -513,7 +513,7 @@ public void delete(String path) { private void checkInZk(String path) { try { // fail if file exists - if (coreContainer.getZkController().getZkClient().exists(ZK_PACKAGESTORE + path, true)) { + if (coreContainer.getZkController().getZkClient().exists(ZK_PACKAGESTORE + path)) { throw new SolrException(BAD_REQUEST, "The path exist ZK, delete and retry"); } @@ -541,7 +541,7 @@ public void refresh(String path) { coreContainer .getZkController() .getZkClient() - .getChildren(ZK_PACKAGESTORE + path, null, true); + .getChildren(ZK_PACKAGESTORE + path, null); } catch (KeeperException.NoNodeException e) { // does not matter } @@ -648,7 +648,7 @@ private static Map _getKeys(Path solrhome) throws IOException { public static void deleteZKFileEntry(SolrZkClient client, String path) { try { - client.delete(ZK_PACKAGESTORE + path, -1, true); + client.delete(ZK_PACKAGESTORE + path, -1); } 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 0a98bba9a2f..482269bf09e 100644 --- a/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java +++ b/solr/core/src/java/org/apache/solr/filestore/PackageStoreAPI.java @@ -139,7 +139,7 @@ public void delete(SolrQueryRequest req, SolrQueryResponse rsp) { coreContainer .getZkController() .getZkClient() - .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL, true); + .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL); String path = req.getPathTemplateValues().get("*"); validateName(path, true); if (coreContainer.getPackageLoader().getPackageAPI().isJarInuse(path)) { @@ -158,7 +158,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, true); + coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1); } catch (Exception e) { log.error("Unexpected error ", e); } @@ -187,7 +187,7 @@ public void upload(SolrQueryRequest req, SolrQueryResponse rsp) { coreContainer .getZkController() .getZkClient() - .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL, true); + .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL); Iterable streams = req.getContentStreams(); if (streams == null) @@ -221,7 +221,7 @@ public void upload(SolrQueryRequest req, SolrQueryResponse rsp) { log.error("Unexpected error", e); } finally { try { - coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1, true); + coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1); } 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 c1a7c31a02d..e5dd96b5500 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 @@ -112,11 +112,11 @@ public void getClusterStatus(NamedList results) } Map roles = null; - if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES, true)) { + if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES)) { roles = (Map) Utils.fromJSON( - zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null, true)); + zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null)); } ClusterState clusterState = zkStateReader.getClusterState(); @@ -192,7 +192,7 @@ public void getClusterStatus(NamedList results) } List liveNodes = - zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true); + zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null); // 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 61e74eb9080..55bd5d8369f 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 @@ -170,7 +170,7 @@ public static Map plugins(Supplier zkClientSupplie try { Map clusterPropsJson = (Map) - Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat(), true)); + Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); 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 a0978c02759..269beccdf7a 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,8 +79,8 @@ protected boolean persistConf(SecurityConfig securityConfig) throws IOException .setData( SOLR_SECURITY_CONF_PATH, Utils.toJSON(securityConfig.getData()), - securityConfig.getVersion(), - true); + securityConfig.getVersion() + ); 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 4e7e1b8124b..7017909f83d 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, true); + List children = zkClient.getChildren(adminFile, null); 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, true); + List fchildren = zkClient.getChildren(adminFile + "/" + f, null); if (fchildren.size() > 0) { fileInfo.add("directory", true); } else { @@ -186,7 +186,7 @@ private void showFromZooKeeper( req.setParams(params); ContentStreamBase content = new ContentStreamBase.ByteArrayStream( - zkClient.getData(adminFile, null, null, true), adminFile); + zkClient.getData(adminFile, null, null), adminFile); content.setContentType(getSafeContentType(req.getParams().get(USE_CONTENT_TYPE))); rsp.add(RawResponseWriter.CONTENT, content); @@ -342,7 +342,7 @@ public static String getAdminFileFromZooKeeper( } // Make sure the file exists, is readable and is not a hidden file - if (!zkClient.exists(adminFile, true)) { + if (!zkClient.exists(adminFile)) { 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 479f9b4115c..334f9c70950 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 @@ -281,7 +281,7 @@ private synchronized List getCollections(SolrZkClient zkClient) // cache is stale, rebuild the full list ... cachedCollections = new ArrayList(); - List fromZk = zkClient.getChildren("/collections", this, true); + List fromZk = zkClient.getChildren("/collections", this); if (fromZk != null) cachedCollections.addAll(fromZk); // sort the final merged set of collections @@ -628,7 +628,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, true); + byte[] data = zkClient.getData(path, null, stat); if (stat.getEphemeralOwner() != 0) { writeKeyValue(json, "ephemeral", true, false); @@ -661,7 +661,7 @@ boolean printTree(JSONWriter json, String path) throws IOException { json.startArray(); try { - List children = zkClient.getChildren(path, null, true); + List children = zkClient.getChildren(path, null); java.util.Collections.sort(children); boolean first = true; @@ -716,7 +716,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, true); + byte[] data = zkClient.getData(path, null, stat); 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 139e3ba3520..8c6d7b27727 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 @@ -91,19 +91,19 @@ public void listNodes(SolrQueryRequest req, SolrQueryResponse rsp) { String path = req.getPathTemplateValues().get("*"); if (path == null || path.isEmpty()) path = "/"; try { - Stat stat = coreContainer.getZkController().getZkClient().exists(path, null, true); + Stat stat = coreContainer.getZkController().getZkClient().exists(path, null); rsp.add("stat", (MapWriter) ew -> printStat(ew, stat)); if (!req.getParams().getBool("c", true)) { return; } - List l = coreContainer.getZkController().getZkClient().getChildren(path, null, false); + List l = coreContainer.getZkController().getZkClient().getChildren(path, null); String prefix = path.endsWith("/") ? path : path + "/"; Map stats = new LinkedHashMap<>(); for (String s : l) { try { stats.put( - s, coreContainer.getZkController().getZkClient().exists(prefix + s, null, false)); + s, coreContainer.getZkController().getZkClient().exists(prefix + s, null)); } catch (Exception e) { throw new RuntimeException(e); } @@ -157,7 +157,7 @@ private void readNodeAndAddToResponse( private byte[] readPathFromZookeeper(String path) { byte[] d; try { - d = coreContainer.getZkController().getZkClient().getData(path, null, null, false); + d = coreContainer.getZkController().getZkClient().getData(path, null, null); } 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/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java index f6fe3193b25..85e92ab9143 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -302,7 +302,7 @@ public ShardHandler getAndPrepShardHandler(SolrQueryRequest req, ResponseBuilder ZkController zkController = cc.getZkController(); boolean zkConnected = zkController != null - && !zkController.getZkClient().getConnectionManager().isLikelyExpired(); + && !zkController.getZkClient().isConnected(); if (requireZkConnected && false == zkConnected) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "ZooKeeper is not connected"); } else { 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 1f228459edb..ad35a8c1ddb 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 @@ -221,7 +221,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, true); + data = zkStateReader().getZkClient().getData(filePath, null, null); } catch (KeeperException | InterruptedException e) { throw new IOException("Error reading file: " + filePath, SolrZkClient.checkInterrupted(e)); } @@ -275,7 +275,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, true); + zkClient.setData(zkPath, data); } 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), true)) { - if (zkClient.exists(getConfigSetZkPath(configSet, null), true)) { + if (!zkClient.exists(getConfigSetZkPath(mutableId, null))) { + if (zkClient.exists(getConfigSetZkPath(configSet, null))) { configId = configSet; } else { throw new SolrException( @@ -1367,7 +1367,7 @@ private void validateNewConfigSetName(String configSet) { private boolean pathExistsInZk(final String zkPath) throws IOException { SolrZkClient zkClient = zkStateReader().getZkClient(); try { - return zkClient.exists(zkPath, true); + return zkClient.exists(zkPath); } 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 3adaf0948af..bffbb3dc53c 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 @@ -709,7 +709,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, true); + Stat stat = cc.getZkController().getZkClient().exists(path, null); if (stat != null) { currentVersion = stat.getVersion(); } @@ -925,7 +925,7 @@ protected ManagedIndexSchema removeLanguageSpecificObjectsAndFiles( for (String path : toRemoveFiles) { try { - zkClient.delete(path, -1, false); + zkClient.delete(path, -1); } catch (KeeperException.NoNodeException nne) { // no-op } catch (KeeperException | InterruptedException e) { @@ -991,9 +991,9 @@ protected ManagedIndexSchema restoreLanguageSpecificObjectsAndFiles( for (String path : langFilesToRestore) { String copyToPath = path.replace(origPathDir, replacePathDir); try { - if (!zkClient.exists(copyToPath, true)) { - zkClient.makePath(copyToPath, false, true); - zkClient.setData(copyToPath, zkClient.getData(path, null, null, true), true); + if (!zkClient.exists(copyToPath)) { + zkClient.makePath(copyToPath, false); + zkClient.setData(copyToPath, zkClient.getData(path, null, null)); } } 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 63e11ea4f5d..6b8d38ae589 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 @@ -129,7 +129,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, true); + data = cc.getZkController().getZkStateReader().getZkClient().getData(path, null, stat); } 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 8909da5fc1d..c5ec7da6f76 100644 --- a/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java +++ b/solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java @@ -176,14 +176,14 @@ public List fetchInstalledPackageInstances() throws SolrExc List ret = new ArrayList<>(); packages = new HashMap<>(); try { - if (zkClient.exists(ZkStateReader.SOLR_PKGS_PATH, true) == true) { + 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, true), + zkClient.getData(ZkStateReader.SOLR_PKGS_PATH, null, null), "UTF-8"), Map.class) .get("packages"); @@ -320,7 +320,7 @@ public Map getPackagesDeployedAsClusterLevelPlugins private void ensureCollectionsExist(List collections) { try { - List existingCollections = zkClient.getChildren("/collections", null, true); + List existingCollections = zkClient.getChildren("/collections", null); Set nonExistent = new HashSet<>(collections); nonExistent.removeAll(existingCollections); if (nonExistent.isEmpty() == false) { @@ -1106,7 +1106,7 @@ public void undeploy( public Map getDeployedCollections(String packageName) { List allCollections; try { - allCollections = zkClient.getChildren(ZkStateReader.COLLECTIONS_ZKNODE, null, true); + allCollections = zkClient.getChildren(ZkStateReader.COLLECTIONS_ZKNODE, null); } 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 d0826a30356..7640e5d33c8 100644 --- a/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java +++ b/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java @@ -116,17 +116,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, true) == false) { + if (packageManager.zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH) == false) { packageManager.zkClient.create( PackageUtils.REPOSITORIES_ZK_PATH, getMapper().writeValueAsString(repos).getBytes("UTF-8"), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); } else { packageManager.zkClient.setData( PackageUtils.REPOSITORIES_ZK_PATH, - getMapper().writeValueAsString(repos).getBytes("UTF-8"), - true); + getMapper().writeValueAsString(repos).getBytes("UTF-8") + ); } addKey(IOUtils.toByteArray(new URL(uri + "/publickey.der").openStream()), repoName + ".der"); @@ -149,9 +149,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, true)) { + if (zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH)) { return new String( - zkClient.getData(PackageUtils.REPOSITORIES_ZK_PATH, null, null, true), "UTF-8"); + zkClient.getData(PackageUtils.REPOSITORIES_ZK_PATH, null, null), "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 985550ce530..bee3cd65fb2 100644 --- a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java +++ b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java @@ -113,8 +113,8 @@ public void process(WatchedEvent event) { refreshPackages(thisWatch); } } - }, - true); + } + ); } public void refreshPackages(Watcher watcher) { @@ -124,7 +124,7 @@ public void refreshPackages(Watcher watcher) { coreContainer .getZkController() .getZkClient() - .getData(SOLR_PKGS_PATH, watcher, stat, true); + .getData(SOLR_PKGS_PATH, watcher, stat); pkgs = readPkgsFromZk(data, stat); packageLoader.refreshPackageConf(); } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) { @@ -145,7 +145,7 @@ 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, true); + coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, null, stat); } 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 b28f4f57c36..d6f84216c6c 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, retryOnConnLoss)) { - zkClient.makePath(znodeBase, retryOnConnLoss); + if (!zkClient.exists(znodeBase)) { + zkClient.makePath(znodeBase); } } 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, retryOnConnLoss); + return zkClient.exists(znodePath); } 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, retryOnConnLoss)) { - znodeData = zkClient.getData(znodePath, null, null, retryOnConnLoss); + if (zkClient.exists(znodePath)) { + znodeData = zkClient.getData(znodePath, null, null); } } 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, retryOnConnLoss)) { - zkClient.setData(znodePath, znodeData, retryOnConnLoss); + if (zkClient.exists(znodePath)) { + zkClient.setData(znodePath, znodeData); log.info("Wrote {} bytes to existing znode {}", znodeData.length, znodePath); } else { - zkClient.makePath(znodePath, znodeData, retryOnConnLoss); + zkClient.makePath(znodePath, znodeData); 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, retryOnConnLoss)) { + if (zkClient.exists(znodePath)) { log.debug("Attempting to delete znode {}", znodePath); - zkClient.delete(znodePath, -1, retryOnConnLoss); - wasDeleted = zkClient.exists(znodePath, retryOnConnLoss); + zkClient.delete(znodePath, -1); + wasDeleted = zkClient.exists(znodePath); 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 48d6fc4a4ef..d0b40e660ee 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java @@ -186,7 +186,7 @@ boolean persistManagedSchemaToZooKeeper(boolean createOnly) { final byte[] data = writer.toString().getBytes(StandardCharsets.UTF_8); if (createOnly) { try { - zkClient.create(managedSchemaPath, data, CreateMode.PERSISTENT, true); + zkClient.create(managedSchemaPath, data, CreateMode.PERSISTENT); schemaZkVersion = 0; log.info("Created and persisted managed schema znode at {}", managedSchemaPath); } catch (KeeperException.NodeExistsException e) { @@ -198,7 +198,7 @@ boolean persistManagedSchemaToZooKeeper(boolean createOnly) { } else { try { // Assumption: the path exists - Stat stat = zkClient.setData(managedSchemaPath, data, schemaZkVersion, true); + Stat stat = zkClient.setData(managedSchemaPath, data, schemaZkVersion); 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 7609149f14c..cadbc54c9f1 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java @@ -122,7 +122,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, true)) { + if (zkClient.exists(legacyManagedSchemaPath)) { log.debug( "Legacy managed schema resource {} found - loading legacy managed schema instead of {} file.", ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME, @@ -214,7 +214,7 @@ public ManagedIndexSchema create( Stat stat = new Stat(); try { // Attempt to load the managed schema - byte[] data = zkClient.getData(managedSchemaPath, null, stat, true); + byte[] data = zkClient.getData(managedSchemaPath, null, stat); schemaZkVersion = stat.getVersion(); schemaInputStream = new ZkSolrResourceLoader.ZkByteArrayInputStream(data, managedSchemaPath, stat); @@ -243,7 +243,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, true); + byte[] data = zkClient.getData(managedSchemaPath, null, stat); schemaZkVersion = stat.getVersion(); schemaInputStream = new ByteArrayInputStream(data); loadedResource = managedSchemaPath; @@ -459,7 +459,7 @@ private void zkUgradeToManagedSchema() { boolean locked = false; try { try { - zkClient.makePath(lockPath, null, CreateMode.EPHEMERAL, null, true, true); + zkClient.makePath(lockPath, null, CreateMode.EPHEMERAL, null, true); locked = true; } catch (Exception e) { // some other node already started the upgrade, or an error occurred - bail out @@ -477,14 +477,14 @@ private void zkUgradeToManagedSchema() { ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(zkController.getClientTimeout()); 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, true); + byte[] bytes = zkController.getZkClient().getData(nonManagedSchemaPath, null, null); final String upgradedSchemaPath = nonManagedSchemaPath + UPGRADED_SCHEMA_EXTENSION; zkCmdExecutor.ensureExists(upgradedSchemaPath, zkController.getZkClient()); - zkController.getZkClient().setData(upgradedSchemaPath, bytes, true); + zkController.getZkClient().setData(upgradedSchemaPath, bytes); // Then delete the non-managed schema znode - if (zkController.getZkClient().exists(nonManagedSchemaPath, true)) { + if (zkController.getZkClient().exists(nonManagedSchemaPath)) { try { - zkController.getZkClient().delete(nonManagedSchemaPath, -1, true); + zkController.getZkClient().delete(nonManagedSchemaPath, -1); } catch (KeeperException.NoNodeException ex) { // ignore - someone beat us to it } @@ -514,7 +514,7 @@ private void zkUgradeToManagedSchema() { if (locked) { // unlock try { - zkClient.delete(lockPath, -1, true); + zkClient.delete(lockPath, -1); } 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 c68d2b53082..73488460a91 100644 --- a/solr/core/src/java/org/apache/solr/schema/SchemaManager.java +++ b/solr/core/src/java/org/apache/solr/schema/SchemaManager.java @@ -475,10 +475,10 @@ private ManagedIndexSchema getFreshManagedSchema(SolrCore core) SolrZkClient zkClient = zkLoader.getZkController().getZkClient(); String managedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + schemaResourceName; try { - if (!zkClient.exists(managedSchemaPath, true)) { + if (!zkClient.exists(managedSchemaPath)) { String backupName = schemaResourceName + ManagedIndexSchemaFactory.UPGRADED_SCHEMA_EXTENSION; - if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + backupName, true)) { + if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + backupName)) { 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 87249cdaf13..3521b9f77bd 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, true); + zkClient.exists(managedSchemaPath, watcher); } 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, true); + byte[] data = zkClient.getData(managedSchemaPath, watcher, stat); 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/QueryRateLimiter.java b/solr/core/src/java/org/apache/solr/servlet/QueryRateLimiter.java index 6b54ce450cd..5b57617fa83 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(), true)); + Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); byte[] configInput = Utils.toJSON(clusterPropsJson.get(RL_CONFIG_KEY)); if (configInput.length == 0) { diff --git a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java index 88e3884412e..8adf37f7743 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java @@ -1463,7 +1463,7 @@ private void zkCheck() { return; } - if (!zkController.getZkClient().getConnectionManager().isLikelyExpired()) { + if (zkController.isConnected()) { return; } diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java index 766dac71619..62df37be67a 100755 --- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java @@ -1577,7 +1577,7 @@ protected void runCloudTool(CloudSolrClient cloudSolrClient, CommandLine cli) th && !"".equals(confname.trim()) && ZkStateReader.from(cloudSolrClient) .getZkClient() - .exists("/configs/" + confname, true); + .exists("/configs/" + confname); if (CollectionAdminParams.SYSTEM_COLL.equals(collectionName)) { // do nothing @@ -2102,7 +2102,7 @@ protected void runImpl(CommandLine cli) throws Exception { } echoIfVerbose("\nConnecting to ZooKeeper at " + zkHost + " ...", cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 30000)) { - if (recurse == false && zkClient.getChildren(znode, null, true).size() != 0) { + if (recurse == false && zkClient.getChildren(znode, null).size() != 0) { throw new SolrServerException( "ZooKeeper node " + znode + " has children and recurse has NOT been specified."); } @@ -2245,7 +2245,7 @@ protected void runImpl(CommandLine cli) throws Exception { String znode = cli.getOptionValue("path"); echo("Creating ZooKeeper path " + znode + " on ZooKeeper at " + zkHost); - zkClient.makePath(znode, true); + zkClient.makePath(znode); } catch (Exception e) { log.error("Could not complete mkroot operation for reason: ", e); throw (e); @@ -4254,8 +4254,8 @@ private int handleKerberos(CommandLine cli) throws Exception { // check if security is already enabled or not if (!zkInaccessible) { try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { - if (zkClient.exists("/security.json", true)) { - byte oldSecurityBytes[] = zkClient.getData("/security.json", null, null, true); + if (zkClient.exists("/security.json")) { + byte oldSecurityBytes[] = zkClient.getData("/security.json", null, null); 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" @@ -4280,7 +4280,7 @@ private int handleKerberos(CommandLine cli) throws Exception { echoIfVerbose("Uploading following security.json: " + securityJson, cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { zkClient.setData( - "/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true); + "/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); } catch (Exception ex) { if (zkInaccessible == false) { CLIO.out( @@ -4327,7 +4327,7 @@ private int handleKerberos(CommandLine cli) throws Exception { echoIfVerbose("Uploading following security.json: {}", cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { - zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8), true); + zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8)); } } @@ -4405,8 +4405,8 @@ private int handleBasicAuth(CommandLine cli) throws Exception { // check if security is already enabled or not try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { - if (zkClient.exists("/security.json", true)) { - byte oldSecurityBytes[] = zkClient.getData("/security.json", null, null, true); + if (zkClient.exists("/security.json")) { + byte oldSecurityBytes[] = zkClient.getData("/security.json", null, null); 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" @@ -4473,7 +4473,7 @@ private int handleBasicAuth(CommandLine cli) throws Exception { echoIfVerbose("Uploading following security.json: " + securityJson, cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { zkClient.setData( - "/security.json", securityJson.getBytes(StandardCharsets.UTF_8), true); + "/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); } } @@ -4521,7 +4521,7 @@ private int handleBasicAuth(CommandLine cli) throws Exception { echoIfVerbose("Uploading following security.json: {}", cli); try (SolrZkClient zkClient = new SolrZkClient(zkHost, 10000)) { - zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8), true); + zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8)); } } 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 591cab3a04b..70dc9eb98f8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java @@ -123,7 +123,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, true); + final byte[] rawBytes = zkStateReader.getZkClient().getData(ALIASES, null, null); 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 ab0f4be3c9c..e23f0834e12 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, true); + cluster.getZkClient().delete("/collections/" + COLLECTION + "/counter", -1); clearedCounter = true; } if (deleteReplica) { @@ -115,7 +115,7 @@ private int getCounter() throws KeeperException, InterruptedException { byte[] data = cluster .getZkClient() - .getData("/collections/" + COLLECTION + "/counter", null, new Stat(), true); + .getData("/collections/" + COLLECTION + "/counter", null, new Stat()); 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 87db1a0df67..4985676198b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java @@ -174,7 +174,7 @@ private void waitForValue(String propertyName, String expectedValue, int timeout cluster .getZkClient() .getData( - "/collections/" + collectionName + "/collectionprops.json", null, null, true), + "/collections/" + collectionName + "/collectionprops.json", null, null), StandardCharsets.UTF_8); } catch (Exception e) { collectionpropsInZk = "Could not get file from ZooKeeper: " + e.getMessage(); @@ -224,7 +224,7 @@ public void testWatcher() throws KeeperException, InterruptedException, IOExcept log.info("deleting props"); zkStateReader .getZkClient() - .delete("/collections/" + collectionName + "/collectionprops.json", -1, true); + .delete("/collections/" + collectionName + "/collectionprops.json", -1); 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 3ff63d93d76..cb61ce54ba2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionStateZnodeTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionStateZnodeTest.java @@ -51,10 +51,10 @@ public void testZkNodeLocation() throws Exception { (n, c) -> DocCollection.isFullyActive(n, c, 2, 2)); assertTrue( "Collection path does not exist", - zkClient().exists(ZkStateReader.getCollectionPath(collectionName), true)); + zkClient().exists(ZkStateReader.getCollectionPath(collectionName))); Stat stat = new Stat(); - zkClient().getData(ZkStateReader.getCollectionPath(collectionName), null, stat, true); + zkClient().getData(ZkStateReader.getCollectionPath(collectionName), null, stat); DocCollection c = getCollectionState(collectionName); @@ -69,6 +69,6 @@ public void testZkNodeLocation() throws Exception { assertFalse( "collection state should not exist", - zkClient().exists(ZkStateReader.getCollectionPath(collectionName), true)); + zkClient().exists(ZkStateReader.getCollectionPath(collectionName))); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java b/solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java index daf0e9585c5..250f42568e8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java @@ -55,7 +55,7 @@ public void testConnectionManager() throws Exception { zkClient.getSolrZooKeeper().closeCnxn(); - long sessionId = zkClient.getSolrZooKeeper().getSessionId(); + long sessionId = zkClient.getZkSessionId(); server.expire(sessionId); Thread.sleep(TIMEOUT); @@ -132,6 +132,7 @@ public void testReconnectWhenZkDisappeared() throws Exception { // reconnect -- should no longer be likely expired cm.process(new WatchedEvent(EventType.None, KeeperState.Expired, "")); + Thread.sleep(5000); assertFalse(cm.isLikelyExpired()); assertTrue(cm.isConnectedAndNotClosed()); assertTrue(strat.isExceptionThrow()); 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 ac0afecb1e9..89514be3e32 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java @@ -288,18 +288,15 @@ public void testPeekElements() throws Exception { } private void forceSessionExpire() throws InterruptedException, TimeoutException { - long sessionId = zkClient.getSolrZooKeeper().getSessionId(); + long sessionId = zkClient.getZkSessionId(); zkServer.expire(sessionId); zkClient.getConnectionManager().waitForDisconnected(10000); zkClient.getConnectionManager().waitForConnected(10000); - for (int i = 0; i < 100; ++i) { - if (zkClient.isConnected()) { - break; - } + for (int i = 0; i < 100 && !zkClient.isConnected(); ++i) { Thread.sleep(50); } assertTrue(zkClient.isConnected()); - assertFalse(sessionId == zkClient.getSolrZooKeeper().getSessionId()); + assertNotEquals(sessionId, zkClient.getZkSessionId()); } protected ZkDistributedQueue makeDistributedQueue(String dqZNode) throws Exception { @@ -329,9 +326,9 @@ public void run() { } protected String setupNewDistributedQueueZNode(String znodePath) throws Exception { - if (!zkClient.exists("/", true)) zkClient.makePath("/", false, true); - if (zkClient.exists(znodePath, true)) zkClient.clean(znodePath); - zkClient.makePath(znodePath, false, true); + if (!zkClient.exists("/")) zkClient.makePath("/", false); + if (zkClient.exists(znodePath)) zkClient.clean(znodePath); + zkClient.makePath(znodePath, false); 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 06deacc0bd9..9ea7082e5a8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java @@ -129,7 +129,7 @@ private List getElectionNodes(String collection, String shard, SolrZkCli throws KeeperException, InterruptedException { return client.getChildren( "/collections/" + collection + "/leader_elect/" + shard + LeaderElector.ELECTION_NODE, - null, - true); + null + ); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java index d2df6971d8c..70f677a4022 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionIntegrationTest.java @@ -103,8 +103,7 @@ public void testSimpleSliceLeaderElection() throws Exception { JettySolrRunner jetty = getRunner(leader); ZkController zkController = jetty.getCoreContainer().getZkController(); - zkController.getZkClient().getSolrZooKeeper().closeCnxn(); - cluster.getZkServer().expire(zkController.getZkClient().getSolrZooKeeper().getSessionId()); + cluster.getZkServer().expire(zkController.getZkClient().getZkSessionId()); for (int i = 0; i < 60; i++) { // wait till leader is changed if (jetty != getRunner(getLeader(collection))) { 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 1ef126083ba..57e6d5b2cba 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java @@ -78,8 +78,8 @@ public void setUp() throws Exception { zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT); zkStateReader = new ZkStateReader(zkClient); seqToThread = Collections.synchronizedMap(new HashMap()); - zkClient.makePath("/collections/collection1", true); - zkClient.makePath("/collections/collection2", true); + zkClient.makePath("/collections/collection1"); + zkClient.makePath("/collections/collection2"); } class TestLeaderElectionContext extends ShardLeaderElectionContextBase { @@ -293,7 +293,7 @@ private String getLeaderUrl(final String collection, final String slice) try { byte[] data = zkClient.getData( - ZkStateReader.getShardLeadersPath(collection, slice), null, null, true); + ZkStateReader.getShardLeadersPath(collection, slice), null, null); ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data)); return leaderProps.getCoreUrl(); } catch (NoNodeException | SessionExpiredException e) { @@ -543,7 +543,7 @@ public void run() { try { threads.get(j).es.zkClient.getSolrZooKeeper().closeCnxn(); if (random().nextBoolean()) { - long sessionId = zkClient.getSolrZooKeeper().getSessionId(); + long sessionId = zkClient.getZkSessionId(); server.expire(sessionId); } } catch (Exception 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 1649dc29d6b..99cdde68839 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderVoteWaitTimeoutTest.java @@ -276,7 +276,7 @@ public void testMostInSyncReplicasCanWinElection() throws Exception { List children = zkClient() .getChildren( - "/collections/" + collectionName + "/leader_elect/shard1/election", null, true); + "/collections/" + collectionName + "/leader_elect/shard1/election", null); log.info("{} election nodes:{}", collectionName, children); throw e; } diff --git a/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java b/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java index 990f760bf55..e5c4ef558bd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/NestedShardedAtomicUpdateTest.java @@ -48,7 +48,7 @@ public static void beforeClass() throws Exception { configureCluster(1).addConfig("_default", configset("cloud-minimal")).configure(); // replace schema.xml with schema-test.xml Path schemaPath = TEST_COLL1_CONF().resolve("schema-nest.xml"); - cluster.getZkClient().setData("/configs/_default/schema.xml", schemaPath, true); + cluster.getZkClient().setData("/configs/_default/schema.xml", schemaPath); cloudClient = cluster.getSolrClient(); cloudClient.setDefaultCollection(DEFAULT_COLLECTION); 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 d17f6ec7c7d..24439108958 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java @@ -70,26 +70,26 @@ public void setUp() throws Exception { System.setProperty("zkHost", zkServer.getZkAddress()); SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); - zkClient.makePath("/solr", false, true); + zkClient.makePath("/solr", false); zkClient.close(); zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.close(); if (log.isInfoEnabled()) { @@ -134,7 +134,7 @@ public void testOpenACLUnsafeAllover() throws Exception { protected void assertOpenACLUnsafeAllover( SolrZkClient zkClient, String path, List verifiedList) throws Exception { - List acls = zkClient.getSolrZooKeeper().getACL(path, new Stat()); + List acls = zkClient.getACL(path, new Stat()); if (log.isInfoEnabled()) { log.info("Verifying {}", path); } @@ -151,7 +151,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, false); + List children = zkClient.getChildren(path, null); 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 0a741c12afa..e08c123dedc 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java @@ -21,8 +21,9 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.List; + +import org.apache.curator.framework.AuthInfo; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.StringUtils; import org.apache.solr.common.cloud.DefaultZkCredentialsProvider; @@ -80,9 +81,10 @@ public void setUp() throws Exception { "connectAndAllACLUsername", "connectAndAllACLPassword", "readonlyACLUsername", - "readonlyACLPassword") + "readonlyACLPassword", + null) .getSolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); - zkClient.makePath("/solr", false, true); + zkClient.makePath("/solr", false); zkClient.close(); zkClient = @@ -90,34 +92,34 @@ public void setUp() throws Exception { "connectAndAllACLUsername", "connectAndAllACLPassword", "readonlyACLUsername", - "readonlyACLPassword") + "readonlyACLPassword", + null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.close(); zkClient = - new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null) - .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - zkClient - .getSolrZooKeeper() - .addAuthInfo( - "digest", - ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(DATA_ENCODING)); + new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null, null) + .getSolrZkClient( + zkServer.getZkAddress(), + AbstractZkTestCase.TIMEOUT, + new AuthInfo("digest", + ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(DATA_ENCODING))); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.close(); if (log.isInfoEnabled()) { @@ -137,7 +139,7 @@ public void tearDown() throws Exception { @Test public void testNoCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { SolrZkClient zkClient = - new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null) + new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest( @@ -152,7 +154,7 @@ public void testWrongCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( - "connectAndAllACLUsername", "connectAndAllACLPasswordWrong", null, null) + "connectAndAllACLUsername", "connectAndAllACLPasswordWrong", null, null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest( @@ -166,7 +168,7 @@ public void testWrongCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() public void testAllCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( - "connectAndAllACLUsername", "connectAndAllACLPassword", null, null) + "connectAndAllACLUsername", "connectAndAllACLPassword", null, null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest( @@ -181,7 +183,7 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( - "readonlyACLUsername", "readonlyACLPassword", null, null) + "readonlyACLUsername", "readonlyACLPassword", null, null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { VMParamsZkACLAndCredentialsProvidersTest.doTest( @@ -265,41 +267,46 @@ private static class SolrZkClientFactoryUsingCompletelyNewProviders { final String digestPassword; final String digestReadonlyUsername; final String digestReadonlyPassword; + final String chroot; public SolrZkClientFactoryUsingCompletelyNewProviders( final String digestUsername, final String digestPassword, final String digestReadonlyUsername, - final String digestReadonlyPassword) { + final String digestReadonlyPassword, + final String chroot) { this.digestUsername = digestUsername; this.digestPassword = digestPassword; this.digestReadonlyUsername = digestReadonlyUsername; this.digestReadonlyPassword = digestReadonlyPassword; + this.chroot = chroot; } public SolrZkClient getSolrZkClient(String zkServerAddress, int zkClientTimeout) { + AuthInfo authInfo = null; + if (!StringUtils.isEmpty(digestUsername) && !StringUtils.isEmpty(digestPassword)) { + authInfo = new AuthInfo( + "digest", + (digestUsername + ":" + digestPassword).getBytes(StandardCharsets.UTF_8)); + } + return getSolrZkClient(zkServerAddress, zkClientTimeout, authInfo); + } + + public SolrZkClient getSolrZkClient(String zkServerAddress, int zkClientTimeout, AuthInfo authInfo) { + final List authInfos = new ArrayList<>(); + if (authInfo != null) { + authInfos.add(authInfo); + } return new SolrZkClient(zkServerAddress, zkClientTimeout) { @Override protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { - return new DefaultZkCredentialsProvider() { - @Override - protected Collection createCredentials() { - List result = new ArrayList<>(); - if (!StringUtils.isEmpty(digestUsername) && !StringUtils.isEmpty(digestPassword)) { - result.add( - new ZkCredentials( - "digest", - (digestUsername + ":" + digestPassword).getBytes(StandardCharsets.UTF_8))); - } - return result; - } - }; + return new DefaultZkCredentialsProvider(authInfos); } @Override - public ZkACLProvider createZkACLProvider() { - return new VMParamsAllAndReadonlyDigestZkACLProvider() { + public ZkACLProvider createACLProvider() { + return new VMParamsAllAndReadonlyDigestZkACLProvider(chroot) { @Override protected List createNonSecurityACLsToAdd() { return createACLsToAdd( @@ -348,7 +355,7 @@ protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { } @Override - public ZkACLProvider createZkACLProvider() { + public ZkACLProvider createACLProvider() { return new VMParamsAllAndReadonlyDigestZkACLProvider( "alternative" + VMParamsSingleSetCredentialsDigestZkCredentialsProvider @@ -361,7 +368,8 @@ public ZkACLProvider createZkACLProvider() { .DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME, "alternative" + VMParamsAllAndReadonlyDigestZkACLProvider - .DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME); + .DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME, + null); } } 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 488386a4a19..ce2a02e5763 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionConfigSetProcessorTest.java @@ -398,7 +398,7 @@ protected Set commonMocks(int liveNodesCount, boolean distributedCluster when(clusterStateMock.getLiveNodes()).thenReturn(liveNodes); - when(solrZkClientMock.setData(anyString(), any(), anyInt(), anyBoolean())) + when(solrZkClientMock.setData(anyString(), any(), anyInt())) .then( invocation -> { System.out.println( @@ -411,7 +411,7 @@ protected Set commonMocks(int liveNodesCount, boolean distributedCluster return null; }); - when(solrZkClientMock.getData(anyString(), any(), any(), anyBoolean())) + when(solrZkClientMock.getData(anyString(), any(), any())) .thenAnswer( invocation -> { byte[] data = zkClientData.get(invocation.getArgument(0)); @@ -421,14 +421,14 @@ protected Set commonMocks(int liveNodesCount, boolean distributedCluster return data; }); - when(solrZkClientMock.create(any(), any(), any(), anyBoolean())) + when(solrZkClientMock.create(any(), any(), any())) .thenAnswer( invocation -> { zkClientData.put(invocation.getArgument(0), invocation.getArgument(1)); return invocation.getArgument(0); }); - when(solrZkClientMock.exists(any(String.class), anyBoolean())) + when(solrZkClientMock.exists(any(String.class))) .thenAnswer( invocation -> { String key = invocation.getArgument(0); @@ -513,7 +513,7 @@ public Void answer(InvocationOnMock invocation) { .when(distribStateManagerMock) .makePath(anyString()); - when(solrZkClientMock.exists(any(String.class), isNull(), anyBoolean())) + when(solrZkClientMock.exists(any(String.class), isNull())) .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 c2a46d36cc4..be30d786b46 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, true); + zkClient.makePath(nodePath, CreateMode.EPHEMERAL); } private void deleteNode(final String path) { try { - zkClient.delete(path, -1, true); + zkClient.delete(path, -1); } 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 it or it // will fail. - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection); ZkNodeProps m = new ZkNodeProps( @@ -287,7 +287,7 @@ public String publishState( try { zkClient.makePath( - "/collections/" + collection + "/leader_elect/" + shardId + "/election", true); + "/collections/" + collection + "/leader_elect/" + shardId + "/election"); } catch (NodeExistsException nee) { } ZkNodeProps props = @@ -450,7 +450,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 it or it // will fail. - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection); ZkNodeProps m = new ZkNodeProps( @@ -1208,7 +1208,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, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); for (int i = 0; i < atLeast(4); i++) { killCounter.incrementAndGet(); // for each round allow 1 kill @@ -1459,7 +1459,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, true); + zkClient.makePath("/collections/perf" + i); ZkNodeProps m = new ZkNodeProps( Overseer.QUEUE_OPERATION, @@ -1580,7 +1580,7 @@ public void testReplay() throws Exception { // state DistributedQueue queue = Overseer.getInternalWorkQueue(zkClient, new Stats()); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); ZkNodeProps m = new ZkNodeProps( @@ -1758,7 +1758,7 @@ public void testExternalClusterStateChangeBehavior() throws Exception { q.offer(Utils.toJSON(m)); final String testCollectionName = "test"; - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + testCollectionName, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + testCollectionName); m = new ZkNodeProps( Overseer.QUEUE_OPERATION, @@ -1776,9 +1776,9 @@ public void testExternalClusterStateChangeBehavior() throws Exception { final String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + testCollectionName + "/state.json"; - byte[] data = zkClient.getData(path, null, null, true); + byte[] data = zkClient.getData(path, null, null); // Simulate an external modification of state.json - zkClient.setData(path, data, true); + zkClient.setData(path, data); m = new ZkNodeProps( @@ -1978,7 +1978,7 @@ public void testRemovalOfLastReplica() throws Exception { // create collection { - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); 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 2c308694650..46f3996a796 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java @@ -120,7 +120,7 @@ public void testUpconfig() throws Exception { String content = new String( - zkClient.getData("/configs/upconfig2/schema.xml", null, null, true), + zkClient.getData("/configs/upconfig2/schema.xml", null, null), StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); @@ -378,7 +378,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", true)); + zkClient.exists("/powerup/solrconfig.xml")); // copy individual file up // src and cp3 are valid @@ -404,7 +404,7 @@ public void testCp() throws Exception { 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", true)); + zkClient.exists("/copyUpFile.xml")); // copy individual file down // src and cp3 are valid @@ -456,7 +456,7 @@ public void testCp() throws Exception { SolrCLI.joinCommonAndToolOptions(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", true)); + "Should have found znode /solrconfig.xml: ", zkClient.exists("/solrconfig.xml")); // Check that the form path/ works for copying files up. Should append the last bit of the // source path to the dst @@ -506,7 +506,7 @@ public void testCp() throws Exception { String content = new String( - zkClient.getData("/cp7/conf/stopwords", null, null, true), StandardCharsets.UTF_8); + zkClient.getData("/cp7/conf/stopwords", null, null), StandardCharsets.UTF_8); assertTrue("There should be content in the node! ", content.contains("{Some Arbitrary Data}")); res = @@ -558,7 +558,7 @@ public void testCp() throws Exception { content = new String( - zkClient.getData("/cp9/conf/stopwords", null, null, true), StandardCharsets.UTF_8); + zkClient.getData("/cp9/conf/stopwords", null, null), 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 @@ -676,7 +676,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", true)); + assertFalse("/configs/mv1 Znode should not be there: ", zkClient.exists("/configs/mv1")); // Files are in mv2 // Now fail if we specify "file:". Everything should still be in /mv2 @@ -706,7 +706,7 @@ public void testMv() throws Exception { SolrCLI.joinCommonAndToolOptions(mvTool.getOptions()), args)); assertEquals("Move should have succeeded.", 0, res); - assertFalse("Znode /mv3 really should be gone", zkClient.exists("/mv3", true)); + assertFalse("Znode /mv3 really should be gone", zkClient.exists("/mv3")); // Now does the moved directory match the original on disk? verifyZkLocalPathsMatch(srcPathCheck, "/mv4"); @@ -725,9 +725,9 @@ public void testMv() throws Exception { assertEquals("Move should have succeeded.", 0, res); assertTrue( "Should be able to move a single file", - zkClient.exists("/testmvsingle/solrconfig.xml", true)); + zkClient.exists("/testmvsingle/solrconfig.xml")); - zkClient.makePath("/parentNode", true); + zkClient.makePath("/parentNode"); // what happens if the destination ends with a slash? args = @@ -744,10 +744,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", true)); + zkClient.exists("/parentnode/schema.xml")); String content = new String( - zkClient.getData("/parentnode/schema.xml", null, null, true), StandardCharsets.UTF_8); + zkClient.getData("/parentnode/schema.xml", null, null), StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); } @@ -921,7 +921,7 @@ public void testRm() throws Exception { SolrCLI.joinCommonAndToolOptions(tool.getOptions()), args)); assertEquals("Should have removed node /configs/rm1", res, 0); assertFalse( - "Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1", true)); + "Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1")); // Check that zk prefix also works. args = @@ -937,7 +937,7 @@ public void testRm() throws Exception { SolrCLI.joinCommonAndToolOptions(tool.getOptions()), args)); assertEquals("Should have removed node /configs/rm2", res, 0); assertFalse( - "Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2", true)); + "Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2")); // This should silently just refuse to do anything to the / or /zookeeper args = @@ -963,14 +963,14 @@ private void verifyZkLocalPathsMatch(Path fileRoot, String zkRoot) } private static boolean isEphemeral(String zkPath) throws KeeperException, InterruptedException { - Stat znodeStat = zkClient.exists(zkPath, null, true); + Stat znodeStat = zkClient.exists(zkPath, null); return znodeStat.getEphemeralOwner() != 0; } void verifyAllZNodesAreFiles(Path fileRoot, String zkRoot) throws KeeperException, InterruptedException { - for (String child : zkClient.getChildren(zkRoot, null, true)) { + for (String child : zkClient.getChildren(zkRoot, null)) { // Skip ephemeral nodes if (zkRoot.endsWith("/") == false) zkRoot += "/"; if (isEphemeral(zkRoot + child)) continue; @@ -994,7 +994,7 @@ void checkPathOnZk(Path path) { String znode = ZkMaintenanceUtils.createZkNodeName(zkRoot, fileRoot, path); try { // It's easier to catch this exception and fail than catch it everywher eles. assertTrue( - "Should have found " + znode + " on Zookeeper", zkClient.exists(znode, true)); + "Should have found " + znode + " on Zookeeper", zkClient.exists(znode)); } catch (Exception e) { fail( "Caught unexpected exception " @@ -1032,10 +1032,10 @@ private void verifyZnodesMatch(String first, String second) // Note, no folderol here with Windows path names. private void verifyFirstZNodesInSecond(String first, String second) throws KeeperException, InterruptedException { - for (String node : zkClient.getChildren(first, null, true)) { + for (String node : zkClient.getChildren(first, null)) { String fNode = first + "/" + node; String sNode = second + "/" + node; - assertTrue("Node " + sNode + " not found. Exists on " + fNode, zkClient.exists(sNode, true)); + assertTrue("Node " + sNode + " not found. Exists on " + fNode, zkClient.exists(sNode)); 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 126e82cb604..0b620f71fd4 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SolrXmlInZkTest.java @@ -75,7 +75,7 @@ private void setUpZkAndDiskXml(boolean toZk, boolean leaveOnLocal) throws Except zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); if (toZk) { - zkClient.makePath("solr.xml", XML_FOR_ZK.getBytes(StandardCharsets.UTF_8), true); + zkClient.makePath("solr.xml", XML_FOR_ZK.getBytes(StandardCharsets.UTF_8)); } 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 3333d8e2da9..bc71c7185dc 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -320,7 +320,7 @@ private NamedList getConfigSetPropertiesFromZk(SolrZkClient zkClient, St throws Exception { byte[] oldPropsData = null; try { - oldPropsData = zkClient.getData(path, null, null, true); + oldPropsData = zkClient.getData(path, null, null); } catch (KeeperException.NoNodeException e) { // okay, properties just don't exist } @@ -412,17 +412,17 @@ public void testUploadErrors() throws Exception { cluster.getZkServer().getZkAddress(), AbstractZkTestCase.TIMEOUT, 45000, null); // Create dummy config files in zookeeper - zkClient.makePath("/configs/myconf", true); + zkClient.makePath("/configs/myconf"); zkClient.create( "/configs/myconf/firstDummyFile", "first dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); zkClient.create( "/configs/myconf/anotherDummyFile", "second dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); // Checking error when configuration name specified already exists ignoreException("already exists"); @@ -440,10 +440,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", true)); + zkClient.exists("/configs/myconf/firstDummyFile")); assertTrue( "Expected file doesnt exist in zk. It's possibly overwritten", - zkClient.exists("/configs/myconf/anotherDummyFile", true)); + zkClient.exists("/configs/myconf/anotherDummyFile")); zkClient.close(); solrClient.close(); @@ -495,7 +495,7 @@ public void testUploadLegacyManagedSchemaFile() throws Exception { assertTrue( "managed-schema file should have been uploaded", - zkClient.exists("/configs/" + configSetName + "/managed-schema", true)); + zkClient.exists("/configs/" + configSetName + "/managed-schema")); } finally { zkClient.close(); } @@ -590,19 +590,19 @@ public void testOverwriteWithCleanup(boolean v2) throws Exception { configPath + "/foo2/1", configPath + "/foo2/2"); for (String f : extraFiles) { - zkClient.makePath(f, true); + zkClient.makePath(f); } assertEquals(0, uploadConfigSet(configsetName, configsetSuffix, null, true, false, v2)); for (String f : extraFiles) { assertTrue( "Expecting file " + f + " to exist in ConfigSet but it's gone", - zkClient.exists(f, true)); + zkClient.exists(f)); } assertEquals(0, uploadConfigSet(configsetName, configsetSuffix, null, true, true, v2)); for (String f : extraFiles) { assertFalse( "Expecting file " + f + " to be deleted from ConfigSet but it wasn't", - zkClient.exists(f, true)); + zkClient.exists(f)); } assertConfigsetFiles(configsetName, configsetSuffix, zkClient); } @@ -842,8 +842,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", - true)); + "/configs/" + configsetName + configsetSuffix + "/test/upload/path/solrconfig.xml" + )); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("ConfigSet uploads do not allow cleanup=true when filePath is used."); } @@ -901,8 +901,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", - true)); + "/configs/" + configsetName + configsetSuffix + "/test/different/path/solrconfig.xml" + )); assertTrue(isTrusted(zkClient, configsetName, configsetSuffix)); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("Trying to make an unstrusted ConfigSet update on a trusted configSet"); @@ -1103,8 +1103,8 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { List children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixTrusted), - null, - true); + null + ); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); @@ -1129,8 +1129,8 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixUntrusted), - null, - true); + null + ); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); } @@ -1140,7 +1140,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, true); + byte[] configSetNodeContent = zkClient.getData(configSetZkPath, null, null); ; @SuppressWarnings("unchecked") @@ -1155,8 +1155,8 @@ private int getConfigZNodeVersion( zkClient.getData( String.format(Locale.ROOT, "/configs/%s%s/%s", configsetName, configsetSuffix, configFile), null, - stat, - true); + stat + ); return stat.getVersion(); } @@ -1282,24 +1282,24 @@ 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", true)); + zkClient.exists("/configs/" + configSetName + suffix + "/managed-schema.xml")); assertTrue( "managed-schema.xml file contents on zookeeper are not exactly same as that of the file uploaded in config", Arrays.equals( zkClient.getData( - "/configs/" + configSetName + suffix + "/managed-schema.xml", null, null, true), + "/configs/" + configSetName + suffix + "/managed-schema.xml", null, null), readFile("solr/configsets/upload/" + configSetName + "/managed-schema.xml"))); assertTrue( "solrconfig.xml file should have been uploaded", - zkClient.exists("/configs/" + configSetName + suffix + "/solrconfig.xml", true)); - byte data[] = zkClient.getData("/configs/" + configSetName + suffix, null, null, true); + zkClient.exists("/configs/" + configSetName + suffix + "/solrconfig.xml")); + byte data[] = zkClient.getData("/configs/" + configSetName + suffix, null, null); // assertEquals("{\"trusted\": false}", new String(data, StandardCharsets.UTF_8)); assertTrue( "solrconfig.xml file contents on zookeeper are not exactly same as that of the file uploaded in config", Arrays.equals( zkClient.getData( - "/configs/" + configSetName + suffix + "/solrconfig.xml", null, null, true), + "/configs/" + configSetName + suffix + "/solrconfig.xml", null, null), 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 26cf55b47a4..ee7e5f76938 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java @@ -96,8 +96,8 @@ private void setupBaseConfigSet(String baseConfigSetName) throws Exception { .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8), - true); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8) + ); } 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 ad6c3b991fc..34a57cff525 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java @@ -156,8 +156,8 @@ private void setupBaseConfigSet(String baseConfigSetName, Map ol .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8), - true); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8) + ); } 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 088250c2140..09ceb5ca54c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java @@ -58,9 +58,9 @@ public void testPut() throws KeeperException, InterruptedException { try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 10000)) { String path = getAndMakeInitialPath(zkClient); DistributedMap map = createMap(zkClient, path); - assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); + assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); map.put("foo", new byte[0]); - assertTrue(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); + assertTrue(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); } } @@ -73,8 +73,8 @@ public void testGet() throws KeeperException, InterruptedException { data, CreateMode.PERSISTENT, null, - false, - true); + false + ); DistributedMap map = createMap(zkClient, path); assertArrayEquals(data, map.get("foo")); } @@ -90,8 +90,8 @@ public void testContains() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false, - true); + false + ); assertTrue(map.contains("foo")); } } @@ -106,11 +106,11 @@ public void testRemove() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false, - true); + false + ); assertTrue(map.remove("foo")); assertFalse(map.contains("foo")); - assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); + assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); } } @@ -192,7 +192,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, true); + zkClient.makePath(path, false); 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 7d7f7024953..67670cda3dd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java @@ -71,14 +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, true); + zkClient.create(ZkStateReader.CONFIGS_ZKNODE + "/conf1/a", null, CreateMode.PERSISTENT); zkClient.create( - ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa1", new byte[1024], CreateMode.PERSISTENT, true); + ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa1", new byte[1024], CreateMode.PERSISTENT); zkClient.create( ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa2", new byte[1024 * 2], - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); List allFiles = new ArrayList<>(); byte[] buf = new byte[3 * 1024]; diff --git a/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionZkExpiry.java b/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionZkExpiry.java index 3328da1b3c1..8041537afe0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionZkExpiry.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestLeaderElectionZkExpiry.java @@ -66,7 +66,7 @@ public void run() { long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS); while (System.nanoTime() < timeout) { - long sessionId = zkController.getZkClient().getSolrZooKeeper().getSessionId(); + long sessionId = zkController.getZkClient().getZkSessionId(); server.expire(sessionId); try { Thread.sleep(10); 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 edfd6ada96d..a8ce5f4f591 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java @@ -194,8 +194,8 @@ public void testCreateDelete() throws Exception { .getZkClient() .getChildren( ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), - null, - true); + null + ); 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 2f291ec4d5e..a055b4ce4a2 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java @@ -126,7 +126,7 @@ private void downAllReplicas() throws Exception { byte[] collectionState = cluster .getZkClient() - .getData("/collections/" + COLLECTION_NAME + "/state.json", null, null, true); + .getData("/collections/" + COLLECTION_NAME + "/state.json", null, null); Map> infectedState = (Map>) Utils.fromJSON(collectionState); @@ -143,7 +143,7 @@ private void downAllReplicas() throws Exception { cluster .getZkClient() .setData( - "/collections/" + COLLECTION_NAME + "/state.json", Utils.toJSON(infectedState), true); + "/collections/" + COLLECTION_NAME + "/state.json", Utils.toJSON(infectedState)); } 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 2f7bc18198f..a633b69e4b1 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java @@ -276,8 +276,8 @@ private void checkOneQueue(DocCollection coll, Slice slice, Set liveRep + "/leader_elect/" + slice.getName() + "/election", - null, - true); + null + ); if (leaderQueue.size() != liveReplicas.size()) { 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 00d57f33c1a..e53d050622a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestStressLiveNodes.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestStressLiveNodes.java @@ -90,7 +90,7 @@ private static List getTrueLiveNodesFromZk() throws Exception { SolrZkClient client = newSolrZkClient(); try { ArrayList result = - new ArrayList<>(client.getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true)); + new ArrayList<>(client.getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null)); Collections.sort(result); return result; } finally { @@ -249,7 +249,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, true); + client.makePath(nodePath, CreateMode.EPHEMERAL); 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 074d83375b9..20ed2597d4e 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -223,8 +223,8 @@ public void testCreateDelete() throws Exception { .getZkClient() .getChildren( ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), - null, - true); + null + ); 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 44d373495ee..9eb664fd6fa 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java @@ -92,7 +92,7 @@ public void setUp() throws Exception { zkServer.run(); System.setProperty("zkHost", zkServer.getZkAddress()); SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); - zkClient.makePath("/solr", false, true); + zkClient.makePath("/solr", false); zkClient.close(); this.zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); @@ -113,7 +113,7 @@ public void testCmdConstants() throws Exception { @Test public void testBootstrapWithChroot() throws Exception { String chroot = "/foo/bar"; - assertFalse(zkClient.exists(chroot, true)); + assertFalse(zkClient.exists(chroot)); String[] args = new String[] { @@ -127,7 +127,7 @@ public void testBootstrapWithChroot() throws Exception { ZkCLI.main(args); - assertTrue(zkClient.exists(chroot + ZkConfigSetService.CONFIGS_ZKNODE + "/collection1", true)); + assertTrue(zkClient.exists(chroot + ZkConfigSetService.CONFIGS_ZKNODE + "/collection1")); } @Test @@ -137,7 +137,7 @@ public void testMakePath() throws Exception { new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "makepath", "/path/mynewpath"}; ZkCLI.main(args); - assertTrue(zkClient.exists("/path/mynewpath", true)); + assertTrue(zkClient.exists("/path/mynewpath")); } @Test @@ -148,17 +148,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, true); + zkClient.getData("/data.txt", null, null); assertArrayEquals( - zkClient.getData("/data.txt", null, null, true), data.getBytes(StandardCharsets.UTF_8)); + zkClient.getData("/data.txt", null, null), 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, true), data.getBytes(StandardCharsets.UTF_8)); + zkClient.getData("/data.txt", null, null), data.getBytes(StandardCharsets.UTF_8)); } @Test @@ -176,7 +176,7 @@ public void testPutFile() throws Exception { ZkCLI.main(args); String fromZk = - new String(zkClient.getData("/solr.xml", null, null, true), StandardCharsets.UTF_8); + new String(zkClient.getData("/solr.xml", null, null), StandardCharsets.UTF_8); File locFile = new File(SOLR_HOME + File.separator + "solr-stress-new.xml"); InputStream is = new FileInputStream(locFile); String fromLoc; @@ -208,7 +208,7 @@ public void testPutFileNotExists() throws Exception { @Test public void testList() throws Exception { - zkClient.makePath("/test", true); + zkClient.makePath("/test"); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "list"}; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); @@ -224,7 +224,7 @@ public void testList() throws Exception { @Test public void testLs() throws Exception { - zkClient.makePath("/test/path", true); + zkClient.makePath("/test/path"); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "ls", "/test"}; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); @@ -277,7 +277,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { } ZkCLI.main(upconfigArgs); - assertTrue(zkClient.exists(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, true)); + assertTrue(zkClient.exists(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname)); // print help // ZkCLI.main(new String[0]); @@ -298,7 +298,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { ZkNodeProps collectionProps = ZkNodeProps.load( - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null, true)); + zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null)); assertTrue(collectionProps.containsKey("configName")); assertEquals(confsetname, collectionProps.getStr("configName")); @@ -323,7 +323,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { File[] files = confDir.listFiles(); List zkFiles = - zkClient.getChildren(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, null, true); + zkClient.getChildren(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, null); assertEquals(files.length, zkFiles.size()); File sourceConfDir = new File(ExternalPaths.TECHPRODUCTS_CONFIGSET); @@ -363,14 +363,14 @@ public void testUpConfigLinkConfigClearZk() throws Exception { args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "clear", "/"}; ZkCLI.main(args); - assertEquals(0, zkClient.getChildren("/", null, true).size()); + assertEquals(0, zkClient.getChildren("/", null).size()); } @Test public void testGet() throws Exception { String getNode = "/getNode"; byte[] data = "getNode-data".getBytes(StandardCharsets.UTF_8); - this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true); + this.zkClient.create(getNode, data, CreateMode.PERSISTENT); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "get", getNode}; ZkCLI.main(args); } @@ -381,7 +381,7 @@ public void testGetFile() throws Exception { String getNode = "/getFileNode"; byte[] data = "getFileNode-data".getBytes(StandardCharsets.UTF_8); - this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true); + this.zkClient.create(getNode, data, CreateMode.PERSISTENT); File file = new File(tmpDir, "solrtest-getfile-" + this.getClass().getName() + "-" + System.nanoTime()); @@ -473,7 +473,7 @@ public void testUpdateAcls() throws Exception { try (SolrZkClient zkClient = new SolrZkClient( zkServer.getZkAddress(), AbstractDistribZkTestBase.DEFAULT_CONNECTION_TIMEOUT)) { - zkClient.getData("/", null, null, true); + zkClient.getData("/", null, null); } 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 4b82516b065..0cbc2f93281 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java @@ -257,8 +257,8 @@ public List getCoreDescriptors() { .makePath( ZkStateReader.getCollectionPathRoot(collectionName), new byte[0], - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); ZkNodeProps m = new ZkNodeProps( 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 3992c19ca81..e9eec23700a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java @@ -20,9 +20,7 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.Arrays; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -32,7 +30,6 @@ import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.data.Stat; @@ -93,7 +90,7 @@ public void testMakeRootNode() throws Exception { final SolrZkClient zkClient = new SolrZkClient(conn.getServer().getZkHost(), AbstractZkTestCase.TIMEOUT); try { - assertTrue(zkClient.exists("/solr", true)); + assertTrue(zkClient.exists("/solr")); } finally { zkClient.close(); } @@ -105,14 +102,14 @@ public void testClean() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/test/path/here", true); + zkClient.makePath("/test/path/here"); - zkClient.makePath("/zz/path/here", true); + zkClient.makePath("/zz/path/here"); zkClient.clean("/"); - assertFalse(zkClient.exists("/test", true)); - assertFalse(zkClient.exists("/zz", true)); + assertFalse(zkClient.exists("/test")); + assertFalse(zkClient.exists("/zz")); } } @@ -125,7 +122,7 @@ public void testReconnect() throws Exception { new SolrZkClient(server.getZkAddress(), AbstractZkTestCase.TIMEOUT); ) { String shardsPath = "/collections/collection1/shards"; - zkClient.makePath(shardsPath, false, true); + zkClient.makePath(shardsPath, false); int zkServerPort = server.getPort(); // this tests disconnect state @@ -137,7 +134,7 @@ public void testReconnect() throws Exception { new Thread() { public void run() { try { - zkClient.makePath("collections/collection2", false); + zkClient.makePath("collections/collection2"); // Assert.fail("Server should be down here"); } catch (KeeperException | InterruptedException e) { @@ -160,7 +157,7 @@ public void run() { public void run() { try { - zkClient.makePath("collections/collection3", true); + zkClient.makePath("collections/collection3"); } catch (KeeperException e) { throw new RuntimeException(e); @@ -176,13 +173,13 @@ public void run() { thread2.join(); - assertNotNull(zkClient.exists("/collections/collection3", null, true)); - assertNotNull(zkClient.exists("/collections/collection1", null, true)); + assertNotNull(zkClient.exists("/collections/collection3", null)); + assertNotNull(zkClient.exists("/collections/collection1", null)); // simulate session expiration // one option - long sessionId = zkClient.getSolrZooKeeper().getSessionId(); + long sessionId = zkClient.getZkSessionId(); server.expire(sessionId); // another option @@ -194,7 +191,7 @@ public void run() { for (int i = 0; i < 8; i++) { try { - zkClient.makePath("collections/collection4", true); + zkClient.makePath("collections/collection4"); break; } catch (KeeperException.SessionExpiredException | KeeperException.ConnectionLossException e) { @@ -205,7 +202,7 @@ public void run() { assertNotNull( "Node does not exist, but it should", - zkClient.exists("/collections/collection4", null, true)); + zkClient.exists("/collections/collection4", null)); } finally { @@ -251,7 +248,7 @@ public void testZkCmdExectutor() throws Exception { public void testMultipleWatchesAsync() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/collections", true); + zkClient.makePath("/collections"); final int numColls = random().nextInt(100); final CountDownLatch latch = new CountDownLatch(numColls); @@ -261,7 +258,7 @@ public void testMultipleWatchesAsync() throws Exception { for (int i = 1; i <= numColls; i++) { String collPath = "/collections/collection" + i; - zkClient.makePath(collPath, true); + zkClient.makePath(collPath); zkClient.getChildren( collPath, new Watcher() { @@ -283,13 +280,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, true); + zkClient.makePath(shardsPath); } assertTrue(latch.await(10000, TimeUnit.MILLISECONDS)); @@ -313,7 +310,7 @@ public void testWatchChildren() throws Exception { final AtomicInteger cnt = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); - zkClient.makePath("/collections", true); + zkClient.makePath("/collections"); zkClient.getChildren( "/collections", @@ -324,23 +321,23 @@ public void process(WatchedEvent event) { cnt.incrementAndGet(); // remake watch try { - zkClient.getChildren("/collections", this, true); + zkClient.getChildren("/collections", this); latch.countDown(); } catch (KeeperException | InterruptedException e) { throw new RuntimeException(e); } } - }, - true); + } + ); - zkClient.makePath("/collections/collection99/shards", true); + zkClient.makePath("/collections/collection99/shards"); latch.await(); // wait until watch has been re-created - zkClient.makePath("collections/collection99/config=collection1", true); + zkClient.makePath("collections/collection99/config=collection1"); - zkClient.makePath("collections/collection99/config=collection3", true); + zkClient.makePath("collections/collection99/config=collection3"); - zkClient.makePath("/collections/collection97/shards", true); + zkClient.makePath("/collections/collection97/shards"); // pause for the watches to fire Thread.sleep(700); @@ -362,11 +359,11 @@ public void testSkipPathPartsOnMakePath() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/test", true); + zkClient.makePath("/test"); // should work zkClient.makePath( - "/test/path/here", (byte[]) null, CreateMode.PERSISTENT, (Watcher) null, true, true, 1); + "/test/path/here", (byte[]) null, CreateMode.PERSISTENT, (Watcher) null, true); zkClient.clean("/"); @@ -381,9 +378,8 @@ public void testSkipPathPartsOnMakePath() throws Exception { (byte[]) null, CreateMode.PERSISTENT, (Watcher) null, - true, - true, - 1)); + true + )); zkClient.clean("/"); @@ -399,7 +395,7 @@ public void testSkipPathPartsOnMakePath() throws Exception { zkClient, 2)); - zkClient.makePath("/collection", true); + zkClient.makePath("/collection"); expectThrows( KeeperException.NoNodeException.class, @@ -411,17 +407,17 @@ public void testSkipPathPartsOnMakePath() throws Exception { CreateMode.PERSISTENT, zkClient, 2)); - zkClient.makePath("/collection/collection", true); + zkClient.makePath("/collection/collection"); byte[] bytes = new byte[10]; zkCmdExecutor.ensureExists( "/collection/collection", bytes, CreateMode.PERSISTENT, zkClient, 2); - byte[] returnedBytes = zkClient.getData("/collection/collection", null, null, true); + byte[] returnedBytes = zkClient.getData("/collection/collection", null, null); assertNull("We skipped 2 path parts, so data won't be written", returnedBytes); - zkClient.makePath("/collection/collection/leader", true); + zkClient.makePath("/collection/collection/leader"); zkCmdExecutor.ensureExists( "/collection/collection/leader", (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); @@ -433,20 +429,15 @@ 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, true); + zkClient.create("/test-node", null, CreateMode.PERSISTENT); - Stat stat = zkClient.exists("/test-node", null, true); + Stat stat = zkClient.exists("/test-node", null); int cversion = stat.getCversion(); - List ops = - Arrays.asList( - Op.create( - "/test-node/abc", - null, - zkClient.getZkACLProvider().getACLsToAdd("/test-node/abc"), - CreateMode.PERSISTENT), - Op.delete("/test-node/abc", -1)); - zkClient.multi(ops, true); - stat = zkClient.exists("/test-node", null, true); + 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); 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 4b5623b5b87..79517900e3e 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 @@ -686,7 +686,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, true)) { + if (ZkStateReader.from(cloudClient).getZkClient().exists(path)) { log.info("=== found lock node"); break; } @@ -704,13 +704,13 @@ public void testSplitLocking() throws Exception { // make sure the lock still exists assertTrue( "lock znode expected but missing", - ZkStateReader.from(cloudClient).getZkClient().exists(path, true)); + ZkStateReader.from(cloudClient).getZkClient().exists(path)); // 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, true)) { + if (!ZkStateReader.from(cloudClient).getZkClient().exists(path)) { 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 948e901b645..0e94167ca41 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 @@ -60,14 +60,14 @@ public void testCreateAndDeleteThenCreateAgain() throws Exception { if (request.get("success") != null) { assertTrue( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName); cloudClient.request(delete); assertFalse( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); // currently, removing a collection does not wait for cores to be unloaded TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); @@ -119,14 +119,14 @@ public void testDeleteAlsoDeletesAutocreatedConfigSet() throws Exception { assertTrue( ZkStateReader.from(cloudClient) .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); 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, true)); + assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName); @@ -134,11 +134,11 @@ public void testDeleteAlsoDeletesAutocreatedConfigSet() throws Exception { // collection has been deleted assertFalse( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); // ... 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, true)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); } } @@ -155,7 +155,7 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // collection exists now assertTrue( getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial, false)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); String configName = cloudClient @@ -165,7 +165,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, true)); + assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); // create a second collection, sharing the same configSet String collectionNameWithSharedConfig = @@ -182,7 +182,7 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception "The new collection should exist after a successful creation", getZkClient() .exists( - ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig, false)); + ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); String configNameOfSecondCollection = cloudClient @@ -204,11 +204,11 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // initial collection has been deleted assertFalse( getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial, false)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); // ... 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, true)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); // delete the second collection - the config set should now be deleted, since it is no longer // shared any other collection @@ -220,12 +220,12 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception assertFalse( getZkClient() .exists( - ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig, false)); + ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); // ... 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, true)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); } } 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 f7e1667dc3d..7a9b9f5ca46 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 @@ -262,11 +262,11 @@ private void testNoConfigset() throws Exception { private void deleteThemAll(SolrZkClient zkClient, String node) throws KeeperException, InterruptedException { - List kids = zkClient.getChildren(node, null, true); + List kids = zkClient.getChildren(node, null); for (String kid : kids) { deleteThemAll(zkClient, node + "/" + kid); } - zkClient.delete(node, -1, true); + zkClient.delete(node, -1); } 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 66d2c5c0d2e..1fe52b1f711 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 @@ -77,8 +77,8 @@ public static void setupClass() throws Exception { .getZkClient() .delete( ZkConfigSetService.CONFIGS_ZKNODE + "/" + "confFaulty" + "/" + "solrconfig.xml", - -1, - true); + -1 + ); 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 639c7538a46..15a3024f252 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 @@ -57,7 +57,7 @@ public void testExternalCollectionWatchedNotWatched() throws Exception { ZkStateWriter writer = new ZkStateWriter(reader, new Stats()); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); // create new collection ZkWriteCommand c1 = @@ -102,7 +102,7 @@ public void testCollectionStateWatcherCaching() throws Exception { reader = new ZkStateReader(zkClient); reader.createClusterStateWatchersAndUpdate(); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); ZkStateWriter writer = new ZkStateWriter(reader, new Stats()); DocCollection state = @@ -115,7 +115,7 @@ public void testCollectionStateWatcherCaching() throws Exception { ZkWriteCommand wc = new ZkWriteCommand("c1", state); writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(wc), null); writer.writePendingUpdates(); - assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true)); + assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); reader.waitForState( "c1", 1, TimeUnit.SECONDS, (liveNodes, collectionState) -> collectionState != null); @@ -164,7 +164,7 @@ public void testWatchedCollectionCreation() throws Exception { // Initially there should be no c1 collection. assertNull(reader.getClusterState().getCollectionRef("c1")); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); reader.forceUpdateCollection("c1"); // Still no c1 collection, despite a collection path. @@ -184,7 +184,7 @@ public void testWatchedCollectionCreation() throws Exception { writer.enqueueUpdate(reader.getClusterState(), Collections.singletonList(wc), null); writer.writePendingUpdates(); - assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", true)); + assertTrue(zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); // reader.forceUpdateCollection("c1"); reader.waitForState("c1", TIMEOUT, TimeUnit.SECONDS, (n, c) -> c != null); 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 2d4b39f7d02..3e11eeda1cb 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 @@ -77,9 +77,9 @@ public void testZkStateWriterBatching() throws Exception { try (ZkStateReader reader = new ZkStateReader(zkClient)) { reader.createClusterStateWatchersAndUpdate(); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c3", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c3"); Map props = Collections.singletonMap( @@ -142,7 +142,7 @@ public void testSingleExternalCollection() throws Exception { ZkStateWriter writer = new ZkStateWriter(reader, new Stats()); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); // create new collection ZkWriteCommand c1 = @@ -163,7 +163,7 @@ public void testSingleExternalCollection() throws Exception { (Map) Utils.fromJSON( zkClient.getData( - ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true)); + ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null)); assertNotNull(map.get("c1")); } } finally { @@ -190,8 +190,8 @@ public void testExternalModification() throws Exception { ZkStateWriter writer = new ZkStateWriter(reader, new Stats()); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2"); ClusterState state = reader.getClusterState(); @@ -212,8 +212,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(ZkStateReader.getCollectionPath("c2"), null, null, true); - zkClient.setData(ZkStateReader.getCollectionPath("c2"), data, true); + byte[] data = zkClient.getData(ZkStateReader.getCollectionPath("c2"), null, null); + zkClient.setData(ZkStateReader.getCollectionPath("c2"), data); // get the most up-to-date state reader.forceUpdateCollection("c2"); 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 5e9e0771382..06cdb6e44e1 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestConfigReload.java +++ b/solr/core/src/test/org/apache/solr/handler/TestConfigReload.java @@ -76,15 +76,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, true); + data = client.getData(resPath, null, stat); } catch (KeeperException.NoNodeException e) { data = "{}".getBytes(StandardCharsets.UTF_8); log.info("creating_node {}", resPath); - client.create(resPath, data, CreateMode.PERSISTENT, true); + client.create(resPath, data, CreateMode.PERSISTENT); } long startTime = System.nanoTime(); - Stat newStat = client.setData(resPath, data, true); - client.setData("/configs/conf1", new byte[] {1}, true); + Stat newStat = client.setData(resPath, data); + client.setData("/configs/conf1", new byte[] {1}); 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 bee96cb6d05..728ae44b090 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 @@ -82,7 +82,7 @@ public void testZkread() throws Exception { } cluster .getZkClient() - .create("/configs/_default/testdata", bytes, CreateMode.PERSISTENT, true); + .create("/configs/_default/testdata", bytes, CreateMode.PERSISTENT); Utils.executeGET( client.getHttpClient(), basezk + "/configs/_default/testdata", 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 26258d52ac0..ec5d9263a36 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 @@ -127,7 +127,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, true)); + assertFalse(zkClient.exists("/configs/" + mutableId)); } @Test @@ -682,7 +682,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, true)); + assertFalse(zkClient.exists("/configs/" + mutableId)); 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 979ecd9ef0b..dcff273af94 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 @@ -181,7 +181,7 @@ public void testEnableDisableOptions() throws Exception { cluster .getZkClient() .exists( - SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"), true)); + SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); assertNotNull(schema.getFieldTypeByName("text_fr")); assertNotNull(schema.getFieldOrNull("*_txt_fr")); assertNull(schema.getFieldOrNull("*_txt_ga")); @@ -205,7 +205,7 @@ public void testEnableDisableOptions() throws Exception { cluster .getZkClient() .exists( - SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"), true)); + SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); 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 1b8ac54026c..830730c2e5c 100644 --- a/solr/core/src/test/org/apache/solr/pkg/TestPackages.java +++ b/solr/core/src/test/org/apache/solr/pkg/TestPackages.java @@ -618,7 +618,7 @@ public void testAPI() throws Exception { new MapWriterMap( (Map) Utils.fromJSON( - cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat(), true))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), Map.of(":packages:test_pkg[0]:version", "0.12", ":packages:test_pkg[0]:files[0]", FILE2)); // post a new jar with a proper signature @@ -642,7 +642,7 @@ public void testAPI() throws Exception { new MapWriterMap( (Map) Utils.fromJSON( - cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat(), true))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), Map.of(":packages:test_pkg[1]:version", "0.13", ":packages:test_pkg[1]:files[0]", FILE3)); // Now we will just delete one version @@ -668,7 +668,7 @@ public void testAPI() throws Exception { new MapWriterMap( (Map) Utils.fromJSON( - cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat(), true))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), 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 ec131cc0243..848679a4409 100644 --- a/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java +++ b/solr/core/src/test/org/apache/solr/schema/TestCloudManagedSchema.java @@ -91,16 +91,16 @@ public void test() throws Exception { private String getFileContentFromZooKeeper(SolrZkClient zkClient, String fileName) throws IOException, SolrServerException, KeeperException, InterruptedException { - return (new String(zkClient.getData(fileName, null, null, true), StandardCharsets.UTF_8)); + return (new String(zkClient.getData(fileName, null, null), StandardCharsets.UTF_8)); } protected final void assertFileNotInZooKeeper( SolrZkClient zkClient, String parent, String fileName) throws Exception { - List kids = zkClient.getChildren(parent, null, true); + List kids = zkClient.getChildren(parent, null); for (String kid : kids) { if (kid.equalsIgnoreCase(fileName)) { String rawContent = - new String(zkClient.getData(fileName, null, null, true), StandardCharsets.UTF_8); + new String(zkClient.getData(fileName, null, null), 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 23bd86e510b..ad8f70bb67d 100644 --- a/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java +++ b/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java @@ -68,11 +68,11 @@ boolean isSlowpoke() { } @Override - public byte[] getData(String path, Watcher watcher, Stat stat, boolean retryOnConnLoss) + public byte[] getData(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException { byte[] data; try { - data = super.getData(path, watcher, stat, retryOnConnLoss); + data = super.getData(path, watcher, stat); } catch (NoNodeException e) { if (isSlowpoke()) { // System.out.println("suspending "+Thread.currentThread()+" on " + path); @@ -156,7 +156,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, true); + Boolean exists = client.exists(path); 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 d8214d690d8..60806d6b813 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.replaceAll("'", "\"").getBytes(UTF_8), true); + zkClient().setData("/security.json", STD_CONF.replaceAll("'", "\"").getBytes(UTF_8)); 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 fde29f411cb..7c8f6370d75 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthOnSingleNodeTest.java @@ -83,7 +83,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, false); + cluster.getZkClient().delete("/security.json", -1); 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 74d0cbdda41..efa447543a2 100644 --- a/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java +++ b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java @@ -54,8 +54,8 @@ public void distribSetUp() throws Exception { ZkStateReader.SOLR_SECURITY_CONF_PATH, "{\"authorization\":{\"class\":\"org.apache.solr.security.MockAuthorizationPlugin\"}}" .getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); } } 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 572667a762f..114ad342460 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 @@ -224,8 +224,8 @@ public void test() throws Exception { + "/" + COLLECTION_PROPS_ZKNODE, null, - null, - true); + null + ); assertNotNull(data); assertTrue(data.length > 0); @SuppressWarnings("unchecked") @@ -1060,8 +1060,8 @@ public void process(WatchedEvent watchedEvent) { aliasUpdate.countDown(); } }, - stat, - true); + stat + ); } /** @@ -1284,7 +1284,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, true); + byte[] data = zkStateReader.getZkClient().getData("/aliases.json", null, null); // some tidbits for handling zk data here are swiped from Aliases.json Map aliasMap; @@ -1305,7 +1305,7 @@ private void manuallyConstructLegacyTRA() throws Exception { colAliases.put(alias, String.join(",", legacy24, legacy23)); data = Utils.toJSON(aliasMap); - zkStateReader.getZkClient().setData("/aliases.json", data, true); + zkStateReader.getZkClient().setData("/aliases.json", data); 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 d6f2bf931dc..504fc7dde7b 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 @@ -18,20 +18,13 @@ import java.io.IOException; import java.util.Enumeration; -import java.util.LinkedList; -import java.util.List; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.AuthInfo; import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.framework.api.ACLProvider; -import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.server.AuthenticationHandler; @@ -39,11 +32,8 @@ import org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkACLProvider; -import org.apache.solr.common.cloud.ZkCredentialsProvider; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.data.ACL; /** * This is an authentication filter based on Hadoop's {@link DelegationTokenAuthenticationFilter}. @@ -143,104 +133,16 @@ protected void initializeAuthHandler(String authHandlerClassName, FilterConfig f protected CuratorFramework getCuratorClient(SolrZkClient zkClient) throws InterruptedException, KeeperException { - // should we try to build a RetryPolicy off of the ZkController? - RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); - if (zkClient == null) { - throw new IllegalArgumentException("zkClient required"); - } - String zkHost = zkClient.getZkServerAddress(); - String zkChroot = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : ""; - String zkNamespace = zkChroot + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH; - zkNamespace = zkNamespace.startsWith("/") ? zkNamespace.substring(1) : zkNamespace; - String zkConnectionString = - zkHost.contains("/") ? zkHost.substring(0, zkHost.indexOf("/")) : zkHost; - SolrZkToCuratorCredentialsACLs curatorToSolrZk = new SolrZkToCuratorCredentialsACLs(zkClient); - final int connectionTimeoutMs = 30000; // this value is currently hard coded, see SOLR-7561. - // Create /security znode upfront. Without this, the curator framework creates this directory // path // without the appropriate ACL configuration. This issue is possibly related to HADOOP-11973 try { zkClient.makePath( - SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT, true); + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException ex) { // ignore? } - curatorFramework = - CuratorFrameworkFactory.builder() - .namespace(zkNamespace) - .connectString(zkConnectionString) - .retryPolicy(retryPolicy) - .aclProvider(curatorToSolrZk.getACLProvider()) - .authorization(curatorToSolrZk.getAuthInfos()) - .sessionTimeoutMs(zkClient.getZkClientTimeout()) - .connectionTimeoutMs(connectionTimeoutMs) - .build(); - curatorFramework.start(); - return curatorFramework; - } - - /** Convert Solr Zk Credentials/ACLs to Curator versions */ - protected static class SolrZkToCuratorCredentialsACLs { - private final String zkChroot; - private final ACLProvider aclProvider; - private final List authInfos; - - public SolrZkToCuratorCredentialsACLs(SolrZkClient zkClient) { - this.aclProvider = createACLProvider(zkClient); - this.authInfos = createAuthInfo(zkClient); - String zkHost = zkClient.getZkServerAddress(); - this.zkChroot = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : null; - } - - public ACLProvider getACLProvider() { - return aclProvider; - } - - public List getAuthInfos() { - return authInfos; - } - - private ACLProvider createACLProvider(SolrZkClient zkClient) { - final ZkACLProvider zkACLProvider = zkClient.getZkACLProvider(); - return new ACLProvider() { - @Override - public List getDefaultAcl() { - return zkACLProvider.getACLsToAdd(null); - } - - @Override - public List getAclForPath(String path) { - List acls = null; - - // The logic in SecurityAwareZkACLProvider does not work when - // the Solr zkPath is chrooted (e.g. /solr instead of /). This - // due to the fact that the getACLsToAdd(..) callback provides - // an absolute path (instead of relative path to the chroot) and - // the string comparison in SecurityAwareZkACLProvider fails. - if (zkACLProvider instanceof SecurityAwareZkACLProvider && zkChroot != null) { - acls = zkACLProvider.getACLsToAdd(path.replace(zkChroot, "")); - } else { - acls = zkACLProvider.getACLsToAdd(path); - } - - return acls; - } - }; - } - - private List createAuthInfo(SolrZkClient zkClient) { - List ret = new LinkedList(); - - // In theory the credentials to add could change here if zookeeper hasn't been initialized - ZkCredentialsProvider credentialsProvider = - zkClient.getZkClientConnectionStrategy().getZkCredentialsToAddAutomatically(); - for (ZkCredentialsProvider.ZkCredentials zkCredentials : - credentialsProvider.getCredentials()) { - ret.add(new AuthInfo(zkCredentials.getScheme(), zkCredentials.getAuth())); - } - return ret; - } + return zkClient.getCuratorFramework().usingNamespace(zkClient.getChroot() + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH); } } 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 74bf5f98c11..4db44119788 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 @@ -17,31 +17,21 @@ package org.apache.solr.security.hadoop; import java.io.IOException; -import java.util.LinkedList; -import java.util.List; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.AuthInfo; import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.framework.api.ACLProvider; -import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.server.AuthenticationHandler; import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter; import org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkACLProvider; -import org.apache.solr.common.cloud.ZkCredentialsProvider; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.data.ACL; /** * This is an authentication filter based on Hadoop's {@link DelegationTokenAuthenticationFilter}. @@ -123,108 +113,17 @@ protected void initializeAuthHandler(String authHandlerClassName, FilterConfig f } protected CuratorFramework getCuratorClient(SolrZkClient zkClient) - throws KeeperException, InterruptedException { - // should we try to build a RetryPolicy off of the ZkController? - RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); - if (zkClient == null) { - throw new IllegalArgumentException("zkClient required"); - } - String zkHost = zkClient.getZkServerAddress(); - String zkChroot = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : ""; - String zkNamespace = zkChroot + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH; - zkNamespace = zkNamespace.startsWith("/") ? zkNamespace.substring(1) : zkNamespace; - String zkConnectionString = - zkHost.contains("/") ? zkHost.substring(0, zkHost.indexOf("/")) : zkHost; - SolrZkToCuratorCredentialsACLs curatorToSolrZk = new SolrZkToCuratorCredentialsACLs(zkClient); - final int connectionTimeoutMs = 30000; // this value is currently hard coded, see SOLR-7561. - + throws InterruptedException, KeeperException { // Create /security znode upfront. Without this, the curator framework creates this directory // path // without the appropriate ACL configuration. This issue is possibly related to HADOOP-11973 try { zkClient.makePath( - SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT, true); - - } catch (KeeperException ex) { - if (ex.code() != KeeperException.Code.NODEEXISTS) { - throw ex; - } - } - - curatorFramework = - CuratorFrameworkFactory.builder() - .namespace(zkNamespace) - .connectString(zkConnectionString) - .retryPolicy(retryPolicy) - .aclProvider(curatorToSolrZk.getACLProvider()) - .authorization(curatorToSolrZk.getAuthInfos()) - .sessionTimeoutMs(zkClient.getZkClientTimeout()) - .connectionTimeoutMs(connectionTimeoutMs) - .build(); - curatorFramework.start(); - return curatorFramework; - } - - /** Convert Solr Zk Credentials/ACLs to Curator versions */ - protected static class SolrZkToCuratorCredentialsACLs { - private final String zkChroot; - private final ACLProvider aclProvider; - private final List authInfos; - - public SolrZkToCuratorCredentialsACLs(SolrZkClient zkClient) { - this.aclProvider = createACLProvider(zkClient); - this.authInfos = createAuthInfo(zkClient); - String zkHost = zkClient.getZkServerAddress(); - this.zkChroot = zkHost.contains("/") ? zkHost.substring(zkHost.indexOf("/")) : null; - } - - public ACLProvider getACLProvider() { - return aclProvider; + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT); + } catch (KeeperException.NodeExistsException ex) { + // ignore? } - public List getAuthInfos() { - return authInfos; - } - - private ACLProvider createACLProvider(SolrZkClient zkClient) { - final ZkACLProvider zkACLProvider = zkClient.getZkACLProvider(); - return new ACLProvider() { - @Override - public List getDefaultAcl() { - return zkACLProvider.getACLsToAdd(null); - } - - @Override - public List getAclForPath(String path) { - List acls = null; - - // The logic in SecurityAwareZkACLProvider does not work when - // the Solr zkPath is chrooted (e.g. /solr instead of /). This - // due to the fact that the getACLsToAdd(..) callback provides - // an absolute path (instead of relative path to the chroot) and - // the string comparison in SecurityAwareZkACLProvider fails. - if (zkACLProvider instanceof SecurityAwareZkACLProvider && zkChroot != null) { - acls = zkACLProvider.getACLsToAdd(path.replace(zkChroot, "")); - } else { - acls = zkACLProvider.getACLsToAdd(path); - } - - return acls; - } - }; - } - - private List createAuthInfo(SolrZkClient zkClient) { - List ret = new LinkedList(); - - // In theory the credentials to add could change here if zookeeper hasn't been initialized - ZkCredentialsProvider credentialsProvider = - zkClient.getZkClientConnectionStrategy().getZkCredentialsToAddAutomatically(); - for (ZkCredentialsProvider.ZkCredentials zkCredentials : - credentialsProvider.getCredentials()) { - ret.add(new AuthInfo(zkCredentials.getScheme(), zkCredentials.getAuth())); - } - return ret; - } + return zkClient.getCuratorFramework().usingNamespace(zkClient.getChroot() + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH); } } 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 530aab2914e..499a3131a1e 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 @@ -23,6 +23,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; + +import org.apache.curator.framework.api.ACLProvider; import org.apache.lucene.util.Constants; import org.apache.lucene.util.QuickPatchThreadsFilter; import org.apache.solr.SolrIgnoredThreadsFilter; @@ -30,7 +32,7 @@ import org.apache.solr.cloud.AbstractVMParamsZkACLAndCredentialsProvidersTestBase; import org.apache.solr.cloud.AbstractZkTestCase; import org.apache.solr.cloud.ZkTestServer; -import org.apache.solr.common.cloud.DefaultZkACLProvider; +import org.apache.solr.common.cloud.DefaultACLProvider; import org.apache.solr.common.cloud.SaslZkACLProvider; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; @@ -94,7 +96,7 @@ public void setUp() throws Exception { ZooKeeperSaslClient saslClient = zkClient.getSolrZooKeeper().getConnection().zooKeeperSaslClient; assumeFalse("Could not set up ZK with SASL", saslClient.isFailed()); - zkClient.makePath("/solr", false, true); + zkClient.makePath("/solr", false); } 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); @@ -111,17 +113,17 @@ protected void setupZNodes() throws Exception { new SolrZkClientWithACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); } finally { zkClient.close(); } @@ -131,13 +133,13 @@ protected void setupZNodes() throws Exception { zkClient.create( "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.makePath( "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); } finally { zkClient.close(); } @@ -183,8 +185,8 @@ public SolrZkClientWithACLs(String zkServerAddress, int zkClientTimeout) { } @Override - public ZkACLProvider createZkACLProvider() { - return new SaslZkACLProvider(); + public ZkACLProvider createACLProvider() { + return new SaslZkACLProvider(getChroot()); } } @@ -196,8 +198,8 @@ public SolrZkClientNoACLs(String zkServerAddress, int zkClientTimeout) { } @Override - public ZkACLProvider createZkACLProvider() { - return new DefaultZkACLProvider(); + public ACLProvider createACLProvider() { + return new DefaultACLProvider(); } } 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 46c1bd68c48..0f2cd7f60b2 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 @@ -356,8 +356,8 @@ public void testZNodePaths() throws Exception { getDelegationToken(null, USER_1, primarySolrClient); SolrZkClient zkClient = new SolrZkClient(cluster.getZkServer().getZkAddress(), 1000); try { - assertTrue(zkClient.exists("/security/zkdtsm", true)); - assertTrue(zkClient.exists("/security/token", true)); + assertTrue(zkClient.exists("/security/zkdtsm")); + assertTrue(zkClient.exists("/security/token")); } finally { zkClient.close(); } 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 796beb9072e..88f1726f432 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 @@ -396,8 +396,8 @@ public void testZNodePaths() throws Exception { getDelegationToken(null, "bar", solrClientPrimary); SolrZkClient zkClient = new SolrZkClient(miniCluster.getZkServer().getZkAddress(), 1000); try { - assertTrue(zkClient.exists("/security/zkdtsm", true)); - assertTrue(zkClient.exists("/security/token", true)); + assertTrue(zkClient.exists("/security/zkdtsm")); + assertTrue(zkClient.exists("/security/token")); } finally { zkClient.close(); } 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 b07d232f83e..7396611bb79 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 @@ -161,8 +161,8 @@ public static void setupClass() throws Exception { + "confFaulty" + Path.SEPARATOR + "solrconfig.xml", - -1, - true); + -1 + ); } @AfterClass diff --git a/solr/server/solr/solr.xml b/solr/server/solr/solr.xml index 60031538f7f..07c2e4dc390 100644 --- a/solr/server/solr/solr.xml +++ b/solr/server/solr/solr.xml @@ -46,7 +46,7 @@ ${distribUpdateSoTimeout:600000} ${distribUpdateConnTimeout:60000} ${zkCredentialsProvider:org.apache.solr.common.cloud.DefaultZkCredentialsProvider} - ${zkACLProvider:org.apache.solr.common.cloud.DefaultZkACLProvider} + ${zkACLProvider:org.apache.solr.common.cloud.DefaultACLProvider} ${distributedClusterStateUpdates:false} ${distributedCollectionConfigSetExecution:false} diff --git a/solr/solrj/build.gradle b/solr/solrj/build.gradle index 1621fa6b78c..ea2781136fa 100644 --- a/solr/solrj/build.gradle +++ b/solr/solrj/build.gradle @@ -36,6 +36,8 @@ dependencies { implementation 'org.apache.commons:commons-math3' + api 'org.apache.curator:curator-framework' + api 'org.eclipse.jetty.http2:http2-client' implementation 'org.eclipse.jetty.http2:http2-http-client-transport' implementation 'org.eclipse.jetty:jetty-http' diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java index 25543892fcd..ef05806a8b1 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java @@ -23,12 +23,13 @@ import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; + +import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.solr.common.SolrCloseable; import org.apache.solr.common.cloud.PerReplicaStates; +import org.apache.solr.common.cloud.SolrZkClient; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; -import org.apache.zookeeper.OpResult; import org.apache.zookeeper.Watcher; /** This interface represents a distributed state repository. */ @@ -80,7 +81,7 @@ void setData(String path, byte[] data, int version) throws BadVersionException, NoSuchElementException, IOException, KeeperException, InterruptedException; - List multi(final Iterable ops) + List multi(final List ops) throws BadVersionException, NoSuchElementException, AlreadyExistsException, IOException, KeeperException, InterruptedException; diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java index e055ee5f6cb..09bc0b9ceea 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ZkDistribStateManager.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.util.List; import java.util.NoSuchElementException; + +import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.solr.client.solrj.cloud.AlreadyExistsException; import org.apache.solr.client.solrj.cloud.BadVersionException; import org.apache.solr.client.solrj.cloud.DistribStateManager; @@ -30,8 +32,6 @@ import org.apache.solr.common.cloud.SolrZkClient; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; -import org.apache.zookeeper.OpResult; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.data.Stat; @@ -47,7 +47,7 @@ public ZkDistribStateManager(SolrZkClient zkClient) { @Override public boolean hasData(String path) throws IOException, KeeperException, InterruptedException { try { - return zkClient.exists(path, true); + return zkClient.exists(path); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new AlreadyClosedException(); @@ -58,7 +58,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, true); + return zkClient.getChildren(path, watcher); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (InterruptedException e) { @@ -78,7 +78,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, true); + byte[] bytes = zkClient.getData(path, watcher, stat); return new VersionedData( stat.getVersion(), bytes, @@ -96,7 +96,7 @@ public VersionedData getData(String path, Watcher watcher) public void makePath(String path) throws AlreadyExistsException, IOException, KeeperException, InterruptedException { try { - zkClient.makePath(path, true); + zkClient.makePath(path); } catch (KeeperException.NodeExistsException e) { throw new AlreadyExistsException(path); } catch (InterruptedException e) { @@ -109,7 +109,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, true); + zkClient.makePath(path, data, createMode, null, failOnExists); } catch (KeeperException.NodeExistsException e) { throw new AlreadyExistsException(path); } catch (InterruptedException e) { @@ -123,7 +123,7 @@ public String createData(String path, byte[] data, CreateMode mode) throws NoSuchElementException, AlreadyExistsException, IOException, KeeperException, InterruptedException { try { - return zkClient.create(path, data, mode, true); + return zkClient.create(path, data, mode); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.NodeExistsException e) { @@ -139,7 +139,7 @@ public void removeData(String path, int version) throws NoSuchElementException, BadVersionException, NotEmptyException, IOException, KeeperException, InterruptedException { try { - zkClient.delete(path, version, true); + zkClient.delete(path, version); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.NotEmptyException e) { @@ -157,7 +157,7 @@ public void setData(String path, byte[] data, int version) throws BadVersionException, NoSuchElementException, IOException, KeeperException, InterruptedException { try { - zkClient.setData(path, data, version, true); + zkClient.setData(path, data, version); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(path); } catch (KeeperException.BadVersionException e) { @@ -169,11 +169,11 @@ public void setData(String path, byte[] data, int version) } @Override - public List multi(Iterable ops) + public List multi(List ops) throws BadVersionException, AlreadyExistsException, NoSuchElementException, IOException, KeeperException, InterruptedException { try { - return zkClient.multi(ops, true); + return zkClient.multi(ops); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException(ops.toString()); } catch (KeeperException.NodeExistsException e) { diff --git a/solr/solrj/src/java/org/apache/solr/common/LazySolrCluster.java b/solr/solrj/src/java/org/apache/solr/common/LazySolrCluster.java index d8bc32869ab..faceb6420d6 100644 --- a/solr/solrj/src/java/org/apache/solr/common/LazySolrCluster.java +++ b/solr/solrj/src/java/org/apache/solr/common/LazySolrCluster.java @@ -246,7 +246,7 @@ public String config() { byte[] d = zkStateReader .getZkClient() - .getData(getCollectionPathRoot(coll.getName()), null, null, true); + .getData(getCollectionPathRoot(coll.getName()), null, null); if (d == null || d.length == 0) return null; Map m = (Map) Utils.fromJSON(d); confName = (String) m.get("configName"); diff --git a/solr/solrj/src/java/org/apache/solr/common/SimpleZkMap.java b/solr/solrj/src/java/org/apache/solr/common/SimpleZkMap.java index 39051da857c..0378bda4fdd 100644 --- a/solr/solrj/src/java/org/apache/solr/common/SimpleZkMap.java +++ b/solr/solrj/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, true), fun); + recursiveRead("", zkStateReader.getZkClient().getChildren(basePath, null), fun); } catch (KeeperException | InterruptedException e) { throwZkExp(e); } @@ -85,7 +85,7 @@ public String name() { public void get(Consumer consumer) throws SolrException { try { byte[] data = - zkStateReader.getZkClient().getData(basePath + "/" + path, null, null, true); + zkStateReader.getZkClient().getData(basePath + "/" + path, null, null); if (data != null && data.length > 0) { consumer.read(new ByteArrayInputStream(data)); } else { @@ -109,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, true); + zkStateReader.getZkClient().getChildren(basePath + "/" + relativePath, null); if (l1 != null && !l1.isEmpty()) { withKids.put(relativePath, l1); } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.java index 64264ddadc5..6faf0ffda0b 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterProperties.java +++ b/solr/solrj/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(), true)); + Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); return convertCollectionDefaultsToNestedFormat(properties); } catch (KeeperException.NoNodeException e) { return Collections.emptyMap(); @@ -197,23 +197,23 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws for (; ; ) { Stat s = new Stat(); try { - if (client.exists(ZkStateReader.CLUSTER_PROPS, true)) { + if (client.exists(ZkStateReader.CLUSTER_PROPS)) { @SuppressWarnings({"rawtypes"}) Map properties = - (Map) Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, s, true)); + (Map) Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, s)); 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(), true); + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion()); } } 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(), true); + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion()); } } } else { @@ -221,7 +221,7 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws Map properties = new LinkedHashMap(); properties.put(propertyName, propertyValue); client.create( - ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT, true); + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT); } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { // race condition diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java index 24afd246c6c..f6ec1b7d1e3 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java @@ -251,7 +251,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, true); + byte[] data = zkClient.getData(path, null, null); if (data != null && data.length > 0) { ZkNodeProps configProp = ZkNodeProps.load(data); String configName = configProp.getStr(ZkStateReader.CONFIGNAME_PROP); diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/CollectionProperties.java b/solr/solrj/src/java/org/apache/solr/common/cloud/CollectionProperties.java index e036ac76217..b045a60a967 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/CollectionProperties.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/CollectionProperties.java @@ -68,7 +68,7 @@ public Map getCollectionProperties(String collection) throws IOE return (Map) Utils.fromJSON( client.getData( - ZkStateReader.getCollectionPropsPath(collection), null, new Stat(), true)); + ZkStateReader.getCollectionPropsPath(collection), null, new Stat())); } catch (KeeperException.NoNodeException e) { return Collections.emptyMap(); } catch (KeeperException | InterruptedException e) { @@ -94,25 +94,25 @@ public void setCollectionProperty(String collection, String propertyName, String while (true) { Stat s = new Stat(); try { - if (client.exists(znodePath, true)) { + if (client.exists(znodePath)) { Map properties = - (Map) Utils.fromJSON(client.getData(znodePath, null, s, true)); + (Map) Utils.fromJSON(client.getData(znodePath, null, s)); if (propertyValue == null) { if (properties.remove(propertyName) != null) { // Don't update ZK unless absolutely necessary. - client.setData(znodePath, Utils.toJSON(properties), s.getVersion(), true); + client.setData(znodePath, Utils.toJSON(properties), s.getVersion()); } } else { if (!propertyValue.equals( properties.put( propertyName, propertyValue))) { // Don't update ZK unless absolutely necessary. - client.setData(znodePath, Utils.toJSON(properties), s.getVersion(), true); + client.setData(znodePath, Utils.toJSON(properties), s.getVersion()); } } } else { Map properties = new LinkedHashMap<>(); properties.put(propertyName, propertyValue); - client.create(znodePath, Utils.toJSON(properties), CreateMode.PERSISTENT, true); + client.create(znodePath, Utils.toJSON(properties), CreateMode.PERSISTENT); } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { // race condition diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java index c2c35941f05..351e735ef51 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java @@ -20,7 +20,10 @@ import static org.apache.zookeeper.Watcher.Event.KeeperState.Disconnected; import static org.apache.zookeeper.Watcher.Event.KeeperState.Expired; +import java.io.IOException; import java.lang.invoke.MethodHandles; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.apache.solr.common.SolrException; @@ -44,9 +47,12 @@ public class ConnectionManager implements Watcher { private final SolrZkClient client; private final OnReconnect onReconnect; - private final BeforeReconnect beforeReconnect; + private final OnDisconnect beforeReconnect; + + private final ExecutorService executorService; private volatile boolean isClosed = false; + private volatile boolean isReconnecting = false; // Track the likely expired state private static class LikelyExpiredState { @@ -76,29 +82,28 @@ public boolean isLikelyExpired(long timeToExpire) { } } - public abstract static class IsClosed { - public abstract boolean isClosed(); + @FunctionalInterface + public interface IsClosed { + boolean isClosed(); } private volatile LikelyExpiredState likelyExpiredState = LikelyExpiredState.EXPIRED; private IsClosed isClosedCheck; - public ConnectionManager( - String name, - SolrZkClient client, - String zkServerAddress, - ZkClientConnectionStrategy strat, - OnReconnect onConnect, - BeforeReconnect beforeReconnect, - IsClosed isClosed) { + public ConnectionManager(String name, SolrZkClient client, String zkServerAddress, ZkClientConnectionStrategy strat, OnReconnect onConnect, OnDisconnect beforeReconnect, IsClosed isClosed) { + this(name, client, zkServerAddress, strat, onConnect, beforeReconnect, isClosed, null); + } + + public ConnectionManager(String name, SolrZkClient client, String zkServerAddress, ZkClientConnectionStrategy strat, OnReconnect onConnect, OnDisconnect onDisconnect, IsClosed isClosed, ExecutorService executorService) { this.name = name; this.client = client; this.connectionStrategy = strat; this.zkServerAddress = zkServerAddress; this.onReconnect = onConnect; - this.beforeReconnect = beforeReconnect; + this.beforeReconnect = onDisconnect; this.isClosedCheck = isClosed; + this.executorService = executorService; } private synchronized void connected() { @@ -119,6 +124,21 @@ private synchronized void disconnected() { @Override public void process(WatchedEvent event) { + if (executorService == null) { + processInternal(event); + } else { + try { + executorService.submit(() -> processInternal(event)); + } catch (RejectedExecutionException e) { + // If not a graceful shutdown + if (!isClosed()) { + throw e; + } + } + } + } + + public void processInternal(WatchedEvent event) { if (event.getState() == AuthFailed || event.getState() == Disconnected || event.getState() == Expired) { @@ -152,6 +172,16 @@ public void process(WatchedEvent event) { log.info("zkClient has connected"); connected(); connectionStrategy.connected(); + + if (isReconnecting && onReconnect != null) { + try { + onReconnect.command(); + } catch (Exception e) { + log.warn("Exception running onReconnect command", e); + } + } + + isReconnecting = false; } else if (state == Expired) { if (isClosed()) { return; @@ -159,6 +189,7 @@ public void process(WatchedEvent event) { // we don't call disconnected here, because we know we are expired connected = false; likelyExpiredState = LikelyExpiredState.EXPIRED; + isReconnecting = true; log.warn( "Our previous ZooKeeper session was expired. Attempting to reconnect to recover relationship with ZooKeeper..."); @@ -171,53 +202,20 @@ public void process(WatchedEvent event) { } } - do { - // This loop will break if a valid connection is made. If a connection is not made then it - // will repeat and try again to create a new connection. - try { - connectionStrategy.reconnect( - zkServerAddress, - client.getZkClientTimeout(), - this, - new ZkClientConnectionStrategy.ZkUpdate() { - @Override - public void update(SolrZooKeeper keeper) { - try { - waitForConnected(Long.MAX_VALUE); - - try { - client.updateKeeper(keeper); - } catch (InterruptedException e) { - closeKeeper(keeper); - Thread.currentThread().interrupt(); - // we must have been asked to stop - throw new RuntimeException(e); - } - - if (onReconnect != null) { - onReconnect.command(); - } - - } catch (Exception e1) { - // if there was a problem creating the new SolrZooKeeper - // or if we cannot run our reconnect command, close the keeper - // our retry loop will try to create one again - closeKeeper(keeper); - throw new RuntimeException(e1); - } - } - }); - - break; - - } catch (Exception e) { - SolrException.log(log, "", e); - log.info("Could not connect due to error, sleeping for 1s and trying again"); - waitSleep(1000); - } - - } while (!isClosed()); - log.info("zkClient Connected: {}", connected); + try { + connectionStrategy.reconnect( + zkServerAddress, + client.getZkClientTimeout(), + this, + client::updateKeeper); + log.info("zkClient reconnect started"); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + // we must have been asked to stop + throw new RuntimeException(e); + } catch (IOException | TimeoutException e) { + log.warn("Could not reconnect to ZK", e); + } } else if (state == KeeperState.Disconnected) { log.warn("zkClient has disconnected"); disconnected(); @@ -251,14 +249,6 @@ public boolean isLikelyExpired() { || likelyExpiredState.isLikelyExpired((long) (client.getZkClientTimeout() * 0.90)); } - public synchronized void waitSleep(long waitFor) { - try { - wait(waitFor); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - /** * Wait for an established zookeeper connection * @@ -291,28 +281,4 @@ public synchronized void waitForConnected(long waitForConnection) throws Timeout } log.info("Client is connected to ZooKeeper"); } - - public synchronized void waitForDisconnected(long timeout) - throws InterruptedException, TimeoutException { - long expire = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS); - long left = timeout; - while (connected && left > 0) { - wait(left); - left = expire - System.nanoTime(); - } - if (connected) { - throw new TimeoutException("Did not disconnect"); - } - } - - private void closeKeeper(SolrZooKeeper keeper) { - try { - keeper.close(); - } catch (InterruptedException e) { - // Restore the interrupted status - Thread.currentThread().interrupt(); - log.error("", e); - throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); - } - } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java similarity index 67% rename from solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java rename to solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java index 5b43414da9d..90751290ac8 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java @@ -17,25 +17,22 @@ package org.apache.solr.common.cloud; import java.util.List; + +import org.apache.curator.framework.api.ACLProvider; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.data.ACL; -public class DefaultZkACLProvider implements ZkACLProvider { +public class DefaultACLProvider implements ACLProvider { - private List globalACLsToAdd; + private final List globalACLsToAdd = ZooDefs.Ids.OPEN_ACL_UNSAFE; @Override - public List getACLsToAdd(String zNodePath) { - // In default (simple) implementation use the same set of ACLs for all znodes - if (globalACLsToAdd == null) { - synchronized (this) { - if (globalACLsToAdd == null) globalACLsToAdd = createGlobalACLsToAdd(); - } - } + public List getAclForPath(String zNodePath) { return globalACLsToAdd; } - protected List createGlobalACLsToAdd() { - return ZooDefs.Ids.OPEN_ACL_UNSAFE; + @Override + public List getDefaultAcl() { + return globalACLsToAdd; } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java index a2ef37b7b1c..3b8ee1bb769 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java @@ -16,24 +16,25 @@ */ package org.apache.solr.common.cloud; +import org.apache.curator.framework.AuthInfo; + import java.util.ArrayList; -import java.util.Collection; +import java.util.List; public class DefaultZkCredentialsProvider implements ZkCredentialsProvider { - private Collection zkCredentials; + private final List zkCredentials; - @Override - public Collection getCredentials() { - if (zkCredentials == null) { - synchronized (this) { - if (zkCredentials == null) zkCredentials = createCredentials(); - } - } - return zkCredentials; + public DefaultZkCredentialsProvider() { + this(new ArrayList<>()); } - protected Collection createCredentials() { - return new ArrayList(); + public DefaultZkCredentialsProvider(List zkCredentials) { + this.zkCredentials = zkCredentials; + } + + @Override + public List getCredentials() { + return zkCredentials; } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/BeforeReconnect.java b/solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java similarity index 68% rename from solr/solrj/src/java/org/apache/solr/common/cloud/BeforeReconnect.java rename to solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java index 928e606c920..49cc0427ab7 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/BeforeReconnect.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java @@ -16,6 +16,17 @@ */ package org.apache.solr.common.cloud; -public interface BeforeReconnect { +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.state.ConnectionState; +import org.apache.curator.framework.state.ConnectionStateListener; + +public interface OnDisconnect extends ConnectionStateListener { public void command(); + + @Override + default void stateChanged(CuratorFramework client, ConnectionState newState) { + if (!newState.isConnected()) { + command(); + } + } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java b/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java index 19acfda4f6a..06fed20a444 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java @@ -16,6 +16,9 @@ */ package org.apache.solr.common.cloud; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.state.ConnectionState; +import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.zookeeper.KeeperException.SessionExpiredException; /** @@ -25,6 +28,13 @@ * org.apache.solr.cloud.ZkController#removeOnReconnectListener(OnReconnect) when it no longer needs * to be notified of ZK reconnection events. */ -public interface OnReconnect { - void command() throws SessionExpiredException; +public interface OnReconnect extends ConnectionStateListener { + void command(); + + @Override + default void stateChanged(CuratorFramework client, ConnectionState newState) { + if (ConnectionState.RECONNECTED.equals(newState)) { + command(); + } + } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java index f05d79042ce..c9656d070ff 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStates.java @@ -127,12 +127,12 @@ public static PerReplicaStates fetch( String path, SolrZkClient zkClient, PerReplicaStates current) { try { if (current != null) { - Stat stat = zkClient.exists(current.path, null, true); + Stat stat = zkClient.exists(current.path, null); if (stat == null) return new PerReplicaStates(path, -1, Collections.emptyList()); if (current.cversion == stat.getCversion()) return current; // not modifiedZkStateReaderTest } Stat stat = new Stat(); - List children = zkClient.getChildren(path, null, stat, true); + List children = zkClient.getChildren(path, null, stat); return new PerReplicaStates(path, stat.getCversion(), Collections.unmodifiableList(children)); } catch (KeeperException e) { throw new SolrException( diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java index 708199561cb..b76223b8aee 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/PerReplicaStatesOps.java @@ -28,7 +28,6 @@ import java.util.function.Function; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; import org.apache.zookeeper.data.Stat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,20 +55,19 @@ private void persist( log.debug("Per-replica state being persisted for : '{}', ops: {}", znode, operations); } - List ops = new ArrayList<>(operations.size()); + List ops = new ArrayList<>(operations.size()); for (PerReplicaStates.Operation op : operations) { // the state of the replica is being updated String path = znode + "/" + op.state.asString; ops.add( op.typ == PerReplicaStates.Operation.Type.ADD - ? Op.create( - path, null, zkClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT) - : Op.delete(path, -1)); + ? zkOp -> zkOp.create().withMode(CreateMode.PERSISTENT).forPath(path, null) + : zkOp -> zkOp.delete().withVersion(-1).forPath(path)); } try { - zkClient.multi(ops, true); + zkClient.multi(ops); } catch (KeeperException e) { - log.error("Multi-op exception: {}", zkClient.getChildren(znode, null, true)); + log.error("Multi-op exception: {}", zkClient.getChildren(znode, null)); throw e; } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java index 2fbfbdd2ef8..b1549853b1b 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java @@ -34,6 +34,10 @@ public class SaslZkACLProvider extends SecurityAwareZkACLProvider { private static final String superUser = System.getProperty("solr.authorization.superuser", "solr"); + public SaslZkACLProvider(String chroot) { + super(chroot); + } + @Override protected List createNonSecurityACLsToAdd() { return Arrays.asList( diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java index 392771661af..094007d0d6d 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java @@ -29,6 +29,17 @@ public abstract class SecurityAwareZkACLProvider implements ZkACLProvider { private List nonSecurityACLsToAdd; private List securityACLsToAdd; + private final String chroot; + + public SecurityAwareZkACLProvider(String chroot) { + if (chroot == null){ + chroot = ""; + } else if (chroot.endsWith("/")) { + chroot = chroot.substring(0, chroot.length() - 1); + } + this.chroot = chroot; + } + @Override public final List getACLsToAdd(String zNodePath) { if (isSecurityZNodePath(zNodePath)) { @@ -38,11 +49,16 @@ public final List getACLsToAdd(String zNodePath) { } } + @Override + public final List getDefaultAcl() { + return getNonSecurityACLsToAdd(); + } + protected boolean isSecurityZNodePath(String zNodePath) { return zNodePath != null - && (zNodePath.equals(ZkStateReader.SOLR_SECURITY_CONF_PATH) - || zNodePath.equals(SECURITY_ZNODE_PATH) - || zNodePath.startsWith(SECURITY_ZNODE_PATH + "/")); + && (zNodePath.equals(chroot + ZkStateReader.SOLR_SECURITY_CONF_PATH) + || zNodePath.equals(chroot + SECURITY_ZNODE_PATH) + || zNodePath.startsWith(chroot + SECURITY_ZNODE_PATH + "/")); } /** diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index e3b2bc99763..e81be03c921 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; @@ -30,6 +31,17 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.apache.curator.RetryPolicy; +import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.framework.api.ACLProvider; +import org.apache.curator.framework.api.transaction.CuratorOp; +import org.apache.curator.framework.api.transaction.CuratorTransactionResult; +import org.apache.curator.framework.api.transaction.TransactionOp; +import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrException; import org.apache.solr.common.StringUtils; @@ -39,17 +51,12 @@ import org.apache.solr.common.util.SolrNamedThreadFactory; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.KeeperException.NoAuthException; import org.apache.zookeeper.KeeperException.NoNodeException; -import org.apache.zookeeper.KeeperException.NodeExistsException; -import org.apache.zookeeper.Op; -import org.apache.zookeeper.OpResult; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; +import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,22 +72,17 @@ public class SolrZkClient implements Closeable { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private ConnectionManager connManager; - - private volatile SolrZooKeeper keeper; - - private ZkCmdExecutor zkCmdExecutor; + CuratorFramework client; private final ExecutorService zkCallbackExecutor = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("zkCallback")); - private final ExecutorService zkConnManagerCallbackExecutor = + private final ExecutorService zkConnectionListenerCallbackExecutor = ExecutorUtil.newMDCAwareSingleThreadExecutor( - new SolrNamedThreadFactory("zkConnectionManagerCallback")); + new SolrNamedThreadFactory("zkConnectionListenerCallback")); private volatile boolean isClosed = false; - private ZkClientConnectionStrategy zkClientConnectionStrategy; private int zkClientTimeout; - private ZkACLProvider zkACLProvider; + private ACLProvider aclProvider; private String zkServerAddress; private IsClosed higherLevelIsClosed; @@ -93,7 +95,7 @@ public int getZkClientTimeout() { public SolrZkClient() {} public SolrZkClient(String zkServerAddress, int zkClientTimeout) { - this(zkServerAddress, zkClientTimeout, new DefaultConnectionStrategy(), null); + this(zkServerAddress, zkClientTimeout, null, null); } public SolrZkClient(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout) { @@ -101,7 +103,7 @@ public SolrZkClient(String zkServerAddress, int zkClientTimeout, int zkClientCon zkServerAddress, zkClientTimeout, zkClientConnectTimeout, - new DefaultConnectionStrategy(), + null, null); } @@ -114,31 +116,31 @@ public SolrZkClient( zkServerAddress, zkClientTimeout, zkClientConnectTimeout, - new DefaultConnectionStrategy(), + null, onReonnect); } public SolrZkClient( String zkServerAddress, int zkClientTimeout, - ZkClientConnectionStrategy strat, + ZkCredentialsProvider zkCredentialsProvider, final OnReconnect onReconnect) { - this(zkServerAddress, zkClientTimeout, DEFAULT_CLIENT_CONNECT_TIMEOUT, strat, onReconnect); + this(zkServerAddress, zkClientTimeout, DEFAULT_CLIENT_CONNECT_TIMEOUT, zkCredentialsProvider, onReconnect); } public SolrZkClient( String zkServerAddress, int zkClientTimeout, int clientConnectTimeout, - ZkClientConnectionStrategy strat, + ZkCredentialsProvider zkCredentialsProvider, final OnReconnect onReconnect) { this( zkServerAddress, zkClientTimeout, clientConnectTimeout, - strat, - onReconnect, + zkCredentialsProvider, null, + onReconnect, null, null); } @@ -147,17 +149,17 @@ public SolrZkClient( String zkServerAddress, int zkClientTimeout, int clientConnectTimeout, - ZkClientConnectionStrategy strat, + ZkCredentialsProvider zkCredentialsProvider, final OnReconnect onReconnect, - BeforeReconnect beforeReconnect) { + OnDisconnect onDisconnect) { this( zkServerAddress, zkClientTimeout, clientConnectTimeout, - strat, - onReconnect, - beforeReconnect, + zkCredentialsProvider, null, + onReconnect, + onDisconnect, null); } @@ -165,107 +167,70 @@ public SolrZkClient( String zkServerAddress, int zkClientTimeout, int clientConnectTimeout, - ZkClientConnectionStrategy strat, + ZkCredentialsProvider zkCredentialsProvider, + ACLProvider aclProvider, final OnReconnect onReconnect, - BeforeReconnect beforeReconnect, - ZkACLProvider zkACLProvider, + OnDisconnect onDisconnect, IsClosed higherLevelIsClosed) { this.zkServerAddress = zkServerAddress; - this.higherLevelIsClosed = higherLevelIsClosed; - if (strat == null) { - strat = new DefaultConnectionStrategy(); + String chroot, zkHost; + int chrootIndex = zkServerAddress.indexOf('/'); + if (chrootIndex == -1) { + zkHost = zkServerAddress; + chroot = null; + } else if (chrootIndex == zkServerAddress.length() - 1) { + zkHost = zkServerAddress.substring(0, zkServerAddress.length() - 1); + chroot = null; + } else { + zkHost = zkServerAddress.substring(0, chrootIndex); + chroot = zkServerAddress.substring(chrootIndex); } - this.zkClientConnectionStrategy = strat; + this.higherLevelIsClosed = higherLevelIsClosed; - if (!strat.hasZkCredentialsToAddAutomatically()) { - ZkCredentialsProvider zkCredentialsToAddAutomatically = - createZkCredentialsToAddAutomatically(); - strat.setZkCredentialsToAddAutomatically(zkCredentialsToAddAutomatically); + if (zkCredentialsProvider == null) { + zkCredentialsProvider = createZkCredentialsToAddAutomatically(); + } + if (aclProvider == null) { + this.aclProvider = createACLProvider(); + } else { + this.aclProvider = aclProvider; } this.zkClientTimeout = zkClientTimeout; - // we must retry at least as long as the session timeout - zkCmdExecutor = - new ZkCmdExecutor( - zkClientTimeout, - new IsClosed() { - - @Override - public boolean isClosed() { - return SolrZkClient.this.isClosed(); - } - }); - connManager = - new ConnectionManager( - "ZooKeeperConnection Watcher:" + zkServerAddress, - this, - zkServerAddress, - strat, - onReconnect, - beforeReconnect, - new IsClosed() { - - @Override - public boolean isClosed() { - return SolrZkClient.this.isClosed(); - } - }); - try { - strat.connect( - zkServerAddress, - zkClientTimeout, - wrapWatcher(connManager), - zooKeeper -> { - SolrZooKeeper oldKeeper = keeper; - keeper = zooKeeper; - try { - closeKeeper(oldKeeper); - } finally { - if (isClosed) { - // we may have been closed - closeKeeper(SolrZkClient.this.keeper); - } - } - }); - } catch (Exception e) { - connManager.close(); - if (keeper != null) { - try { - keeper.close(); - } catch (InterruptedException e1) { - Thread.currentThread().interrupt(); - } - } - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); - } + RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); + var clientBuilder = CuratorFrameworkFactory.builder() + .ensembleProvider(new FixedEnsembleProvider(zkHost)) + .namespace(chroot) + .connectionTimeoutMs(clientConnectTimeout) + .aclProvider(this.aclProvider) + .authorization(zkCredentialsProvider.getCredentials()) + .retryPolicy(retryPolicy); + client = clientBuilder.build(); + if (onReconnect != null) { + client.getConnectionStateListenable().addListener(onReconnect, zkConnectionListenerCallbackExecutor); + } + if (onDisconnect != null) { + client.getConnectionStateListenable().addListener(onDisconnect, zkConnectionListenerCallbackExecutor); + } + client.start(); try { - connManager.waitForConnected(clientConnectTimeout); - } catch (Exception e) { - connManager.close(); - try { - keeper.close(); - } catch (InterruptedException e1) { - Thread.currentThread().interrupt(); - } - zkConnManagerCallbackExecutor.shutdown(); + client.blockUntilConnected(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); } + assert ObjectReleaseTracker.track(this); - if (zkACLProvider == null) { - this.zkACLProvider = createZkACLProvider(); - } else { - this.zkACLProvider = zkACLProvider; - } } - public ConnectionManager getConnectionManager() { - return connManager; + public CuratorFramework getCuratorFramework() { + return client; } - public ZkClientConnectionStrategy getZkClientConnectionStrategy() { - return zkClientConnectionStrategy; + public ConnectionManager getConnectionManager() { + return connManager; } public static final String ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME = "zkCredentialsProvider"; @@ -291,47 +256,39 @@ protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { public static final String ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME = "zkACLProvider"; - protected ZkACLProvider createZkACLProvider() { - String zkACLProviderClassName = System.getProperty(ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME); - if (!StringUtils.isEmpty(zkACLProviderClassName)) { + protected ACLProvider createACLProvider() { + String aclProviderClassName = System.getProperty(ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME); + if (!StringUtils.isEmpty(aclProviderClassName)) { try { - log.info("Using ZkACLProvider: {}", zkACLProviderClassName); - return (ZkACLProvider) Class.forName(zkACLProviderClassName).getConstructor().newInstance(); + log.info("Using ACLProvider: {}", aclProviderClassName); + return (ACLProvider) Class.forName(aclProviderClassName).getConstructor().newInstance(); } catch (Throwable t) { // just ignore - go default log.warn( - "VM param zkACLProvider does not point to a class implementing ZkACLProvider and with a non-arg constructor", + "VM param zkACLProvider does not point to a class implementingACLProvider and with a non-arg constructor", t); } } - log.debug("Using default ZkACLProvider"); - return new DefaultZkACLProvider(); + log.debug("Using default ACLProvider"); + return new DefaultACLProvider(); } /** Returns true if client is connected */ public boolean isConnected() { - return keeper != null && keeper.getState() == ZooKeeper.States.CONNECTED; + return client.getZookeeperClient().isConnected(); } - public void delete(final String path, final int version, boolean retryOnConnLoss) + public void delete(final String path, final int version) throws InterruptedException, KeeperException { - if (retryOnConnLoss) { - zkCmdExecutor.retryOperation( - () -> { - keeper.delete(path, version); - return null; - }); - } else { - keeper.delete(path, version); - } + runWithCorrectThrows( + "deleting znode", + () -> client.delete().withVersion(version).forPath(path)); } /** * 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, org.apache.zookeeper.Watcher, - * boolean)} or {@link #getData(String, org.apache.zookeeper.Watcher, - * org.apache.zookeeper.data.Stat, boolean)}. + * watcher using this method before calling {@link #exists(String, Watcher)} or {@link #getData(String, Watcher, Stat)}. */ public Watcher wrapWatcher(final Watcher watcher) { if (watcher == null || watcher instanceof ProcessWatchWithExecutor) return watcher; @@ -352,67 +309,45 @@ 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, boolean retryOnConnLoss) + public Stat exists(final String path, final Watcher watcher) throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.exists(path, wrapWatcher(watcher))); - } else { - return keeper.exists(path, wrapWatcher(watcher)); - } + return runWithCorrectThrows( + "checking exists", + () -> client.checkExists().usingWatcher(wrapWatcher(watcher)).forPath(path)); } /** Returns true if path exists */ - public Boolean exists(final String path, boolean retryOnConnLoss) + public Boolean exists(final String path) throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.exists(path, null) != null); - } else { - return keeper.exists(path, null) != null; - } + return runWithCorrectThrows( + "checking exists", + () -> client.checkExists().forPath(path) != null); } /** Returns children of the node at the path */ - public List getChildren(final String path, final Watcher watcher, boolean retryOnConnLoss) + public List getChildren(final String path, final Watcher watcher) throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.getChildren(path, wrapWatcher(watcher))); - } else { - return keeper.getChildren(path, wrapWatcher(watcher)); - } + return runWithCorrectThrows( + "getting children", + () -> client.getChildren().usingWatcher(wrapWatcher(watcher)).forPath(path)); } /** Returns children of the node at the path */ public List getChildren( - final String path, final Watcher watcher, Stat stat, boolean retryOnConnLoss) + final String path, final Watcher watcher, Stat stat) throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation( - () -> keeper.getChildren(path, wrapWatcher(watcher), stat)); - } else { - return keeper.getChildren(path, wrapWatcher(watcher), stat); - } + return runWithCorrectThrows( + "getting children", + () -> client.getChildren().storingStatIn(stat).usingWatcher(wrapWatcher(watcher)).forPath(path)); } /** Returns node's data */ public byte[] getData( - final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) + final String path, final Watcher watcher, final Stat stat) throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.getData(path, wrapWatcher(watcher), stat)); - } else { - return keeper.getData(path, wrapWatcher(watcher), stat); - } - } - - /** Returns node's state */ - public Stat setData( - final String path, final byte data[], final int version, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.setData(path, data, version)); - } else { - return keeper.setData(path, data, version); - } + return runWithCorrectThrows( + "getting data", + () -> client.getData().storingStatIn(stat).usingWatcher(wrapWatcher(watcher)).forPath(path)); } public void atomicUpdate(String path, Function editor) @@ -427,14 +362,14 @@ public void atomicUpdate(String path, BiFunction editor) byte[] zkData = null; Stat s = new Stat(); try { - if (exists(path, true)) { - zkData = getData(path, null, s, true); + if (exists(path)) { + zkData = getData(path, null, s); modified = editor.apply(s, zkData); if (modified == null) { // no change , no need to persist return; } - setData(path, modified, s.getVersion(), true); + setData(path, modified, s.getVersion()); break; } else { modified = editor.apply(s, null); @@ -442,7 +377,7 @@ public void atomicUpdate(String path, BiFunction editor) // no change , no need to persist return; } - create(path, modified, CreateMode.PERSISTENT, true); + create(path, modified, CreateMode.PERSISTENT); break; } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { @@ -453,15 +388,11 @@ public void atomicUpdate(String path, BiFunction editor) /** Returns path of created node */ public String create( - final String path, final byte[] data, final CreateMode createMode, boolean retryOnConnLoss) + final String path, final byte[] data, final CreateMode createMode) throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation( - () -> keeper.create(path, data, zkACLProvider.getACLsToAdd(path), createMode)); - } else { - List acls = zkACLProvider.getACLsToAdd(path); - return keeper.create(path, data, acls, createMode); - } + return runWithCorrectThrows( + "creating znode", + () -> client.create().withMode(createMode).forPath(path, data)); } /** @@ -470,36 +401,35 @@ public String create( *

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, boolean retryOnConnLoss) + public void makePath(String path) throws KeeperException, InterruptedException { - makePath(path, null, CreateMode.PERSISTENT, retryOnConnLoss); + makePath(path, null, CreateMode.PERSISTENT); } - public void makePath(String path, boolean failOnExists, boolean retryOnConnLoss) + public void makePath(String path, boolean failOnExists) throws KeeperException, InterruptedException { - makePath(path, null, CreateMode.PERSISTENT, null, failOnExists, retryOnConnLoss, 0); + makePath(path, null, CreateMode.PERSISTENT, null, failOnExists); } - public void makePath(String path, Path data, boolean failOnExists, boolean retryOnConnLoss) + public void makePath(String path, Path data, boolean failOnExists) throws IOException, KeeperException, InterruptedException { makePath( path, Files.readAllBytes(data), CreateMode.PERSISTENT, null, - failOnExists, - retryOnConnLoss, - 0); + failOnExists + ); } - public void makePath(String path, Path data, boolean retryOnConnLoss) + public void makePath(String path, Path data) throws IOException, KeeperException, InterruptedException { - makePath(path, Files.readAllBytes(data), retryOnConnLoss); + makePath(path, Files.readAllBytes(data)); } - public void makePath(String path, CreateMode createMode, boolean retryOnConnLoss) + public void makePath(String path, CreateMode createMode) throws KeeperException, InterruptedException { - makePath(path, null, createMode, retryOnConnLoss); + makePath(path, null, createMode); } /** @@ -507,9 +437,9 @@ public void makePath(String path, CreateMode createMode, boolean retryOnConnLoss * * @param data to set on the last zkNode */ - public void makePath(String path, byte[] data, boolean retryOnConnLoss) + public void makePath(String path, byte[] data) throws KeeperException, InterruptedException { - makePath(path, data, CreateMode.PERSISTENT, retryOnConnLoss); + makePath(path, data, CreateMode.PERSISTENT); } /** @@ -520,23 +450,15 @@ public void makePath(String path, byte[] data, boolean retryOnConnLoss) * * @param data to set on the last zkNode */ - public void makePath(String path, byte[] data, CreateMode createMode, boolean retryOnConnLoss) + public void makePath(String path, byte[] data, CreateMode createMode) throws KeeperException, InterruptedException { - makePath(path, data, createMode, null, retryOnConnLoss); + makePath(path, data, createMode, null); } - /** - * Creates the path in ZooKeeper, creating each node as necessary. - * - *

e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, - * each will be created. - * - * @param data to set on the last zkNode - */ public void makePath( - String path, byte[] data, CreateMode createMode, Watcher watcher, boolean retryOnConnLoss) + String zkPath, CreateMode createMode, Watcher watcher) throws KeeperException, InterruptedException { - makePath(path, data, createMode, watcher, true, retryOnConnLoss, 0); + makePath(zkPath, null, createMode, watcher); } /** @@ -548,14 +470,9 @@ public void makePath( * @param data to set on the last zkNode */ public void makePath( - String path, - byte[] data, - CreateMode createMode, - Watcher watcher, - boolean failOnExists, - boolean retryOnConnLoss) + String path, byte[] data, CreateMode createMode, Watcher watcher) throws KeeperException, InterruptedException { - makePath(path, data, createMode, watcher, failOnExists, retryOnConnLoss, 0); + makePath(path, data, createMode, watcher, true); } /** @@ -564,11 +481,6 @@ public void makePath( *

e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, * each will be created. * - *

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

Note: retryOnConnLoss is only respected for the final node - nodes before that are always - * retried on connection loss. - * *

Note: if failOnExists == false then we will always overwrite the existing data with the * given data */ @@ -577,117 +489,83 @@ public void makePath( byte[] data, CreateMode createMode, Watcher watcher, - boolean failOnExists, - boolean retryOnConnLoss, - int skipPathParts) + boolean failOnExists) throws KeeperException, InterruptedException { log.debug("makePath: {}", path); - boolean retry = true; - - if (path.startsWith("/")) { - path = path.substring(1, path.length()); - } - String[] paths = path.split("/"); - StringBuilder sbPath = new StringBuilder(); - for (int i = 0; i < paths.length; i++) { - String pathPiece = paths[i]; - sbPath.append("/").append(pathPiece); - if (i < skipPathParts) { - continue; - } - byte[] bytes = null; - final String currentPath = sbPath.toString(); - - CreateMode mode = CreateMode.PERSISTENT; - if (i == paths.length - 1) { - mode = createMode; - bytes = data; - if (!retryOnConnLoss) retry = false; - } - try { - if (retry) { - final CreateMode finalMode = mode; - final byte[] finalBytes = bytes; - zkCmdExecutor.retryOperation( - () -> { - keeper.create( - currentPath, finalBytes, zkACLProvider.getACLsToAdd(currentPath), finalMode); - return null; - }); - } else { - keeper.create(currentPath, bytes, zkACLProvider.getACLsToAdd(currentPath), mode); - } - } catch (NoAuthException e) { - // in auth cases, we may not have permission for an earlier part of a path, which is fine - if (i == paths.length - 1 || !exists(currentPath, retryOnConnLoss)) { - - throw e; - } - } catch (NodeExistsException e) { - if (log.isDebugEnabled()) { - log.debug("Node exists: {}", e.getPath()); - } - - if (!failOnExists && i == paths.length - 1) { - // TODO: version ? for now, don't worry about race - setData(currentPath, data, -1, retryOnConnLoss); - // set new watch - exists(currentPath, watcher, retryOnConnLoss); - return; - } - - // ignore unless it's the last node in the path - if (i == paths.length - 1) { - throw e; - } - } - } - } - - public void makePath( - String zkPath, CreateMode createMode, Watcher watcher, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { - makePath(zkPath, null, createMode, watcher, retryOnConnLoss); + var createBuilder = client.create(); + if (!failOnExists) { + createBuilder.orSetData(); + } + runWithCorrectThrows( + "making path", + () -> { + createBuilder.creatingParentsIfNeeded().withMode(createMode).forPath(path, data); + return client.checkExists().usingWatcher(wrapWatcher(watcher)).forPath(path); + }); } /** Write data to ZooKeeper. */ - public Stat setData(String path, byte[] data, boolean retryOnConnLoss) + public Stat setData(String path, byte[] data) throws KeeperException, InterruptedException { - return setData(path, data, -1, retryOnConnLoss); + return setData(path, data, -1); } /** * Write file to ZooKeeper - default system encoding used. - * - * @param path path to upload file to e.g. /solr/conf/solrconfig.xml + * @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, boolean retryOnConnLoss) + public Stat setData(String path, Path data) throws IOException, KeeperException, InterruptedException { if (log.isDebugEnabled()) { log.debug("Write to ZooKeeper: {} to {}", data.toAbsolutePath(), path); } - return setData(path, Files.readAllBytes(data), retryOnConnLoss); + return setData(path, Files.readAllBytes(data)); } - public List multi(final Iterable ops, boolean retryOnConnLoss) - throws InterruptedException, KeeperException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.multi(ops)); - } else { - return keeper.multi(ops); + /** Returns node's state */ + public Stat setData( + final String path, final byte[] data, final int version) + throws KeeperException, InterruptedException { + return runWithCorrectThrows( + "setting data", + () -> client.setData().withVersion(version).forPath(path, data)); + } + + @FunctionalInterface + public interface CuratorOpBuilder { + CuratorOp build(TransactionOp startingOp) throws Exception; + + default CuratorOp buildWithoutThrows(TransactionOp startingOp) { + try { + return build(startingOp); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } } } + public List multi(CuratorOpBuilder... ops) + throws InterruptedException, KeeperException { + return multi(Arrays.asList(ops)); + } + + public List multi(final List ops) + throws InterruptedException, KeeperException { + return runWithCorrectThrows( + "executing multi-transaction", + () -> client.transaction().forOperations(ops.stream().map(op -> op.buildWithoutThrows(client.transactionOp())).collect(Collectors.toList()))); + } + /** 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, true); - List children = getChildren(path, null, true); + byte[] data = getData(path, null, null); + List children = getChildren(path, null); StringBuilder dent = new StringBuilder(); - for (int i = 0; i < indent; i++) { - dent.append(" "); - } + dent.append(" ".repeat(Math.max(0, indent))); string.append(dent).append(path).append(" (").append(children.size()).append(")").append(NEWL); if (data != null) { String dataString = new String(data, StandardCharsets.UTF_8); @@ -727,8 +605,7 @@ public void close() { try { closeCallbackExecutor(); } finally { - connManager.close(); - closeKeeper(keeper); + client.close(); } assert ObjectReleaseTracker.release(this); } @@ -737,32 +614,26 @@ public boolean isClosed() { return isClosed || (higherLevelIsClosed != null && higherLevelIsClosed.isClosed()); } - /** Allows package private classes to update volatile ZooKeeper. */ - void updateKeeper(SolrZooKeeper keeper) throws InterruptedException { - SolrZooKeeper oldKeeper = this.keeper; - this.keeper = keeper; - if (oldKeeper != null) { - oldKeeper.close(); - } - // we might have been closed already - if (isClosed) this.keeper.close(); + public SolrZooKeeper getSolrZooKeeper() { + return null; } - public SolrZooKeeper getSolrZooKeeper() { - return keeper; + public long getZkSessionId() { + if (isConnected()) { + try { + return client.getZookeeperClient().getZooKeeper().getSessionId(); + } catch (Exception ignored) { } + } + return -1; } - private void closeKeeper(SolrZooKeeper keeper) { - if (keeper != null) { + public int getZkSessionTimeout() { + if (isConnected()) { try { - keeper.close(); - } catch (InterruptedException e) { - // Restore the interrupted status - Thread.currentThread().interrupt(); - log.error("", e); - throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e); - } + return client.getZookeeperClient().getZooKeeper().getSessionTimeout(); + } catch (Exception ignored) { } } + return 0; } private void closeCallbackExecutor() { @@ -773,7 +644,7 @@ private void closeCallbackExecutor() { } try { - ExecutorUtil.shutdownAndAwaitTermination(zkConnManagerCallbackExecutor); + ExecutorUtil.shutdownAndAwaitTermination(zkConnectionListenerCallbackExecutor); } catch (Exception e) { SolrException.log(log, e); } @@ -806,6 +677,13 @@ public String getZkServerAddress() { return zkServerAddress; } + /** + * @return the address of the zookeeper cluster + */ + public String getChroot() { + return client.getNamespace(); + } + /** * Gets the raw config node /zookeeper/config as returned by server. Response may look like * @@ -820,37 +698,27 @@ public String getZkServerAddress() { * string */ public String getConfig() { - try { - Stat stat = new Stat(); - keeper.sync(ZooDefs.CONFIG_NODE, null, null); - byte[] data = keeper.getConfig(false, stat); - if (data == null || data.length == 0) { - return ""; - } - return new String(data, StandardCharsets.UTF_8); - } catch (NoNodeException nne) { + QuorumVerifier currentConfig = client.getCurrentConfig(); + if (currentConfig == null) { log.debug("Zookeeper does not have the /zookeeper/config znode, assuming old ZK version"); return ""; - } catch (KeeperException | InterruptedException ex) { - throw new SolrException( - SolrException.ErrorCode.SERVER_ERROR, "Failed to get config from zookeeper", ex); + } else { + return currentConfig.toString(); } } - public ZkACLProvider getZkACLProvider() { - return zkACLProvider; + public ACLProvider getZkACLProvider() { + return aclProvider; } /** * @return the ACLs on a single node in ZooKeeper. */ - public List getACL(String path, Stat stat, boolean retryOnConnLoss) + public List getACL(String path, Stat stat) throws KeeperException, InterruptedException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.getACL(path, stat)); - } else { - return keeper.getACL(path, stat); - } + return runWithCorrectThrows( + "getting acls", + () -> client.getACL().storingStatIn(stat).forPath(path)); } /** @@ -858,16 +726,13 @@ public List getACL(String path, Stat stat, boolean retryOnConnLoss) * * @param path path to set ACL on e.g. /solr/conf/solrconfig.xml * @param acls a list of {@link ACL}s to be applied - * @param retryOnConnLoss true if the command should be retried on connection loss * @return the stat of the node */ - public Stat setACL(String path, List acls, boolean retryOnConnLoss) + public Stat setACL(String path, List acls) throws InterruptedException, KeeperException { - if (retryOnConnLoss) { - return zkCmdExecutor.retryOperation(() -> keeper.setACL(path, acls, -1)); - } else { - return keeper.setACL(path, acls, -1); - } + return runWithCorrectThrows( + "setting acls", + () -> client.setACL().withVersion(-1).withACL(acls).forPath(path)); } /** @@ -882,14 +747,33 @@ public void updateACLs(final String root) throws KeeperException, InterruptedExc ZkMaintenanceUtils.VISIT_ORDER.VISIT_POST, path -> { try { - setACL(path, getZkACLProvider().getACLsToAdd(path), true); - log.debug("Updated ACL on {}", path); + runWithCorrectThrows( + "updating acls", + () -> client.setACL().withACL(null).forPath(path)); } catch (NoNodeException ignored) { // If a node was deleted, don't bother trying to set ACLs on it. } }); } + @FunctionalInterface + private static interface SupplierWithException { + T get() throws Exception; + } + + private T runWithCorrectThrows(String action, SupplierWithException func) throws KeeperException, InterruptedException { + try { + return func.get(); + } catch (KeeperException | RuntimeException e) { + throw e; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw e; + } catch (Exception e) { + throw new RuntimeException("Exception occurred while " + action, e); + } + } + // Some pass-throughs to allow less code disruption to other classes that use SolrZkClient. public void clean(String path) throws InterruptedException, KeeperException { ZkMaintenanceUtils.clean(this, path); @@ -956,11 +840,7 @@ private final class ProcessWatchWithExecutor implements Watcher { // see below f public void process(final WatchedEvent event) { log.debug("Submitting job to respond to event {}", event); try { - if (watcher instanceof ConnectionManager) { - zkConnManagerCallbackExecutor.submit(() -> watcher.process(event)); - } else { - zkCallbackExecutor.submit(() -> watcher.process(event)); - } + zkCallbackExecutor.submit(() -> watcher.process(event)); } catch (RejectedExecutionException e) { // If not a graceful shutdown if (!isClosed()) { diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java index 3d67cd16833..f541f115b96 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java @@ -42,21 +42,24 @@ public class VMParamsAllAndReadonlyDigestZkACLProvider extends SecurityAwareZkAC final String zkDigestReadonlyPasswordVMParamName; final Properties credentialsProps; - public VMParamsAllAndReadonlyDigestZkACLProvider() { + public VMParamsAllAndReadonlyDigestZkACLProvider(String chroot) { this( VMParamsSingleSetCredentialsDigestZkCredentialsProvider .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, VMParamsSingleSetCredentialsDigestZkCredentialsProvider .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME, - DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME); + DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME, + chroot); } public VMParamsAllAndReadonlyDigestZkACLProvider( String zkDigestAllUsernameVMParamName, String zkDigestAllPasswordVMParamName, String zkDigestReadonlyUsernameVMParamName, - String zkDigestReadonlyPasswordVMParamName) { + String zkDigestReadonlyPasswordVMParamName, + String chroot) { + super(chroot); this.zkDigestAllUsernameVMParamName = zkDigestAllUsernameVMParamName; this.zkDigestAllPasswordVMParamName = zkDigestAllPasswordVMParamName; this.zkDigestReadonlyUsernameVMParamName = zkDigestReadonlyUsernameVMParamName; diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkACLProvider.java index 4b3ad36ed42..9c27efbb3f4 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkACLProvider.java @@ -17,9 +17,16 @@ package org.apache.solr.common.cloud; import java.util.List; + +import org.apache.curator.framework.api.ACLProvider; import org.apache.zookeeper.data.ACL; -public interface ZkACLProvider { +public interface ZkACLProvider extends ACLProvider { List getACLsToAdd(String zNodePath); + + @Override + default List getAclForPath(String zNodePath) { + return getACLsToAdd(zNodePath); + } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java index 1ca3b55da04..7c578b4b100 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.concurrent.TimeoutException; import org.apache.solr.common.SolrException; -import org.apache.solr.common.cloud.ZkCredentialsProvider.ZkCredentials; import org.apache.zookeeper.Watcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java index 06134f1fbae..b0a0ddcb9bc 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java @@ -142,7 +142,7 @@ public void ensureExists( int skipPathParts) throws KeeperException, InterruptedException { - if (zkClient.exists(path, true)) { + if (zkClient.exists(path)) { return; } try { diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java index b34998d32a0..35d5e49de88 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java @@ -16,28 +16,11 @@ */ package org.apache.solr.common.cloud; -import java.util.Collection; +import org.apache.curator.framework.AuthInfo; -public interface ZkCredentialsProvider { - - public class ZkCredentials { - String scheme; - byte[] auth; - - public ZkCredentials(String scheme, byte[] auth) { - super(); - this.scheme = scheme; - this.auth = auth; - } +import java.util.List; - public String getScheme() { - return scheme; - } - - public byte[] getAuth() { - return auth; - } - } +public interface ZkCredentialsProvider { - Collection getCredentials(); + List getCredentials(); } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java index 40da28d255d..15d20a99985 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java @@ -83,7 +83,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, true)) { + for (String node : zkClient.getChildren(root, null)) { if (node.equals("zookeeper") == false) { sb.append(node).append(System.lineSeparator()); } @@ -137,7 +137,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, true).size() != 0) { + if (zkClient.getChildren(src, null).size() != 0) { throw new SolrServerException( "Zookeeper node " + src + " has children and recurse is false"); } @@ -169,7 +169,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, true).size() > 0) { + if (zkClient.getChildren(src, null).size() > 0) { downloadFromZK(zkClient, src, Paths.get(dst)); return; } @@ -179,7 +179,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, true); + byte[] data = zkClient.getData(src, null, null); Path filename = Paths.get(dst); Files.createDirectories(filename.getParent()); log.info("Writing file {}", filename); @@ -217,9 +217,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, true).size() == 0) { - zkClient.makePath(destName, false, true); - zkClient.setData(destName, zkClient.getData(src, null, null, true), true); + if (zkClient.getChildren(src, null).size() == 0) { + zkClient.makePath(destName, false); + zkClient.setData(destName, zkClient.getData(src, null, null)); } else { traverseZkTree(zkClient, src, VISIT_ORDER.VISIT_PRE, new ZkCopier(zkClient, src, destName)); } @@ -236,8 +236,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, true)) { - if (zkClient.exists(dst + "/" + node, true) == false) { + for (String node : zkClient.getChildren(src, null)) { + if (zkClient.exists(dst + "/" + node) == false) { throw new SolrServerException( "mv command did not move node " + dst + "/" + node + " source left intact"); } @@ -256,7 +256,7 @@ public static void clean(SolrZkClient zkClient, String path) try { if (!znode.equals("/")) { try { - zkClient.delete(znode, -1, true); + zkClient.delete(znode, -1); } catch (KeeperException.NotEmptyException e) { clean(zkClient, znode); } @@ -295,7 +295,7 @@ public static void clean(SolrZkClient zkClient, String path, Predicate f for (String subpath : paths) { if (!subpath.equals("/")) { try { - zkClient.delete(subpath, -1, true); + zkClient.delete(subpath, -1); } catch (KeeperException.NotEmptyException | KeeperException.NoNodeException e) { // expected } @@ -339,11 +339,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) 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, true)) { - zkClient.setData(zkNode, file, true); + && zkClient.exists(zkNode)) { + zkClient.setData(zkNode, file); } else if (file == rootPath) { // We are only uploading a single file, preVisitDirectory was never called - zkClient.makePath(zkNode, file, false, true); + zkClient.makePath(zkNode, file, false); } else { // Skip path parts here because they should have been created during // preVisitDirectory @@ -374,7 +374,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) try { if (dir.equals(rootPath)) { // Make sure the root path exists, including potential parents - zkClient.makePath(zkNode, true); + zkClient.makePath(zkNode); } else { // Skip path parts here because they should have been created during previous visits int pathParts = dir.getNameCount() + partsOffset; @@ -397,13 +397,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, true); + Stat znodeStat = zkClient.exists(zkPath, null); 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, true); + byte[] data = zkClient.getData(zkPath, null, null); if (data != null && data.length > 0) { // There are apparently basically empty ZNodes. log.info("Writing file {}", file); Files.write(file, data); @@ -415,7 +415,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, true); + List children = zkClient.getChildren(zkPath, null); // 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) { @@ -482,7 +482,7 @@ public static void traverseZkTree( } List children; try { - children = zkClient.getChildren(path, null, true); + children = zkClient.getChildren(path, null); } catch (KeeperException.NoNodeException r) { return; } @@ -569,7 +569,7 @@ class ZkCopier implements ZkMaintenanceUtils.ZkVisitor { 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, true); - zkClient.setData(finalDestination, zkClient.getData(path, null, null, true), true); + zkClient.makePath(finalDestination, false); + zkClient.setData(finalDestination, zkClient.getData(path, null, null)); } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java index b25e5f53c20..f572d25cc80 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java @@ -486,9 +486,9 @@ public void process(WatchedEvent event) { byte[] data = "{}".getBytes(StandardCharsets.UTF_8); if (EventType.NodeDeleted.equals(event.getType())) { // Node deleted, just recreate watch without attempting a read - SOLR-9679 - getZkClient().exists(SOLR_SECURITY_CONF_PATH, this, true); + getZkClient().exists(SOLR_SECURITY_CONF_PATH, this); } else { - data = getZkClient().getData(SOLR_SECURITY_CONF_PATH, this, stat, true); + data = getZkClient().getData(SOLR_SECURITY_CONF_PATH, this, stat); } try { callback.call(new Pair<>(data, stat)); @@ -508,8 +508,8 @@ public void process(WatchedEvent event) { log.warn("Interrupted", e); } } - }, - true); + } + ); } /** @@ -577,7 +577,7 @@ private void refreshCollectionList(Watcher watcher) throws KeeperException, Inte synchronized (refreshCollectionListLock) { List children = null; try { - children = zkClient.getChildren(COLLECTIONS_ZKNODE, watcher, true); + children = zkClient.getChildren(COLLECTIONS_ZKNODE, watcher); } catch (KeeperException.NoNodeException e) { log.warn("Error fetching collection names: ", e); // fall through @@ -671,7 +671,7 @@ public synchronized DocCollection get(boolean allowCached) { if (cachedDocCollection != null) { Stat freshStats = null; try { - freshStats = zkClient.exists(getCollectionPath(collName), null, true); + freshStats = zkClient.exists(getCollectionPath(collName), null); } catch (Exception e) { } if (freshStats != null @@ -709,7 +709,7 @@ private void refreshLiveNodes(Watcher watcher) throws KeeperException, Interrupt synchronized (refreshLiveNodesLock) { SortedSet newLiveNodes; try { - List nodeList = zkClient.getChildren(LIVE_NODES_ZKNODE, watcher, true); + List nodeList = zkClient.getChildren(LIVE_NODES_ZKNODE, watcher); newLiveNodes = new TreeSet<>(nodeList); } catch (KeeperException.NoNodeException e) { newLiveNodes = emptySortedSet(); @@ -1063,7 +1063,7 @@ private void loadClusterProperties() { try { byte[] data = zkClient.getData( - ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat(), true); + ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat()); @SuppressWarnings("unchecked") Map properties = (Map) Utils.fromJSON(data); this.clusterProperties = @@ -1079,7 +1079,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, true) == null) + if (zkClient.exists(ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher) == null) return; } } @@ -1192,7 +1192,7 @@ private VersionedCollectionProps fetchCollectionProperties(String collection, Wa while (true) { try { Stat stat = new Stat(); - byte[] data = zkClient.getData(znodePath, watcher, stat, true); + byte[] data = zkClient.getData(znodePath, watcher, stat); @SuppressWarnings("unchecked") Map props = (Map) Utils.fromJSON(data); return new VersionedCollectionProps(stat.getVersion(), props); @@ -1204,7 +1204,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, true); + Stat exists = zkClient.exists(znodePath, watcher); 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. @@ -1228,9 +1228,9 @@ public ConfigData getSecurityProps(boolean getFresh) { } try { Stat stat = new Stat(); - if (getZkClient().exists(SOLR_SECURITY_CONF_PATH, true)) { + if (getZkClient().exists(SOLR_SECURITY_CONF_PATH)) { final byte[] data = - getZkClient().getData(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, stat, true); + getZkClient().getData(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, stat); return data != null && data.length > 0 ? new ConfigData((Map) Utils.fromJSON(data), stat.getVersion()) : null; @@ -1330,7 +1330,7 @@ private void refreshAndWatchChildren() throws KeeperException, InterruptedExcept Stat stat = new Stat(); List replicaStates = null; try { - replicaStates = zkClient.getChildren(collectionPath, this, stat, true); + replicaStates = zkClient.getChildren(collectionPath, this, stat); PerReplicaStates newStates = new PerReplicaStates(collectionPath, stat.getCversion(), replicaStates); DocCollection oldState = watchedCollectionStates.get(coll); @@ -1558,7 +1558,7 @@ private DocCollection fetchCollectionState(String coll, Watcher watcher) }); try { Stat stat = new Stat(); - byte[] data = zkClient.getData(collectionPath, watcher, stat, true); + byte[] data = zkClient.getData(collectionPath, watcher, stat); // This factory method can detect a missing configName and supply it by reading it from the // old ZK location. @@ -1572,7 +1572,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, true); + Stat exists = zkClient.exists(collectionPath, watcher); 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. @@ -2122,7 +2122,7 @@ public Aliases getAliases() { private void refreshAliases(AliasesManager watcher) throws KeeperException, InterruptedException { synchronized (getUpdateLock()) { constructState(Collections.emptySet()); - zkClient.exists(ALIASES, watcher, true); + zkClient.exists(ALIASES, watcher); } aliasesManager.update(); } @@ -2181,7 +2181,7 @@ public void applyModificationAndExportToZk(UnaryOperator op) { try { try { final Stat stat = - getZkClient().setData(ALIASES, modAliasesJson, curAliases.getZNodeVersion(), true); + getZkClient().setData(ALIASES, modAliasesJson, curAliases.getZNodeVersion()); setIfNewer(Aliases.fromJSON(modAliasesJson, stat.getVersion())); return; } catch (KeeperException.BadVersionException e) { @@ -2223,7 +2223,7 @@ public boolean update() throws KeeperException, InterruptedException { // Call sync() first to ensure the subsequent read (getData) is up to date. zkClient.getSolrZooKeeper().sync(ALIASES, null, null); Stat stat = new Stat(); - final byte[] data = zkClient.getData(ALIASES, null, stat, true); + final byte[] data = zkClient.getData(ALIASES, null, stat); return setIfNewer(Aliases.fromJSON(data, stat.getVersion())); } @@ -2239,7 +2239,7 @@ public void process(WatchedEvent event) { // re-register the watch Stat stat = new Stat(); - final byte[] data = zkClient.getData(ALIASES, this, stat, true); + final byte[] data = zkClient.getData(ALIASES, this, stat); // note: it'd be nice to avoid possibly needlessly parsing if we don't update aliases but // not a big deal setIfNewer(Aliases.fromJSON(data, stat.getVersion())); diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java index 032b132b6a3..c2850970377 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java @@ -698,7 +698,7 @@ public static Map getJson( SolrZkClient zkClient, String path, boolean retryOnConnLoss) throws KeeperException, InterruptedException { try { - byte[] bytes = zkClient.getData(path, null, null, retryOnConnLoss); + byte[] bytes = zkClient.getData(path, null, null); if (bytes != null && bytes.length > 0) { return (Map) Utils.fromJSON(bytes); } 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 9b12452bc6a..50705d23ce5 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 @@ -69,7 +69,7 @@ public void testHttpClusterStateWithSSL() throws Exception { byte[] stateJsonBytes = cluster .getZkClient() - .getData(ZkStateReader.getCollectionPath(collectionId), null, null, true); + .getData(ZkStateReader.getCollectionPath(collectionId), null, null); 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 c885bde0bfa..29dc3a38bbf 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 @@ -83,7 +83,7 @@ public void testCloudClientUploads() throws Exception { assertTrue( "List of uploaded configs does not contain 'testconfig'", - cluster.getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + "testconfig", true)); + cluster.getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + "testconfig")); } finally { cluster.shutdown(); diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java index 086c9159091..0736ee403b0 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java @@ -75,17 +75,17 @@ public void setUp() throws Exception { try (SolrZkClient client = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { // Set up chroot - client.makePath("/solr", false, true); + client.makePath("/solr", false); } defaultClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - defaultClient.makePath(PATH, true); + defaultClient.makePath(PATH); aclClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT) { @Override - protected ZkACLProvider createZkACLProvider() { - return new DefaultZkACLProvider() { + protected ZkACLProvider createACLProvider() { + return new DefaultACLProvider() { @Override protected List createGlobalACLsToAdd() { try { @@ -201,11 +201,11 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null, true); + "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); ZkStateReader.from(solrClient) .getZkClient() .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null, true); + "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bam") .process(solrClient); @@ -220,11 +220,11 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null, true); + "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); ZkStateReader.from(solrClient) .getZkClient() .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null, true); + "/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bang") .process(solrClient); @@ -241,7 +241,7 @@ public void process(WatchedEvent event) { private static boolean canRead(SolrZkClient zkClient, String path) throws KeeperException, InterruptedException { try { - zkClient.getData(path, null, null, true); + zkClient.getData(path, null, null); return true; } catch (KeeperException.NoAuthException e) { return false; diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java index 942002dd764..9938c48cd55 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestPerReplicaStates.java @@ -91,13 +91,13 @@ public void testEntries() { public void testReplicaStateOperations() throws Exception { String root = "/testReplicaStateOperations"; - cluster.getZkClient().create(root, null, CreateMode.PERSISTENT, true); + cluster.getZkClient().create(root, null, CreateMode.PERSISTENT); ImmutableList states = ImmutableList.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, true); + cluster.getZkClient().create(root + "/" + state, null, CreateMode.PERSISTENT); } ZkStateReader zkStateReader = cluster.getZkStateReader(); @@ -112,7 +112,7 @@ public void testReplicaStateOperations() throws Exception { rs = PerReplicaStates.fetch(root, zkStateReader.getZkClient(), null); assertEquals(4, rs.states.size()); assertTrue(rs.cversion >= 6); - assertEquals(6, cluster.getZkClient().getChildren(root, null, true).size()); + assertEquals(6, cluster.getZkClient().getChildren(root, null).size()); ops = PerReplicaStatesOps.flipState("R1", State.DOWN, rs); assertEquals(4, ops.ops.size()); diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java index eccc739729d..f93b9613b82 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java @@ -146,7 +146,7 @@ public void testUploadWithACL() throws IOException { final String writeablePassword = "writeable"; ZkACLProvider aclProvider = - new DefaultZkACLProvider() { + new DefaultACLProvider() { @Override protected List createGlobalACLsToAdd() { try { @@ -240,7 +240,7 @@ public void testBootstrapConf() throws IOException, KeeperException, Interrupted System.setProperty("zkHost", zkServer.getZkAddress()); SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); - zkClient.makePath("/solr", false, true); + zkClient.makePath("/solr", false); cc.setCoreConfigService(new ZkConfigSetService(zkClient)); assertFalse(cc.getConfigSetService().checkConfigExists("collection1")); ConfigSetService.bootstrapConf(cc); @@ -260,7 +260,7 @@ protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { } @Override - protected ZkACLProvider createZkACLProvider() { + protected ZkACLProvider createACLProvider() { return aclProvider; } }; diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java index b2c92e86cde..c51d92cf027 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java @@ -80,18 +80,18 @@ public void testClean() String data2 = "myStringData2"; String longData = "myLongStringData"; // create zk nodes that have the same path length - zkClient.create("/myPath", null, CreateMode.PERSISTENT, true); - zkClient.create(path, null, CreateMode.PERSISTENT, true); + zkClient.create("/myPath", null, CreateMode.PERSISTENT); + zkClient.create(path, null, CreateMode.PERSISTENT); zkClient.create( - path + "/file1.txt", data1.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); - zkClient.create(path + "/nothing.txt", null, CreateMode.PERSISTENT, true); + path + "/file1.txt", data1.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); + zkClient.create(path + "/nothing.txt", null, CreateMode.PERSISTENT); zkClient.create( - path + "/file2.txt", data2.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); + path + "/file2.txt", data2.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); zkClient.create( path + "/some_longer_file2.txt", longData.getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); /* RUN */ // delete all nodes that contain "file" @@ -133,9 +133,9 @@ public void testPaths() { @Test public void testTraverseZkTree() throws Exception { try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 10000)) { - zkClient.makePath("/testTraverseZkTree/1/1", true, true); - zkClient.makePath("/testTraverseZkTree/1/2", false, true); - zkClient.makePath("/testTraverseZkTree/2", false, true); + zkClient.makePath("/testTraverseZkTree/1/1", true); + zkClient.makePath("/testTraverseZkTree/1/2", false); + zkClient.makePath("/testTraverseZkTree/2", false); assertEquals( Arrays.asList( "/testTraverseZkTree", @@ -163,7 +163,7 @@ public void testOneByteFile() throws Exception { try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 10000)) { byte[] oneByte = new byte[1]; oneByte[0] = 0x30; - zkClient.makePath("/test1byte/one", oneByte, true); + zkClient.makePath("/test1byte/one", oneByte); Path tmpDest = Paths.get(createTempDir().toFile().getAbsolutePath(), "MustBeOne"); ZkMaintenanceUtils.downloadFromZK(zkClient, "/test1byte/one", tmpDest); 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 6c11cc72e8b..567f0712ea4 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -934,7 +934,7 @@ public static void deleteCore() { CoreContainer cc = h.getCoreContainer(); if (!cc.getCores().isEmpty() && cc.isZooKeeperAware()) { try { - cc.getZkController().getZkClient().exists("/", false); + cc.getZkController().getZkClient().exists("/"); } 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 371281d534a..9c71ff610d1 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 @@ -268,7 +268,7 @@ private void bringDownShardIndexSomeDocsAndRecover() throws Exception { int oldLiveNodes = ZkStateReader.from(cloudClient) .getZkClient() - .getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true) + .getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null) .size(); assertEquals(5, oldLiveNodes); 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 b138b902c67..b08af52ec25 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 @@ -269,18 +269,18 @@ public void distribSetUp() throws Exception { .create( ZkStateReader.CLUSTER_PROPS, Utils.toJSON(Collections.singletonMap(URL_SCHEME, HTTPS)), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT + ); } catch (KeeperException.NodeExistsException e) { ZkNodeProps props = ZkNodeProps.load( zkStateReader .getZkClient() - .getData(ZkStateReader.CLUSTER_PROPS, null, null, true)); + .getData(ZkStateReader.CLUSTER_PROPS, null, null)); zkStateReader .getZkClient() .setData( - ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS)), true); + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS))); } } } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java index 35247b5b3a5..55f7d03f559 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java @@ -83,20 +83,20 @@ public void setUp() throws Exception { null, null, null); - zkClient.makePath("/solr", false, true); + zkClient.makePath("/solr", false); zkClient.close(); zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.close(); clearSecuritySystemProperties(); @@ -112,12 +112,12 @@ public void setUp() throws Exception { "digest", ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT + ); zkClient.close(); if (log.isInfoEnabled()) { @@ -211,15 +211,15 @@ public void testRepairACL() throws Exception { .getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, false); - assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); + "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); + assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); } setSecuritySystemProperties(); try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { ZkController.createClusterZkNodes(zkClient); - assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); + assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); } useReadonlyCredentials(); @@ -227,7 +227,7 @@ public void testRepairACL() throws Exception { new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { NoAuthException e = assertThrows( - NoAuthException.class, () -> zkClient.getData("/security.json", null, null, false)); + NoAuthException.class, () -> zkClient.getData("/security.json", null, null)); assertEquals("/security.json", e.getPath()); } } @@ -268,27 +268,27 @@ protected static void doTest( boolean setData, boolean delete) throws Exception { - doTest(getData, () -> zkClient.getData(path, null, null, false)); - doTest(list, () -> zkClient.getChildren(path, null, false)); + doTest(getData, () -> zkClient.getData(path, null, null)); + doTest(list, () -> zkClient.getChildren(path, null)); doTest( create, () -> { - zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT, false); - zkClient.delete(path + "/subnode", -1, false); + zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT); + zkClient.delete(path + "/subnode", -1); }); doTest( create, () -> { - zkClient.makePath(path + "/subnode/subsubnode", false); - zkClient.delete(path + "/subnode/subsubnode", -1, false); - zkClient.delete(path + "/subnode", -1, false); + zkClient.makePath(path + "/subnode/subsubnode"); + zkClient.delete(path + "/subnode/subsubnode", -1); + zkClient.delete(path + "/subnode", -1); }); - doTest(setData, () -> zkClient.setData(path, (byte[]) null, false)); + doTest(setData, () -> zkClient.setData(path, (byte[]) null)); // Actually about the ACLs on /solr, but that is protected - doTest(delete, () -> zkClient.delete(path, -1, false)); + doTest(delete, () -> zkClient.delete(path, -1)); } interface ExceptingRunnable { diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java index 020445142c9..83c99b255bd 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java @@ -149,7 +149,7 @@ public void expireSession(final JettySolrRunner jetty) { if (cores != null) { monkeyLog("expire session for " + jetty.getLocalPort() + " !"); causeConnectionLoss(jetty); - long sessionId = cores.getZkController().getZkClient().getSolrZooKeeper().getSessionId(); + long sessionId = cores.getZkController().getZkClient().getZkSessionId(); zkServer.expire(sessionId); } } 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 f1c51012d5e..b6c735be823 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 @@ -334,17 +334,17 @@ public MiniSolrCloudCluster( try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { - if (!zkClient.exists("/solr/solr.xml", true)) { - zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset()), true); + if (!zkClient.exists("/solr/solr.xml")) { + zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset())); if (jettyConfig.sslConfig != null && jettyConfig.sslConfig.isSSLMode()) { zkClient.makePath( "/solr" + ZkStateReader.CLUSTER_PROPS, - "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8), - true); + "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8) + ); } if (securityJson.isPresent()) { // configure Solr security zkClient.makePath( - "/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset()), true); + "/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset())); } } } @@ -687,8 +687,8 @@ public void deleteAllConfigSets() throws Exception { getZkClient() .delete( ZkConfigSetService.CONFIGS_ZKNODE + "/" + configSet + "/" + DEFAULT_FILENAME, - -1, - true); + -1 + ); } catch (KeeperException.NoNodeException nne) { } new ConfigSetAdminRequest.Delete().setConfigSetName(configSet).process(solrClient); @@ -740,7 +740,7 @@ public SolrZkClient getZkClient() { public void zkSetData(String path, byte[] data, boolean retryOnConnLoss) throws InterruptedException { try { - getZkClient().setData(path, data, -1, retryOnConnLoss); + getZkClient().setData(path, data, -1); } catch (KeeperException e) { throw new SolrException(ErrorCode.UNKNOWN, "Failed writing to Zookeeper", e); } @@ -795,7 +795,7 @@ public void expireZkSession(JettySolrRunner jetty) { if (cores != null) { SolrZkClient zkClient = cores.getZkController().getZkClient(); zkClient.getSolrZooKeeper().closeCnxn(); - long sessionId = zkClient.getSolrZooKeeper().getSessionId(); + long sessionId = zkClient.getZkSessionId(); zkServer.expire(sessionId); if (log.isInfoEnabled()) { log.info("Expired zookeeper session {} from node {}", sessionId, jetty.getBaseUrl()); 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 9ab12d46854..356342410d7 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,7 +29,7 @@ public MockSolrZkClient() { } @Override - public Boolean exists(final String path, boolean retryOnConnLoss) + public Boolean exists(final String path) throws KeeperException, InterruptedException { return false; @@ -37,7 +37,7 @@ public Boolean exists(final String path, boolean retryOnConnLoss) @Override public byte[] getData( - final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) + final String path, final Watcher watcher, final Stat stat) 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 ed6d8badb63..c4e2c534908 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 @@ -49,7 +49,6 @@ import org.apache.solr.util.TimeOut; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.Op; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.data.Stat; @@ -486,7 +485,7 @@ public String getZkAddress(String chroot) { */ public void ensurePathExists(String path) throws IOException { try (SolrZkClient client = new SolrZkClient(getZkHost(), 10000)) { - client.makePath(path, null, CreateMode.PERSISTENT, null, false, true, 0); + client.makePath(path, null, CreateMode.PERSISTENT, null, false); } catch (InterruptedException | KeeperException e) { e.printStackTrace(); throw new IOException("Error checking path " + path, SolrZkClient.checkInterrupted(e)); @@ -839,7 +838,7 @@ public static void putConfig( if (log.isInfoEnabled()) { log.info("put {} to {}", file.toAbsolutePath(), destPath); } - zkClient.makePath(destPath, file, false, true); + zkClient.makePath(destPath, file, false); } // static to share with distrib test @@ -849,42 +848,15 @@ public void buildZooKeeper(Path solrhome, String config, String schema) throws E props.put("configName", "conf1"); final ZkNodeProps zkProps = new ZkNodeProps(props); - List ops = new ArrayList<>(2); - String path = "/collections"; - ops.add( - Op.create( - path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT)); - path = "/collections/collection1"; - ops.add( - Op.create( - path, - Utils.toJSON(zkProps), - chRootClient.getZkACLProvider().getACLsToAdd(path), - CreateMode.PERSISTENT)); - path = "/collections/collection1/shards"; - ops.add( - Op.create( - path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT)); - path = "/collections/control_collection"; - ops.add( - Op.create( - path, - Utils.toJSON(zkProps), - chRootClient.getZkACLProvider().getACLsToAdd(path), - CreateMode.PERSISTENT)); - path = "/collections/control_collection/shards"; - ops.add( - Op.create( - path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT)); - path = "/configs"; - ops.add( - Op.create( - path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT)); - path = "/configs/conf1"; - ops.add( - Op.create( - path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT)); - chRootClient.multi(ops, true); + chRootClient.multi( + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections", null), + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/collection1", Utils.toJSON(zkProps)), + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/collection1/shards", null), + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/control_collection", Utils.toJSON(zkProps)), + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/control_collection/shards", null), + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/configs", null), + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/configs/conf1", null) + ); // for now, always upload the config and schema to the canonical names putConfig("conf1", chRootClient, solrhome, config, "solrconfig.xml"); @@ -902,7 +874,7 @@ public void buildZooKeeper(Path solrhome, String config, String schema) throws E } public void makeSolrZkNode() throws Exception { - rootClient.makePath("/solr", false, true); + rootClient.makePath("/solr", false); } public void tryCleanSolrZkNode() throws Exception { @@ -910,7 +882,7 @@ public void tryCleanSolrZkNode() throws Exception { } void tryCleanPath(String path) throws Exception { - if (rootClient.exists(path, true)) { + if (rootClient.exists(path)) { 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 d56895fa174..f36aa41b322 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 @@ -128,7 +128,7 @@ public void testCreationAndDeletion() throws Exception { assertFalse( cluster .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); } @Test @@ -136,7 +136,7 @@ public void deleteCollectionRemovesStaleZkCollectionsNode() throws Exception { String collectionName = "out_of_sync_collection"; // manually create a collections zknode - cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true); + cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName); CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient()); @@ -146,7 +146,7 @@ public void deleteCollectionRemovesStaleZkCollectionsNode() throws Exception { assertFalse( cluster .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); } @Test @@ -184,7 +184,7 @@ public void deleteCollectionOnlyInZk() throws Exception { final String collectionName = "onlyinzk"; // create the collections node, but nothing else - cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true); + cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName); // delete via API - should remove collections node CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient()); From e31dea0a8619e341d177e6e0168e8964caa62a56 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Mon, 21 Mar 2022 17:48:20 -0400 Subject: [PATCH 02/14] It compiles --- .../org/apache/solr/cloud/DistributedMap.java | 4 +- .../org/apache/solr/cloud/LeaderElector.java | 9 +- .../java/org/apache/solr/cloud/Overseer.java | 7 +- .../solr/cloud/OverseerElectionContext.java | 4 +- .../cloud/ShardLeaderElectionContextBase.java | 3 +- .../org/apache/solr/cloud/ZkController.java | 16 +- .../apache/solr/cloud/ZkDistributedQueue.java | 7 +- .../handler/admin/CollectionsHandler.java | 12 +- .../schema/ManagedIndexSchemaFactory.java | 5 +- .../solr/cloud/ConnectionManagerTest.java | 173 ----------- .../solr/cloud/DistributedQueueTest.java | 12 +- .../apache/solr/cloud/ZkSolrClientTest.java | 52 +--- .../impl/SolrClientNodeStateProvider.java | 2 +- .../solr/common/cloud/ConnectionManager.java | 284 ------------------ .../solr/common/cloud/DefaultACLProvider.java | 26 +- .../cloud/DefaultConnectionStrategy.java | 73 ----- .../cloud/DefaultZkCredentialsProvider.java | 14 +- .../cloud/SecurityAwareZkACLProvider.java | 4 +- .../solr/common/cloud/SolrZkClient.java | 87 +++++- ...redentialsDigestZkCredentialsProvider.java | 8 +- .../cloud/ZkClientConnectionStrategy.java | 123 -------- .../solr/common/cloud/ZkCmdExecutor.java | 163 ---------- .../solr/common/cloud/ZkMaintenanceUtils.java | 20 +- .../org/apache/solr/common/util/Utils.java | 4 +- .../solr/common/cloud/SolrZkClientTest.java | 31 +- .../common/cloud/TestZkConfigSetService.java | 90 +++--- 26 files changed, 211 insertions(+), 1022 deletions(-) delete mode 100644 solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java delete mode 100644 solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java delete mode 100644 solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java delete mode 100644 solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java delete mode 100644 solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java 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 543bc2eefa1..5ea160b06c0 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java @@ -22,7 +22,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.NodeExistsException; @@ -42,9 +41,8 @@ public class DistributedMap { public DistributedMap(SolrZkClient zookeeper, String dir) { this.dir = dir; - ZkCmdExecutor cmdExecutor = new ZkCmdExecutor(zookeeper.getZkClientTimeout()); try { - cmdExecutor.ensureExists(dir, zookeeper); + zookeeper.ensureExists(dir); } catch (KeeperException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); } catch (InterruptedException e) { 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 2023663060d..142ed50ad70 100644 --- a/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java +++ b/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java @@ -29,7 +29,6 @@ import org.apache.solr.common.AlreadyClosedException; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.solr.common.cloud.ZooKeeperException; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -62,8 +61,6 @@ public class LeaderElector { protected SolrZkClient zkClient; - private ZkCmdExecutor zkCmdExecutor; - private volatile ElectionContext context; private ElectionWatcher watcher; @@ -73,13 +70,11 @@ public class LeaderElector { public LeaderElector(SolrZkClient zkClient) { this.zkClient = zkClient; - zkCmdExecutor = new ZkCmdExecutor(zkClient.getZkClientTimeout()); } public LeaderElector( SolrZkClient zkClient, ContextKey key, Map electionContexts) { this.zkClient = zkClient; - zkCmdExecutor = new ZkCmdExecutor(zkClient.getZkClientTimeout()); this.electionContexts = electionContexts; this.contextKey = key; } @@ -367,10 +362,10 @@ public void process(WatchedEvent event) { public void setup(final ElectionContext context) throws InterruptedException, KeeperException { String electZKPath = context.electionPath + LeaderElector.ELECTION_NODE; if (context instanceof OverseerElectionContext) { - zkCmdExecutor.ensureExists(electZKPath, zkClient); + zkClient.ensureExists(electZKPath, null, CreateMode.PERSISTENT); } else { // we use 2 param so that replica won't create /collection/{collection} if it doesn't exist - zkCmdExecutor.ensureExists(electZKPath, (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); + zkClient.ensureExists(electZKPath, null, CreateMode.PERSISTENT, 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 544131d0b46..04923f58421 100644 --- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java +++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java @@ -52,7 +52,6 @@ import org.apache.solr.common.SolrCloseable; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.ClusterState; -import org.apache.solr.common.cloud.ConnectionManager; import org.apache.solr.common.cloud.DocCollection; import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.cloud.SolrZkClient; @@ -1021,11 +1020,7 @@ ZkDistributedQueue getStateUpdateQueue(Stats zkStats) { "/overseer/queue", zkStats, STATE_UPDATE_MAX_QUEUE, - new ConnectionManager.IsClosed() { - public boolean isClosed() { - return Overseer.this.isClosed() || zkController.getCoreContainer().isShutDown(); - } - }); + () -> Overseer.this.isClosed() || zkController.getCoreContainer().isShutDown()); } /** 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 60a30183913..952217cae80 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerElectionContext.java @@ -23,7 +23,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.util.Utils; import org.apache.zookeeper.CreateMode; @@ -43,8 +42,7 @@ public OverseerElectionContext( this.overseer = overseer; this.zkClient = zkClient; try { - new ZkCmdExecutor(zkClient.getZkClientTimeout()) - .ensureExists(Overseer.OVERSEER_ELECT, zkClient); + zkClient.ensureExists(Overseer.OVERSEER_ELECT); } catch (KeeperException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); } catch (InterruptedException e) { diff --git a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java index a28be615369..893310ca05d 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java @@ -77,11 +77,10 @@ public ShardLeaderElectionContextBase( this.collection = collection; String parent = ZkMaintenanceUtils.getZkParent(leaderPath); - ZkCmdExecutor zcmd = new ZkCmdExecutor(30000); // only if /collections/{collection} exists already do we succeed in creating this path log.info("make sure parent is created {}", parent); try { - zcmd.ensureExists(parent, (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); + zkClient.ensureExists(parent, null, CreateMode.PERSISTENT); } catch (KeeperException e) { throw new RuntimeException(e); } catch (InterruptedException e) { 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 fb8dc106c43..77a594ec23e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -318,7 +318,6 @@ public ZkController( this.leaderConflictResolveWait = cloudConfig.getLeaderConflictResolveWait(); this.clientTimeout = cloudConfig.getZkClientTimeout(); - DefaultConnectionStrategy strat = new DefaultConnectionStrategy(); String zkACLProviderClass = cloudConfig.getZkACLProviderClass(); ZkACLProvider zkACLProvider = null; if (zkACLProviderClass != null && zkACLProviderClass.trim().length() > 0) { @@ -908,20 +907,19 @@ boolean isClosed() { */ public static void createClusterZkNodes(SolrZkClient zkClient) throws KeeperException, InterruptedException, IOException { - ZkCmdExecutor cmdExecutor = new ZkCmdExecutor(zkClient.getZkClientTimeout()); - cmdExecutor.ensureExists(ZkStateReader.LIVE_NODES_ZKNODE, zkClient); - cmdExecutor.ensureExists(ZkStateReader.NODE_ROLES, zkClient); + zkClient.ensureExists(ZkStateReader.LIVE_NODES_ZKNODE); + zkClient.ensureExists(ZkStateReader.NODE_ROLES); for (NodeRoles.Role role : NodeRoles.Role.values()) { - cmdExecutor.ensureExists(NodeRoles.getZNodeForRole(role), zkClient); + zkClient.ensureExists(NodeRoles.getZNodeForRole(role)); for (String mode : role.supportedModes()) { - cmdExecutor.ensureExists(NodeRoles.getZNodeForRoleMode(role, mode), zkClient); + zkClient.ensureExists(NodeRoles.getZNodeForRoleMode(role, mode)); } } - cmdExecutor.ensureExists(ZkStateReader.COLLECTIONS_ZKNODE, zkClient); - cmdExecutor.ensureExists(ZkStateReader.ALIASES, zkClient); + zkClient.ensureExists(ZkStateReader.COLLECTIONS_ZKNODE); + zkClient.ensureExists(ZkStateReader.ALIASES); byte[] emptyJson = "{}".getBytes(StandardCharsets.UTF_8); - cmdExecutor.ensureExists(ZkStateReader.SOLR_SECURITY_CONF_PATH, emptyJson, zkClient); + zkClient.ensureExists(ZkStateReader.SOLR_SECURITY_CONF_PATH, emptyJson); repairSecurityJson(zkClient); } 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 e9b4ea1ba23..d30774a2fad 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java @@ -38,9 +38,8 @@ import org.apache.solr.client.solrj.cloud.DistributedQueue; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; -import org.apache.solr.common.cloud.ConnectionManager.IsClosed; +import org.apache.solr.common.cloud.SolrZkClient.IsClosed; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.solr.common.util.Pair; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -136,10 +135,8 @@ public ZkDistributedQueue( IsClosed higherLevelIsClosed) { this.dir = dir; - ZkCmdExecutor cmdExecutor = - new ZkCmdExecutor(zookeeper.getZkClientTimeout(), higherLevelIsClosed); try { - cmdExecutor.ensureExists(dir, zookeeper); + zookeeper.ensureExists(dir); } catch (KeeperException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); } catch (InterruptedException e) { diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java index dd0881295ca..95d01c5328f 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java @@ -89,7 +89,6 @@ import org.apache.solr.common.cloud.Replica.State; import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.solr.common.cloud.ZkCoreNodeProps; import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.cloud.ZkStateReader; @@ -423,10 +422,9 @@ public Category getCategory() { private static void createSysConfigSet(CoreContainer coreContainer) throws KeeperException, InterruptedException { SolrZkClient zk = coreContainer.getZkController().getZkStateReader().getZkClient(); - ZkCmdExecutor cmdExecutor = new ZkCmdExecutor(zk.getZkClientTimeout()); - cmdExecutor.ensureExists(ZkStateReader.CONFIGS_ZKNODE, zk); - cmdExecutor.ensureExists( - ZkStateReader.CONFIGS_ZKNODE + "/" + CollectionAdminParams.SYSTEM_COLL, zk); + zk.ensureExists(ZkStateReader.CONFIGS_ZKNODE); + zk.ensureExists( + ZkStateReader.CONFIGS_ZKNODE + "/" + CollectionAdminParams.SYSTEM_COLL); try { String path = @@ -435,7 +433,7 @@ private static void createSysConfigSet(CoreContainer coreContainer) IOUtils.toByteArray( CollectionsHandler.class.getResourceAsStream("/SystemCollectionSchema.xml")); assert data != null && data.length > 0; - cmdExecutor.ensureExists(path, data, CreateMode.PERSISTENT, zk); + zk.ensureExists(path, data, CreateMode.PERSISTENT); path = ZkStateReader.CONFIGS_ZKNODE + "/" @@ -445,7 +443,7 @@ private static void createSysConfigSet(CoreContainer coreContainer) IOUtils.toByteArray( CollectionsHandler.class.getResourceAsStream("/SystemCollectionSolrConfig.xml")); assert data != null && data.length > 0; - cmdExecutor.ensureExists(path, data, CreateMode.PERSISTENT, zk); + zk.ensureExists(path, data, CreateMode.PERSISTENT); } catch (IOException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); } 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 cadbc54c9f1..d38994edab3 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java @@ -30,7 +30,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.core.ConfigSetService; @@ -474,13 +473,11 @@ private void zkUgradeToManagedSchema() { // Rename the non-managed schema znode in ZooKeeper final String nonManagedSchemaPath = zkLoader.getConfigSetZkPath() + "/" + resourceName; try { - ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(zkController.getClientTimeout()); 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); final String upgradedSchemaPath = nonManagedSchemaPath + UPGRADED_SCHEMA_EXTENSION; - zkCmdExecutor.ensureExists(upgradedSchemaPath, zkController.getZkClient()); - zkController.getZkClient().setData(upgradedSchemaPath, bytes); + zkController.getZkClient().makePath(upgradedSchemaPath, bytes, CreateMode.PERSISTENT, null, false); // Then delete the non-managed schema znode if (zkController.getZkClient().exists(nonManagedSchemaPath)) { try { diff --git a/solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java b/solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java deleted file mode 100644 index 250f42568e8..00000000000 --- a/solr/core/src/test/org/apache/solr/cloud/ConnectionManagerTest.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.cloud; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeoutException; -import org.apache.lucene.util.LuceneTestCase.Slow; -import org.apache.solr.SolrTestCaseJ4; -import org.apache.solr.common.cloud.ConnectionManager; -import org.apache.solr.common.cloud.DefaultConnectionStrategy; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.util.SolrNamedThreadFactory; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.Watcher.Event.EventType; -import org.apache.zookeeper.Watcher.Event.KeeperState; -import org.junit.Ignore; -import org.junit.Test; - -@Slow -public class ConnectionManagerTest extends SolrTestCaseJ4 { - - static final int TIMEOUT = 3000; - - @Ignore - public void testConnectionManager() throws Exception { - - // setup a SolrZkClient to do some getBaseUrlForNodeName testing - Path zkDir = createTempDir("zkData"); - ZkTestServer server = new ZkTestServer(zkDir); - try { - server.run(); - - SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT); - ConnectionManager cm = zkClient.getConnectionManager(); - try { - assertFalse(cm.isLikelyExpired()); - - zkClient.getSolrZooKeeper().closeCnxn(); - - long sessionId = zkClient.getZkSessionId(); - server.expire(sessionId); - Thread.sleep(TIMEOUT); - - assertTrue(cm.isLikelyExpired()); - } finally { - cm.close(); - zkClient.close(); - } - } finally { - server.shutdown(); - } - } - - public void testLikelyExpired() throws Exception { - - // setup a SolrZkClient to do some getBaseUrlForNodeName testing - Path zkDir = createTempDir("zkData"); - ZkTestServer server = new ZkTestServer(zkDir); - try { - server.run(); - - SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT); - ConnectionManager cm = zkClient.getConnectionManager(); - try { - assertFalse(cm.isLikelyExpired()); - assertTrue(cm.isConnectedAndNotClosed()); - cm.process(new WatchedEvent(EventType.None, KeeperState.Disconnected, "")); - // disconnect shouldn't immediately set likelyExpired - assertFalse(cm.isConnectedAndNotClosed()); - assertFalse(cm.isLikelyExpired()); - - // but it should after the timeout - Thread.sleep((long) (zkClient.getZkClientTimeout() * 1.5)); - assertFalse(cm.isConnectedAndNotClosed()); - assertTrue(cm.isLikelyExpired()); - - // even if we disconnect immediately again - cm.process(new WatchedEvent(EventType.None, KeeperState.Disconnected, "")); - assertFalse(cm.isConnectedAndNotClosed()); - assertTrue(cm.isLikelyExpired()); - - // reconnect -- should no longer be likely expired - cm.process(new WatchedEvent(EventType.None, KeeperState.SyncConnected, "")); - assertFalse(cm.isLikelyExpired()); - assertTrue(cm.isConnectedAndNotClosed()); - } finally { - cm.close(); - zkClient.close(); - } - } finally { - server.shutdown(); - } - } - - @Test - public void testReconnectWhenZkDisappeared() throws Exception { - ScheduledExecutorService executor = - Executors.newSingleThreadScheduledExecutor( - new SolrNamedThreadFactory("connectionManagerTest")); - - // setup a SolrZkClient to do some getBaseUrlForNodeName testing - Path zkDir = createTempDir("zkData"); - ZkTestServer server = new ZkTestServer(zkDir); - try { - server.run(); - - MockZkClientConnectionStrategy strat = new MockZkClientConnectionStrategy(); - SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT, strat, null); - ConnectionManager cm = zkClient.getConnectionManager(); - - try { - assertFalse(cm.isLikelyExpired()); - assertTrue(cm.isConnectedAndNotClosed()); - - // reconnect -- should no longer be likely expired - cm.process(new WatchedEvent(EventType.None, KeeperState.Expired, "")); - Thread.sleep(5000); - assertFalse(cm.isLikelyExpired()); - assertTrue(cm.isConnectedAndNotClosed()); - assertTrue(strat.isExceptionThrow()); - } finally { - cm.close(); - zkClient.close(); - executor.shutdown(); - } - } finally { - server.shutdown(); - } - } - - private static class MockZkClientConnectionStrategy extends DefaultConnectionStrategy { - int called = 0; - boolean exceptionThrown = false; - - @Override - public void reconnect( - final String serverAddress, - final int zkClientTimeout, - final Watcher watcher, - final ZkUpdate updater) - throws IOException, InterruptedException, TimeoutException { - - if (called++ < 1) { - exceptionThrown = true; - throw new IOException("Testing"); - } - - super.reconnect(serverAddress, zkClientTimeout, watcher, updater); - } - - public boolean isExceptionThrow() { - return exceptionThrown; - } - } -} 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 89514be3e32..967707d56a6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java @@ -18,6 +18,7 @@ import java.nio.charset.Charset; import java.util.NoSuchElementException; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -25,6 +26,7 @@ import java.util.function.Predicate; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.cloud.DistributedQueue; +import org.apache.solr.common.cloud.OnDisconnect; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.util.ExecutorUtil; import org.apache.solr.common.util.SolrNamedThreadFactory; @@ -288,13 +290,13 @@ public void testPeekElements() throws Exception { } private void forceSessionExpire() throws InterruptedException, TimeoutException { + final CountDownLatch hasDisconnected = new CountDownLatch(1); + zkClient.getCuratorFramework().getConnectionStateListenable().addListener((OnDisconnect) hasDisconnected::countDown); long sessionId = zkClient.getZkSessionId(); zkServer.expire(sessionId); - zkClient.getConnectionManager().waitForDisconnected(10000); - zkClient.getConnectionManager().waitForConnected(10000); - for (int i = 0; i < 100 && !zkClient.isConnected(); ++i) { - Thread.sleep(50); - } + hasDisconnected.await(10, TimeUnit.SECONDS); + assertEquals("ZK Client did not disconnect after session expiration", 0, hasDisconnected.getCount()); + zkClient.getCuratorFramework().blockUntilConnected(10, TimeUnit.SECONDS); assertTrue(zkClient.isConnected()); assertNotEquals(sessionId, zkClient.getZkSessionId()); } 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 e9eec23700a..11066fe5a1f 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java @@ -27,7 +27,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkCmdExecutor; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; @@ -212,37 +211,6 @@ public void run() { } } - public void testZkCmdExectutor() throws Exception { - Path zkDir = createTempDir("zkData"); - ZkTestServer server = null; - - try { - server = new ZkTestServer(zkDir); - server.run(); - - final int timeout = random().nextInt(10000) + 5000; - - ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(timeout); - final long start = System.nanoTime(); - expectThrows( - KeeperException.SessionExpiredException.class, - () -> { - zkCmdExecutor.retryOperation( - () -> { - if (System.nanoTime() - start - > TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS)) { - throw new KeeperException.SessionExpiredException(); - } - throw new KeeperException.ConnectionLossException(); - }); - }); - } finally { - if (server != null) { - server.shutdown(); - } - } - } - @Test @SuppressWarnings({"try"}) public void testMultipleWatchesAsync() throws Exception { @@ -383,17 +351,14 @@ public void testSkipPathPartsOnMakePath() throws Exception { zkClient.clean("/"); - ZkCmdExecutor zkCmdExecutor = new ZkCmdExecutor(30000); expectThrows( KeeperException.NoNodeException.class, "We should not be able to create this path", () -> - zkCmdExecutor.ensureExists( + zkClient.ensureExists( "/collection/collection/leader", - (byte[]) null, - CreateMode.PERSISTENT, - zkClient, - 2)); + null, + CreateMode.PERSISTENT)); zkClient.makePath("/collection"); @@ -401,17 +366,16 @@ public void testSkipPathPartsOnMakePath() throws Exception { KeeperException.NoNodeException.class, "We should not be able to create this path", () -> - zkCmdExecutor.ensureExists( + zkClient.ensureExists( "/collections/collection/leader", (byte[]) null, CreateMode.PERSISTENT, - zkClient, 2)); zkClient.makePath("/collection/collection"); byte[] bytes = new byte[10]; - zkCmdExecutor.ensureExists( - "/collection/collection", bytes, CreateMode.PERSISTENT, zkClient, 2); + zkClient.ensureExists( + "/collection/collection", bytes, CreateMode.PERSISTENT, 2); byte[] returnedBytes = zkClient.getData("/collection/collection", null, null); @@ -419,8 +383,8 @@ public void testSkipPathPartsOnMakePath() throws Exception { zkClient.makePath("/collection/collection/leader"); - zkCmdExecutor.ensureExists( - "/collection/collection/leader", (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); + zkClient.ensureExists( + "/collection/collection/leader", (byte[]) null, CreateMode.PERSISTENT, 2); } } diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java index 07bb2c8f57a..2f5456004a9 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java @@ -347,7 +347,7 @@ public ClientSnitchCtx( @Override public Map getZkJson(String path) throws KeeperException, InterruptedException { return Utils.getJson( - zkClientClusterStateProvider.getZkStateReader().getZkClient(), path, true); + zkClientClusterStateProvider.getZkStateReader().getZkClient(), path); } /** diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java deleted file mode 100644 index 351e735ef51..00000000000 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.common.cloud; - -import static org.apache.zookeeper.Watcher.Event.KeeperState.AuthFailed; -import static org.apache.zookeeper.Watcher.Event.KeeperState.Disconnected; -import static org.apache.zookeeper.Watcher.Event.KeeperState.Expired; - -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.apache.solr.common.SolrException; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.Watcher.Event.KeeperState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ConnectionManager implements Watcher { - private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - private final String name; - - private volatile boolean connected = false; - - private final ZkClientConnectionStrategy connectionStrategy; - - private final String zkServerAddress; - - private final SolrZkClient client; - - private final OnReconnect onReconnect; - private final OnDisconnect beforeReconnect; - - private final ExecutorService executorService; - - private volatile boolean isClosed = false; - private volatile boolean isReconnecting = false; - - // Track the likely expired state - private static class LikelyExpiredState { - private static LikelyExpiredState NOT_EXPIRED = - new LikelyExpiredState(StateType.NOT_EXPIRED, 0); - private static LikelyExpiredState EXPIRED = new LikelyExpiredState(StateType.EXPIRED, 0); - - public enum StateType { - NOT_EXPIRED, // definitely not expired - EXPIRED, // definitely expired - TRACKING_TIME // not sure, tracking time of last disconnect - } - - private StateType stateType; - private long lastDisconnectTime; - - public LikelyExpiredState(StateType stateType, long lastDisconnectTime) { - this.stateType = stateType; - this.lastDisconnectTime = lastDisconnectTime; - } - - public boolean isLikelyExpired(long timeToExpire) { - return stateType == StateType.EXPIRED - || (stateType == StateType.TRACKING_TIME - && (System.nanoTime() - lastDisconnectTime - > TimeUnit.NANOSECONDS.convert(timeToExpire, TimeUnit.MILLISECONDS))); - } - } - - @FunctionalInterface - public interface IsClosed { - boolean isClosed(); - } - - private volatile LikelyExpiredState likelyExpiredState = LikelyExpiredState.EXPIRED; - - private IsClosed isClosedCheck; - - public ConnectionManager(String name, SolrZkClient client, String zkServerAddress, ZkClientConnectionStrategy strat, OnReconnect onConnect, OnDisconnect beforeReconnect, IsClosed isClosed) { - this(name, client, zkServerAddress, strat, onConnect, beforeReconnect, isClosed, null); - } - - public ConnectionManager(String name, SolrZkClient client, String zkServerAddress, ZkClientConnectionStrategy strat, OnReconnect onConnect, OnDisconnect onDisconnect, IsClosed isClosed, ExecutorService executorService) { - this.name = name; - this.client = client; - this.connectionStrategy = strat; - this.zkServerAddress = zkServerAddress; - this.onReconnect = onConnect; - this.beforeReconnect = onDisconnect; - this.isClosedCheck = isClosed; - this.executorService = executorService; - } - - private synchronized void connected() { - connected = true; - likelyExpiredState = LikelyExpiredState.NOT_EXPIRED; - notifyAll(); - } - - private synchronized void disconnected() { - connected = false; - // record the time we expired unless we are already likely expired - if (!likelyExpiredState.isLikelyExpired(0)) { - likelyExpiredState = - new LikelyExpiredState(LikelyExpiredState.StateType.TRACKING_TIME, System.nanoTime()); - } - notifyAll(); - } - - @Override - public void process(WatchedEvent event) { - if (executorService == null) { - processInternal(event); - } else { - try { - executorService.submit(() -> processInternal(event)); - } catch (RejectedExecutionException e) { - // If not a graceful shutdown - if (!isClosed()) { - throw e; - } - } - } - } - - public void processInternal(WatchedEvent event) { - if (event.getState() == AuthFailed - || event.getState() == Disconnected - || event.getState() == Expired) { - log.warn( - "Watcher {} name: {} got event {} path: {} type: {}", - this, - name, - event, - event.getPath(), - event.getType()); - } else { - if (log.isDebugEnabled()) { - log.debug( - "Watcher {} name: {} got event {} path: {} type: {}", - this, - name, - event, - event.getPath(), - event.getType()); - } - } - - if (isClosed()) { - log.debug("Client->ZooKeeper status change trigger but we are already closed"); - return; - } - - KeeperState state = event.getState(); - - if (state == KeeperState.SyncConnected) { - log.info("zkClient has connected"); - connected(); - connectionStrategy.connected(); - - if (isReconnecting && onReconnect != null) { - try { - onReconnect.command(); - } catch (Exception e) { - log.warn("Exception running onReconnect command", e); - } - } - - isReconnecting = false; - } else if (state == Expired) { - if (isClosed()) { - return; - } - // we don't call disconnected here, because we know we are expired - connected = false; - likelyExpiredState = LikelyExpiredState.EXPIRED; - isReconnecting = true; - - log.warn( - "Our previous ZooKeeper session was expired. Attempting to reconnect to recover relationship with ZooKeeper..."); - - if (beforeReconnect != null) { - try { - beforeReconnect.command(); - } catch (Exception e) { - log.warn("Exception running beforeReconnect command", e); - } - } - - try { - connectionStrategy.reconnect( - zkServerAddress, - client.getZkClientTimeout(), - this, - client::updateKeeper); - log.info("zkClient reconnect started"); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - // we must have been asked to stop - throw new RuntimeException(e); - } catch (IOException | TimeoutException e) { - log.warn("Could not reconnect to ZK", e); - } - } else if (state == KeeperState.Disconnected) { - log.warn("zkClient has disconnected"); - disconnected(); - connectionStrategy.disconnected(); - } else if (state == KeeperState.AuthFailed) { - log.warn("zkClient received AuthFailed"); - } - } - - public synchronized boolean isConnectedAndNotClosed() { - return !isClosed() && connected; - } - - public synchronized boolean isConnected() { - return connected; - } - - // we use a volatile rather than sync - // to avoid possible deadlock on shutdown - public void close() { - this.isClosed = true; - this.likelyExpiredState = LikelyExpiredState.EXPIRED; - } - - private boolean isClosed() { - return isClosed || isClosedCheck.isClosed(); - } - - public boolean isLikelyExpired() { - return isClosed() - || likelyExpiredState.isLikelyExpired((long) (client.getZkClientTimeout() * 0.90)); - } - - /** - * Wait for an established zookeeper connection - * - * @param waitForConnection time to wait, in ms - */ - public synchronized void waitForConnected(long waitForConnection) throws TimeoutException { - log.info("Waiting up to {}ms for client to connect to ZooKeeper", waitForConnection); - long expire = - System.nanoTime() + TimeUnit.NANOSECONDS.convert(waitForConnection, TimeUnit.MILLISECONDS); - long left = 1; - while (!connected && left > 0) { - if (isClosed()) { - break; - } - try { - wait(500); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - left = expire - System.nanoTime(); - } - if (!connected) { - throw new TimeoutException( - "Could not connect to ZooKeeper " - + zkServerAddress - + " within " - + waitForConnection - + " ms"); - } - log.info("Client is connected to ZooKeeper"); - } -} diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java index 90751290ac8..126eea389c9 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java @@ -24,15 +24,39 @@ public class DefaultACLProvider implements ACLProvider { - private final List globalACLsToAdd = ZooDefs.Ids.OPEN_ACL_UNSAFE; + private volatile List globalACLsToAdd; + + public DefaultACLProvider() { + this(null); + } + + public DefaultACLProvider(List globalACLsToAdd) { + this.globalACLsToAdd = globalACLsToAdd; + } @Override public List getAclForPath(String zNodePath) { + // In default (simple) implementation use the same set of ACLs for all znodes + if (globalACLsToAdd == null) { + synchronized (this) { + if (globalACLsToAdd == null) globalACLsToAdd = createGlobalACLsToAdd(); + } + } return globalACLsToAdd; } @Override public List getDefaultAcl() { + // In default (simple) implementation use the same set of ACLs for all znodes + if (globalACLsToAdd == null) { + synchronized (this) { + if (globalACLsToAdd == null) globalACLsToAdd = createGlobalACLsToAdd(); + } + } return globalACLsToAdd; } + + protected List createGlobalACLsToAdd() { + return ZooDefs.Ids.OPEN_ACL_UNSAFE; + } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java deleted file mode 100644 index d0797a67d82..00000000000 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultConnectionStrategy.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.common.cloud; - -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.concurrent.TimeoutException; -import org.apache.solr.common.AlreadyClosedException; -import org.apache.zookeeper.Watcher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** TODO: improve backoff retry impl */ -public class DefaultConnectionStrategy extends ZkClientConnectionStrategy { - - private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - @Override - public void connect(String serverAddress, int timeout, Watcher watcher, ZkUpdate updater) - throws IOException, InterruptedException, TimeoutException { - SolrZooKeeper zk = createSolrZooKeeper(serverAddress, timeout, watcher); - boolean success = false; - try { - updater.update(zk); - success = true; - } finally { - if (!success) { - zk.close(); - } - } - } - - @Override - public void reconnect( - final String serverAddress, - final int zkClientTimeout, - final Watcher watcher, - final ZkUpdate updater) - throws IOException, InterruptedException, TimeoutException { - log.warn("Connection expired - starting a new one..."); - SolrZooKeeper zk = createSolrZooKeeper(serverAddress, zkClientTimeout, watcher); - boolean success = false; - try { - updater.update(zk); - success = true; - log.info("Reconnected to ZooKeeper"); - } catch (AlreadyClosedException e) { - - } finally { - if (!success) { - try { - zk.close(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } -} diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java index 3b8ee1bb769..4557e834a2a 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java @@ -19,14 +19,15 @@ import org.apache.curator.framework.AuthInfo; import java.util.ArrayList; +import java.util.Collection; import java.util.List; public class DefaultZkCredentialsProvider implements ZkCredentialsProvider { - private final List zkCredentials; + private volatile List zkCredentials; public DefaultZkCredentialsProvider() { - this(new ArrayList<>()); + this(null); } public DefaultZkCredentialsProvider(List zkCredentials) { @@ -35,6 +36,15 @@ public DefaultZkCredentialsProvider(List zkCredentials) { @Override public List getCredentials() { + if (zkCredentials == null) { + synchronized (this) { + if (zkCredentials == null) zkCredentials = createCredentials(); + } + } return zkCredentials; } + + protected List createCredentials() { + return new ArrayList<>(); + } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java index 094007d0d6d..fd831051b80 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java @@ -26,8 +26,8 @@ public abstract class SecurityAwareZkACLProvider implements ZkACLProvider { public static final String SECURITY_ZNODE_PATH = "/security"; - private List nonSecurityACLsToAdd; - private List securityACLsToAdd; + private volatile List nonSecurityACLsToAdd; + private volatile List securityACLsToAdd; private final String chroot; diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index e81be03c921..1baf5cab708 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -45,7 +45,6 @@ import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrException; import org.apache.solr.common.StringUtils; -import org.apache.solr.common.cloud.ConnectionManager.IsClosed; import org.apache.solr.common.util.ExecutorUtil; import org.apache.solr.common.util.ObjectReleaseTracker; import org.apache.solr.common.util.SolrNamedThreadFactory; @@ -229,10 +228,6 @@ public CuratorFramework getCuratorFramework() { return client; } - public ConnectionManager getConnectionManager() { - return connManager; - } - public static final String ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME = "zkCredentialsProvider"; protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { @@ -504,6 +499,81 @@ public void makePath( }); } + /** + * Create a node if it does not exist + * + * @param path the path at which to create the znode + */ + public void ensureExists(final String path) + throws KeeperException, InterruptedException { + ensureExists(path, null); + } + + /** + * Create a node if it does not exist + * + * @param path the path at which to create the znode + * @param data the optional data to set on the znode + */ + public void ensureExists( + final String path, + final byte[] data) + throws KeeperException, InterruptedException { + ensureExists(path, data, CreateMode.PERSISTENT); + } + + /** + * Create a node if it does not exist + * + * @param path the path at which to create the znode + * @param data the optional data to set on the znode + * @param createMode the mode with which to create the znode + */ + public void ensureExists( + final String path, + final byte[] data, + CreateMode createMode) + throws KeeperException, InterruptedException { + ensureExists(path, data, createMode, 0); + } + + /** + * Create a node if it does not exist + * + * @param path the path at which to create the znode + * @param data the optional data to set on the znode + * @param createMode the mode with which to create the znode + * @param skipPathParts how many path elements to skip + */ + public void ensureExists( + final String path, + final byte[] data, + CreateMode createMode, + int skipPathParts) + throws KeeperException, InterruptedException { + if (exists(path)) { + return; + } + try { + if (skipPathParts > 0) { + int endingIndex = 0; + for (int i = 0; i < skipPathParts && endingIndex >= 0; i++) { + endingIndex = path.indexOf('/', endingIndex + 1); + } + if (endingIndex == -1 || endingIndex == path.length() - 1) { + throw new KeeperException.NoNodeException(path); + } + String startingPath = path.substring(endingIndex + 1); + if (!exists(startingPath)) { + throw new KeeperException.NoNodeException(startingPath); + } + } + makePath(path, data, createMode, null, true); + } 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 { @@ -757,7 +827,7 @@ public void updateACLs(final String root) throws KeeperException, InterruptedExc } @FunctionalInterface - private static interface SupplierWithException { + private interface SupplierWithException { T get() throws Exception; } @@ -821,6 +891,11 @@ public void downloadFromZK(String zkPath, Path dir) throws IOException { ZkMaintenanceUtils.downloadFromZK(this, zkPath, dir); } + @FunctionalInterface + public interface IsClosed { + boolean isClosed(); + } + /** * Watcher wrapper that ensures that heavy implementations of process do not interfere with our * ability to react to other watches, but also ensures that two wrappers containing equal watches diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java index 3d6b2a35ede..a478233ccbd 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.List; import java.util.Properties; + +import org.apache.curator.framework.AuthInfo; import org.apache.solr.common.SolrException; import org.apache.solr.common.StringUtils; @@ -60,8 +62,8 @@ public VMParamsSingleSetCredentialsDigestZkCredentialsProvider( } @Override - protected Collection createCredentials() { - List result = new ArrayList<>(); + protected List createCredentials() { + List result = new ArrayList<>(); String pathToFile = System.getProperty(DEFAULT_DIGEST_FILE_VM_PARAM_NAME); Properties props = @@ -71,7 +73,7 @@ protected Collection createCredentials() { String digestPassword = props.getProperty(zkDigestPasswordVMParamName); if (!StringUtils.isEmpty(digestUsername) && !StringUtils.isEmpty(digestPassword)) { result.add( - new ZkCredentials( + new AuthInfo( "digest", (digestUsername + ":" + digestPassword).getBytes(StandardCharsets.UTF_8))); } return result; diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java deleted file mode 100644 index 7c578b4b100..00000000000 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkClientConnectionStrategy.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.common.cloud; - -import java.io.IOException; -import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeoutException; -import org.apache.solr.common.SolrException; -import org.apache.zookeeper.Watcher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** */ -public abstract class ZkClientConnectionStrategy { - private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - private volatile ZkCredentialsProvider zkCredentialsToAddAutomatically; - private volatile boolean zkCredentialsToAddAutomaticallyUsed; - - private List disconnectedListeners = new ArrayList<>(); - private List connectedListeners = new ArrayList<>(); - - public abstract void connect( - String zkServerAddress, int zkClientTimeout, Watcher watcher, ZkUpdate updater) - throws IOException, InterruptedException, TimeoutException; - - public abstract void reconnect( - String serverAddress, int zkClientTimeout, Watcher watcher, ZkUpdate updater) - throws IOException, InterruptedException, TimeoutException; - - public ZkClientConnectionStrategy() { - zkCredentialsToAddAutomaticallyUsed = false; - } - - public synchronized void disconnected() { - for (DisconnectedListener listener : disconnectedListeners) { - try { - listener.disconnected(); - } catch (Exception e) { - SolrException.log(log, "", e); - } - } - } - - public synchronized void connected() { - for (ConnectedListener listener : connectedListeners) { - try { - listener.connected(); - } catch (Exception e) { - SolrException.log(log, "", e); - } - } - } - - public interface DisconnectedListener { - void disconnected(); - } - - public interface ConnectedListener { - void connected(); - } - - public synchronized void addDisconnectedListener(DisconnectedListener listener) { - disconnectedListeners.add(listener); - } - - public synchronized void removeDisconnectedListener(DisconnectedListener listener) { - disconnectedListeners.remove(listener); - } - - public synchronized void addConnectedListener(ConnectedListener listener) { - connectedListeners.add(listener); - } - - public interface ZkUpdate { - void update(SolrZooKeeper zooKeeper) throws InterruptedException, TimeoutException, IOException; - } - - public void setZkCredentialsToAddAutomatically( - ZkCredentialsProvider zkCredentialsToAddAutomatically) { - if (zkCredentialsToAddAutomaticallyUsed || (zkCredentialsToAddAutomatically == null)) - throw new RuntimeException( - "Cannot change zkCredentialsToAddAutomatically after it has been (connect or reconnect was called) used or to null"); - this.zkCredentialsToAddAutomatically = zkCredentialsToAddAutomatically; - } - - public boolean hasZkCredentialsToAddAutomatically() { - return zkCredentialsToAddAutomatically != null; - } - - public ZkCredentialsProvider getZkCredentialsToAddAutomatically() { - return zkCredentialsToAddAutomatically; - } - - protected SolrZooKeeper createSolrZooKeeper( - final String serverAddress, final int zkClientTimeout, final Watcher watcher) - throws IOException { - SolrZooKeeper result = new SolrZooKeeper(serverAddress, zkClientTimeout, watcher); - - zkCredentialsToAddAutomaticallyUsed = true; - for (ZkCredentials zkCredentials : zkCredentialsToAddAutomatically.getCredentials()) { - result.addAuthInfo(zkCredentials.getScheme(), zkCredentials.getAuth()); - } - - return result; - } -} diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java deleted file mode 100644 index b0a0ddcb9bc..00000000000 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.common.cloud; - -import java.lang.invoke.MethodHandles; -import org.apache.solr.common.AlreadyClosedException; -import org.apache.solr.common.cloud.ConnectionManager.IsClosed; -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.KeeperException.NodeExistsException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ZkCmdExecutor { - private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - private long retryDelay = 1500L; // 1 second would match timeout, so 500 ms over for padding - private int retryCount; - private double timeouts; - private IsClosed isClosed; - - public ZkCmdExecutor(int timeoutms) { - this(timeoutms, null); - } - - /** - * TODO: At this point, this should probably take a SolrZkClient in its constructor. - * - * @param timeoutms the client timeout for the ZooKeeper clients that will be used with this - * class. - */ - public ZkCmdExecutor(int timeoutms, IsClosed isClosed) { - timeouts = timeoutms / 1000.0; - this.retryCount = Math.round(0.5f * ((float) Math.sqrt(8.0f * timeouts + 1.0f) - 1.0f)) + 1; - this.isClosed = isClosed; - } - - public long getRetryDelay() { - return retryDelay; - } - - public void setRetryDelay(long retryDelay) { - this.retryDelay = retryDelay; - } - - /** Perform the given operation, retrying if the connection fails */ - public T retryOperation(ZkOperation operation) - throws KeeperException, InterruptedException { - KeeperException exception = null; - for (int i = 0; i < retryCount; i++) { - try { - if (log.isTraceEnabled()) { - log.trace("Begin zookeeper operation {}, attempt={}", operation, i); - } - if (i > 0 && isClosed()) { - throw new AlreadyClosedException(); - } - return operation.execute(); - } catch (KeeperException.ConnectionLossException e) { - if (exception == null) { - exception = e; - } - if (Thread.currentThread().isInterrupted()) { - Thread.currentThread().interrupt(); - throw new InterruptedException(); - } - if (i != retryCount - 1) { - retryDelay(i); - } - } finally { - if (log.isTraceEnabled()) { - log.trace("End zookeeper operation {}", operation); - } - } - } - throw exception; - } - - private boolean isClosed() { - return isClosed != null && isClosed.isClosed(); - } - - /** - * Create a persistent znode with no data if it does not already exist - * - * @see #ensureExists(String, byte[], CreateMode, SolrZkClient, int) - */ - public void ensureExists(String path, final SolrZkClient zkClient) - throws KeeperException, InterruptedException { - ensureExists(path, null, CreateMode.PERSISTENT, zkClient, 0); - } - - /** - * Create a persistent znode with the given data if it does not already exist - * - * @see #ensureExists(String, byte[], CreateMode, SolrZkClient, int) - */ - public void ensureExists(String path, final byte[] data, final SolrZkClient zkClient) - throws KeeperException, InterruptedException { - ensureExists(path, data, CreateMode.PERSISTENT, zkClient, 0); - } - - /** - * Create a znode with the given mode and data if it does not already exist - * - * @see #ensureExists(String, byte[], CreateMode, SolrZkClient, int) - */ - public void ensureExists( - String path, final byte[] data, CreateMode createMode, final SolrZkClient zkClient) - throws KeeperException, InterruptedException { - ensureExists(path, data, createMode, zkClient, 0); - } - - /** - * Create a node if it does not exist - * - * @param path the path at which to create the znode - * @param data the optional data to set on the znode - * @param createMode the mode with which to create the znode - * @param zkClient the client to use to check and create - * @param skipPathParts how many path elements to skip - */ - public void ensureExists( - final String path, - final byte[] data, - CreateMode createMode, - final SolrZkClient zkClient, - int skipPathParts) - throws KeeperException, InterruptedException { - - if (zkClient.exists(path)) { - return; - } - try { - zkClient.makePath(path, data, createMode, null, true, true, skipPathParts); - } catch (NodeExistsException ignored) { - // it's okay if another beats us creating the node - } - } - - /** - * Performs a retry delay if this is not the first attempt - * - * @param attemptCount the number of the attempts performed so far - */ - protected void retryDelay(int attemptCount) throws InterruptedException { - Thread.sleep((attemptCount + 1) * retryDelay); - } -} diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java index 15d20a99985..12a07239abd 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java @@ -319,11 +319,9 @@ 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 { @@ -344,18 +342,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) } else if (file == rootPath) { // We are only uploading a single file, preVisitDirectory was never called zkClient.makePath(zkNode, file, false); - } 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( @@ -376,9 +362,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) // Make sure the root path exists, including potential parents zkClient.makePath(zkNode); } 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); + zkClient.makePath(zkNode, null, true); } } catch (KeeperException.NodeExistsException ignored) { // Using fail-on-exists == false has side effect of makePath attempting to setData on diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java index c2850970377..75a749b6c58 100644 --- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java +++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java @@ -688,14 +688,12 @@ public static Map getJson(DistribStateManager distribStateManage * * @param zkClient the zookeeper client * @param path the path to the znode being read - * @param retryOnConnLoss whether to retry the operation automatically on connection loss, see - * {@link org.apache.solr.common.cloud.ZkCmdExecutor#retryOperation(ZkOperation)} * @return a Map if the node exists and contains valid JSON or an empty map if znode does not * exist or has a null data */ @SuppressWarnings({"unchecked"}) public static Map getJson( - SolrZkClient zkClient, String path, boolean retryOnConnLoss) + SolrZkClient zkClient, String path) throws KeeperException, InterruptedException { try { byte[] bytes = zkClient.getData(path, null, null); diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java index 0736ee403b0..7300a196360 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java @@ -27,6 +27,9 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.curator.framework.AuthInfo; +import org.apache.curator.framework.api.ACLProvider; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.cloud.AbstractZkTestCase; @@ -84,18 +87,12 @@ public void setUp() throws Exception { aclClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT) { @Override - protected ZkACLProvider createACLProvider() { - return new DefaultACLProvider() { - @Override - protected List createGlobalACLsToAdd() { - try { - Id id = new Id(SCHEME, DigestAuthenticationProvider.generateDigest(AUTH)); - return Collections.singletonList(new ACL(ZooDefs.Perms.ALL, id)); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } - }; + protected ACLProvider createACLProvider() { + try { + return new DefaultACLProvider(Collections.singletonList(new ACL(ZooDefs.Perms.ALL, new Id(SCHEME, DigestAuthenticationProvider.generateDigest(AUTH))))); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } } }; @@ -103,13 +100,9 @@ protected List createGlobalACLsToAdd() { new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT) { @Override protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { - return new DefaultZkCredentialsProvider() { - @Override - protected Collection createCredentials() { - return Collections.singleton( - new ZkCredentials(SCHEME, AUTH.getBytes(StandardCharsets.UTF_8))); - } - }; + return new DefaultZkCredentialsProvider( + Collections.singletonList( + new AuthInfo(SCHEME, AUTH.getBytes(StandardCharsets.UTF_8)))); } }; } diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java index f93b9613b82..5f550874fdb 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java @@ -24,9 +24,13 @@ import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Properties; + +import org.apache.curator.framework.AuthInfo; +import org.apache.curator.framework.api.ACLProvider; import org.apache.solr.SolrJettyTestBase; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.cloud.AbstractZkTestCase; @@ -136,7 +140,7 @@ public void testUploadConfig() throws IOException { } @Test - public void testUploadWithACL() throws IOException { + public void testUploadWithACL() throws IOException, NoSuchAlgorithmException { zkServer.ensurePathExists("/acl"); @@ -145,59 +149,33 @@ public void testUploadWithACL() throws IOException { final String writeableUsername = "writeable"; final String writeablePassword = "writeable"; - ZkACLProvider aclProvider = - new DefaultACLProvider() { - @Override - protected List createGlobalACLsToAdd() { - try { - List result = new ArrayList<>(); - result.add( - new ACL( - ZooDefs.Perms.ALL, - new Id( - "digest", - DigestAuthenticationProvider.generateDigest( - writeableUsername + ":" + writeablePassword)))); - result.add( - new ACL( - ZooDefs.Perms.READ, - new Id( - "digest", - DigestAuthenticationProvider.generateDigest( - readOnlyUsername + ":" + readOnlyPassword)))); - return result; - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } - }; - - ZkCredentialsProvider readonly = - new DefaultZkCredentialsProvider() { - @Override - protected Collection createCredentials() { - List credentials = new ArrayList<>(); - credentials.add( - new ZkCredentials( - "digest", - (readOnlyUsername + ":" + readOnlyPassword).getBytes(StandardCharsets.UTF_8))); - return credentials; - } - }; - - ZkCredentialsProvider writeable = - new DefaultZkCredentialsProvider() { - @Override - protected Collection createCredentials() { - List credentials = new ArrayList<>(); - credentials.add( - new ZkCredentials( - "digest", - (writeableUsername + ":" + writeablePassword) - .getBytes(StandardCharsets.UTF_8))); - return credentials; - } - }; + List acls = List.of( + new ACL( + ZooDefs.Perms.ALL, + new Id( + "digest", + DigestAuthenticationProvider.generateDigest( + writeableUsername + ":" + writeablePassword))), + new ACL( + ZooDefs.Perms.READ, + new Id( + "digest", + DigestAuthenticationProvider.generateDigest( + readOnlyUsername + ":" + readOnlyPassword)))); + ACLProvider aclProvider = new DefaultACLProvider(acls); + + List credentials = List.of( + new AuthInfo( + "digest", + (readOnlyUsername + ":" + readOnlyPassword).getBytes(StandardCharsets.UTF_8))); + ZkCredentialsProvider readonly = new DefaultZkCredentialsProvider(credentials); + + List writeableCredentials = List.of( + new AuthInfo( + "digest", + (writeableUsername + ":" + writeablePassword) + .getBytes(StandardCharsets.UTF_8))); + ZkCredentialsProvider writeable = new DefaultZkCredentialsProvider(writeableCredentials); Path configPath = createTempDir("acl-config"); Files.createFile(configPath.resolve("file1")); @@ -251,7 +229,7 @@ public void testBootstrapConf() throws IOException, KeeperException, Interrupted static SolrZkClient buildZkClient( String zkAddress, - final ZkACLProvider aclProvider, + final ACLProvider aclProvider, final ZkCredentialsProvider credentialsProvider) { return new SolrZkClient(zkAddress, 10000) { @Override @@ -260,7 +238,7 @@ protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { } @Override - protected ZkACLProvider createACLProvider() { + protected ACLProvider createACLProvider() { return aclProvider; } }; From df93241956c1de5ef09d235a1c807035ad53bd40 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Tue, 22 Mar 2022 14:01:03 -0400 Subject: [PATCH 03/14] SolrJ Tests all pass --- .../org/apache/solr/cloud/ZkController.java | 4 +- .../apache/solr/cloud/LeaderElectionTest.java | 2 +- .../hadoop/SaslZkACLProviderTest.java | 4 +- solr/server/solr/solr.xml | 2 +- solr/solrj/build.gradle | 4 +- ...rovider.java => DefaultZkACLProvider.java} | 6 +-- .../solr/common/cloud/SaslZkACLProvider.java | 3 +- .../solr/common/cloud/SolrZkClient.java | 26 +++++++++---- .../solr/common/cloud/ZkMaintenanceUtils.java | 4 +- .../solr/common/cloud/ZkStateReader.java | 37 ++++++++++--------- .../solr/common/cloud/SolrZkClientTest.java | 8 ++-- .../common/cloud/TestZkConfigSetService.java | 7 ++-- versions.lock | 8 ++-- versions.props | 2 +- 14 files changed, 65 insertions(+), 52 deletions(-) rename solr/solrj/src/java/org/apache/solr/common/cloud/{DefaultACLProvider.java => DefaultZkACLProvider.java} (92%) 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 77a594ec23e..79bdea2347a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -319,9 +319,9 @@ public ZkController( this.clientTimeout = cloudConfig.getZkClientTimeout(); String zkACLProviderClass = cloudConfig.getZkACLProviderClass(); - ZkACLProvider zkACLProvider = null; + ACLProvider zkACLProvider = null; if (zkACLProviderClass != null && zkACLProviderClass.trim().length() > 0) { - zkACLProvider = cc.getResourceLoader().newInstance(zkACLProviderClass, ZkACLProvider.class); + zkACLProvider = cc.getResourceLoader().newInstance(zkACLProviderClass, ACLProvider.class); } String zkCredentialsProviderClass = cloudConfig.getZkCredentialsProviderClass(); 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 57e6d5b2cba..bd22ed7c4ec 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java @@ -582,7 +582,7 @@ public void run() { // cleanup any threads still running for (ClientThread thread : threads) { - thread.es.zkClient.getSolrZooKeeper().close(); + thread.es.zkClient.close(); thread.close(); } 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 499a3131a1e..377c18f22fe 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 @@ -32,7 +32,7 @@ import org.apache.solr.cloud.AbstractVMParamsZkACLAndCredentialsProvidersTestBase; import org.apache.solr.cloud.AbstractZkTestCase; import org.apache.solr.cloud.ZkTestServer; -import org.apache.solr.common.cloud.DefaultACLProvider; +import org.apache.solr.common.cloud.DefaultZkACLProvider; import org.apache.solr.common.cloud.SaslZkACLProvider; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; @@ -199,7 +199,7 @@ public SolrZkClientNoACLs(String zkServerAddress, int zkClientTimeout) { @Override public ACLProvider createACLProvider() { - return new DefaultACLProvider(); + return new DefaultZkACLProvider(); } } diff --git a/solr/server/solr/solr.xml b/solr/server/solr/solr.xml index 07c2e4dc390..60031538f7f 100644 --- a/solr/server/solr/solr.xml +++ b/solr/server/solr/solr.xml @@ -46,7 +46,7 @@ ${distribUpdateSoTimeout:600000} ${distribUpdateConnTimeout:60000} ${zkCredentialsProvider:org.apache.solr.common.cloud.DefaultZkCredentialsProvider} - ${zkACLProvider:org.apache.solr.common.cloud.DefaultACLProvider} + ${zkACLProvider:org.apache.solr.common.cloud.DefaultZkACLProvider} ${distributedClusterStateUpdates:false} ${distributedCollectionConfigSetExecution:false} diff --git a/solr/solrj/build.gradle b/solr/solrj/build.gradle index ea2781136fa..cfae6859b24 100644 --- a/solr/solrj/build.gradle +++ b/solr/solrj/build.gradle @@ -36,7 +36,9 @@ dependencies { implementation 'org.apache.commons:commons-math3' - api 'org.apache.curator:curator-framework' + api('org.apache.curator:curator-framework', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) api 'org.eclipse.jetty.http2:http2-client' implementation 'org.eclipse.jetty.http2:http2-http-client-transport' diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java similarity index 92% rename from solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java rename to solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java index 126eea389c9..447a8d93802 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java @@ -22,15 +22,15 @@ import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.data.ACL; -public class DefaultACLProvider implements ACLProvider { +public class DefaultZkACLProvider implements ACLProvider { private volatile List globalACLsToAdd; - public DefaultACLProvider() { + public DefaultZkACLProvider() { this(null); } - public DefaultACLProvider(List globalACLsToAdd) { + public DefaultZkACLProvider(List globalACLsToAdd) { this.globalACLsToAdd = globalACLsToAdd; } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java index b1549853b1b..1feb218e656 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java @@ -47,6 +47,7 @@ protected List createNonSecurityACLsToAdd() { @Override protected List createSecurityACLsToAdd() { - return Collections.singletonList(new ACL(ZooDefs.Perms.ALL, new Id("sasl", superUser))); + // Must be Arrays.asList(), Zookeeper does not allow for immutable list types for ACLs + return Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id("sasl", superUser))); } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index 1baf5cab708..97eb95d84bb 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -25,8 +25,11 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; @@ -41,6 +44,8 @@ import org.apache.curator.framework.api.transaction.CuratorOp; import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.curator.framework.api.transaction.TransactionOp; +import org.apache.curator.framework.state.SessionConnectionStateErrorPolicy; +import org.apache.curator.framework.state.StandardConnectionStateErrorPolicy; import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrException; @@ -182,7 +187,7 @@ public SolrZkClient( chroot = null; } else { zkHost = zkServerAddress.substring(0, chrootIndex); - chroot = zkServerAddress.substring(chrootIndex); + chroot = zkServerAddress.substring(chrootIndex + 1); } this.higherLevelIsClosed = higherLevelIsClosed; @@ -215,9 +220,14 @@ public SolrZkClient( } client.start(); try { - client.blockUntilConnected(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + if (!client.blockUntilConnected(clientConnectTimeout, TimeUnit.MILLISECONDS)) { + throw new TimeoutException(String.format(Locale.ROOT, "Timeout while waiting for Zookeeper Client to connect: %d ms", clientConnectTimeout)); + }; + } catch (Exception e) { + if (e instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } + client.close(); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); } @@ -265,7 +275,7 @@ protected ACLProvider createACLProvider() { } } log.debug("Using default ACLProvider"); - return new DefaultACLProvider(); + return new DefaultZkACLProvider(); } /** Returns true if client is connected */ @@ -563,7 +573,7 @@ public void ensureExists( if (endingIndex == -1 || endingIndex == path.length() - 1) { throw new KeeperException.NoNodeException(path); } - String startingPath = path.substring(endingIndex + 1); + String startingPath = path.substring(0, endingIndex); if (!exists(startingPath)) { throw new KeeperException.NoNodeException(startingPath); } @@ -827,11 +837,11 @@ public void updateACLs(final String root) throws KeeperException, InterruptedExc } @FunctionalInterface - private interface SupplierWithException { + protected interface SupplierWithException { T get() throws Exception; } - private T runWithCorrectThrows(String action, SupplierWithException func) throws KeeperException, InterruptedException { + protected T runWithCorrectThrows(String action, SupplierWithException func) throws KeeperException, InterruptedException { try { return func.get(); } catch (KeeperException | RuntimeException e) { diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java index 12a07239abd..399765a6f98 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java @@ -339,7 +339,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) if (file.toFile().getName().equals(ZKNODE_DATA_FILE) && zkClient.exists(zkNode)) { zkClient.setData(zkNode, file); - } else if (file == rootPath) { + } else { // We are only uploading a single file, preVisitDirectory was never called zkClient.makePath(zkNode, file, false); } @@ -362,7 +362,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) // Make sure the root path exists, including potential parents zkClient.makePath(zkNode); } else { - zkClient.makePath(zkNode, null, true); + zkClient.makePath(zkNode, true); } } catch (KeeperException.NodeExistsException ignored) { // Using fail-on-exists == false has side effect of makePath attempting to setData on diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java index f572d25cc80..fb71ef8294f 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java @@ -284,22 +284,19 @@ public ZkStateReader(String zkServerAddress, int zkClientTimeout, int zkClientCo zkClientTimeout, zkClientConnectTimeout, // on reconnect, reload cloud info - new OnReconnect() { - @Override - public void command() { - try { - ZkStateReader.this.createClusterStateWatchersAndUpdate(); - } catch (KeeperException e) { - log.error("A ZK error has occurred", e); - throw new ZooKeeperException( - SolrException.ErrorCode.SERVER_ERROR, "A ZK error has occurred", e); - } catch (InterruptedException e) { - // Restore the interrupted status - Thread.currentThread().interrupt(); - log.error("Interrupted", e); - throw new ZooKeeperException( - SolrException.ErrorCode.SERVER_ERROR, "Interrupted", e); - } + () -> { + try { + ZkStateReader.this.createClusterStateWatchersAndUpdate(); + } catch (KeeperException e) { + log.error("A ZK error has occurred", e); + throw new ZooKeeperException( + ErrorCode.SERVER_ERROR, "A ZK error has occurred", e); + } catch (InterruptedException e) { + // Restore the interrupted status + Thread.currentThread().interrupt(); + log.error("Interrupted", e); + throw new ZooKeeperException( + ErrorCode.SERVER_ERROR, "Interrupted", e); } }); this.closeClient = true; @@ -454,13 +451,17 @@ public synchronized void createClusterStateWatchersAndUpdate() collectionPropsWatchers.computeIfAbsent(k, PropsWatcher::new).refreshAndWatch(true); }); } catch (KeeperException.NoNodeException nne) { + String noNodePath = nne.getPath(); + if (noNodePath.length() > zkClient.getCuratorFramework().getNamespace().length()) { + noNodePath = noNodePath.substring(zkClient.getCuratorFramework().getNamespace().length() + 1); + } throw new SolrException( ErrorCode.SERVICE_UNAVAILABLE, "Cannot connect to cluster at " + zkClient.getZkServerAddress() + ": cluster not found/not ready." + " Expected node '" - + nne.getPath() + + noNodePath + "' does not exist."); } } @@ -2221,7 +2222,7 @@ public void applyModificationAndExportToZk(UnaryOperator op) { public boolean update() throws KeeperException, InterruptedException { log.debug("Checking ZK for most up to date Aliases {}", ALIASES); // Call sync() first to ensure the subsequent read (getData) is up to date. - zkClient.getSolrZooKeeper().sync(ALIASES, null, null); + zkClient.runWithCorrectThrows("syncing aliases", () -> zkClient.getCuratorFramework().sync().forPath(ALIASES)); Stat stat = new Stat(); final byte[] data = zkClient.getData(ALIASES, null, stat); return setIfNewer(Aliases.fromJSON(data, stat.getVersion())); diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java index 7300a196360..571692d0505 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/SolrZkClientTest.java @@ -21,9 +21,8 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.security.NoSuchAlgorithmException; -import java.util.Collection; +import java.util.Arrays; import java.util.Collections; -import java.util.List; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -89,7 +88,8 @@ public void setUp() throws Exception { @Override protected ACLProvider createACLProvider() { try { - return new DefaultACLProvider(Collections.singletonList(new ACL(ZooDefs.Perms.ALL, new Id(SCHEME, DigestAuthenticationProvider.generateDigest(AUTH))))); + // Must be Arrays.asList(), Zookeeper does not allow for immutable list types for ACLs + return new DefaultZkACLProvider(Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id(SCHEME, DigestAuthenticationProvider.generateDigest(AUTH))))); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } @@ -245,7 +245,7 @@ private static boolean canRead(SolrZkClient zkClient, String path) public void getConfig() { // As the embedded ZK is hardcoded to standalone, there is no way to test actual config data // here - assertEquals("", defaultClient.getConfig()); + assertEquals("version=0", defaultClient.getConfig()); } @Test diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java index 5f550874fdb..8603c44215c 100644 --- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java +++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkConfigSetService.java @@ -23,9 +23,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Properties; @@ -149,7 +147,8 @@ public void testUploadWithACL() throws IOException, NoSuchAlgorithmException { final String writeableUsername = "writeable"; final String writeablePassword = "writeable"; - List acls = List.of( + // Must be Arrays.asList(), Zookeeper does not allow for immutable list types for ACLs + List acls = Arrays.asList( new ACL( ZooDefs.Perms.ALL, new Id( @@ -162,7 +161,7 @@ public void testUploadWithACL() throws IOException, NoSuchAlgorithmException { "digest", DigestAuthenticationProvider.generateDigest( readOnlyUsername + ":" + readOnlyPassword)))); - ACLProvider aclProvider = new DefaultACLProvider(acls); + ACLProvider aclProvider = new DefaultZkACLProvider(acls); List credentials = List.of( new AuthInfo( diff --git a/versions.lock b/versions.lock index b81b67c3fed..dff7fa5d19a 100644 --- a/versions.lock +++ b/versions.lock @@ -126,9 +126,9 @@ org.apache.commons:commons-exec:1.3 (2 constraints: a41056b8) org.apache.commons:commons-lang3:3.12.0 (5 constraints: 8b3d17f8) org.apache.commons:commons-math3:3.6.1 (3 constraints: d817cc9d) org.apache.commons:commons-text:1.8 (2 constraints: fe1528d0) -org.apache.curator:curator-client:4.3.0 (2 constraints: e214cba2) -org.apache.curator:curator-framework:4.3.0 (2 constraints: ff13b474) -org.apache.curator:curator-recipes:4.3.0 (1 constraints: 09050836) +org.apache.curator:curator-client:5.2.1 (2 constraints: e414fea2) +org.apache.curator:curator-framework:5.2.1 (2 constraints: 0114e574) +org.apache.curator:curator-recipes:5.2.1 (1 constraints: 0a050b36) org.apache.hadoop:hadoop-annotations:3.3.2 (1 constraints: 0a050536) org.apache.hadoop:hadoop-auth:3.3.2 (1 constraints: 0a050536) org.apache.hadoop:hadoop-client-api:3.3.2 (3 constraints: 1928ac5e) @@ -198,7 +198,7 @@ org.apache.thrift:libthrift:0.14.1 (1 constraints: 900d0134) org.apache.tika:tika-core:1.28.1 (2 constraints: d011ef10) org.apache.tika:tika-parsers:1.28.1 (1 constraints: 3e05463b) org.apache.xmlbeans:xmlbeans:3.1.0 (1 constraints: d90d973d) -org.apache.zookeeper:zookeeper:3.7.0 (2 constraints: 9e13f45e) +org.apache.zookeeper:zookeeper:3.7.0 (2 constraints: 9b13f35e) org.apache.zookeeper:zookeeper-jute:3.7.0 (2 constraints: 95120523) org.apiguardian:apiguardian-api:1.1.0 (2 constraints: 5c1b7da8) org.bitbucket.b_c:jose4j:0.7.9 (1 constraints: 12050936) diff --git a/versions.props b/versions.props index d73e19a5a27..94185138b50 100644 --- a/versions.props +++ b/versions.props @@ -40,7 +40,7 @@ org.apache.commons:commons-exec=1.3 org.apache.commons:commons-lang3=3.12.0 org.apache.commons:commons-math3=3.6.1 org.apache.commons:commons-text=1.8 -org.apache.curator:*=4.3.0 +org.apache.curator:*=5.2.1 org.apache.hadoop.thirdparty:*=1.1.1 org.apache.hadoop:*=3.3.2 org.apache.httpcomponents:httpclient=4.5.13 From 3923bf6ee005c0dbe4206a37e54260690b44785d Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Tue, 22 Mar 2022 17:04:16 -0400 Subject: [PATCH 04/14] Fix a lot of errors --- .../solr/cloud/OverseerTaskProcessor.java | 4 +- .../solr/handler/component/SearchHandler.java | 2 +- ...iddenZkACLAndCredentialsProvidersTest.java | 152 +++++++----------- .../test/org/apache/solr/cloud/ZkCLITest.java | 9 +- .../hadoop/SaslZkACLProviderTest.java | 2 +- .../solr/common/cloud/SaslZkACLProvider.java | 4 - .../cloud/SecurityAwareZkACLProvider.java | 35 +++- .../solr/common/cloud/SolrZkClient.java | 19 ++- ...ramsAllAndReadonlyDigestZkACLProvider.java | 9 +- ...sZkACLAndCredentialsProvidersTestBase.java | 78 ++++----- 10 files changed, 141 insertions(+), 173 deletions(-) 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 48ef7b2a304..c6e4b594693 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java @@ -602,7 +602,7 @@ public void run() { response.getResponse()); } success = true; - } catch (AlreadyClosedException e) { + } catch (IllegalStateException ignored) { } catch (KeeperException e) { SolrException.log(log, "", e); @@ -617,7 +617,7 @@ public void run() { // Reset task from tracking data structures so that it can be retried. try { resetTaskWithException(messageHandler, head.getId(), asyncId, taskKey, message); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException ignored) { } } diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java index 85e92ab9143..ccb6289b84c 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -302,7 +302,7 @@ public ShardHandler getAndPrepShardHandler(SolrQueryRequest req, ResponseBuilder ZkController zkController = cc.getZkController(); boolean zkConnected = zkController != null - && !zkController.getZkClient().isConnected(); + && zkController.getZkClient().isConnected(); if (requireZkConnected && false == zkConnected) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "ZooKeeper is not connected"); } else { 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 e08c123dedc..9ea929f00ef 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java @@ -45,7 +45,7 @@ public class OverriddenZkACLAndCredentialsProvidersTest extends SolrTestCaseJ4 { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static final Charset DATA_ENCODING = Charset.forName("UTF-8"); + private static final Charset DATA_ENCODING = StandardCharsets.UTF_8; protected ZkTestServer zkServer; @@ -76,51 +76,49 @@ public void setUp() throws Exception { System.setProperty("zkHost", zkServer.getZkAddress()); - SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( "connectAndAllACLUsername", "connectAndAllACLPassword", "readonlyACLUsername", - "readonlyACLPassword", - null) - .getSolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT); - zkClient.makePath("/solr", false); - zkClient.close(); + "readonlyACLPassword") + .getSolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) { + zkClient.makePath("/solr", false); + } - zkClient = + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( "connectAndAllACLUsername", "connectAndAllACLPassword", "readonlyACLUsername", - "readonlyACLPassword", - null) - .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); - zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); - zkClient.create( - SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); - zkClient.close(); - - zkClient = - new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null, null) + "readonlyACLPassword") + .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { + zkClient.create( + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + zkClient.makePath( + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + zkClient.create( + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT + ); + } + + try (SolrZkClient zkClient = + new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null) .getSolrZkClient( zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, new AuthInfo("digest", - ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(DATA_ENCODING))); - zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); - zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); - zkClient.close(); + ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(DATA_ENCODING)))) { + zkClient.create( + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + zkClient.makePath( + "/unprotectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT + ); + } if (log.isInfoEnabled()) { log.info("####SETUP_END {}", getTestName()); @@ -138,58 +136,42 @@ public void tearDown() throws Exception { @Test public void testNoCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - SolrZkClient zkClient = - new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null, null) - .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null) + .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, false, false, false, false, false, false, false, false, false, false); - } finally { - zkClient.close(); } } @Test public void testWrongCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - SolrZkClient zkClient = - new SolrZkClientFactoryUsingCompletelyNewProviders( - "connectAndAllACLUsername", "connectAndAllACLPasswordWrong", null, null, null) - .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( + "connectAndAllACLUsername", "connectAndAllACLPasswordWrong", null, null) + .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, false, false, false, false, false, false, false, false, false, false); - } finally { - zkClient.close(); } } @Test public void testAllCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - SolrZkClient zkClient = - new SolrZkClientFactoryUsingCompletelyNewProviders( - "connectAndAllACLUsername", "connectAndAllACLPassword", null, null, null) - .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( + "connectAndAllACLUsername", "connectAndAllACLPassword", null, null) + .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, true, true, true, true, true, true, true, true, true, true); - } finally { - zkClient.close(); } } @Test public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - SolrZkClient zkClient = - new SolrZkClientFactoryUsingCompletelyNewProviders( - "readonlyACLUsername", "readonlyACLPassword", null, null, null) - .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( + "readonlyACLUsername", "readonlyACLPassword", null, null) + .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, true, true, false, false, false, false, false, false, false, false); - } finally { - zkClient.close(); } } @@ -199,14 +181,10 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useNoCredentials(); - SolrZkClient zkClient = - new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( - zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( + zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, false, false, false, false, false, false, false, false, false, false); - } finally { - zkClient.close(); } } @@ -216,14 +194,10 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useWrongCredentials(); - SolrZkClient zkClient = - new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( - zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( + zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, false, false, false, false, false, false, false, false, false, false); - } finally { - zkClient.close(); } } @@ -233,14 +207,10 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useAllCredentials(); - SolrZkClient zkClient = - new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( - zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( + zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, true, true, true, true, true, true, true, true, true, true); - } finally { - zkClient.close(); } } @@ -250,14 +220,10 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useReadonlyCredentials(); - SolrZkClient zkClient = - new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( - zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - try { + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( + zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { VMParamsZkACLAndCredentialsProvidersTest.doTest( zkClient, true, true, false, false, false, false, false, false, false, false); - } finally { - zkClient.close(); } } @@ -267,19 +233,16 @@ private static class SolrZkClientFactoryUsingCompletelyNewProviders { final String digestPassword; final String digestReadonlyUsername; final String digestReadonlyPassword; - final String chroot; public SolrZkClientFactoryUsingCompletelyNewProviders( final String digestUsername, final String digestPassword, final String digestReadonlyUsername, - final String digestReadonlyPassword, - final String chroot) { + final String digestReadonlyPassword) { this.digestUsername = digestUsername; this.digestPassword = digestPassword; this.digestReadonlyUsername = digestReadonlyUsername; this.digestReadonlyPassword = digestReadonlyPassword; - this.chroot = chroot; } public SolrZkClient getSolrZkClient(String zkServerAddress, int zkClientTimeout) { @@ -297,16 +260,10 @@ public SolrZkClient getSolrZkClient(String zkServerAddress, int zkClientTimeout, if (authInfo != null) { authInfos.add(authInfo); } - return new SolrZkClient(zkServerAddress, zkClientTimeout) { - - @Override - protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { - return new DefaultZkCredentialsProvider(authInfos); - } - + return new SolrZkClient(zkServerAddress, zkClientTimeout, new DefaultZkCredentialsProvider(authInfos), null) { @Override public ZkACLProvider createACLProvider() { - return new VMParamsAllAndReadonlyDigestZkACLProvider(chroot) { + return new VMParamsAllAndReadonlyDigestZkACLProvider() { @Override protected List createNonSecurityACLsToAdd() { return createACLsToAdd( @@ -368,8 +325,7 @@ public ZkACLProvider createACLProvider() { .DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME, "alternative" + VMParamsAllAndReadonlyDigestZkACLProvider - .DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME, - null); + .DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME); } } 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 9eb664fd6fa..e6aa8b3c986 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java @@ -409,12 +409,9 @@ public void testGetFileNotExists() throws Exception { } public void testInvalidZKAddress() throws SolrException { - SolrException ex = - expectThrows( - SolrException.class, - () -> { - new SolrZkClient("----------:33332", 100); - }); + expectThrows( + SolrException.class, + () -> new SolrZkClient("----------:33332", 100, 100)); zkClient.close(); } 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 377c18f22fe..04139c6447d 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 @@ -186,7 +186,7 @@ public SolrZkClientWithACLs(String zkServerAddress, int zkClientTimeout) { @Override public ZkACLProvider createACLProvider() { - return new SaslZkACLProvider(getChroot()); + return new SaslZkACLProvider(); } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java index 1feb218e656..54d034f3ac6 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java @@ -34,10 +34,6 @@ public class SaslZkACLProvider extends SecurityAwareZkACLProvider { private static final String superUser = System.getProperty("solr.authorization.superuser", "solr"); - public SaslZkACLProvider(String chroot) { - super(chroot); - } - @Override protected List createNonSecurityACLsToAdd() { return Arrays.asList( diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java index fd831051b80..338df455f68 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java @@ -29,7 +29,13 @@ public abstract class SecurityAwareZkACLProvider implements ZkACLProvider { private volatile List nonSecurityACLsToAdd; private volatile List securityACLsToAdd; - private final String chroot; + private final String securityConfPath; + private final String securityZNodePath; + private final String securityZNodePathDir; + + public SecurityAwareZkACLProvider() { + this(null); + } public SecurityAwareZkACLProvider(String chroot) { if (chroot == null){ @@ -37,7 +43,26 @@ public SecurityAwareZkACLProvider(String chroot) { } else if (chroot.endsWith("/")) { chroot = chroot.substring(0, chroot.length() - 1); } - this.chroot = chroot; + if (chroot.length() > 0 && !chroot.startsWith("/")) { + chroot = "/" + chroot; + } + this.securityConfPath = chroot + ZkStateReader.SOLR_SECURITY_CONF_PATH; + this.securityZNodePath = chroot + SECURITY_ZNODE_PATH; + this.securityZNodePathDir = chroot + SECURITY_ZNODE_PATH + "/"; + } + + public SecurityAwareZkACLProvider withChroot(String chroot) { + return new SecurityAwareZkACLProvider(chroot) { + @Override + protected List createNonSecurityACLsToAdd() { + return SecurityAwareZkACLProvider.this.createNonSecurityACLsToAdd(); + } + + @Override + protected List createSecurityACLsToAdd() { + return SecurityAwareZkACLProvider.this.createSecurityACLsToAdd(); + } + }; } @Override @@ -56,9 +81,9 @@ public final List getDefaultAcl() { protected boolean isSecurityZNodePath(String zNodePath) { return zNodePath != null - && (zNodePath.equals(chroot + ZkStateReader.SOLR_SECURITY_CONF_PATH) - || zNodePath.equals(chroot + SECURITY_ZNODE_PATH) - || zNodePath.startsWith(chroot + SECURITY_ZNODE_PATH + "/")); + && (zNodePath.equals(securityConfPath) + || zNodePath.equals(securityZNodePath) + || zNodePath.startsWith(securityZNodePathDir)); } /** diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index 97eb95d84bb..40c465f3eb0 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -195,7 +195,10 @@ public SolrZkClient( zkCredentialsProvider = createZkCredentialsToAddAutomatically(); } if (aclProvider == null) { - this.aclProvider = createACLProvider(); + aclProvider = createACLProvider(); + } + if (chroot != null && aclProvider instanceof SecurityAwareZkACLProvider) { + this.aclProvider = ((SecurityAwareZkACLProvider)aclProvider).withChroot(chroot); } else { this.aclProvider = aclProvider; } @@ -270,7 +273,7 @@ protected ACLProvider createACLProvider() { } catch (Throwable t) { // just ignore - go default log.warn( - "VM param zkACLProvider does not point to a class implementingACLProvider and with a non-arg constructor", + "VM param zkACLProvider does not point to a class implementingACLProvider and with a single-arg constructor (passing through the chroot)", t); } } @@ -501,11 +504,17 @@ public void makePath( if (!failOnExists) { createBuilder.orSetData(); } + final String finalPath; + if (!path.startsWith("/")) { + finalPath = "/" + path; + } else { + finalPath = path; + } runWithCorrectThrows( "making path", () -> { - createBuilder.creatingParentsIfNeeded().withMode(createMode).forPath(path, data); - return client.checkExists().usingWatcher(wrapWatcher(watcher)).forPath(path); + createBuilder.creatingParentsIfNeeded().withMode(createMode).forPath(finalPath, data); + return client.checkExists().usingWatcher(wrapWatcher(watcher)).forPath(finalPath); }); } @@ -647,7 +656,7 @@ public void printLayout(String path, int indent, StringBuilder string) StringBuilder dent = new StringBuilder(); dent.append(" ".repeat(Math.max(0, indent))); string.append(dent).append(path).append(" (").append(children.size()).append(")").append(NEWL); - if (data != null) { + if (data != null && data.length > 0) { String dataString = new String(data, StandardCharsets.UTF_8); if (!path.endsWith(".txt") && !path.endsWith(".xml")) { string diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java index f541f115b96..3d67cd16833 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/VMParamsAllAndReadonlyDigestZkACLProvider.java @@ -42,24 +42,21 @@ public class VMParamsAllAndReadonlyDigestZkACLProvider extends SecurityAwareZkAC final String zkDigestReadonlyPasswordVMParamName; final Properties credentialsProps; - public VMParamsAllAndReadonlyDigestZkACLProvider(String chroot) { + public VMParamsAllAndReadonlyDigestZkACLProvider() { this( VMParamsSingleSetCredentialsDigestZkCredentialsProvider .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, VMParamsSingleSetCredentialsDigestZkCredentialsProvider .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME, - DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME, - chroot); + DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME); } public VMParamsAllAndReadonlyDigestZkACLProvider( String zkDigestAllUsernameVMParamName, String zkDigestAllPasswordVMParamName, String zkDigestReadonlyUsernameVMParamName, - String zkDigestReadonlyPasswordVMParamName, - String chroot) { - super(chroot); + String zkDigestReadonlyPasswordVMParamName) { this.zkDigestAllUsernameVMParamName = zkDigestAllUsernameVMParamName; this.zkDigestAllPasswordVMParamName = zkDigestAllPasswordVMParamName; this.zkDigestReadonlyUsernameVMParamName = zkDigestReadonlyUsernameVMParamName; diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java index 55f7d03f559..22f0e2d7574 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java @@ -24,8 +24,12 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import java.util.Arrays; import java.util.Properties; + +import org.apache.curator.framework.AuthInfo; import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.common.cloud.DefaultZkCredentialsProvider; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.VMParamsAllAndReadonlyDigestZkACLProvider; @@ -75,50 +79,42 @@ public void setUp() throws Exception { setSecuritySystemProperties(); - SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClient( zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null, null, - null); - zkClient.makePath("/solr", false); - zkClient.close(); + null)) { + zkClient.makePath("/solr", false); + } - zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); - zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { + zkClient.create( + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + zkClient.makePath( + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); - zkClient.create( - SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); - zkClient.close(); + zkClient.create( + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT + ); + } clearSecuritySystemProperties(); - zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); - // Currently no credentials on ZK connection, because those same VM-params are used for adding - // ACLs, and here we want - // no (or completely open) ACLs added. Therefore hack your way into being authorized for - // creating anyway - zkClient - .getSolrZooKeeper() - .addAuthInfo( - "digest", - ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(StandardCharsets.UTF_8)); - zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); - zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); - zkClient.close(); + try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, new DefaultZkCredentialsProvider(Arrays.asList(new AuthInfo("digest", + ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(StandardCharsets.UTF_8)))), null)) { + zkClient.create( + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); + zkClient.makePath( + "/unprotectedMakePathNode", + "content".getBytes(DATA_ENCODING), + CreateMode.PERSISTENT + ); + } if (log.isInfoEnabled()) { log.info("####SETUP_END {}", getTestName()); @@ -198,17 +194,9 @@ public void testAllCredentialsFromFile() throws Exception { public void testRepairACL() throws Exception { clearSecuritySystemProperties(); try (SolrZkClient zkClient = - new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { - // Currently no credentials on ZK connection, because those same VM-params are used for adding - // ACLs, and here we want - // no (or completely open) ACLs added. Therefore hack your way into being authorized for - // creating anyway - zkClient - .getSolrZooKeeper() - .addAuthInfo( - "digest", - ("connectAndAllACLUsername:connectAndAllACLPassword") - .getBytes(StandardCharsets.UTF_8)); + new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, new DefaultZkCredentialsProvider(Arrays.asList(new AuthInfo("digest", + ("connectAndAllACLUsername:connectAndAllACLPassword") + .getBytes(StandardCharsets.UTF_8)))), null)) { zkClient.create( "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); @@ -228,7 +216,7 @@ public void testRepairACL() throws Exception { NoAuthException e = assertThrows( NoAuthException.class, () -> zkClient.getData("/security.json", null, null)); - assertEquals("/security.json", e.getPath()); + assertEquals("/solr/security.json", e.getPath()); } } From fbcce63119f518f623c014b45294cf29d08e91f3 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Wed, 23 Mar 2022 17:27:01 -0400 Subject: [PATCH 05/14] Everything works. Just some leader election issues when the client cnxn is killed without an expiry --- .../org/apache/solr/cloud/LeaderElector.java | 2 +- .../java/org/apache/solr/cloud/Overseer.java | 10 +- .../solr/cloud/OverseerTaskProcessor.java | 6 +- .../org/apache/solr/cloud/ZkController.java | 6 +- .../org/apache/solr/core/ZkContainer.java | 2 +- .../apache/solr/cloud/LeaderElectionTest.java | 61 +++++----- .../org/apache/solr/cloud/OverseerTest.java | 10 +- .../apache/solr/cloud/ZkSolrClientTest.java | 8 +- .../solr/common/cloud/OnDisconnect.java | 2 +- .../apache/solr/common/cloud/OnReconnect.java | 10 +- .../solr/common/cloud/SolrZkClient.java | 4 - .../solr/common/cloud/SolrZooKeeper.java | 113 ------------------ solr/test-framework/build.gradle | 5 + .../solr/cloud/AbstractDistribZkTestBase.java | 1 + .../org/apache/solr/cloud/ChaosMonkey.java | 10 +- .../solr/cloud/MiniSolrCloudCluster.java | 8 +- versions.lock | 8 +- 17 files changed, 92 insertions(+), 174 deletions(-) delete mode 100644 solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java 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 142ed50ad70..2790cb7f2d4 100644 --- a/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java +++ b/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java @@ -348,7 +348,7 @@ public void process(WatchedEvent event) { try { // am I the next leader? checkIfIamLeader(context, true); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { } catch (Exception e) { if (!zkClient.isClosed()) { 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 04923f58421..c65e73b3b84 100644 --- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java +++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java @@ -297,7 +297,7 @@ public void run() { // the workQueue is empty now, use stateUpdateQueue as fallback queue fallbackQueue = stateUpdateQueue; fallbackQueueSize = 0; - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { return; } catch (KeeperException.SessionExpiredException e) { log.warn("Solr cannot talk to ZK, exiting Overseer work queue loop", e); @@ -323,7 +323,7 @@ public void run() { } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { } catch (Exception e) { log.error("Exception in Overseer main queue loop", e); @@ -383,7 +383,7 @@ public void run() { } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { } catch (Exception e) { log.error("Exception in Overseer main queue loop", e); @@ -461,7 +461,7 @@ private void checkIfIamStillLeader() { byte[] data; try { data = zkClient.getData(path, null, stat); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { return; } catch (Exception e) { log.warn("Error communicating with ZooKeeper", e); @@ -615,7 +615,7 @@ private LeaderStatus amILeader() { } catch (InterruptedException e) { success = false; Thread.currentThread().interrupt(); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { success = false; } catch (Exception e) { success = false; 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 c6e4b594693..6a3940154d1 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java @@ -190,7 +190,7 @@ public void run() { // We don't need to handle this. This is just a fail-safe which comes in handy in skipping // already processed async calls. SolrException.log(log, "", e); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { return; } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -204,7 +204,7 @@ public void run() { try { prioritizer.prioritizeOverseerNodes(myId); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { return; } catch (Exception e) { if (!zkStateReader.getZkClient().isClosed()) { @@ -397,7 +397,7 @@ public void run() { } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { } catch (Exception e) { SolrException.log(log, "", e); 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 79bdea2347a..91cb2d2e49b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -663,7 +663,7 @@ public void preClose() { try { this.removeEphemeralLiveNode(); - } catch (AlreadyClosedException + } catch (IllegalStateException | SessionExpiredException | KeeperException.ConnectionLossException e) { @@ -1488,7 +1488,7 @@ private String getLeader(final CloudDescriptor cloudDesc, int timeoutms) { leaderUrl = getLeaderProps(collection, cloudDesc.getShardId(), timeoutms).getCoreUrl(); } - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { throw e; } catch (Exception e) { log.error("Error getting leader from zk", e); @@ -2886,7 +2886,7 @@ public void publishNodeAsDown(String nodeName) { nodeName); try { overseer.getStateUpdateQueue().offer(Utils.toJSON(m)); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { log.info( "Not publishing node as DOWN because a resource required to do so is already closed."); } catch (InterruptedException e) { diff --git a/solr/core/src/java/org/apache/solr/core/ZkContainer.java b/solr/core/src/java/org/apache/solr/core/ZkContainer.java index fef2afa7cd9..58d0d321244 100644 --- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java +++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java @@ -200,7 +200,7 @@ public void registerInZk(final SolrCore core, boolean background, boolean skipRe SolrException.log(log, "", e); } catch (KeeperException e) { SolrException.log(log, "", e); - } catch (AlreadyClosedException e) { + } catch (IllegalStateException e) { } catch (Exception e) { try { 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 bd22ed7c4ec..93249acc82c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java @@ -29,6 +29,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; + +import org.apache.curator.test.KillSession; import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.cloud.OnReconnect; @@ -118,7 +120,7 @@ public ElectorSetup(OnReconnect onReconnect) { zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT, TIMEOUT, onReconnect); zkStateReader = new ZkStateReader(zkClient); elector = new LeaderElector(zkClient); - zkController = MockSolrSource.makeSimpleMock(null, zkStateReader, null); + zkController = MockSolrSource.makeSimpleMock(null, zkStateReader, zkClient); } public void close() { @@ -187,9 +189,10 @@ private void setupOnConnect() throws InterruptedException, KeeperException, IOEx public void run() { try { setupOnConnect(); + } catch (IllegalStateException ignored) { + return; } catch (Throwable e) { log.error("setup failed", e); - es.close(); return; } @@ -478,8 +481,7 @@ public void testStressElection() throws Exception { final List threads = Collections.synchronizedList(new ArrayList()); // start with a leader - ClientThread thread1 = null; - thread1 = new ClientThread("shard1", 0); + ClientThread thread1 = new ClientThread("shard1", 0); threads.add(thread1); scheduler.schedule(thread1, 0, TimeUnit.MILLISECONDS); @@ -541,9 +543,11 @@ public void run() { int j; j = random().nextInt(threads.size()); try { - threads.get(j).es.zkClient.getSolrZooKeeper().closeCnxn(); + long sessionId = threads.get(j).es.zkClient.getZkSessionId(); + if (sessionId >= 0) { + KillSession.kill(threads.get(j).es.zkClient.getCuratorFramework().getZookeeperClient().getZooKeeper()); + } if (random().nextBoolean()) { - long sessionId = zkClient.getZkSessionId(); server.expire(sessionId); } } catch (Exception e) { @@ -558,36 +562,37 @@ public void run() { } }; - scheduleThread.start(); - connLossThread.start(); - killThread.start(); - - Thread.sleep(4000); + try { + scheduleThread.start(); + connLossThread.start(); + killThread.start(); - stopStress = true; + Thread.sleep(4000); - scheduleThread.interrupt(); - connLossThread.interrupt(); - killThread.interrupt(); + stopStress = true; - scheduleThread.join(); - scheduler.shutdownNow(); + scheduleThread.interrupt(); + connLossThread.interrupt(); + killThread.interrupt(); - connLossThread.join(); - killThread.join(); + scheduleThread.join(); + scheduler.shutdownNow(); - int seq = threads.get(getLeaderThread()).getSeq(); + connLossThread.join(); + killThread.join(); - // we have a leader we know, TODO: lets check some other things + int seq = threads.get(getLeaderThread()).getSeq(); - // cleanup any threads still running - for (ClientThread thread : threads) { - thread.es.zkClient.close(); - thread.close(); - } + // we have a leader we know, TODO: lets check some other things + } finally { + // cleanup any threads still running + for (ClientThread thread : threads) { + thread.close(); + } - for (Thread thread : threads) { - thread.join(); + for (Thread thread : threads) { + thread.join(); + } } } 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 be30d786b46..0cf426d7cd9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java @@ -1235,7 +1235,7 @@ public void testShardLeaderChange() throws Exception { ZkDistributedQueue q = getOpenOverseer().getStateUpdateQueue(); q.offer(Utils.toJSON(m)); break; - } catch (SolrException | KeeperException | AlreadyClosedException e) { + } catch (SolrException | KeeperException | IllegalStateException e) { e.printStackTrace(); } } @@ -1253,7 +1253,7 @@ public void testShardLeaderChange() throws Exception { true, getOpenOverseer()); break; - } catch (SolrException | KeeperException | AlreadyClosedException e) { + } catch (SolrException | KeeperException | IllegalStateException e) { e.printStackTrace(); } } @@ -1278,7 +1278,7 @@ public void testShardLeaderChange() throws Exception { true, getOpenOverseer()); break; - } catch (SolrException | AlreadyClosedException e) { + } catch (SolrException | IllegalStateException e) { e.printStackTrace(); } } @@ -1298,7 +1298,7 @@ public void testShardLeaderChange() throws Exception { true, getOpenOverseer()); break; - } catch (SolrException | AlreadyClosedException e) { + } catch (SolrException | IllegalStateException e) { e.printStackTrace(); } } @@ -1318,7 +1318,7 @@ public void testShardLeaderChange() throws Exception { true, getOpenOverseer()); break; - } catch (SolrException | AlreadyClosedException e) { + } catch (SolrException | IllegalStateException e) { e.printStackTrace(); } } 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 11066fe5a1f..1de743ff8f1 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java @@ -341,12 +341,11 @@ public void testSkipPathPartsOnMakePath() throws Exception { KeeperException.NoNodeException.class, "We should not be able to create this path", () -> - zkClient.makePath( + zkClient.ensureExists( "/test/path/here", (byte[]) null, CreateMode.PERSISTENT, - (Watcher) null, - true + 1 )); zkClient.clean("/"); @@ -358,7 +357,8 @@ public void testSkipPathPartsOnMakePath() throws Exception { zkClient.ensureExists( "/collection/collection/leader", null, - CreateMode.PERSISTENT)); + CreateMode.PERSISTENT, + 2)); zkClient.makePath("/collection"); diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java b/solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java index 49cc0427ab7..f33013c5185 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java @@ -25,7 +25,7 @@ public interface OnDisconnect extends ConnectionStateListener { @Override default void stateChanged(CuratorFramework client, ConnectionState newState) { - if (!newState.isConnected()) { + if (newState == ConnectionState.LOST) { command(); } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java b/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java index 06fed20a444..ecd3f623975 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/OnReconnect.java @@ -21,6 +21,8 @@ import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.zookeeper.KeeperException.SessionExpiredException; +import java.util.concurrent.atomic.AtomicBoolean; + /** * Implementations are expected to implement a correct hashCode and equals method needed to uniquely * identify the listener as listeners are managed in a Set. In addition, your listener @@ -31,10 +33,16 @@ public interface OnReconnect extends ConnectionStateListener { void command(); + AtomicBoolean sessionEnded = new AtomicBoolean(false); + @Override default void stateChanged(CuratorFramework client, ConnectionState newState) { if (ConnectionState.RECONNECTED.equals(newState)) { - command(); + if (sessionEnded.getAndSet(false)) { + command(); + } + } else if (ConnectionState.LOST == newState) { + sessionEnded.set(true); } } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index 40c465f3eb0..f3585860881 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -703,10 +703,6 @@ public boolean isClosed() { return isClosed || (higherLevelIsClosed != null && higherLevelIsClosed.isClosed()); } - public SolrZooKeeper getSolrZooKeeper() { - return null; - } - public long getZkSessionId() { if (isConnected()) { try { diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java deleted file mode 100644 index 4d126b4971c..00000000000 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.common.cloud; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.SocketAddress; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import org.apache.solr.common.util.SuppressForbidden; -import org.apache.zookeeper.ClientCnxn; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooKeeper; - -// we use this class to expose nasty stuff for tests -@SuppressWarnings({"try"}) -public class SolrZooKeeper extends ZooKeeper { - final Set spawnedThreads = new CopyOnWriteArraySet<>(); - - // for test debug - // static Map clients = new ConcurrentHashMap(); - - public SolrZooKeeper(String connectString, int sessionTimeout, Watcher watcher) - throws IOException { - super(connectString, sessionTimeout, watcher); - // clients.put(this, new RuntimeException()); - } - - public ClientCnxn getConnection() { - return cnxn; - } - - public SocketAddress getSocketAddress() { - return testableLocalSocketAddress(); - } - - public void closeCnxn() { - final Thread t = - new Thread( - new Runnable() { - @Override - public void run() { - try { - AccessController.doPrivileged( - (PrivilegedAction) this::closeZookeeperChannel); - } finally { - spawnedThreads.remove(Thread.currentThread()); - } - } - - @SuppressForbidden(reason = "Hack for Zookeeper needs access to private methods.") - private Void closeZookeeperChannel() { - final ClientCnxn cnxn = getConnection(); - synchronized (cnxn) { - try { - final Field sendThreadFld = cnxn.getClass().getDeclaredField("sendThread"); - sendThreadFld.setAccessible(true); - Object sendThread = sendThreadFld.get(cnxn); - if (sendThread != null) { - Method method = - sendThread.getClass().getDeclaredMethod("testableCloseSocket"); - method.setAccessible(true); - try { - method.invoke(sendThread); - } catch (InvocationTargetException e) { - // is fine - } - } - } catch (Exception e) { - throw new RuntimeException("Closing Zookeeper send channel failed.", e); - } - } - return null; // Void - } - }, - "closeCnxn"); - spawnedThreads.add(t); - t.start(); - } - - @Override - public synchronized void close() throws InterruptedException { - super.close(); - } - - // public static void assertCloses() { - // if (clients.size() > 0) { - // Iterator stacktraces = clients.values().iterator(); - // Exception cause = null; - // cause = stacktraces.next(); - // throw new RuntimeException("Found a bad one!", cause); - // } - // } - -} diff --git a/solr/test-framework/build.gradle b/solr/test-framework/build.gradle index 569f0e275c5..4fcef683789 100644 --- a/solr/test-framework/build.gradle +++ b/solr/test-framework/build.gradle @@ -46,6 +46,11 @@ dependencies { implementation ('org.apache.zookeeper:zookeeper-jute') { exclude group: 'org.apache.yetus', module: 'audience-annotations' } + api('org.apache.curator:curator-test') { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + exclude group: 'com.google.guava', module: 'guava' + exclude group: 'io.dropwizard.metrics', module: 'metrics-core' + } implementation 'commons-io:commons-io' implementation 'org.slf4j:slf4j-api' 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 8a2679a0191..1721717446e 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 @@ -390,6 +390,7 @@ 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/ChaosMonkey.java b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java index 83c99b255bd..6af1a42c7f7 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java @@ -28,6 +28,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; + +import org.apache.curator.test.KillSession; import org.apache.lucene.util.LuceneTestCase; import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.cloud.AbstractFullDistribZkTestBase.CloudJettyRunner; @@ -148,9 +150,9 @@ public void expireSession(final JettySolrRunner jetty) { CoreContainer cores = jetty.getCoreContainer(); if (cores != null) { monkeyLog("expire session for " + jetty.getLocalPort() + " !"); - causeConnectionLoss(jetty); long sessionId = cores.getZkController().getZkClient().getZkSessionId(); zkServer.expire(sessionId); + causeConnectionLoss(jetty); } } @@ -180,7 +182,11 @@ public static void causeConnectionLoss(JettySolrRunner jetty) { if (cores != null) { monkeyLog("Will cause connection loss on " + jetty.getLocalPort()); SolrZkClient zkClient = cores.getZkController().getZkClient(); - zkClient.getSolrZooKeeper().closeCnxn(); + try { + KillSession.kill(zkClient.getCuratorFramework().getZookeeperClient().getZooKeeper()); + } catch (Exception e) { + e.printStackTrace(); + } } } 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 b6c735be823..21d290b869d 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 @@ -52,6 +52,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import javax.servlet.Filter; + +import org.apache.curator.test.KillSession; import org.apache.lucene.util.LuceneTestCase; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.client.solrj.embedded.JettyConfig; @@ -794,9 +796,13 @@ public void expireZkSession(JettySolrRunner jetty) { CoreContainer cores = jetty.getCoreContainer(); if (cores != null) { SolrZkClient zkClient = cores.getZkController().getZkClient(); - zkClient.getSolrZooKeeper().closeCnxn(); long sessionId = zkClient.getZkSessionId(); zkServer.expire(sessionId); + try { + KillSession.kill(zkClient.getCuratorFramework().getZookeeperClient().getZooKeeper()); + } catch (Exception e) { + e.printStackTrace(); + } if (log.isInfoEnabled()) { log.info("Expired zookeeper session {} from node {}", sessionId, jetty.getBaseUrl()); } diff --git a/versions.lock b/versions.lock index dff7fa5d19a..087ac819b45 100644 --- a/versions.lock +++ b/versions.lock @@ -129,6 +129,7 @@ org.apache.commons:commons-text:1.8 (2 constraints: fe1528d0) org.apache.curator:curator-client:5.2.1 (2 constraints: e414fea2) org.apache.curator:curator-framework:5.2.1 (2 constraints: 0114e574) org.apache.curator:curator-recipes:5.2.1 (1 constraints: 0a050b36) +org.apache.curator:curator-test:5.2.1 (1 constraints: 0a050b36) org.apache.hadoop:hadoop-annotations:3.3.2 (1 constraints: 0a050536) org.apache.hadoop:hadoop-auth:3.3.2 (1 constraints: 0a050536) org.apache.hadoop:hadoop-client-api:3.3.2 (3 constraints: 1928ac5e) @@ -250,10 +251,13 @@ org.hamcrest:hamcrest-core:2.2 (1 constraints: cc05fe3f) org.itadaki:bzip2:0.9.1 (2 constraints: bd0c4b2c) org.jctools:jctools-core:3.3.0 (1 constraints: 08050336) org.jdom:jdom2:2.0.6.1 (1 constraints: be0c371b) -org.junit:junit-bom:5.8.2 (1 constraints: c8116cde) +org.junit:junit-bom:5.8.2 (3 constraints: 323381d6) +org.junit.jupiter:junit-jupiter-api:5.8.2 (2 constraints: e716cc4d) +org.junit.platform:junit-platform-commons:1.8.2 (2 constraints: 8018a5a1) org.locationtech.spatial4j:spatial4j:0.8 (1 constraints: 59105498) org.opengis:geoapi:3.0.1 (7 constraints: 1361d046) org.openjdk.jmh:jmh-core:1.32 (1 constraints: da04f730) +org.opentest4j:opentest4j:1.2.0 (1 constraints: 670f0e7d) org.ow2.asm:asm:9.2 (4 constraints: 4931393a) org.ow2.asm:asm-commons:7.2 (1 constraints: 6b0f7267) org.quicktheories:quicktheories:0.26 (1 constraints: dc04f530) @@ -267,7 +271,7 @@ org.tallison:metadata-extractor:2.15.0.1 (1 constraints: ee0c2f28) org.tallison.xmp:xmpcore-shaded:6.1.11 (1 constraints: 310e8e49) org.threeten:threetenbp:1.5.2 (4 constraints: 0433f25e) org.tukaani:xz:1.9 (1 constraints: 030c5be9) -org.xerial.snappy:snappy-java:1.1.8.2 (4 constraints: 8c382ee2) +org.xerial.snappy:snappy-java:1.1.8.2 (5 constraints: 59463907) software.amazon.awssdk:annotations:2.17.63 (17 constraints: e2ff18d3) software.amazon.awssdk:apache-client:2.17.63 (3 constraints: 951d4b90) software.amazon.awssdk:arns:2.17.63 (2 constraints: 21185ac1) From d3949b12d0d6ebb99ac66654cb8b8e1ecd07f234 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Thu, 24 Mar 2022 11:57:57 -0400 Subject: [PATCH 06/14] Small changes. --- .../hadoop/DelegationTokenKerberosFilter.java | 3 ++- .../solr/security/hadoop/HadoopAuthFilter.java | 3 ++- .../common/cloud/SecurityAwareZkACLProvider.java | 16 +++++----------- .../apache/solr/common/cloud/SolrZkClient.java | 8 ++++++++ 4 files changed, 17 insertions(+), 13 deletions(-) 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 504fc7dde7b..66a93f14bca 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 @@ -25,6 +25,7 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.utils.ZKPaths; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.server.AuthenticationHandler; @@ -143,6 +144,6 @@ protected CuratorFramework getCuratorClient(SolrZkClient zkClient) // ignore? } - return zkClient.getCuratorFramework().usingNamespace(zkClient.getChroot() + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH); + return zkClient.getCuratorFramework().usingNamespace(zkClient.getAbsolutePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH)); } } 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 4db44119788..e6a3a5eacd5 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 @@ -24,6 +24,7 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.utils.ZKPaths; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.server.AuthenticationHandler; import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter; @@ -124,6 +125,6 @@ protected CuratorFramework getCuratorClient(SolrZkClient zkClient) // ignore? } - return zkClient.getCuratorFramework().usingNamespace(zkClient.getChroot() + SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH); + return zkClient.getCuratorFramework().usingNamespace(zkClient.getAbsolutePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH)); } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java index 338df455f68..ae4fa4ecac6 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java @@ -17,6 +17,8 @@ package org.apache.solr.common.cloud; import java.util.List; + +import org.apache.curator.utils.ZKPaths; import org.apache.zookeeper.data.ACL; /** @@ -38,17 +40,9 @@ public SecurityAwareZkACLProvider() { } public SecurityAwareZkACLProvider(String chroot) { - if (chroot == null){ - chroot = ""; - } else if (chroot.endsWith("/")) { - chroot = chroot.substring(0, chroot.length() - 1); - } - if (chroot.length() > 0 && !chroot.startsWith("/")) { - chroot = "/" + chroot; - } - this.securityConfPath = chroot + ZkStateReader.SOLR_SECURITY_CONF_PATH; - this.securityZNodePath = chroot + SECURITY_ZNODE_PATH; - this.securityZNodePathDir = chroot + SECURITY_ZNODE_PATH + "/"; + this.securityConfPath = ZKPaths.makePath(chroot, ZkStateReader.SOLR_SECURITY_CONF_PATH); + this.securityZNodePath = ZKPaths.makePath(chroot, SECURITY_ZNODE_PATH); + this.securityZNodePathDir = securityZNodePath + "/"; } public SecurityAwareZkACLProvider withChroot(String chroot) { diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index f3585860881..5cb672455e6 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -47,6 +47,7 @@ import org.apache.curator.framework.state.SessionConnectionStateErrorPolicy; import org.apache.curator.framework.state.StandardConnectionStateErrorPolicy; import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.curator.utils.ZKPaths; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrException; import org.apache.solr.common.StringUtils; @@ -769,6 +770,13 @@ public String getChroot() { return client.getNamespace(); } + /** + * @return the address of the zookeeper cluster + */ + public String getAbsolutePath(String path) { + return ZKPaths.fixForNamespace(getChroot(), path); + } + /** * Gets the raw config node /zookeeper/config as returned by server. Response may look like * From bb7d04af197c597b9ce3480f01aac4f77f083fa5 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Thu, 24 Mar 2022 13:37:39 -0400 Subject: [PATCH 07/14] Add-back-in path start index for leader election --- .../org/apache/solr/cloud/ShardLeaderElectionContextBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java index 893310ca05d..34862ef6d78 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java @@ -80,7 +80,7 @@ public ShardLeaderElectionContextBase( // only if /collections/{collection} exists already do we succeed in creating this path log.info("make sure parent is created {}", parent); try { - zkClient.ensureExists(parent, null, CreateMode.PERSISTENT); + zkClient.ensureExists(parent, null, CreateMode.PERSISTENT, 2); } catch (KeeperException e) { throw new RuntimeException(e); } catch (InterruptedException e) { From 5137cb8898d48cdf495d57ba783e339f80607c13 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Thu, 24 Mar 2022 17:01:09 -0400 Subject: [PATCH 08/14] Change test to do stuff correctly. Add in sessionTimeout --- .../test/org/apache/solr/cloud/LeaderElectionTest.java | 10 +++++----- .../org/apache/solr/common/cloud/SolrZkClient.java | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) 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 93249acc82c..0ffa257962c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java @@ -543,12 +543,12 @@ public void run() { int j; j = random().nextInt(threads.size()); try { - long sessionId = threads.get(j).es.zkClient.getZkSessionId(); - if (sessionId >= 0) { - KillSession.kill(threads.get(j).es.zkClient.getCuratorFramework().getZookeeperClient().getZooKeeper()); - } if (random().nextBoolean()) { - server.expire(sessionId); + long sessionId = threads.get(j).es.zkClient.getZkSessionId(); + if (sessionId >= 0) { + KillSession.kill(threads.get(j).es.zkClient.getCuratorFramework().getZookeeperClient().getZooKeeper()); + server.expire(sessionId); + } } } catch (Exception e) { e.printStackTrace(); diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java index 5cb672455e6..7aa9832ea51 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java @@ -210,6 +210,7 @@ public SolrZkClient( var clientBuilder = CuratorFrameworkFactory.builder() .ensembleProvider(new FixedEnsembleProvider(zkHost)) .namespace(chroot) + .sessionTimeoutMs(zkClientTimeout) .connectionTimeoutMs(clientConnectTimeout) .aclProvider(this.aclProvider) .authorization(zkCredentialsProvider.getCredentials()) From fc773aff206a9c8244cf215d2a785da9eba450a0 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Thu, 24 Mar 2022 17:05:40 -0400 Subject: [PATCH 09/14] Fix unrelated issue found in PR --- .../apache/solr/cloud/api/collections/OverseerRoleCmd.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 52278c93509..b7258bbf139 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,8 +75,8 @@ public void call(ClusterState state, ZkNodeProps message, NamedList resu } String roleName = message.getStr("role"); - boolean nodeExists = false; - if (nodeExists = zkClient.exists(ZkStateReader.ROLES)) { + boolean nodeExists = zkClient.exists(ZkStateReader.ROLES); + if (nodeExists) { @SuppressWarnings("unchecked") Map> tmp = (Map>) From 539ca79e4d58750b223f1e70b4bb28ac253d882d Mon Sep 17 00:00:00 2001 From: Kevin Risden Date: Sat, 7 Oct 2023 20:56:53 -0400 Subject: [PATCH 10/14] Fixes after merging main --- solr/core/build.gradle | 10 + .../java/org/apache/solr/cli/AuthTool.java | 11 +- .../java/org/apache/solr/cli/CreateTool.java | 4 +- .../java/org/apache/solr/cli/ZkRmTool.java | 2 +- .../cloud/DistributedApiAsyncTracker.java | 6 +- .../cloud/DistributedClusterStateUpdater.java | 4 +- .../org/apache/solr/cloud/DistributedMap.java | 6 +- .../org/apache/solr/cloud/LeaderElector.java | 21 +- .../solr/cloud/OverseerNodePrioritizer.java | 3 +- .../solr/cloud/OverseerTaskProcessor.java | 5 +- .../apache/solr/cloud/OverseerTaskQueue.java | 4 +- .../cloud/ShardLeaderElectionContextBase.java | 42 +- .../apache/solr/cloud/ZkConfigSetService.java | 7 +- .../org/apache/solr/cloud/ZkController.java | 73 ++-- .../apache/solr/cloud/ZkDistributedLock.java | 3 +- .../apache/solr/cloud/ZkDistributedQueue.java | 8 +- .../solr/cloud/ZkSolrResourceLoader.java | 2 +- .../api/collections/CreateCollectionCmd.java | 6 +- .../cloud/api/collections/SplitShardCmd.java | 9 +- .../org/apache/solr/core/RequestParams.java | 3 +- .../org/apache/solr/core/ZkContainer.java | 1 - .../solr/filestore/DistribPackageStore.java | 14 +- .../solr/handler/admin/ClusterStatus.java | 3 +- .../handler/admin/SecurityConfHandlerZk.java | 3 +- .../handler/admin/ShowFileRequestHandler.java | 3 +- .../solr/handler/admin/ZookeeperReadAPI.java | 6 +- .../solr/handler/component/SearchHandler.java | 4 +- .../packagemanager/RepositoryManager.java | 9 +- .../java/org/apache/solr/pkg/PackageAPI.java | 11 +- .../schema/ManagedIndexSchemaFactory.java | 2 +- .../org/apache/solr/servlet/HttpSolrCall.java | 2 +- .../solr/cloud/CollectionPropsTest.java | 3 +- .../solr/cloud/DistributedQueueTest.java | 8 +- .../cloud/LeaderElectionContextKeyTest.java | 3 +- .../apache/solr/cloud/LeaderElectionTest.java | 33 +- ...OfBoxZkACLAndCredentialsProvidersTest.java | 8 +- ...iddenZkACLAndCredentialsProvidersTest.java | 71 ++-- .../org/apache/solr/cloud/OverseerTest.java | 1 - .../apache/solr/cloud/SolrCLIZkUtilsTest.java | 30 +- .../apache/solr/cloud/TestConfigSetsAPI.java | 38 +- .../cloud/TestConfigSetsAPIExclusivity.java | 3 +- .../cloud/TestConfigSetsAPIZkFailure.java | 3 +- .../apache/solr/cloud/TestDistributedMap.java | 15 +- .../solr/cloud/TestLazySolrCluster.java | 5 +- .../apache/solr/cloud/TestPullReplica.java | 4 +- .../cloud/TestQueryingOnDownCollection.java | 3 +- .../solr/cloud/TestRebalanceLeaders.java | 3 +- .../cloud/TestSizeLimitedDistributedMap.java | 2 +- .../apache/solr/cloud/TestTlogReplica.java | 4 +- .../test/org/apache/solr/cloud/ZkCLITest.java | 13 +- .../apache/solr/cloud/ZkControllerTest.java | 29 +- .../apache/solr/cloud/ZkSolrClientTest.java | 49 +-- .../SimpleCollectionCreateDeleteTest.java | 23 +- .../TestLocalFSCloudBackupRestore.java | 4 +- .../cloud/overseer/ZkStateReaderTest.java | 8 +- .../cloud/overseer/ZkStateWriterTest.java | 9 +- .../handler/admin/ZookeeperReadAPITest.java | 4 +- .../TestSchemaDesignerConfigSetHelper.java | 6 +- .../security/TestAuthorizationFramework.java | 3 +- .../TimeRoutedAliasUpdateProcessorTest.java | 6 +- ...ICENSE-ASL.txt => curator-LICENSE-ASL.txt} | 0 ...r-client-NOTICE.txt => curator-NOTICE.txt} | 0 .../curator-framework-LICENSE-ASL.txt | 202 ---------- solr/licenses/curator-framework-NOTICE.txt | 5 - solr/licenses/curator-recipes-LICENSE-ASL.txt | 202 ---------- solr/licenses/curator-recipes-NOTICE.txt | 5 - solr/licenses/curator-test-5.5.0.jar.sha1 | 1 + solr/modules/hadoop-auth/build.gradle | 16 +- .../hadoop/DelegationTokenKerberosFilter.java | 33 +- .../security/hadoop/HadoopAuthFilter.java | 28 +- .../security/hadoop/HadoopAuthPlugin.java | 2 + .../solr/security/hadoop/KerberosPlugin.java | 3 + .../hadoop/SaslZkACLProviderTest.java | 18 +- .../TestImpersonationWithHadoopAuth.java | 3 +- .../TestSolrCloudWithDelegationTokens.java | 9 +- .../TestHdfsCloudBackupRestore.java | 3 +- solr/solrj-zookeeper/build.gradle | 7 + .../solrj/cloud/DistribStateManager.java | 1 - .../impl/ZkClientClusterStateProvider.java | 2 +- .../solrj/impl/ZkDistribStateManager.java | 1 - .../org/apache/solr/common/SimpleZkMap.java | 3 +- .../solr/common/cloud/ClusterProperties.java | 6 +- .../common/cloud/CollectionProperties.java | 3 +- .../common/cloud/DefaultZkACLProvider.java | 15 +- .../cloud/DefaultZkCredentialsProvider.java | 16 +- .../common/cloud/DigestZkACLProvider.java | 4 +- .../cloud/DigestZkCredentialsProvider.java | 21 +- .../solr/common/cloud/OnDisconnect.java | 0 .../apache/solr/common/cloud/OnReconnect.java | 4 +- .../common/cloud/PerReplicaStatesOps.java | 4 +- .../solr/common/cloud/SaslZkACLProvider.java | 1 - .../cloud/SecurityAwareZkACLProvider.java | 29 +- .../common/cloud/SecurityNodeWatcher.java | 13 +- .../solr/common/cloud/SolrZkClient.java | 359 +++++++++++------- ...redentialsDigestZkCredentialsProvider.java | 5 +- .../solr/common/cloud/ZkACLProvider.java | 4 +- .../common/cloud/ZkCredentialsProvider.java | 3 +- .../solr/common/cloud/ZkMaintenanceUtils.java | 7 +- .../solr/common/cloud/ZkStateReader.java | 11 +- .../solr/common/cloud/SolrZkClientTest.java | 19 +- .../common/cloud/TestZkConfigSetService.java | 47 +-- .../common/cloud/TestZkMaintenanceUtils.java | 3 +- .../solrj/impl/HttpClusterStateSSLTest.java | 4 +- .../PerReplicaStatesIntegrationTest.java | 10 +- .../cloud/SolrZkClientCompressedDataTest.java | 7 +- solr/test-framework/build.gradle | 6 + .../java/org/apache/solr/SolrTestCaseJ4.java | 2 - ...tZkACLAndCredentialsProvidersTestBase.java | 43 +-- .../cloud/AbstractFullDistribZkTestBase.java | 10 +- .../org/apache/solr/cloud/ChaosMonkey.java | 20 +- .../solr/cloud/MiniSolrCloudCluster.java | 9 +- .../apache/solr/cloud/MockSolrZkClient.java | 6 +- .../solr/cloud/TestConnectionStrategy.java | 35 -- .../org/apache/solr/cloud/ZkTestServer.java | 23 +- ...ctCollectionsAPIDistributedZkTestBase.java | 8 +- versions.lock | 6 +- 116 files changed, 720 insertions(+), 1265 deletions(-) rename solr/licenses/{curator-client-LICENSE-ASL.txt => curator-LICENSE-ASL.txt} (100%) rename solr/licenses/{curator-client-NOTICE.txt => curator-NOTICE.txt} (100%) delete mode 100644 solr/licenses/curator-framework-LICENSE-ASL.txt delete mode 100644 solr/licenses/curator-framework-NOTICE.txt delete mode 100644 solr/licenses/curator-recipes-LICENSE-ASL.txt delete mode 100644 solr/licenses/curator-recipes-NOTICE.txt create mode 100644 solr/licenses/curator-test-5.5.0.jar.sha1 rename solr/{solrj => solrj-zookeeper}/src/java/org/apache/solr/common/cloud/OnDisconnect.java (100%) delete mode 100644 solr/test-framework/src/java/org/apache/solr/cloud/TestConnectionStrategy.java diff --git a/solr/core/build.gradle b/solr/core/build.gradle index 61ecd1713af..12dedcf9e69 100644 --- a/solr/core/build.gradle +++ b/solr/core/build.gradle @@ -121,6 +121,16 @@ dependencies { implementation 'org.eclipse.jetty:jetty-io' implementation 'org.eclipse.jetty.toolchain:jetty-servlet-api' + implementation('org.apache.curator:curator-framework', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) + testImplementation('org.apache.curator:curator-client', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) + testImplementation('org.apache.curator:curator-test', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) + // ZooKeeper implementation('org.apache.zookeeper:zookeeper', { exclude group: "org.apache.yetus", module: "audience-annotations" 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 2afd71706b6..1f2fc2ac0dd 100644 --- a/solr/core/src/java/org/apache/solr/cli/AuthTool.java +++ b/solr/core/src/java/org/apache/solr/cli/AuthTool.java @@ -217,8 +217,7 @@ 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), true); + zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); } catch (Exception ex) { CLIO.out( "Unable to access ZooKeeper. Please add the following security.json to ZooKeeper (in case of SolrCloud):\n" @@ -384,7 +383,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), true); + zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); } } @@ -452,8 +451,8 @@ private int handleBasicAuth(CommandLine cli) throws Exception { private void checkSecurityJsonExists(SolrZkClient zkClient) throws KeeperException, InterruptedException { - if (zkClient.exists("/security.json", true)) { - byte[] oldSecurityBytes = zkClient.getData("/security.json", null, null, true); + if (zkClient.exists("/security.json")) { + byte[] oldSecurityBytes = zkClient.getData("/security.json", null, null); 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" @@ -479,7 +478,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), true); + zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8)); } } } 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 e62c42d185a..64f8a9ceaca 100644 --- a/solr/core/src/java/org/apache/solr/cli/CreateTool.java +++ b/solr/core/src/java/org/apache/solr/cli/CreateTool.java @@ -243,9 +243,7 @@ protected void createCollection(CloudSolrClient cloudSolrClient, CommandLine cli boolean configExistsInZk = confName != null && !confName.trim().isEmpty() - && ZkStateReader.from(cloudSolrClient) - .getZkClient() - .exists("/configs/" + confName, true); + && ZkStateReader.from(cloudSolrClient).getZkClient().exists("/configs/" + confName); 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 dad5bdbbe94..4b106a540b5 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, true).size() != 0) { + if (!recurse && zkClient.getChildren(znode, null).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/DistributedApiAsyncTracker.java b/solr/core/src/java/org/apache/solr/cloud/DistributedApiAsyncTracker.java index 5e8d0529ec1..6120d8ad6b2 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedApiAsyncTracker.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedApiAsyncTracker.java @@ -329,13 +329,11 @@ void createNewInFlightTask(String asyncId) throws KeeperException, InterruptedEx zkClient.create( getPath(asyncId), State.SUBMITTED.shorthand.getBytes(StandardCharsets.UTF_8), - CreateMode.EPHEMERAL - ); + CreateMode.EPHEMERAL); } 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)); } void deleteInFlightTask(String asyncId) throws KeeperException, InterruptedException { 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 4e2b2f88eaa..02543e51e40 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java @@ -607,9 +607,7 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState) jsonPath, collection.getZNodeVersion()); } - zkStateReader - .getZkClient() - .setData(jsonPath, stateJson, collection.getZNodeVersion()); + zkStateReader.getZkClient().setData(jsonPath, stateJson, collection.getZNodeVersion()); } } } 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 e740b40963d..532a782825b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java @@ -68,8 +68,7 @@ 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); } /** @@ -81,8 +80,7 @@ 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); return true; } catch (NodeExistsException e) { return false; 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 27ce01ee9d4..760d6ae04ab 100644 --- a/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java +++ b/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java @@ -25,7 +25,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.solr.cloud.ZkController.ContextKey; -import org.apache.solr.common.AlreadyClosedException; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.ZkMaintenanceUtils; @@ -107,7 +106,7 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement // If any double-registrations exist for me, remove all but this latest one! // TODO: can we even get into this state? - String prefix = zkClient.getZooKeeper().getSessionId() + "-" + context.id + "-"; + String prefix = zkClient.getZkSessionId() + "-" + context.id + "-"; Iterator it = seqs.iterator(); while (it.hasNext()) { String elec = it.next(); @@ -149,8 +148,7 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement watcher = new ElectionWatcher( context.leaderSeqPath, watchedNode, getSeq(context.leaderSeqPath), context), - null - ); + null); log.debug("Watching path {} to know if I could be the leader", watchedNode); } catch (KeeperException.SessionExpiredException e) { throw e; @@ -227,7 +225,7 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo final String shardsElectZkPath = context.electionPath + LeaderElector.ELECTION_NODE; - long sessionId = zkClient.getZooKeeper().getSessionId(); + long sessionId = zkClient.getZkSessionId(); String id = sessionId + "-" + context.id; String leaderSeqPath = null; boolean cont = true; @@ -241,10 +239,7 @@ 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); } else { String firstInLine = nodes.get(1); log.debug("The current head: {}", firstInLine); @@ -258,10 +253,7 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo } else { leaderSeqPath = zkClient.create( - shardsElectZkPath + "/" + id + "-n_", - null, - CreateMode.EPHEMERAL_SEQUENTIAL - ); + shardsElectZkPath + "/" + id + "-n_", null, CreateMode.EPHEMERAL_SEQUENTIAL); } log.debug("Joined leadership election with path: {}", leaderSeqPath); @@ -365,8 +357,7 @@ 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, (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); + ZkMaintenanceUtils.ensureExists(electZKPath, null, CreateMode.PERSISTENT, zkClient, 2); } this.context = context; 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 de06c2205f9..0e1a0acd58e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java @@ -68,8 +68,7 @@ public synchronized void prioritizeOverseerNodes(String overseerId) throws Excep 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())); + Map m = (Map) Utils.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat())); @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 d6af62efc59..9ebe8644626 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskProcessor.java @@ -36,7 +36,6 @@ import java.util.function.Predicate; import org.apache.solr.cloud.Overseer.LeaderStatus; import org.apache.solr.cloud.OverseerTaskQueue.QueueEvent; -import org.apache.solr.common.AlreadyClosedException; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.cloud.ZkStateReader; @@ -481,9 +480,7 @@ 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)); 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 1ffb96a5411..a7b81e2889e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerTaskQueue.java @@ -295,9 +295,7 @@ 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), 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/ShardLeaderElectionContextBase.java b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java index 929a1ae2b77..f7544f094ec 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java @@ -19,8 +19,6 @@ import java.lang.invoke.MethodHandles; import java.util.List; - -import org.apache.curator.framework.api.transaction.CuratorOp; import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.curator.framework.api.transaction.OperationType; import org.apache.solr.cloud.overseer.OverseerAction; @@ -40,11 +38,6 @@ import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.NoNodeException; import org.apache.zookeeper.KeeperException.NodeExistsException; -import org.apache.zookeeper.Op; -import org.apache.zookeeper.OpResult; -import org.apache.zookeeper.OpResult.SetDataResult; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.data.Stat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -112,8 +105,7 @@ public void cancelElection() throws InterruptedException, KeeperException { String parent = ZkMaintenanceUtils.getZkParent(leaderPath); zkClient.multi( op -> op.check().withVersion(leaderZkNodeParentVersion).forPath(parent), - op -> op.delete().withVersion(-1).forPath(leaderPath) - ); + op -> op.delete().withVersion(-1).forPath(leaderPath)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw e; @@ -150,19 +142,25 @@ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStartMs) // be used to make sure we only remove our own leader registration node. // The setData call used to get the parent version is also the trigger to // increment the version. We also do a sanity check that our leaderSeqPath exists. - List results = zkClient.multi( - op -> op.check().withVersion(-1).forPath(leaderSeqPath), - op -> op.create() - .withMode(CreateMode.EPHEMERAL) - .forPath(leaderPath, Utils.toJSON(leaderProps)), - op -> op.setData().withVersion(-1).forPath(parent, null) - ); - leaderZkNodeParentVersion = results.stream() - .filter(CuratorTransactionResult.ofTypeAndPath(OperationType.SET_DATA, parent)) - .findFirst() - .orElseThrow(() -> new RuntimeException("Could not set data for parent path in ZK: " + parent)) - .getResultStat() - .getVersion(); + List results = + zkClient.multi( + op -> op.check().withVersion(-1).forPath(leaderSeqPath), + op -> + op.create() + .withMode(CreateMode.EPHEMERAL) + .forPath(leaderPath, Utils.toJSON(leaderProps)), + op -> op.setData().withVersion(-1).forPath(parent, null)); + leaderZkNodeParentVersion = + results.stream() + .filter( + CuratorTransactionResult.ofTypeAndPath(OperationType.SET_DATA, parent)) + .findFirst() + .orElseThrow( + () -> + new RuntimeException( + "Could not set data for parent path in ZK: " + parent)) + .getResultStat() + .getVersion(); } }); } catch (NoNodeException e) { 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 98a38dcfab0..fa3f1b4037b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java @@ -139,7 +139,7 @@ public String configSetName(CoreDescriptor cd) { @Override public boolean checkConfigExists(String configName) throws IOException { try { - return zkClient.exists(CONFIGS_ZKNODE + "/" + configName, true); + return zkClient.exists(CONFIGS_ZKNODE + "/" + configName); } catch (KeeperException | InterruptedException e) { throw new IOException( "Error checking whether config exists", SolrZkClient.checkInterrupted(e)); @@ -224,8 +224,7 @@ public void setConfigMetadata(String configName, Map data) throw Utils.toJSON(data), CreateMode.PERSISTENT, null, - false - ); + false); } catch (KeeperException | InterruptedException e) { throw new IOException("Error setting config metadata", SolrZkClient.checkInterrupted(e)); } @@ -338,7 +337,7 @@ private void copyData(String fromZkFilePath, String toZkFilePath) toZkFilePath); } else { log.debug("Copying zk node {} to {}", fromZkFilePath, toZkFilePath); - byte[] data = zkClient.getData(fromZkFilePath, null, null, true); + byte[] data = zkClient.getData(fromZkFilePath, null, null); zkClient.makePath(toZkFilePath, data); } } 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 40f08aa7d2c..44e72a76d84 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -53,7 +53,6 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; - import org.apache.curator.framework.api.ACLProvider; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.cloud.SolrCloudManager; @@ -71,7 +70,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.ClusterState; -import org.apache.solr.common.cloud.DefaultConnectionStrategy; import org.apache.solr.common.cloud.DefaultZkACLProvider; import org.apache.solr.common.cloud.DefaultZkCredentialsInjector; import org.apache.solr.common.cloud.DefaultZkCredentialsProvider; @@ -88,7 +86,6 @@ import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.ZkACLProvider; -import org.apache.solr.common.cloud.ZkClientConnectionStrategy; import org.apache.solr.common.cloud.ZkCoreNodeProps; import org.apache.solr.common.cloud.ZkCredentialsInjector; import org.apache.solr.common.cloud.ZkCredentialsProvider; @@ -232,6 +229,8 @@ public String toString() { private boolean genericCoreNodeNames; + private int clientTimeout; + private volatile boolean isClosed; private final ConcurrentHashMap replicasMetTragicEvent = @@ -328,28 +327,28 @@ public ZkController( this.leaderVoteWait = cloudConfig.getLeaderVoteWait(); this.leaderConflictResolveWait = cloudConfig.getLeaderConflictResolveWait(); -<<<<<<< HEAD - this.clientTimeout = cloudConfig.getZkClientTimeout(); - String zkCredentialsInjectorClass = cloudConfig.getZkCredentialsInjectorClass(); ZkCredentialsInjector zkCredentialsInjector = StrUtils.isNullOrEmpty(zkCredentialsInjectorClass) ? new DefaultZkCredentialsInjector() : cc.getResourceLoader() - .newInstance(zkCredentialsInjectorClass, ZkCredentialsInjector.class); + .newInstance(zkCredentialsInjectorClass, ZkCredentialsInjector.class); + + this.clientTimeout = cloudConfig.getZkClientTimeout(); String zkACLProviderClass = cloudConfig.getZkACLProviderClass(); - ACLProvider zkACLProvider = null; - if (zkACLProviderClass != null && zkACLProviderClass.trim().length() > 0) { - zkACLProvider = cc.getResourceLoader().newInstance(zkACLProviderClass, ACLProvider.class); - } + ZkACLProvider zkACLProvider = + StrUtils.isNullOrEmpty(zkACLProviderClass) + ? new DefaultZkACLProvider() + : cc.getResourceLoader().newInstance(zkACLProviderClass, ZkACLProvider.class); + zkACLProvider.setZkCredentialsInjector(zkCredentialsInjector); String zkCredentialsProviderClass = cloudConfig.getZkCredentialsProviderClass(); - ZkCredentialsProvider zkCredentialsProvider = null; - if (zkCredentialsProviderClass != null && zkCredentialsProviderClass.trim().length() > 0) { - zkCredentialsProvider = cc.getResourceLoader() - .newInstance(zkCredentialsProviderClass, ZkCredentialsProvider.class); - } + ZkCredentialsProvider zkCredentialsProvider = + StrUtils.isNullOrEmpty(zkCredentialsProviderClass) + ? new DefaultZkCredentialsProvider() + : cc.getResourceLoader() + .newInstance(zkCredentialsProviderClass, ZkCredentialsProvider.class); zkCredentialsProvider.setZkCredentialsInjector(zkCredentialsInjector); addOnReconnectListener(getConfigDirListener()); @@ -365,7 +364,6 @@ public ZkController( .withUrl(zkServerAddress) .withTimeout(clientTimeout, TimeUnit.MILLISECONDS) .withConnTimeOut(zkClientConnectTimeout, TimeUnit.MILLISECONDS) - .withConnStrategy(strat) .withReconnectListener(() -> onReconnect(descriptorsSupplier)) .withBeforeConnect(() -> beforeReconnect(descriptorsSupplier)) .withAclProvider(zkACLProvider) @@ -413,8 +411,7 @@ private void beforeReconnect(Supplier> descriptorsSupplier) markAllAsNotLeader(descriptorsSupplier); } - private void onReconnect(Supplier> descriptorsSupplier) - throws SessionExpiredException { + private void onReconnect(Supplier> descriptorsSupplier) { // on reconnect, reload cloud info log.info("ZooKeeper session re-connected ... refreshing core states after session expiration."); clearZkCollectionTerms(); @@ -515,8 +512,6 @@ private void onReconnect(Supplier> descriptorsSupplier) // Restore the interrupted status Thread.currentThread().interrupt(); throw new ZooKeeperException(ErrorCode.SERVER_ERROR, "", e); - } catch (SessionExpiredException e) { - throw e; } catch (Exception e) { log.error("Exception during reconnect", e); throw new ZooKeeperException(ErrorCode.SERVER_ERROR, "", e); @@ -534,8 +529,7 @@ private void checkNoOldClusterstate(final SolrZkClient zkClient) throws Interrup if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE)) { return; } - final byte[] data = - zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null); + final byte[] data = zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null); if (Arrays.equals("{}".getBytes(StandardCharsets.UTF_8), data)) { // Empty json. This log will only occur once. @@ -606,8 +600,7 @@ private void registerAllCoresAsDown( + "/leader_elect/" + slice + "/election", - null - ) + null) .size(); if (children == 0) { log.debug( @@ -1040,8 +1033,7 @@ private void checkForExistingEphemeralNode() throws KeeperException, Interrupted if (Watcher.Event.EventType.NodeDeleted.equals(event.getType())) { deletedLatch.countDown(); } - } - ); + }); if (stat == null) { // znode suddenly disappeared but that's okay @@ -1049,8 +1041,7 @@ private void checkForExistingEphemeralNode() throws KeeperException, Interrupted } boolean deleted = - deletedLatch.await( - zkClient.getZkSessionTimeout() * 2L, TimeUnit.MILLISECONDS); + deletedLatch.await(zkClient.getZkSessionTimeout() * 2L, TimeUnit.MILLISECONDS); if (!deleted) { throw new SolrException( ErrorCode.SERVER_ERROR, @@ -1180,19 +1171,14 @@ private void createEphemeralLiveNode() throws KeeperException, InterruptedExcept log.info("Register node as live in ZooKeeper:{}", nodePath); Map roles = cc.nodeRoles.getRoles(); List ops = new ArrayList<>(2); - ops.add( - op -> op - .create() - .withMode(CreateMode.EPHEMERAL) - .forPath(nodePath)); + ops.add(op -> op.create().withMode(CreateMode.EPHEMERAL).forPath(nodePath)); // Create the roles node as well - roles - .forEach( - (role, mode) -> - ops.add( - op -> op - .create() + roles.forEach( + (role, mode) -> + ops.add( + op -> + op.create() .withMode(CreateMode.EPHEMERAL) .forPath(NodeRoles.getZNodeForRoleMode(role, mode) + "/" + nodeName))); @@ -1534,8 +1520,7 @@ 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); ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data)); return leaderProps; } catch (InterruptedException e) { @@ -2338,9 +2323,7 @@ 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); } catch (NoNodeException e) { // no problem } catch (InterruptedException e) { 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 9c74a67ebab..469986960d6 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java @@ -92,8 +92,7 @@ protected ZkDistributedLock(SolrZkClient zkClient, String lockDir, String lockNo + DistributedCollectionConfigSetCommandRunner.ZK_PATH_SEPARATOR + lockNodePrefix, null, - CreateMode.EPHEMERAL_SEQUENTIAL - ); + CreateMode.EPHEMERAL_SEQUENTIAL); sequence = getSequenceFromNodename(lockNode); } 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 79449806a80..c8bc80615f0 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedQueue.java @@ -32,13 +32,12 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Predicate; - import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.solr.client.solrj.cloud.DistributedQueue; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; -import org.apache.solr.common.cloud.SolrZkClient.IsClosed; import org.apache.solr.common.cloud.SolrZkClient; +import org.apache.solr.common.cloud.SolrZkClient.IsClosed; import org.apache.solr.common.cloud.ZkMaintenanceUtils; import org.apache.solr.common.util.Pair; import org.apache.zookeeper.CreateMode; @@ -258,8 +257,9 @@ public void remove(Collection paths) throws KeeperException, Interrupted for (CuratorTransactionResult result : results) { if (result.getError() != 0) { try { - zookeeper.delete(result.getForPath(), -1); - } catch (KeeperException.NoNodeException ignored) { } + zookeeper.delete(result.getForPath(), -1); + } catch (KeeperException.NoNodeException ignored) { + } } } } 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 ba8d984b671..0d9ef1c8338 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, true); + Stat stat = zkController.getZkClient().exists(file, null); if (stat != null) { return new Pair<>(file, stat.getVersion()); } else { 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 f4e9922e963..59db03a4c73 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,9 +190,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList results) if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES)) { roles = (Map) - Utils.fromJSON( - zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null)); + Utils.fromJSON(zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null)); } ClusterState clusterState = zkStateReader.getClusterState(); 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 269beccdf7a..09d8cbcddf6 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,8 +79,7 @@ protected boolean persistConf(SecurityConfig securityConfig) throws IOException .setData( SOLR_SECURITY_CONF_PATH, Utils.toJSON(securityConfig.getData()), - securityConfig.getVersion() - ); + securityConfig.getVersion()); 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 d52cdcee692..71b2127f790 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 @@ -185,8 +185,7 @@ 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), adminFile); content.setContentType(getSafeContentType(req.getParams().get(USE_CONTENT_TYPE))); rsp.add(RawResponseWriter.CONTENT, content); 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 796ab61afca..4e958192c7a 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 @@ -126,15 +126,13 @@ public ListZkChildrenResponse listNodes( if (includeChildren != null && !includeChildren.booleanValue()) { return listResponse; } - List l = - coreContainer.getZkController().getZkClient().getChildren(zkPath, null); + List l = coreContainer.getZkController().getZkClient().getChildren(zkPath, null); 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)); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java index 9cd14635e7c..3e5c2086b16 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -324,9 +324,7 @@ public ShardHandler getAndPrepShardHandler(SolrQueryRequest req, ResponseBuilder boolean requireZkConnected = shardsTolerant != null && shardsTolerant.equals(ShardParams.REQUIRE_ZK_CONNECTED); ZkController zkController = cc.getZkController(); - boolean zkConnected = - zkController != null - && zkController.getZkClient().isConnected(); + boolean zkConnected = zkController != null && zkController.getZkClient().isConnected(); if (requireZkConnected && false == zkConnected) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "ZooKeeper is not connected"); } else { 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 2f756e5d798..9ee18360c31 100644 --- a/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java +++ b/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java @@ -123,13 +123,11 @@ public void addRepository(String repoName, String uri) throws Exception { packageManager.zkClient.create( PackageUtils.REPOSITORIES_ZK_PATH, getMapper().writeValueAsString(repos).getBytes("UTF-8"), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); } else { packageManager.zkClient.setData( PackageUtils.REPOSITORIES_ZK_PATH, - getMapper().writeValueAsString(repos).getBytes("UTF-8") - ); + getMapper().writeValueAsString(repos).getBytes("UTF-8")); } try (InputStream is = new URL(uri + "/publickey.der").openStream()) { @@ -154,8 +152,7 @@ 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"); + return new String(zkClient.getData(PackageUtils.REPOSITORIES_ZK_PATH, null, null), "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 e21202a86cd..3bb8f6578d0 100644 --- a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java +++ b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java @@ -113,18 +113,14 @@ public void process(WatchedEvent event) { refreshPackages(thisWatch); } } - } - ); + }); } 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); pkgs = readPkgsFromZk(data, stat); packageLoader.refreshPackageConf(); } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) { @@ -144,8 +140,7 @@ 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); } Packages packages = null; if (data == null || data.length == 0) { 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 f07f268bad6..8bf2f3d1668 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java @@ -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, true); + byte[] data = zkClient.getData(managedSchemaPath, null, stat); schemaZkVersion = stat.getVersion(); schemaInputStream = new ZkSolrResourceLoader.ZkByteArrayInputStream(data, managedSchemaPath, stat); 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 ce9b1f8e6be..3dfd33ee6b9 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), true)) { + .exists(DocCollection.getCollectionPath(collectionName))) { // no change and such a collection does not exist. go back return; } 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 245d10ddd17..87f71cc0570 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java @@ -171,8 +171,7 @@ 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), StandardCharsets.UTF_8); } catch (Exception e) { collectionpropsInZk = "Could not get file from ZooKeeper: " + e.getMessage(); 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 4c6cd072921..7a5836391c8 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistributedQueueTest.java @@ -292,11 +292,15 @@ public void testPeekElements() throws Exception { private void forceSessionExpire() throws InterruptedException, TimeoutException { final CountDownLatch hasDisconnected = new CountDownLatch(1); - zkClient.getCuratorFramework().getConnectionStateListenable().addListener((OnDisconnect) hasDisconnected::countDown); + zkClient + .getCuratorFramework() + .getConnectionStateListenable() + .addListener((OnDisconnect) hasDisconnected::countDown); long sessionId = zkClient.getZkSessionId(); zkServer.expire(sessionId); hasDisconnected.await(10, TimeUnit.SECONDS); - assertEquals("ZK Client did not disconnect after session expiration", 0, hasDisconnected.getCount()); + assertEquals( + "ZK Client did not disconnect after session expiration", 0, hasDisconnected.getCount()); zkClient.getCuratorFramework().blockUntilConnected(10, TimeUnit.SECONDS); assertTrue(zkClient.isConnected()); assertNotEquals(sessionId, zkClient.getZkSessionId()); 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 234e7c03151..6e0860023fd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java @@ -130,7 +130,6 @@ private List getElectionNodes(String collection, String shard, SolrZkCli throws KeeperException, InterruptedException { return client.getChildren( "/collections/" + collection + "/leader_elect/" + shard + LeaderElector.ELECTION_NODE, - null - ); + null); } } 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 ded82b0ee06..6446a7ced54 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java @@ -28,6 +28,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.apache.curator.test.KillSession; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.cloud.OnReconnect; import org.apache.solr.common.cloud.SolrZkClient; @@ -39,8 +40,6 @@ import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.NoNodeException; import org.apache.zookeeper.KeeperException.SessionExpiredException; -import org.apache.zookeeper.TestableZooKeeper; -import org.apache.zookeeper.ZooKeeper; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -293,8 +292,7 @@ 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); ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data)); return leaderProps.getCoreUrl(); } catch (NoNodeException | SessionExpiredException e) { @@ -539,11 +537,15 @@ public void run() { int j; j = random().nextInt(threads.size()); try { - ZooKeeper zk = threads.get(j).es.zkClient.getZooKeeper(); - assertTrue(zk instanceof TestableZooKeeper); - ((TestableZooKeeper) zk).testableConnloss(); if (random().nextBoolean()) { - server.expire(zk.getSessionId()); + KillSession.kill( + threads + .get(j) + .es + .zkClient + .getCuratorFramework() + .getZookeeperClient() + .getZooKeeper()); } } catch (Exception e) { log.error("error expiring session", e); @@ -583,14 +585,15 @@ public void run() { thread.close(); } - // cleanup any threads still running - for (ClientThread thread : threads) { - thread.es.zkClient.getZooKeeper().close(); - thread.close(); - } + // cleanup any threads still running + for (ClientThread thread : threads) { + thread.es.zkClient.close(); + thread.close(); + } - for (Thread thread : threads) { - thread.join(); + for (Thread thread : threads) { + thread.join(); + } } } 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 0cb3970e4b7..b211096aae3 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OutOfBoxZkACLAndCredentialsProvidersTest.java @@ -91,15 +91,11 @@ public void setUp() throws Exception { zkClient.create( "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); zkClient.close(); if (log.isInfoEnabled()) { 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 b6a1feefaf8..cc593562d4e 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverriddenZkACLAndCredentialsProvidersTest.java @@ -30,15 +30,16 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.curator.framework.AuthInfo; +import org.apache.curator.framework.api.ACLProvider; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.cloud.DigestZkACLProvider; import org.apache.solr.common.cloud.DigestZkCredentialsProvider; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.cloud.VMParamsZkCredentialsInjector; -import org.apache.solr.common.cloud.ZkACLProvider; import org.apache.solr.common.cloud.ZkCredentialsInjector; import org.apache.solr.common.cloud.ZkCredentialsProvider; +import org.apache.solr.common.util.StrUtils; import org.apache.zookeeper.CreateMode; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -105,8 +106,7 @@ public void setUp() throws Exception { zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); } try (SolrZkClient zkClient = @@ -114,15 +114,14 @@ public void setUp() throws Exception { .getSolrZkClient( zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, - new AuthInfo("digest", - ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(DATA_ENCODING)))) { + new AuthInfo( + "digest", + ("connectAndAllACLUsername:connectAndAllACLPassword") + .getBytes(DATA_ENCODING)))) { zkClient.create( "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); } if (log.isInfoEnabled()) { @@ -141,7 +140,7 @@ public void tearDown() throws Exception { @Test public void testNoCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders(null, null, null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { AbstractDigestZkACLAndCredentialsProvidersTestBase.doTest( @@ -152,7 +151,7 @@ public void testNoCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() th @Test public void testWrongCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( "connectAndAllACLUsername", "connectAndAllACLPasswordWrong", null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { @@ -163,7 +162,7 @@ public void testWrongCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() @Test public void testAllCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( "connectAndAllACLUsername", "connectAndAllACLPassword", null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { @@ -175,7 +174,7 @@ public void testAllCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() t @Test public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProviders() throws Exception { - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientFactoryUsingCompletelyNewProviders( "readonlyACLUsername", "readonlyACLPassword", null, null) .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { @@ -190,7 +189,7 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useNoCredentials(); - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( new SolrZkClient.Builder() .withUrl(zkServer.getZkAddress()) @@ -206,7 +205,7 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useWrongCredentials(); - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( new SolrZkClient.Builder() .withUrl(zkServer.getZkAddress()) @@ -222,11 +221,11 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useAllCredentials(); - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( new SolrZkClient.Builder() .withUrl(zkServer.getZkAddress()) - .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS))) { + .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS))) { AbstractDigestZkACLAndCredentialsProvidersTestBase.doTest( zkClient, true, true, true, true, true, true, true, true, true, true); } @@ -238,7 +237,7 @@ public void testReadonlyCredentialsSolrZkClientFactoryUsingCompletelyNewProvider throws Exception { useReadonlyCredentials(); - try(SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClientUsingVMParamsProvidersButWithDifferentVMParamsNames( new SolrZkClient.Builder() .withUrl(zkServer.getZkAddress()) @@ -267,44 +266,38 @@ public SolrZkClientFactoryUsingCompletelyNewProviders( this.digestReadonlyPassword = digestReadonlyPassword; zkCredentialsInjector = () -> { - List zkCredentials = new ArrayList<>(2); ZkCredentialsInjector.ZkCredential allCreds = new ZkCredentialsInjector.ZkCredential(digestUsername, digestPassword, Perms.ALL); ZkCredentialsInjector.ZkCredential readCreds = new ZkCredentialsInjector.ZkCredential( digestReadonlyUsername, digestReadonlyPassword, Perms.READ); - zkCredentials.add(allCreds); - zkCredentials.add(readCreds); - return zkCredentials; + return List.of(allCreds, readCreds); }; } public SolrZkClient getSolrZkClient(String zkServerAddress, int zkClientTimeout) { AuthInfo authInfo = null; - if (!StringUtils.isEmpty(digestUsername) && !StringUtils.isEmpty(digestPassword)) { - authInfo = new AuthInfo( - "digest", - (digestUsername + ":" + digestPassword).getBytes(StandardCharsets.UTF_8)); + if (StrUtils.isNotNullOrEmpty(digestUsername) && StrUtils.isNotNullOrEmpty(digestPassword)) { + authInfo = + new AuthInfo( + "digest", (digestUsername + ":" + digestPassword).getBytes(StandardCharsets.UTF_8)); } return getSolrZkClient(zkServerAddress, zkClientTimeout, authInfo); } - public SolrZkClient getSolrZkClient(String zkServerAddress, int zkClientTimeout, AuthInfo authInfo) { + public SolrZkClient getSolrZkClient( + String zkServerAddress, int zkClientTimeout, AuthInfo authInfo) { final List authInfos = new ArrayList<>(); if (authInfo != null) { authInfos.add(authInfo); } - return new SolrZkClient(zkServerAddress, zkClientTimeout, new DefaultZkCredentialsProvider(authInfos), null) { - @Override - protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { - return new DigestZkCredentialsProvider(zkCredentialsInjector); - } - - @Override - public ZkACLProvider createZkACLProvider() { - return new DigestZkACLProvider(zkCredentialsInjector); - } - }; + return new SolrZkClient.Builder() + .withUrl(zkServerAddress) + .withZkCredentialsProvider( + new DigestZkCredentialsProvider(zkCredentialsInjector, authInfos)) + .withAclProvider(new DigestZkACLProvider(zkCredentialsInjector)) + .withTimeout(zkClientTimeout, TimeUnit.MILLISECONDS) + .build(); } } @@ -334,7 +327,7 @@ protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { } @Override - public ZkACLProvider createZkACLProvider() { + public ACLProvider createACLProvider() { return new DigestZkACLProvider(vmParamsZkCredentialsInjector); } } 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 8e55f38f018..573a7d0191c 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java @@ -58,7 +58,6 @@ import org.apache.solr.cloud.overseer.NodeMutator; import org.apache.solr.cloud.overseer.OverseerAction; import org.apache.solr.cloud.overseer.ZkWriteCommand; -import org.apache.solr.common.AlreadyClosedException; import org.apache.solr.common.SolrException; import org.apache.solr.common.cloud.ClusterState; import org.apache.solr.common.cloud.DocCollection; 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 f3c8186a8e8..a5439a1c2e0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java @@ -124,8 +124,7 @@ 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), StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); } @@ -374,8 +373,7 @@ 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")); // copy individual file down // src and cp3 are valid @@ -422,8 +420,7 @@ 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")); // Check that the form path/ works for copying files up. Should append the last bit of the // source path to the dst @@ -468,8 +465,7 @@ 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), StandardCharsets.UTF_8); assertTrue("There should be content in the node! ", content.contains("{Some Arbitrary Data}")); res = @@ -514,8 +510,7 @@ 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), 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 @@ -665,8 +660,7 @@ 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")); zkClient.makePath("/parentNode"); @@ -685,8 +679,7 @@ public void testMv() throws Exception { "Should be able to move a single file to a parent znode", zkClient.exists("/parentnode/schema.xml")); String content = - new String( - zkClient.getData("/parentnode/schema.xml", null, null), StandardCharsets.UTF_8); + new String(zkClient.getData("/parentnode/schema.xml", null, null), StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); } @@ -832,8 +825,7 @@ 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")); // Check that zk prefix also works. args = @@ -845,8 +837,7 @@ 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")); // This should silently just refuse to do anything to the / or /zookeeper args = @@ -896,8 +887,7 @@ 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)); } catch (Exception e) { fail( "Caught unexpected exception " 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 517482bbb27..0272ac5f806 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -448,13 +448,11 @@ public void testUploadErrors() throws Exception { zkClient.create( "/configs/myconf/firstDummyFile", "first dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); zkClient.create( "/configs/myconf/anotherDummyFile", "second dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); // Checking error when configuration name specified already exists ignoreException("already exists"); @@ -641,8 +639,7 @@ public void testOverwriteWithCleanup(boolean v2) throws Exception { 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)); } assertEquals(0, uploadConfigSet(configsetName, configsetSuffix, null, true, true, v2, false)); for (String f : extraFiles) { @@ -680,7 +677,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, true)); + zkClient.exists(f)); } } } @@ -989,8 +986,7 @@ 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")); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("ConfigSet uploads do not allow cleanup=true when filePath is used."); } @@ -1051,8 +1047,10 @@ 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")); assertTrue(isTrusted(zkClient, configsetName, configsetSuffix)); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("Trying to make an unstrusted ConfigSet update on a trusted configSet"); @@ -1125,8 +1123,7 @@ public void testSingleFileForbiddenType(boolean v2) throws Exception { + configsetName + configsetSuffix + "/test/different/path/solrconfig." - + fileType, - true)); + + fileType)); unIgnoreException("is forbidden for use in configSets"); } } @@ -1309,8 +1306,7 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { List children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixTrusted), - null - ); + null); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); @@ -1335,8 +1331,7 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixUntrusted), - null - ); + null); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); } @@ -1361,8 +1356,7 @@ private int getConfigZNodeVersion( zkClient.getData( String.format(Locale.ROOT, "/configs/%s%s/%s", configsetName, configsetSuffix, configFile), null, - stat - ); + stat); return stat.getVersion(); } @@ -1491,8 +1485,7 @@ private void assertConfigsetFiles(String configSetName, String suffix, SolrZkCli zkClient.exists("/configs/" + configSetName + suffix + "/managed-schema.xml")); 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), readFile("solr/configsets/upload/" + configSetName + "/managed-schema.xml")); assertTrue( @@ -1502,8 +1495,7 @@ private void assertConfigsetFiles(String configSetName, String suffix, SolrZkCli // 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), 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 4bd283f3500..4c30011b7be 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java @@ -96,8 +96,7 @@ private void setupBaseConfigSet(String baseConfigSetName) throws Exception { .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8) - ); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8)); } 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 efaeb816e55..94b7b3585d0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java @@ -156,8 +156,7 @@ private void setupBaseConfigSet(String baseConfigSetName, Map ol .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8) - ); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8)); } 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 263517a5adf..7a5c12a1278 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestDistributedMap.java @@ -79,12 +79,7 @@ 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); DistributedMap map = createMap(zkClient, path); assertArrayEquals(data, map.get("foo")); } @@ -104,8 +99,7 @@ public void testContains() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false - ); + false); assertTrue(map.contains("foo")); } } @@ -124,8 +118,7 @@ public void testRemove() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false - ); + false); assertTrue(map.remove("foo")); assertFalse(map.contains("foo")); assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); @@ -240,7 +233,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], true); + zkClient.makePath(path + "/" + DistributedMap.PREFIX + key, new byte[0]); DistributedMap map = createMap(zkClient, path); assertEquals(1, map.size()); 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 67670cda3dd..9fa4f473d07 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java @@ -75,10 +75,7 @@ public void test() throws Exception { zkClient.create( ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa1", new byte[1024], CreateMode.PERSISTENT); 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); 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 f658af2a8c8..96ef9151720 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java @@ -192,9 +192,7 @@ public void testCreateDelete() throws Exception { cluster .getZkClient() .getChildren( - ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), - null - ); + ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null); 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 dc21d5342fc..9fe42b53af0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestQueryingOnDownCollection.java @@ -139,8 +139,7 @@ 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)); } 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 b5a0ffcabf2..e891e567136 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java @@ -275,8 +275,7 @@ private void checkOneQueue(DocCollection coll, Slice slice, Set liveRep + "/leader_elect/" + slice.getName() + "/election", - null - ); + null); 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 a534e2e2a30..385c39c26d2 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], true); + zkClient.makePath(path + "/" + DistributedMap.PREFIX + "slash/test/0", new byte[0]); AtomicInteger overFlowCounter = new AtomicInteger(); DistributedMap map = 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 e8b0abb4465..d2b772b44f7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -222,9 +222,7 @@ public void testCreateDelete() throws Exception { cluster .getZkClient() .getChildren( - ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), - null - ); + ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null); 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 0799852edbc..95ca8d13ac0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java @@ -188,7 +188,7 @@ public void testPutCompressed() throws Exception { String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "put", "/state.json", data}; ZkCLI.main(args); - assertArrayEquals(zkClient.getZooKeeper().getData("/state.json", null, null), expected); + assertArrayEquals(zkClient.getCuratorFramework().getData().forPath("/state.json"), expected); // test re-put to existing data = "my data deux"; @@ -199,7 +199,7 @@ public void testPutCompressed() throws Exception { : zLibCompressor.compressBytes(dataBytes, dataBytes.length / 10); args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "put", "/state.json", data}; ZkCLI.main(args); - assertArrayEquals(zkClient.getZooKeeper().getData("/state.json", null, null), expected); + assertArrayEquals(zkClient.getCuratorFramework().getData().forPath("/state.json"), expected); } @Test @@ -216,8 +216,7 @@ 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), 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); @@ -240,7 +239,7 @@ public void testPutFileCompressed() throws Exception { }; ZkCLI.main(args); - byte[] fromZk = zkClient.getZooKeeper().getData("/state.json", null, null); + byte[] fromZk = zkClient.getCuratorFramework().getData().forPath("/state.json"); Path locFile = Path.of(SOLR_HOME, "solr-stress-new.xml"); byte[] fromLoc = new ZLibCompressor().compressBytes(Files.readAllBytes(locFile)); assertArrayEquals("Should get back what we put in ZK", fromLoc, fromZk); @@ -454,7 +453,7 @@ public void testGetCompressed() throws Exception { random().nextBoolean() ? zLibCompressor.compressBytes(data) : zLibCompressor.compressBytes(data, data.length / 10); - this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT, true); + this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "get", getNode}; ZkCLI.setStdout(new PrintStream(systemOut, true, StandardCharsets.UTF_8)); ZkCLI.main(args); @@ -501,7 +500,7 @@ public void testGetFileCompressed() throws Exception { random().nextBoolean() ? zLibCompressor.compressBytes(data) : zLibCompressor.compressBytes(data, data.length / 10); - this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT, true); + this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT); Path file = tmpDir.resolve("solrtest-getfile-" + this.getClass().getName() + "-" + System.nanoTime()); 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 84660ff2541..a83e5c31b1d 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java @@ -233,8 +233,7 @@ public List getCoreDescriptors() { .makePath( DocCollection.getCollectionPathRoot(collectionName), new byte[0], - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); ZkNodeProps m = new ZkNodeProps( @@ -340,30 +339,29 @@ public void testTouchConfDir() throws Exception { // touchConfDir doesn't make the znode Stat s = new Stat(); - assertFalse(zkClient.exists(zkpath, true)); + assertFalse(zkClient.exists(zkpath)); zkClient.makePath(zkpath, true); - assertTrue(zkClient.exists(zkpath, true)); - assertNull(zkClient.getData(zkpath, null, s, true)); + assertTrue(zkClient.exists(zkpath)); + assertNull(zkClient.getData(zkpath, null, s)); assertEquals(0, s.getVersion()); // touchConfDir should only set the data to new byte[] {0} ZkController.touchConfDir(loader); - assertTrue(zkClient.exists(zkpath, true)); - assertArrayEquals( - ZkController.TOUCHED_ZNODE_DATA, zkClient.getData(zkpath, null, s, true)); + assertTrue(zkClient.exists(zkpath)); + assertArrayEquals(ZkController.TOUCHED_ZNODE_DATA, zkClient.getData(zkpath, null, s)); 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, true); + s = zkClient.setData(zkpath, data); assertEquals(2, s.getVersion()); // make sure touchConfDir doesn't overwrite existing data. // touchConfDir should update version. - assertTrue(zkClient.exists(zkpath, true)); + assertTrue(zkClient.exists(zkpath)); ZkController.touchConfDir(loader); - assertTrue(zkClient.exists(zkpath, true)); - assertArrayEquals(data, zkClient.getData(zkpath, null, s, true)); + assertTrue(zkClient.exists(zkpath)); + assertArrayEquals(data, zkClient.getData(zkpath, null, s)); assertEquals(3, s.getVersion()); } } @@ -390,10 +388,7 @@ public void testCheckNoOldClusterstate() throws Exception { server .getZkClient() .create( - "/clusterstate.json", - "{}".getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT, - true); + "/clusterstate.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); AtomicInteger idx = new AtomicInteger(); CountDownLatch latch = new CountDownLatch(nThreads); CountDownLatch done = new CountDownLatch(nThreads); @@ -420,7 +415,7 @@ public void testCheckNoOldClusterstate() throws Exception { }); } done.await(); - assertFalse(server.getZkClient().exists("/clusterstate.json", true)); + assertFalse(server.getZkClient().exists("/clusterstate.json")); 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 6446b9cce08..bf2f1389a30 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java @@ -47,8 +47,8 @@ public static void beforeClass() throws Exception { @SuppressWarnings({"try"}) static class ZkConnection implements AutoCloseable { - private ZkTestServer server = null; - private SolrZkClient zkClient = null; + private final ZkTestServer server; + private final SolrZkClient zkClient; ZkConnection() throws Exception { Path zkDir = createTempDir("zkData"); @@ -87,15 +87,12 @@ public void testConnect() throws Exception { @SuppressWarnings({"try"}) public void testMakeRootNode() throws Exception { try (ZkConnection conn = new ZkConnection()) { - final SolrZkClient zkClient = + try (SolrZkClient zkClient = new SolrZkClient.Builder() .withUrl(conn.getServer().getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) - .build(); - try { + .build()) { assertTrue(zkClient.exists("/solr")); - } finally { - zkClient.close(); } } } @@ -118,7 +115,7 @@ public void testClean() throws Exception { public void testReconnect() throws Exception { Path zkDir = createTempDir("zkData"); - ZkTestServer server = null; + ZkTestServer server; server = new ZkTestServer(zkDir); server.run(); try (SolrZkClient zkClient = @@ -209,8 +206,7 @@ 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)); } finally { @@ -257,8 +253,7 @@ public void process(WatchedEvent event) { } watchesDone.countDown(); } - } - ); + }); } for (int i = 1; i <= numColls; i++) { @@ -304,8 +299,7 @@ public void process(WatchedEvent event) { throw new RuntimeException(e); } } - } - ); + }); zkClient.makePath("/collections/collection99/shards"); latch.await(); // wait until watch has been re-created @@ -336,11 +330,10 @@ public void testSkipPathPartsOnMakePath() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/test"); + zkClient.makePath("/test", true); // should work - zkClient.makePath( - "/test/path/here", (byte[]) null, CreateMode.PERSISTENT, (Watcher) null, true); + zkClient.makePath("/test/path/here", null, CreateMode.PERSISTENT, null, true, 1); zkClient.clean("/"); @@ -350,12 +343,7 @@ public void testSkipPathPartsOnMakePath() throws Exception { KeeperException.NoNodeException.class, "We should not be able to create this path", () -> - zkClient.ensureExists( - "/test/path/here", - (byte[]) null, - CreateMode.PERSISTENT, - 1 - )); + zkClient.makePath("/test/path/here", null, CreateMode.PERSISTENT, null, true, 1)); zkClient.clean("/"); @@ -365,11 +353,12 @@ public void testSkipPathPartsOnMakePath() throws Exception { () -> ZkMaintenanceUtils.ensureExists( "/collection/collection/leader", - null, + (byte[]) null, CreateMode.PERSISTENT, + zkClient, 2)); - zkClient.makePath("/collection"); + zkClient.makePath("/collection", true); expectThrows( KeeperException.NoNodeException.class, @@ -379,8 +368,9 @@ public void testSkipPathPartsOnMakePath() throws Exception { "/collections/collection/leader", (byte[]) null, CreateMode.PERSISTENT, + zkClient, 2)); - zkClient.makePath("/collection/collection"); + zkClient.makePath("/collection/collection", true); byte[] bytes = new byte[10]; ZkMaintenanceUtils.ensureExists( @@ -390,10 +380,10 @@ public void testSkipPathPartsOnMakePath() throws Exception { assertNull("We skipped 2 path parts, so data won't be written", returnedBytes); - zkClient.makePath("/collection/collection/leader"); + zkClient.makePath("/collection/collection/leader", true); ZkMaintenanceUtils.ensureExists( - "/collection/collection/leader", (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); + "/collection/collection/leader", null, CreateMode.PERSISTENT, zkClient, 2); } } @@ -408,8 +398,7 @@ public void testZkBehavior() throws Exception { 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") - ); + op -> op.delete().withVersion(-1).forPath("/test-node/abc")); stat = zkClient.exists("/test-node", null); assertTrue(stat.getCversion() >= cversion + 2); } finally { 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 226f6996aa2..021b93a9812 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,15 +65,13 @@ 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)); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName); cloudClient.request(delete); - assertFalse( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + assertFalse(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); // currently, removing a collection does not wait for cores to be unloaded TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); @@ -119,7 +117,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, true); + getZkClient().getNode(DocCollection.getCollectionPath(collectionName), null); DocCollection c = ClusterState.createFromCollectionMap( @@ -165,8 +163,7 @@ public void testDeleteAlsoDeletesAutocreatedConfigSet() throws Exception { cloudClient.request(delete); // collection has been deleted - assertFalse( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); + assertFalse(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); // ... and so has its autocreated config set assertFalse( "The auto-created config set should have been deleted with its collection", @@ -186,8 +183,7 @@ 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)); String configName = cloudClient @@ -213,8 +209,7 @@ 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)); String configNameOfSecondCollection = cloudClient @@ -235,8 +230,7 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // initial collection has been deleted assertFalse( - getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); // ... 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.", @@ -251,8 +245,7 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // the collection has been deleted assertFalse( getZkClient() - .exists( - ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); // ... and the config set is now also deleted - once it doesn't get referenced by any // collection assertFalse( 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 d1000a4eb56..04e1fff06e7 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,9 +76,7 @@ public static void setupClass() throws Exception { cluster .getZkClient() .delete( - ZkConfigSetService.CONFIGS_ZKNODE + "/" + "confFaulty" + "/" + "solrconfig.xml", - -1 - ); + ZkConfigSetService.CONFIGS_ZKNODE + "/" + "confFaulty" + "/" + "solrconfig.xml", -1); 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 3e1ca33963c..bb5a5fc0524 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); // 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); 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 92c8639a8c9..1ef1cb28a0c 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 @@ -500,9 +500,7 @@ public void testSingleExternalCollectionCompressedState() throws Exception { writer.writePendingUpdates(); byte[] data = - zkClient - .getZooKeeper() - .getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null); + zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null); Map map = (Map) Utils.fromJSON(data); assertNotNull(map.get("c1")); } @@ -537,8 +535,9 @@ public void testSingleExternalCollectionCompressedState() throws Exception { byte[] data = zkClient - .getZooKeeper() - .getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c2/state.json", null, null); + .getCuratorFramework() + .getData() + .forPath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2/state.json"); assertTrue(compressor.isCompressedBytes(data)); Map map = (Map) Utils.fromJSON(compressor.decompressBytes(data)); assertNotNull(map.get("c2")); 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 4ddf7c1e80b..ee4cf40ed34 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,9 +86,7 @@ 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); Utils.executeGET( client.getHttpClient(), basezk + "/configs/_default/testdata", 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 dcff273af94..bcb51f4217d 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,8 +180,7 @@ public void testEnableDisableOptions() throws Exception { assertTrue( cluster .getZkClient() - .exists( - SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); + .exists(SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); assertNotNull(schema.getFieldTypeByName("text_fr")); assertNotNull(schema.getFieldOrNull("*_txt_fr")); assertNull(schema.getFieldOrNull("*_txt_ga")); @@ -204,8 +203,7 @@ public void testEnableDisableOptions() throws Exception { assertTrue( cluster .getZkClient() - .exists( - SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); + .exists(SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); 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/security/TestAuthorizationFramework.java b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java index 5f7fae6031c..ee04fcf20ed 100644 --- a/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java +++ b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java @@ -53,8 +53,7 @@ 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); } } 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 41a46a23453..efba05bc1ca 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,8 +214,7 @@ public void test() throws Exception { + "/" + COLLECTION_PROPS_ZKNODE, null, - null - ); + null); assertNotNull(data); assertTrue(data.length > 0); @SuppressWarnings("unchecked") @@ -1048,8 +1047,7 @@ public void process(WatchedEvent watchedEvent) { aliasUpdate.countDown(); } }, - stat - ); + stat); } /** diff --git a/solr/licenses/curator-client-LICENSE-ASL.txt b/solr/licenses/curator-LICENSE-ASL.txt similarity index 100% rename from solr/licenses/curator-client-LICENSE-ASL.txt rename to solr/licenses/curator-LICENSE-ASL.txt diff --git a/solr/licenses/curator-client-NOTICE.txt b/solr/licenses/curator-NOTICE.txt similarity index 100% rename from solr/licenses/curator-client-NOTICE.txt rename to solr/licenses/curator-NOTICE.txt diff --git a/solr/licenses/curator-framework-LICENSE-ASL.txt b/solr/licenses/curator-framework-LICENSE-ASL.txt deleted file mode 100644 index 7a4a3ea2424..00000000000 --- a/solr/licenses/curator-framework-LICENSE-ASL.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/solr/licenses/curator-framework-NOTICE.txt b/solr/licenses/curator-framework-NOTICE.txt deleted file mode 100644 index f568d0fe32e..00000000000 --- a/solr/licenses/curator-framework-NOTICE.txt +++ /dev/null @@ -1,5 +0,0 @@ -Apache Curator -Copyright 2013-2014 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). \ No newline at end of file diff --git a/solr/licenses/curator-recipes-LICENSE-ASL.txt b/solr/licenses/curator-recipes-LICENSE-ASL.txt deleted file mode 100644 index 7a4a3ea2424..00000000000 --- a/solr/licenses/curator-recipes-LICENSE-ASL.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/solr/licenses/curator-recipes-NOTICE.txt b/solr/licenses/curator-recipes-NOTICE.txt deleted file mode 100644 index f568d0fe32e..00000000000 --- a/solr/licenses/curator-recipes-NOTICE.txt +++ /dev/null @@ -1,5 +0,0 @@ -Apache Curator -Copyright 2013-2014 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). \ No newline at end of file diff --git a/solr/licenses/curator-test-5.5.0.jar.sha1 b/solr/licenses/curator-test-5.5.0.jar.sha1 new file mode 100644 index 00000000000..5f377502d11 --- /dev/null +++ b/solr/licenses/curator-test-5.5.0.jar.sha1 @@ -0,0 +1 @@ +065586d87700aa29855e6aa566b210eadd1bb38d diff --git a/solr/modules/hadoop-auth/build.gradle b/solr/modules/hadoop-auth/build.gradle index 3bf7bfab75f..3aec2cfd644 100644 --- a/solr/modules/hadoop-auth/build.gradle +++ b/solr/modules/hadoop-auth/build.gradle @@ -50,14 +50,15 @@ dependencies { implementation('org.apache.zookeeper:zookeeper', { exclude group: "org.apache.yetus", module: "audience-annotations" }) - implementation ('org.apache.zookeeper:zookeeper-jute') { - exclude group: 'org.apache.yetus', module: 'audience-annotations' - } // required for instantiating a Zookeeper server (for embedding ZK or running tests) runtimeOnly 'org.xerial.snappy:snappy-java' - implementation 'org.apache.curator:curator-client' - implementation 'org.apache.curator:curator-framework' - runtimeOnly 'org.apache.curator:curator-recipes' + + implementation('org.apache.curator:curator-framework', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) + runtimeOnly('org.apache.curator:curator-recipes', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) // Hadoop auth framework implementation 'org.apache.hadoop:hadoop-annotations' @@ -105,6 +106,9 @@ dependencies { testImplementation('org.apache.zookeeper:zookeeper', { exclude group: "org.apache.yetus", module: "audience-annotations" }) + testImplementation ('org.apache.zookeeper:zookeeper-jute') { + exclude group: 'org.apache.yetus', module: 'audience-annotations' + } // required for instantiating a Zookeeper server in tests or embedded testRuntimeOnly ('org.xerial.snappy:snappy-java') } 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 4e52c11ac8d..a1c211b05ad 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 @@ -20,11 +20,8 @@ import static org.apache.hadoop.security.token.delegation.ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH_DEAFULT; import java.io.IOException; -import java.util.ArrayList; import java.util.Enumeration; -import java.util.List; import java.util.Objects; -import java.util.concurrent.ExecutorService; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; @@ -32,7 +29,6 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.utils.ZKPaths; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.server.AuthenticationHandler; @@ -40,10 +36,6 @@ import org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkACLProvider; -import org.apache.solr.common.cloud.ZkCredentialsProvider; -import org.apache.solr.common.util.ExecutorUtil; -import org.apache.solr.common.util.SolrNamedThreadFactory; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -53,9 +45,6 @@ * reuse the authentication of an end-user or another application. */ public class DelegationTokenKerberosFilter extends DelegationTokenAuthenticationFilter { - private ExecutorService curatorSafeServiceExecutor; - private CuratorFramework curatorFramework; - @Override public void init(FilterConfig conf) throws ServletException { if (conf != null && "zookeeper".equals(conf.getInitParameter("signer.secret.provider"))) { @@ -124,19 +113,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo super.doFilter(request, response, filterChainWrapper); } - @Override - public void destroy() { - super.destroy(); - if (curatorFramework != null) { - curatorFramework.close(); - curatorFramework = null; - } - if (curatorSafeServiceExecutor != null) { - ExecutorUtil.shutdownNowAndAwaitTermination(curatorSafeServiceExecutor); - curatorSafeServiceExecutor = null; - } - } - @Override protected void initializeAuthHandler(String authHandlerClassName, FilterConfig filterConfig) throws ServletException { @@ -182,12 +158,15 @@ 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); } catch (KeeperException.NodeExistsException ex) { // ignore? } - return zkClient.getCuratorFramework().usingNamespace(zkClient.getAbsolutePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH)); + // Note - Curator complains if the namespace starts with / + String namespace = zkClient.getAbsolutePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH); + namespace = namespace.startsWith("/") ? namespace.substring(1) : namespace; + + return zkClient.getCuratorFramework().usingNamespace(namespace); } } 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 328cc871fc7..9a5dcff772d 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 @@ -20,10 +20,7 @@ import static org.apache.hadoop.security.token.delegation.ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH_DEAFULT; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; -import java.util.concurrent.ExecutorService; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; @@ -31,17 +28,12 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.utils.ZKPaths; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.server.AuthenticationHandler; import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter; import org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation; import org.apache.solr.common.cloud.SecurityAwareZkACLProvider; import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.ZkACLProvider; -import org.apache.solr.common.cloud.ZkCredentialsProvider; -import org.apache.solr.common.util.ExecutorUtil; -import org.apache.solr.common.util.SolrNamedThreadFactory; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -55,9 +47,6 @@ public class HadoopAuthFilter extends DelegationTokenAuthenticationFilter { */ static final String DELEGATION_TOKEN_ZK_CLIENT = "solr.kerberos.delegation.token.zk.client"; - private ExecutorService curatorSafeServiceExecutor; - private CuratorFramework curatorFramework; - @Override public void init(FilterConfig conf) throws ServletException { if (conf != null && "zookeeper".equals(conf.getInitParameter("signer.secret.provider"))) { @@ -106,14 +95,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo @Override public void destroy() { super.destroy(); - if (curatorFramework != null) { - curatorFramework.close(); - curatorFramework = null; - } - if (curatorSafeServiceExecutor != null) { - ExecutorUtil.shutdownNowAndAwaitTermination(curatorSafeServiceExecutor); - curatorSafeServiceExecutor = null; - } } @Override @@ -161,12 +142,15 @@ 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); } catch (KeeperException.NodeExistsException ex) { // ignore? } - return zkClient.getCuratorFramework().usingNamespace(zkClient.getAbsolutePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH)); + // Note - Curator complains if the namespace starts with / + String namespace = zkClient.getAbsolutePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH); + namespace = namespace.startsWith("/") ? namespace.substring(1) : namespace; + + return zkClient.getCuratorFramework().usingNamespace(namespace); } } diff --git a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthPlugin.java b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthPlugin.java index 3e9d904d6f9..f48d36d6d18 100644 --- a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthPlugin.java +++ b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/HadoopAuthPlugin.java @@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.hadoop.security.authentication.server.AuthenticationFilter; +import org.apache.hadoop.security.authentication.util.ZKSignerSecretProvider; import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationHandler; import org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder; import org.apache.solr.cloud.ZkController; @@ -189,6 +190,7 @@ protected FilterConfig getInitFilterConfig(Map pluginConfig) { ZkController controller = coreContainer.getZkController(); if (controller != null) { servletContext.setAttribute(DELEGATION_TOKEN_ZK_CLIENT, controller.getZkClient()); + params.put(ZKSignerSecretProvider.DISCONNECT_FROM_ZOOKEEPER_ON_SHUTDOWN, "false"); } FilterConfig conf = diff --git a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/KerberosPlugin.java b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/KerberosPlugin.java index 34729db1f1d..45aa467ba00 100644 --- a/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/KerberosPlugin.java +++ b/solr/modules/hadoop-auth/src/java/org/apache/solr/security/hadoop/KerberosPlugin.java @@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.hadoop.security.authentication.util.KerberosName; +import org.apache.hadoop.security.authentication.util.ZKSignerSecretProvider; import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationHandler; import org.apache.http.HttpRequest; import org.apache.http.protocol.HttpContext; @@ -157,6 +158,8 @@ protected FilterConfig getInitFilterConfig( "/token"); // ensure krb5 is setup properly before running curator getHttpClientBuilder(SolrHttpClientBuilder.create()); + + params.put(ZKSignerSecretProvider.DISCONNECT_FROM_ZOOKEEPER_ON_SHUTDOWN, "false"); } } else { log.info( 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 8fe877ef628..79f69681947 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 @@ -114,15 +114,11 @@ protected void setupZNodes() throws Exception { zkClient.create( "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); } finally { zkClient.close(); } @@ -130,15 +126,9 @@ 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); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT - ); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); } finally { zkClient.close(); } diff --git a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java index 6a1d484c917..2adb385ff04 100644 --- a/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java +++ b/solr/modules/hadoop-auth/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java @@ -53,8 +53,7 @@ public static void setupClass() throws Exception { InetAddress loopback = InetAddress.getLoopbackAddress(); Path securityJsonPath = TEST_PATH().resolve("security").resolve("hadoop_simple_auth_with_delegation.json"); - String securityJson = - new String(Files.readAllBytes(securityJsonPath), Charset.defaultCharset()); + String securityJson = Files.readString(securityJsonPath, Charset.defaultCharset()); Map securityConfig = (Map) Utils.fromJSONString(securityJson); Map authConfig = (Map) securityConfig.get("authentication"); 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 035b3211368..1a99d543af5 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 @@ -77,10 +77,6 @@ public static void startup() throws Exception { @AfterClass public static void shutdown() throws Exception { - if (miniCluster != null) { - miniCluster.shutdown(); - miniCluster = null; - } if (null != solrClientPrimary) { solrClientPrimary.close(); solrClientPrimary = null; @@ -89,6 +85,11 @@ public static void shutdown() throws Exception { solrClientSecondary.close(); solrClientSecondary = null; } + + if (miniCluster != null) { + miniCluster.shutdown(); + miniCluster = null; + } System.clearProperty("authenticationPlugin"); System.clearProperty(KerberosPlugin.DELEGATION_TOKEN_ENABLED); System.clearProperty("solr.kerberos.cookie.domain"); 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 aad14e6d956..b1616c20b6f 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,8 +160,7 @@ public static void setupClass() throws Exception { + "confFaulty" + Path.SEPARATOR + "solrconfig.xml", - -1 - ); + -1); } @AfterClass diff --git a/solr/solrj-zookeeper/build.gradle b/solr/solrj-zookeeper/build.gradle index 1ac5febdb06..0ddc632759a 100644 --- a/solr/solrj-zookeeper/build.gradle +++ b/solr/solrj-zookeeper/build.gradle @@ -32,6 +32,13 @@ dependencies { implementation project(':solr:solrj') + api('org.apache.curator:curator-client', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) + api('org.apache.curator:curator-framework', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) + // declare dependencies we use even though already declared by solrj-core implementation 'org.slf4j:slf4j-api' implementation 'org.apache.httpcomponents:httpclient' diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java index c280693edfa..c558debc62d 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/client/solrj/cloud/DistribStateManager.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; - import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.solr.common.SolrCloseable; import org.apache.solr.common.cloud.DocCollection; 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 075c1e4d3de..4e74981a661 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, true); + byte[] data = zkClient.getData(path, null, null); 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 d41bac688ef..15d3ebc2651 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 @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; - import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.solr.client.solrj.cloud.AlreadyExistsException; import org.apache.solr.client.solrj.cloud.BadVersionException; 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 0378bda4fdd..5848831fd76 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 @@ -84,8 +84,7 @@ 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); if (data != null && data.length > 0) { consumer.read(new ByteArrayInputStream(data)); } else { 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 6faf0ffda0b..784046c122a 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 @@ -205,15 +205,13 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws // 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()); } } 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()); } } } else { 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 b045a60a967..25b13086267 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,8 +67,7 @@ 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())); } catch (KeeperException.NoNodeException e) { return Collections.emptyMap(); } catch (KeeperException | InterruptedException e) { diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java index 447a8d93802..2582d01a0b9 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkACLProvider.java @@ -17,12 +17,10 @@ package org.apache.solr.common.cloud; import java.util.List; - -import org.apache.curator.framework.api.ACLProvider; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.data.ACL; -public class DefaultZkACLProvider implements ACLProvider { +public class DefaultZkACLProvider implements ZkACLProvider { private volatile List globalACLsToAdd; @@ -34,6 +32,17 @@ public DefaultZkACLProvider(List globalACLsToAdd) { this.globalACLsToAdd = globalACLsToAdd; } + @Override + public List getACLsToAdd(String zNodePath) { + // In default (simple) implementation use the same set of ACLs for all znodes + if (globalACLsToAdd == null) { + synchronized (this) { + if (globalACLsToAdd == null) globalACLsToAdd = createGlobalACLsToAdd(); + } + } + return globalACLsToAdd; + } + @Override public List getAclForPath(String zNodePath) { // In default (simple) implementation use the same set of ACLs for all znodes diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java index d6e6f3f8652..cfdd2098f94 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DefaultZkCredentialsProvider.java @@ -16,11 +16,9 @@ */ package org.apache.solr.common.cloud; -import org.apache.curator.framework.AuthInfo; - import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import org.apache.curator.framework.AuthInfo; public class DefaultZkCredentialsProvider implements ZkCredentialsProvider { @@ -28,11 +26,21 @@ public class DefaultZkCredentialsProvider implements ZkCredentialsProvider { protected ZkCredentialsInjector zkCredentialsInjector; public DefaultZkCredentialsProvider() { - this(new DefaultZkCredentialsInjector()); + this(new DefaultZkCredentialsInjector(), null); + } + + public DefaultZkCredentialsProvider(List zkCredentials) { + this(new DefaultZkCredentialsInjector(), zkCredentials); } public DefaultZkCredentialsProvider(ZkCredentialsInjector zkCredentialsInjector) { + this(zkCredentialsInjector, null); + } + + public DefaultZkCredentialsProvider( + ZkCredentialsInjector zkCredentialsInjector, List zkCredentials) { this.zkCredentialsInjector = zkCredentialsInjector; + this.zkCredentials = zkCredentials; } @Override diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java index 314990ff278..6b6edaafc85 100755 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java @@ -39,7 +39,9 @@ public class DigestZkACLProvider extends SecurityAwareZkACLProvider { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); /** Called by reflective instantiation */ - public DigestZkACLProvider() {} + public DigestZkACLProvider() { + super(); + } public DigestZkACLProvider(ZkCredentialsInjector zkCredentialsInjector) { super(zkCredentialsInjector); diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkCredentialsProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkCredentialsProvider.java index cfe30286dc9..6eeefc6c106 100755 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkCredentialsProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/DigestZkCredentialsProvider.java @@ -19,8 +19,8 @@ import java.lang.invoke.MethodHandles; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import org.apache.curator.framework.AuthInfo; import org.apache.solr.common.util.StrUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,15 +34,26 @@ public class DigestZkCredentialsProvider extends DefaultZkCredentialsProvider { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); /** Called by reflective instantiation */ - public DigestZkCredentialsProvider() {} + public DigestZkCredentialsProvider() { + super(); + } public DigestZkCredentialsProvider(ZkCredentialsInjector zkCredentialsInjector) { super(zkCredentialsInjector); } + public DigestZkCredentialsProvider(List zkCredentials) { + super(new DefaultZkCredentialsInjector(), zkCredentials); + } + + public DigestZkCredentialsProvider( + ZkCredentialsInjector zkCredentialsInjector, List zkCredentials) { + super(zkCredentialsInjector, zkCredentials); + } + @Override - protected Collection createCredentials() { - List result = new ArrayList<>(1); + protected List createCredentials() { + List result = new ArrayList<>(1); List zkCredentials = zkCredentialsInjector.getZkCredentials(); log.debug("createCredentials using zkCredentials: {}", zkCredentials); @@ -52,7 +63,7 @@ protected Collection createCredentials() { if (StrUtils.isNotNullOrEmpty(zkCredential.getUsername()) && StrUtils.isNotNullOrEmpty(zkCredential.getPassword())) { result.add( - new ZkCredentials( + new AuthInfo( "digest", (zkCredential.getUsername() + ":" + zkCredential.getPassword()) .getBytes(StandardCharsets.UTF_8))); diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/OnDisconnect.java similarity index 100% rename from solr/solrj/src/java/org/apache/solr/common/cloud/OnDisconnect.java rename to solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/OnDisconnect.java diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/OnReconnect.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/OnReconnect.java index ecd3f623975..1863d797938 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/OnReconnect.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/OnReconnect.java @@ -16,12 +16,10 @@ */ package org.apache.solr.common.cloud; +import java.util.concurrent.atomic.AtomicBoolean; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.framework.state.ConnectionStateListener; -import org.apache.zookeeper.KeeperException.SessionExpiredException; - -import java.util.concurrent.atomic.AtomicBoolean; /** * Implementations are expected to implement a correct hashCode and equals method needed to uniquely 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 350bb8fd766..2194defcdde 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, true); + Stat stat = zkClient.exists(current.path, null); 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, true); + List children = zkClient.getChildren(path, null, stat); return new PerReplicaStates(path, stat.getCversion(), Collections.unmodifiableList(children)); } catch (KeeperException.NoNodeException e) { throw new PrsZkNodeNotFoundException( diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java index 54d034f3ac6..ca2ba3bfe0a 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SaslZkACLProvider.java @@ -17,7 +17,6 @@ package org.apache.solr.common.cloud; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.data.ACL; diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java index 67b680d4aa8..e0a42c79ebb 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java @@ -17,7 +17,6 @@ package org.apache.solr.common.cloud; import java.util.List; - import org.apache.curator.utils.ZKPaths; import org.apache.zookeeper.data.ACL; @@ -28,7 +27,6 @@ public abstract class SecurityAwareZkACLProvider implements ZkACLProvider { public static final String SECURITY_ZNODE_PATH = "/security"; -<<<<<<< HEAD:solr/solrj/src/java/org/apache/solr/common/cloud/SecurityAwareZkACLProvider.java private volatile List nonSecurityACLsToAdd; private volatile List securityACLsToAdd; @@ -43,9 +41,24 @@ public SecurityAwareZkACLProvider() { } public SecurityAwareZkACLProvider(String chroot) { - this.securityConfPath = ZKPaths.makePath(chroot, ZkStateReader.SOLR_SECURITY_CONF_PATH); - this.securityZNodePath = ZKPaths.makePath(chroot, SECURITY_ZNODE_PATH); - this.securityZNodePathDir = securityZNodePath + "/"; + this(new DefaultZkCredentialsInjector(), chroot); + } + + public SecurityAwareZkACLProvider(ZkCredentialsInjector zkCredentialsInjector) { + this(zkCredentialsInjector, null); + } + + public SecurityAwareZkACLProvider(ZkCredentialsInjector zkCredentialsInjector, String chroot) { + this.zkCredentialsInjector = zkCredentialsInjector; + if (chroot != null) { + this.securityConfPath = ZKPaths.makePath(chroot, ZkStateReader.SOLR_SECURITY_CONF_PATH); + this.securityZNodePath = ZKPaths.makePath(chroot, SECURITY_ZNODE_PATH); + this.securityZNodePathDir = securityZNodePath + "/"; + } else { + this.securityConfPath = null; + this.securityZNodePath = null; + this.securityZNodePathDir = null; + } } public SecurityAwareZkACLProvider withChroot(String chroot) { @@ -62,10 +75,6 @@ protected List createSecurityACLsToAdd() { }; } - public SecurityAwareZkACLProvider(ZkCredentialsInjector zkCredentialsInjector) { - this.zkCredentialsInjector = zkCredentialsInjector; - } - @Override public void setZkCredentialsInjector(ZkCredentialsInjector zkCredentialsInjector) { this.zkCredentialsInjector = zkCredentialsInjector; @@ -89,7 +98,7 @@ protected boolean isSecurityZNodePath(String zNodePath) { return zNodePath != null && (zNodePath.equals(securityConfPath) || zNodePath.equals(securityZNodePath) - || zNodePath.startsWith(securityZNodePathDir)); + || (securityZNodePathDir != null && zNodePath.startsWith(securityZNodePathDir))); } /** 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 487fa6b427b..0a35bad37e5 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,12 +71,9 @@ 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, true); + zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); } else { - data = - zkStateReader - .getZkClient() - .getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, this, true); + data = zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); } try { callback.call(data); @@ -97,7 +94,7 @@ public void process(WatchedEvent event) { } void register() throws InterruptedException, KeeperException { - zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this, true); + zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); securityData = getSecurityProps(true); } @@ -108,9 +105,9 @@ ZkStateReader.ConfigData getSecurityProps(boolean getFresh) { return new ZkStateReader.ConfigData(securityData.data, securityData.version); } try { - if (zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, true)) { + if (zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH)) { SolrZkClient.NodeData d = - zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, true); + zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, null); 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 b8bd32c95be..c87be19e421 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 @@ -29,14 +29,13 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.LongAdder; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Collectors; - import org.apache.curator.RetryPolicy; import org.apache.curator.ensemble.fixed.FixedEnsembleProvider; import org.apache.curator.framework.CuratorFramework; @@ -45,8 +44,6 @@ import org.apache.curator.framework.api.transaction.CuratorOp; import org.apache.curator.framework.api.transaction.CuratorTransactionResult; import org.apache.curator.framework.api.transaction.TransactionOp; -import org.apache.curator.framework.state.SessionConnectionStateErrorPolicy; -import org.apache.curator.framework.state.StandardConnectionStateErrorPolicy; import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.curator.utils.ZKPaths; import org.apache.solr.client.solrj.SolrServerException; @@ -54,9 +51,9 @@ import org.apache.solr.common.MapWriter; import org.apache.solr.common.SolrException; import org.apache.solr.common.annotation.JsonProperty; -import org.apache.solr.common.cloud.ConnectionManager.IsClosed; import org.apache.solr.common.util.Compressor; import org.apache.solr.common.util.ExecutorUtil; +import org.apache.solr.common.util.IOUtils; import org.apache.solr.common.util.ObjectReleaseTracker; import org.apache.solr.common.util.ReflectMapWriter; import org.apache.solr.common.util.SolrNamedThreadFactory; @@ -67,6 +64,7 @@ import org.apache.zookeeper.KeeperException.NoNodeException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier; @@ -84,6 +82,7 @@ public class SolrZkClient implements Closeable { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private ExecutorService curatorSafeServiceExecutor; CuratorFramework client; private final ZkMetrics metrics = new ZkMetrics(); @@ -102,7 +101,7 @@ public MapWriter getMetrics() { private volatile boolean isClosed = false; private int zkClientTimeout; - private ZkACLProvider zkACLProvider; + private ACLProvider aclProvider; private ZkCredentialsInjector zkCredentialsInjector; private String zkServerAddress; private SolrClassLoader solrClassLoader; @@ -118,10 +117,10 @@ public SolrZkClient(Builder builder) { builder.zkServerAddress, builder.zkClientTimeout, builder.zkClientConnectTimeout, - builder.connectionStrategy, + builder.zkCredentialsProvider, + builder.aclProvider, builder.onReconnect, builder.beforeReconnect, - builder.zkACLProvider, builder.higherLevelIsClosed, builder.compressor, builder.solrClassLoader); @@ -135,7 +134,6 @@ private SolrZkClient( ACLProvider aclProvider, final OnReconnect onReconnect, BeforeReconnect beforeReconnect, - ZkACLProvider zkACLProvider, IsClosed higherLevelIsClosed, Compressor compressor, SolrClassLoader solrClassLoader) { @@ -145,44 +143,73 @@ private SolrZkClient( return; } this.zkServerAddress = zkServerAddress; + String chroot, zkHost; + int chrootIndex = zkServerAddress.indexOf('/'); + if (chrootIndex == -1) { + zkHost = zkServerAddress; + chroot = null; + } else if (chrootIndex == zkServerAddress.length() - 1) { + zkHost = zkServerAddress.substring(0, zkServerAddress.length() - 1); + chroot = null; + } else { + zkHost = zkServerAddress.substring(0, chrootIndex); + chroot = zkServerAddress.substring(chrootIndex + 1); + } + this.higherLevelIsClosed = higherLevelIsClosed; if (zkCredentialsProvider == null) { + zkCredentialsInjector = createZkCredentialsInjector(); zkCredentialsProvider = createZkCredentialsToAddAutomatically(); } if (aclProvider == null) { aclProvider = createACLProvider(); } if (chroot != null && aclProvider instanceof SecurityAwareZkACLProvider) { - this.aclProvider = ((SecurityAwareZkACLProvider)aclProvider).withChroot(chroot); + this.aclProvider = ((SecurityAwareZkACLProvider) aclProvider).withChroot(chroot); } else { this.aclProvider = aclProvider; } this.zkClientTimeout = zkClientTimeout; + curatorSafeServiceExecutor = + ExecutorUtil.newMDCAwareSingleThreadExecutor( + new SolrNamedThreadFactory("curator-safeService")); + RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); - var clientBuilder = CuratorFrameworkFactory.builder() - .ensembleProvider(new FixedEnsembleProvider(zkHost)) - .namespace(chroot) - .sessionTimeoutMs(zkClientTimeout) - .connectionTimeoutMs(clientConnectTimeout) - .aclProvider(this.aclProvider) - .authorization(zkCredentialsProvider.getCredentials()) - .retryPolicy(retryPolicy); + var clientBuilder = + CuratorFrameworkFactory.builder() + .ensembleProvider(new FixedEnsembleProvider(zkHost)) + .namespace(chroot) + .sessionTimeoutMs(zkClientTimeout) + .connectionTimeoutMs(clientConnectTimeout) + .aclProvider(this.aclProvider) + .authorization(zkCredentialsProvider.getCredentials()) + .retryPolicy(retryPolicy) + .runSafeService(curatorSafeServiceExecutor); client = clientBuilder.build(); if (onReconnect != null) { - client.getConnectionStateListenable().addListener(onReconnect, zkConnectionListenerCallbackExecutor); + client + .getConnectionStateListenable() + .addListener(onReconnect, zkConnectionListenerCallbackExecutor); } if (beforeReconnect != null) { - client.getConnectionStateListenable().addListener(beforeReconnect, zkConnectionListenerCallbackExecutor); + client + .getConnectionStateListenable() + .addListener(beforeReconnect, zkConnectionListenerCallbackExecutor); } client.start(); try { if (!client.blockUntilConnected(clientConnectTimeout, TimeUnit.MILLISECONDS)) { - throw new TimeoutException(String.format(Locale.ROOT, "Timeout while waiting for Zookeeper Client to connect: %d ms", clientConnectTimeout)); - }; + throw new TimeoutException( + String.format( + Locale.ROOT, + "Timeout while waiting for Zookeeper Client to connect: %d ms", + clientConnectTimeout)); + } + ; } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); @@ -192,11 +219,6 @@ private SolrZkClient( } assert ObjectReleaseTracker.track(this); - if (zkACLProvider == null) { - this.zkACLProvider = createZkACLProvider(); - } else { - this.zkACLProvider = zkACLProvider; - } if (compressor == null) { this.compressor = new ZLibCompressor(); @@ -241,19 +263,31 @@ protected ZkCredentialsProvider createZkCredentialsToAddAutomatically() { public static final String ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME = "zkACLProvider"; protected ACLProvider createACLProvider() { - String aclProviderClassName = System.getProperty(ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME); - if (StrUtils.isNotNullOrEmpty(aclProviderClassName)) { + String zkACLProviderClassName = System.getProperty(ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME); + if (StrUtils.isNotNullOrEmpty(zkACLProviderClassName)) { try { - log.info("Using ACLProvider: {}", aclProviderClassName); - return (ACLProvider) Class.forName(aclProviderClassName).getConstructor().newInstance(); - } catch (Throwable t) { - // just ignore - go default - log.warn( - "VM param zkACLProvider does not point to a class implementingACLProvider and with a single-arg constructor (passing through the chroot)", - t); + log.info("Using ZkACLProvider: {}", zkACLProviderClassName); + ZkACLProvider zkACLProvider = + solrClassLoader == null + ? Class.forName(zkACLProviderClassName) + .asSubclass(ZkACLProvider.class) + .getConstructor() + .newInstance() + : solrClassLoader.newInstance(zkACLProviderClassName, ZkACLProvider.class); + zkACLProvider.setZkCredentialsInjector(zkCredentialsInjector); + return zkACLProvider; + } catch (Exception e) { + // Fail-fast. If the instantiation fails better fail-fast rather than use the default unsafe + // ZkACLProvider + throw new SolrException( + SolrException.ErrorCode.SERVER_ERROR, + "VM param zkACLProvider does not point to a class implementing " + + "ZkACLProvider and with a non-arg constructor", + e); } } - log.debug("Using default ACLProvider"); + log.warn( + "Using default ZkACLProvider. DefaultZkACLProvider is not secure, it creates 'OPEN_ACL_UNSAFE' ACLs to Zookeeper nodes"); return new DefaultZkACLProvider(); } @@ -297,15 +331,15 @@ public boolean isConnected() { public void delete(final String path, final int version) throws InterruptedException, KeeperException { runWithCorrectThrows( - "deleting znode", - () -> client.delete().withVersion(version).forPath(path)); + "deleting znode", () -> client.delete().withVersion(version).forPath(path)); metrics.deletes.increment(); } /** * 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, Watcher)} or {@link + * #getData(String, Watcher, Stat)}. */ public Watcher wrapWatcher(final Watcher watcher) { if (watcher == null || watcher instanceof ProcessWatchWithExecutor) return watcher; @@ -328,19 +362,18 @@ public Watcher wrapWatcher(final Watcher watcher) { */ public Stat exists(final String path, final Watcher watcher) throws KeeperException, InterruptedException { - Stat result = runWithCorrectThrows( - "checking exists", - () -> client.checkExists().usingWatcher(wrapWatcher(watcher)).forPath(path)); + Stat result = + runWithCorrectThrows( + "checking exists", + () -> client.checkExists().usingWatcher(wrapWatcher(watcher)).forPath(path)); metrics.existsChecks.increment(); return result; } /** Returns true if path exists */ - public Boolean exists(final String path) - throws KeeperException, InterruptedException { - Boolean result = runWithCorrectThrows( - "checking exists", - () -> client.checkExists().forPath(path) != null); + public Boolean exists(final String path) throws KeeperException, InterruptedException { + Boolean result = + runWithCorrectThrows("checking exists", () -> client.checkExists().forPath(path) != null); metrics.existsChecks.increment(); return result; } @@ -348,9 +381,10 @@ public Boolean exists(final String path) /** Returns children of the node at the path */ public List getChildren(final String path, final Watcher watcher) throws KeeperException, InterruptedException { - List result = runWithCorrectThrows( - "getting children", - () -> client.getChildren().usingWatcher(wrapWatcher(watcher)).forPath(path)); + List result = + runWithCorrectThrows( + "getting children", + () -> client.getChildren().usingWatcher(wrapWatcher(watcher)).forPath(path)); metrics.childFetches.increment(); if (result != null) { @@ -360,12 +394,17 @@ 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) throws KeeperException, InterruptedException { - List result = runWithCorrectThrows( - "getting children", - () -> client.getChildren().storingStatIn(stat).usingWatcher(wrapWatcher(watcher)).forPath(path)); + List result = + runWithCorrectThrows( + "getting children", + () -> + client + .getChildren() + .storingStatIn(stat) + .usingWatcher(wrapWatcher(watcher)) + .forPath(path)); metrics.childFetches.increment(); if (result != null) { @@ -375,12 +414,17 @@ public List getChildren( } /** 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) throws KeeperException, InterruptedException { - byte[] result = runWithCorrectThrows( - "getting data", - () -> client.getData().storingStatIn(stat).usingWatcher(wrapWatcher(watcher)).forPath(path)); + byte[] result = + runWithCorrectThrows( + "getting data", + () -> + client + .getData() + .storingStatIn(stat) + .usingWatcher(wrapWatcher(watcher)) + .forPath(path)); if (compressor.isCompressedBytes(result)) { log.debug("Zookeeper data at path {} is compressed", path); try { @@ -400,21 +444,18 @@ public byte[] getData( return result; } - public NodeData getNode(final String path, Watcher watcher, boolean retryOnConnLoss) + public NodeData getNode(final String path, Watcher watcher) throws KeeperException, InterruptedException { Stat stat = new Stat(); - return new NodeData(stat, getData(path, watcher, stat, retryOnConnLoss)); + return new NodeData(stat, getData(path, watcher, stat)); } /** Returns node's state */ - public Stat setData( - final String path, final byte data[], final int version, boolean retryOnConnLoss) + public Stat setData(final String path, final byte data[], final int version) throws KeeperException, InterruptedException { - Stat result = null; - - Stat result = runWithCorrectThrows( - "setting data", - () -> client.setData().withVersion(version).forPath(path, data)); + Stat result = + runWithCorrectThrows( + "setting data", () -> client.setData().withVersion(version).forPath(path, data)); metrics.writes.increment(); if (data != null) { metrics.bytesWritten.add(data.length); @@ -459,12 +500,11 @@ 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) throws KeeperException, InterruptedException { - String result runWithCorrectThrows( - "creating znode", - () -> client.create().withMode(createMode).forPath(path, data)); + String result = + runWithCorrectThrows( + "creating znode", () -> client.create().withMode(createMode).forPath(path, data)); metrics.writes.increment(); if (data != null) { metrics.bytesWritten.add(data.length); @@ -478,25 +518,18 @@ String result runWithCorrectThrows( *

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 { + public void makePath(String path) throws KeeperException, InterruptedException { makePath(path, null, CreateMode.PERSISTENT); } public void makePath(String path, boolean failOnExists) throws KeeperException, InterruptedException { - makePath(path, null, CreateMode.PERSISTENT, null, failOnExists); + makePath(path, null, CreateMode.PERSISTENT, null, failOnExists, 0); } public void makePath(String path, Path data, boolean failOnExists) throws IOException, KeeperException, InterruptedException { - makePath( - path, - Files.readAllBytes(data), - CreateMode.PERSISTENT, - null, - failOnExists - ); + makePath(path, Files.readAllBytes(data), CreateMode.PERSISTENT, null, failOnExists, 0); } public void makePath(String path, Path data) @@ -514,8 +547,7 @@ 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 { + public void makePath(String path, byte[] data) throws KeeperException, InterruptedException { makePath(path, data, CreateMode.PERSISTENT); } @@ -532,10 +564,22 @@ public void makePath(String path, byte[] data, CreateMode createMode) makePath(path, data, createMode, null); } - public void makePath( - String zkPath, CreateMode createMode, Watcher watcher) + public void makePath(String zkPath, CreateMode createMode, Watcher watcher) + throws KeeperException, InterruptedException { + makePath(zkPath, null, createMode, watcher, true, 0); + } + + /** + * Creates the path in ZooKeeper, creating each node as necessary. + * + *

e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, + * each will be created. + * + * @param data to set on the last zkNode + */ + public void makePath(String path, byte[] data, CreateMode createMode, Watcher watcher) throws KeeperException, InterruptedException { - makePath(zkPath, null, createMode, watcher); + makePath(path, data, createMode, watcher, true, 0); } /** @@ -547,9 +591,9 @@ public void makePath( * @param data to set on the last zkNode */ public void makePath( - String path, byte[] data, CreateMode createMode, Watcher watcher) + String path, byte[] data, CreateMode createMode, Watcher watcher, boolean failOnExists) throws KeeperException, InterruptedException { - makePath(path, data, createMode, watcher, true); + makePath(path, data, createMode, watcher, failOnExists, 0); } /** @@ -558,6 +602,8 @@ public void makePath( *

e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, * each will be created. * + *

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

Note: if failOnExists == false then we will always overwrite the existing data with the * given data */ @@ -566,20 +612,48 @@ public void makePath( byte[] data, CreateMode createMode, Watcher watcher, - boolean failOnExists) + boolean failOnExists, + int skipPathParts) throws KeeperException, InterruptedException { log.debug("makePath: {}", path); var createBuilder = client.create(); if (!failOnExists) { createBuilder.orSetData(); + } metrics.writes.increment(); if (data != null) { metrics.bytesWritten.add(data.length); } if (path.startsWith("/")) { - path = path.substring(1, path.length()); + path = path.substring(1); } + if (skipPathParts > 0) { + String[] paths = path.split("/"); + StringBuilder sbPath = new StringBuilder(); + for (int i = 0; i < paths.length; i++) { + if (i == skipPathParts) { + break; + } + String pathPiece = paths[i]; + sbPath.append("/").append(pathPiece); + } + String skipPathPartsPath = sbPath.toString(); + final String finalSkipPathPartsPath; + if (!skipPathPartsPath.startsWith("/")) { + finalSkipPathPartsPath = "/" + skipPathPartsPath; + } else { + finalSkipPathPartsPath = skipPathPartsPath; + } + Stat exists = + runWithCorrectThrows( + "checking skipPathParts exists", + () -> client.checkExists().forPath(finalSkipPathPartsPath)); + if (exists == null) { + throw new KeeperException.NoNodeException(finalSkipPathPartsPath + " didn't already exist"); + } + } + final String finalPath; if (!path.startsWith("/")) { finalPath = "/" + path; @@ -599,8 +673,7 @@ public void makePath( * * @param path the path at which to create the znode */ - public void ensureExists(final String path) - throws KeeperException, InterruptedException { + public void ensureExists(final String path) throws KeeperException, InterruptedException { ensureExists(path, null); } @@ -610,9 +683,7 @@ public void ensureExists(final String path) * @param path the path at which to create the znode * @param data the optional data to set on the znode */ - public void ensureExists( - final String path, - final byte[] data) + public void ensureExists(final String path, final byte[] data) throws KeeperException, InterruptedException { ensureExists(path, data, CreateMode.PERSISTENT); } @@ -624,10 +695,7 @@ public void ensureExists( * @param data the optional data to set on the znode * @param createMode the mode with which to create the znode */ - public void ensureExists( - final String path, - final byte[] data, - CreateMode createMode) + public void ensureExists(final String path, final byte[] data, CreateMode createMode) throws KeeperException, InterruptedException { ensureExists(path, data, createMode, 0); } @@ -641,10 +709,7 @@ public void ensureExists( * @param skipPathParts how many path elements to skip */ public void ensureExists( - final String path, - final byte[] data, - CreateMode createMode, - int skipPathParts) + final String path, final byte[] data, CreateMode createMode, int skipPathParts) throws KeeperException, InterruptedException { if (exists(path)) { return; @@ -663,21 +728,21 @@ public void ensureExists( throw new KeeperException.NoNodeException(startingPath); } } - makePath(path, data, createMode, null, true); + makePath(path, data, createMode, null, 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 { + public Stat setData(String path, byte[] data) throws KeeperException, InterruptedException { return setData(path, data, -1); } /** * Write file to ZooKeeper - default system encoding used. - * @param path path to upload file to e.g. /solr/conf/solrconfig.xml + * + * @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) @@ -710,15 +775,22 @@ public List multi(CuratorOpBuilder... ops) public List multi(final List ops) throws InterruptedException, KeeperException { - List result = runWithCorrectThrows( - "executing multi-transaction", - () -> client.transaction().forOperations(ops.stream().map(op -> op.buildWithoutThrows(client.transactionOp())).collect(Collectors.toList()))); - - metrics.multiOps.increment(); - if (result != null) { - metrics.cumulativeMultiOps.add(result.size()); - } - return result; + List result = + runWithCorrectThrows( + "executing multi-transaction", + () -> + client + .transaction() + .forOperations( + ops.stream() + .map(op -> op.buildWithoutThrows(client.transactionOp())) + .collect(Collectors.toList()))); + + metrics.multiOps.increment(); + if (result != null) { + metrics.cumulativeMultiOps.add(result.size()); + } + return result; } /** Fills string with printout of current ZooKeeper layout. */ @@ -768,7 +840,8 @@ public void close() { try { closeCallbackExecutor(); } finally { - client.close(); + IOUtils.closeQuietly(client); + ExecutorUtil.shutdownNowAndAwaitTermination(curatorSafeServiceExecutor); } assert ObjectReleaseTracker.release(this); } @@ -777,11 +850,16 @@ public boolean isClosed() { return isClosed || (higherLevelIsClosed != null && higherLevelIsClosed.isClosed()); } + public ZooKeeper getZooKeeper() throws Exception { + return client.getZookeeperClient().getZooKeeper(); + } + public long getZkSessionId() { if (isConnected()) { try { return client.getZookeeperClient().getZooKeeper().getSessionId(); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } } return -1; } @@ -790,7 +868,8 @@ public int getZkSessionTimeout() { if (isConnected()) { try { return client.getZookeeperClient().getZooKeeper().getSessionTimeout(); - } catch (Exception ignored) { } + } catch (Exception ignored) { + } } return 0; } @@ -880,11 +959,9 @@ 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) throws KeeperException, InterruptedException { return runWithCorrectThrows( - "getting acls", - () -> client.getACL().storingStatIn(stat).forPath(path)); + "getting acls", () -> client.getACL().storingStatIn(stat).forPath(path)); } /** @@ -894,11 +971,9 @@ public List getACL(String path, Stat stat) * @param acls a list of {@link ACL}s to be applied * @return the stat of the node */ - public Stat setACL(String path, List acls) - throws InterruptedException, KeeperException { + public Stat setACL(String path, List acls) throws InterruptedException, KeeperException { return runWithCorrectThrows( - "setting acls", - () -> client.setACL().withVersion(-1).withACL(acls).forPath(path)); + "setting acls", () -> client.setACL().withVersion(-1).withACL(acls).forPath(path)); } /** @@ -914,8 +989,7 @@ public void updateACLs(final String root) throws KeeperException, InterruptedExc path -> { try { runWithCorrectThrows( - "updating acls", - () -> client.setACL().withACL(null).forPath(path)); + "updating acls", () -> client.setACL().withACL(null).forPath(path)); } catch (NoNodeException ignored) { // If a node was deleted, don't bother trying to set ACLs on it. } @@ -927,7 +1001,8 @@ protected interface SupplierWithException { T get() throws Exception; } - protected T runWithCorrectThrows(String action, SupplierWithException func) throws KeeperException, InterruptedException { + protected T runWithCorrectThrows(String action, SupplierWithException func) + throws KeeperException, InterruptedException { try { return func.get(); } catch (KeeperException | RuntimeException e) { @@ -1095,8 +1170,8 @@ public static class Builder { public int zkClientConnectTimeout = SolrZkClientTimeout.DEFAULT_ZK_CONNECT_TIMEOUT; public OnReconnect onReconnect; public BeforeReconnect beforeReconnect; - public ZkClientConnectionStrategy connectionStrategy; - public ZkACLProvider zkACLProvider; + public ZkCredentialsProvider zkCredentialsProvider; + public ACLProvider aclProvider; public IsClosed higherLevelIsClosed; public SolrClassLoader solrClassLoader; @@ -1134,18 +1209,18 @@ public Builder withReconnectListener(OnReconnect onReconnect) { return this; } - public Builder withConnStrategy(ZkClientConnectionStrategy strat) { - this.connectionStrategy = strat; + public Builder withBeforeConnect(BeforeReconnect beforeReconnect) { + this.beforeReconnect = beforeReconnect; return this; } - public Builder withBeforeConnect(BeforeReconnect beforeReconnect) { - this.beforeReconnect = beforeReconnect; + public Builder withZkCredentialsProvider(ZkCredentialsProvider zkCredentialsProvider) { + this.zkCredentialsProvider = zkCredentialsProvider; return this; } - public Builder withAclProvider(ZkACLProvider zkACLProvider) { - this.zkACLProvider = zkACLProvider; + public Builder withAclProvider(ACLProvider aclProvider) { + this.aclProvider = aclProvider; return this; } diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java index 0674a088616..05c3d88d199 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/VMParamsSingleSetCredentialsDigestZkCredentialsProvider.java @@ -16,7 +16,8 @@ */ package org.apache.solr.common.cloud; -import java.util.Collection; +import java.util.List; +import org.apache.curator.framework.AuthInfo; /** * Deprecated in favor of a combination of {@link DigestZkCredentialsProvider} and {@link @@ -64,7 +65,7 @@ public void setZkCredentialsInjector(ZkCredentialsInjector zkCredentialsInjector } @Override - protected Collection createCredentials() { + protected List createCredentials() { return digestZkCredentialsProvider.createCredentials(); } } diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkACLProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkACLProvider.java index e3a8b7b920c..4364d0ba236 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkACLProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkACLProvider.java @@ -17,7 +17,6 @@ package org.apache.solr.common.cloud; import java.util.List; - import org.apache.curator.framework.api.ACLProvider; import org.apache.zookeeper.data.ACL; @@ -28,7 +27,8 @@ public interface ZkACLProvider extends ACLProvider { @Override default List getAclForPath(String zNodePath) { return getACLsToAdd(zNodePath); - + } + /** * @param zkCredentialsInjector The ZkCredentialsInjector that injects ZK credentials */ diff --git a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java index 6a4d86a1d37..24091258593 100644 --- a/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java +++ b/solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkCredentialsProvider.java @@ -16,9 +16,8 @@ */ package org.apache.solr.common.cloud; -import org.apache.curator.framework.AuthInfo; - import java.util.List; +import org.apache.curator.framework.AuthInfo; public interface ZkCredentialsProvider { List getCredentials(); 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 00509115a52..658281dd09c 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 @@ -348,8 +348,7 @@ 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)) { + if (file.toFile().getName().equals(ZKNODE_DATA_FILE) && zkClient.exists(zkNode)) { zkClient.setData(zkNode, file); } else { // We are only uploading a single file, preVisitDirectory was never called @@ -627,7 +626,7 @@ public static void ensureExists( return; } try { - zkClient.makePath(path, data, createMode, null, true, true); + zkClient.makePath(path, data, createMode, null, true, skipPathParts); } catch (NodeExistsException ignored) { // it's okay if another beats us creating the node } @@ -654,7 +653,7 @@ public void visit(String path) throws InterruptedException, KeeperException { if (path.equals(source) == false) finalDestination += "/" + path.substring(source.length() + 1); zkClient.makePath(finalDestination, false); - zkClient.setData(finalDestination, zkClient.getData(path, null, null, true)); + zkClient.setData(finalDestination, zkClient.getData(path, null, null)); } } } 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 8111d87ef8d..f16360a34be 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 @@ -576,7 +576,8 @@ public synchronized void createClusterStateWatchersAndUpdate() } catch (KeeperException.NoNodeException nne) { String noNodePath = nne.getPath(); if (noNodePath.length() > zkClient.getCuratorFramework().getNamespace().length()) { - noNodePath = noNodePath.substring(zkClient.getCuratorFramework().getNamespace().length() + 1); + noNodePath = + noNodePath.substring(zkClient.getCuratorFramework().getNamespace().length() + 1); } throw new SolrException( ErrorCode.SERVICE_UNAVAILABLE, @@ -1143,8 +1144,7 @@ private void loadClusterProperties() { while (true) { try { byte[] data = - zkClient.getData( - ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat()); + zkClient.getData(ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat()); @SuppressWarnings("unchecked") Map properties = (Map) Utils.fromJSON(data); this.clusterProperties = @@ -1634,7 +1634,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, true); + Stat exists = zkClient.exists(collectionPath, watcher); 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.", @@ -2242,7 +2242,8 @@ public boolean update() throws KeeperException, InterruptedException { log.debug("Checking ZK for most up to date Aliases {}", ALIASES); } // Call sync() first to ensure the subsequent read (getData) is up to date. - zkClient.runWithCorrectThrows("syncing aliases", () -> zkClient.getCuratorFramework().sync().forPath(ALIASES)); + zkClient.runWithCorrectThrows( + "syncing aliases", () -> zkClient.getCuratorFramework().sync().forPath(ALIASES)); return setIfNewer(zkClient.getNode(ALIASES, null)); } 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 eccff75dd9b..cb8723c6e68 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 @@ -28,7 +28,6 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; - import org.apache.curator.framework.AuthInfo; import org.apache.curator.framework.api.ACLProvider; import org.apache.solr.client.solrj.impl.CloudSolrClient; @@ -106,7 +105,11 @@ public void setUp() throws Exception { protected ACLProvider createACLProvider() { try { // Must be Arrays.asList(), Zookeeper does not allow for immutable list types for ACLs - return new DefaultZkACLProvider(Arrays.asList(new ACL(ZooDefs.Perms.ALL, new Id(SCHEME, DigestAuthenticationProvider.generateDigest(AUTH))))); + return new DefaultZkACLProvider( + Arrays.asList( + new ACL( + ZooDefs.Perms.ALL, + new Id(SCHEME, DigestAuthenticationProvider.generateDigest(AUTH))))); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } @@ -213,12 +216,10 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bam") .process(solrClient); @@ -232,12 +233,10 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bang") .process(solrClient); 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 084aa960083..50df39f1156 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 @@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit; import org.apache.curator.framework.AuthInfo; import org.apache.curator.framework.api.ACLProvider; -import org.apache.solr.SolrJettyTestBase; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.cloud.AbstractZkTestCase; import org.apache.solr.cloud.ZkConfigSetService; @@ -152,32 +151,34 @@ public void testUploadWithACL() throws IOException, NoSuchAlgorithmException { final String writeablePassword = "writeable"; // Must be Arrays.asList(), Zookeeper does not allow for immutable list types for ACLs - List acls = Arrays.asList( - new ACL( - ZooDefs.Perms.ALL, - new Id( - "digest", - DigestAuthenticationProvider.generateDigest( - writeableUsername + ":" + writeablePassword))), - new ACL( - ZooDefs.Perms.READ, - new Id( - "digest", - DigestAuthenticationProvider.generateDigest( - readOnlyUsername + ":" + readOnlyPassword)))); + List acls = + Arrays.asList( + new ACL( + ZooDefs.Perms.ALL, + new Id( + "digest", + DigestAuthenticationProvider.generateDigest( + writeableUsername + ":" + writeablePassword))), + new ACL( + ZooDefs.Perms.READ, + new Id( + "digest", + DigestAuthenticationProvider.generateDigest( + readOnlyUsername + ":" + readOnlyPassword)))); ACLProvider aclProvider = new DefaultZkACLProvider(acls); - List credentials = List.of( - new AuthInfo( - "digest", - (readOnlyUsername + ":" + readOnlyPassword).getBytes(StandardCharsets.UTF_8))); + List credentials = + List.of( + new AuthInfo( + "digest", + (readOnlyUsername + ":" + readOnlyPassword).getBytes(StandardCharsets.UTF_8))); ZkCredentialsProvider readonly = new DefaultZkCredentialsProvider(credentials); - List writeableCredentials = List.of( - new AuthInfo( - "digest", - (writeableUsername + ":" + writeablePassword) - .getBytes(StandardCharsets.UTF_8))); + List writeableCredentials = + List.of( + new AuthInfo( + "digest", + (writeableUsername + ":" + writeablePassword).getBytes(StandardCharsets.UTF_8))); ZkCredentialsProvider writeable = new DefaultZkCredentialsProvider(writeableCredentials); Path configPath = createTempDir("acl-config"); 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 34beb9fd2f1..bbdd7de8cf3 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 @@ -91,8 +91,7 @@ public void testClean() throws KeeperException, InterruptedException, SolrServer zkClient.create( path + "/some_longer_file2.txt", longData.getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); /* RUN */ // delete all nodes that contain "file" 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 391f87bb8f3..79398676f3d 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,9 +66,7 @@ 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); assertNotNull(stateJsonBytes); Map replicasMap = (Map) 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 e75100f1a50..aa9b5427c99 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(NONPRS_COLL), null); 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // +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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // 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 82682e5e122..71f95b23c4b 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 @@ -75,14 +75,11 @@ public void getData() throws Exception { + "\"leader\":\"true\"}}}}}}"; byte[] arr = state.getBytes(StandardCharsets.UTF_8); byte[] compressedData = zLibStateCompression.compressBytes(arr); - ZkACLProvider aclProvider = new DefaultZkACLProvider(); String path = ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"; - zkClient - .getZooKeeper() - .create(path, compressedData, aclProvider.getACLsToAdd(path), CreateMode.PERSISTENT); + zkClient.create(path, compressedData, CreateMode.PERSISTENT); byte[] data = - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true); + zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null); Map map = (Map) Utils.fromJSON(data); assertEquals(arr.length, data.length); assertNotNull(map.get("c1")); diff --git a/solr/test-framework/build.gradle b/solr/test-framework/build.gradle index 75ecd2348ba..0798dd83f85 100644 --- a/solr/test-framework/build.gradle +++ b/solr/test-framework/build.gradle @@ -43,6 +43,12 @@ dependencies { var zkExcludes = { exclude group: "org.apache.yetus", module: "audience-annotations" } + api('org.apache.curator:curator-client', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) + api('org.apache.curator:curator-framework', { + exclude group: 'org.apache.zookeeper', module: 'zookeeper' + }) api('org.apache.curator:curator-test') { exclude group: 'org.apache.zookeeper', module: 'zookeeper' exclude group: 'com.google.guava', module: 'guava' 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 7fe79f56d66..d7590f6c257 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -94,7 +94,6 @@ import org.apache.solr.client.solrj.util.ClientUtils; import org.apache.solr.cloud.IpTables; import org.apache.solr.cloud.MiniSolrCloudCluster; -import org.apache.solr.cloud.TestConnectionStrategy; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrException; @@ -288,7 +287,6 @@ public static void setupTestCases() { System.setProperty("solr.v2RealPath", "true"); System.setProperty("zookeeper.forceSync", "no"); System.setProperty("jetty.testMode", "true"); - System.setProperty("solr.zookeeper.connectionStrategy", TestConnectionStrategy.class.getName()); System.setProperty("enable.update.log", Boolean.toString(usually())); System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong())); System.setProperty("solr.clustering.enabled", "false"); 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 dbbf308bad1..02935f94b96 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, true); + zkClient.makePath("/solr", false); zkClient.close(); zkClient = @@ -111,15 +111,14 @@ public void setUp() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT); zkClient.close(); clearSecuritySystemProperties(); @@ -138,12 +137,9 @@ public void setUp() throws Exception { .addAuthInfo( "digest", (ALL_USERNAME + ":" + ALL_PASSWORD).getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.close(); setDigestZkSystemProps(); @@ -312,8 +308,8 @@ public void testRepairACL() throws Exception { .getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, false); - assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); + "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); + assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); } setSecuritySystemProperties(); @@ -323,7 +319,7 @@ public void testRepairACL() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { ZkController.createClusterZkNodes(zkClient); - assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); + assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); } useZkCredentialsInjector(ConnectWithReadonlyCredsInjector.class); @@ -334,9 +330,8 @@ public void testRepairACL() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { NoAuthException e = - assertThrows( - NoAuthException.class, () -> zkClient.getData("/security.json", null, null, false)); - assertEquals("/security.json", e.getPath()); + assertThrows(NoAuthException.class, () -> zkClient.getData("/security.json", null, null)); + assertEquals("/solr/security.json", e.getPath()); } } @@ -401,27 +396,27 @@ protected static void doTest( boolean setData, boolean delete) throws Exception { - doTest(getData, () -> zkClient.getData(path, null, null, false)); - doTest(list, () -> zkClient.getChildren(path, null, false)); + doTest(getData, () -> zkClient.getData(path, null, null)); + doTest(list, () -> zkClient.getChildren(path, null)); doTest( create, () -> { - zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT, false); - zkClient.delete(path + "/subnode", -1, false); + zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT); + zkClient.delete(path + "/subnode", -1); }); doTest( create, () -> { zkClient.makePath(path + "/subnode/subsubnode", false); - zkClient.delete(path + "/subnode/subsubnode", -1, false); - zkClient.delete(path + "/subnode", -1, false); + zkClient.delete(path + "/subnode/subsubnode", -1); + zkClient.delete(path + "/subnode", -1); }); - doTest(setData, () -> zkClient.setData(path, (byte[]) null, false)); + doTest(setData, () -> zkClient.setData(path, (byte[]) null)); // Actually about the ACLs on /solr, but that is protected - doTest(delete, () -> zkClient.delete(path, -1, false)); + doTest(delete, () -> zkClient.delete(path, -1)); } interface ExceptingRunnable { 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 f98947a7d14..c0f4ce77a69 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,18 +262,14 @@ public void distribSetUp() throws Exception { .create( ZkStateReader.CLUSTER_PROPS, Utils.toJSON(Collections.singletonMap(URL_SCHEME, HTTPS)), - CreateMode.PERSISTENT - ); + CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException e) { ZkNodeProps props = ZkNodeProps.load( - zkStateReader - .getZkClient() - .getData(ZkStateReader.CLUSTER_PROPS, null, null)); + zkStateReader.getZkClient().getData(ZkStateReader.CLUSTER_PROPS, null, null)); zkStateReader .getZkClient() - .setData( - ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS))); + .setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS))); } } } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java index 31cd34d3b20..439e2be77c6 100644 --- a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java +++ b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java @@ -16,7 +16,6 @@ */ package org.apache.solr.cloud; -import java.io.IOException; import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.List; @@ -30,7 +29,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; import org.apache.curator.test.KillSession; -import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.solr.cloud.AbstractFullDistribZkTestBase.CloudJettyRunner; import org.apache.solr.common.cloud.DocCollection; @@ -50,8 +48,6 @@ import org.apache.solr.util.TestInjection; import org.apache.solr.util.TimeOut; import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.TestableZooKeeper; -import org.apache.zookeeper.ZooKeeper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -185,21 +181,11 @@ public static void causeConnectionLoss(JettySolrRunner jetty) { if (cores != null) { monkeyLog("Will cause connection loss on " + jetty.getLocalPort()); SolrZkClient zkClient = cores.getZkController().getZkClient(); - causeConnectionLoss(zkClient.getZooKeeper()); - } - } - - public static void causeConnectionLoss(ZooKeeper zooKeeper) { - assert zooKeeper instanceof TestableZooKeeper - : "Can only cause connection loss for TestableZookeeper"; - if (zooKeeper instanceof TestableZooKeeper) { try { - ((TestableZooKeeper) zooKeeper).testableConnloss(); - } catch (IOException ignored) { - // best effort + KillSession.kill(zkClient.getCuratorFramework().getZookeeperClient().getZooKeeper()); + } catch (Exception e) { + log.warn("Exception causing connection loss", e); } - } else { - // TODO what now? } } 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 6acfdc08c6e..66ae8b2d301 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,13 +301,12 @@ public MiniSolrCloudCluster( .withUrl(zkServer.getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - if (!zkClient.exists("/solr/solr.xml", true)) { + if (!zkClient.exists("/solr/solr.xml")) { zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset())); 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)); } if (securityJson.isPresent()) { // configure Solr security zkClient.makePath( @@ -646,9 +645,7 @@ 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); } catch (KeeperException.NoNodeException nne) { } new ConfigSetAdminRequest.Delete().setConfigSetName(configSet).process(solrClient); 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 6d782c82e4f..e9bd640d101 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,15 +29,13 @@ public MockSolrZkClient() { } @Override - public Boolean exists(final String path) - throws KeeperException, InterruptedException { + public Boolean exists(final String path) 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) throws KeeperException, InterruptedException { return null; } diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/TestConnectionStrategy.java b/solr/test-framework/src/java/org/apache/solr/cloud/TestConnectionStrategy.java deleted file mode 100644 index 88d94faaa85..00000000000 --- a/solr/test-framework/src/java/org/apache/solr/cloud/TestConnectionStrategy.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.solr.cloud; - -import java.io.IOException; -import org.apache.solr.common.cloud.DefaultConnectionStrategy; -import org.apache.zookeeper.TestableZooKeeper; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooKeeper; - -/** - * Connection strategy that creates instances of {@link TestableZooKeeper} instead of plain {@link - * ZooKeeper} objects. Useful for adding pause and disconnect events. - */ -public class TestConnectionStrategy extends DefaultConnectionStrategy { - @Override - protected ZooKeeper newZooKeeperInstance( - String serverAddress, int zkClientTimeout, Watcher watcher) throws IOException { - return new TestableZooKeeper(serverAddress, zkClientTimeout, watcher); - } -} 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 95ad6a34446..b93f100f012 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 @@ -810,13 +810,24 @@ public void buildZooKeeper(Path solrhome, String config, String schema) throws E chRootClient.multi( op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections", null), - op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/collection1", Utils.toJSON(zkProps)), - op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/collection1/shards", null), - op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/control_collection", Utils.toJSON(zkProps)), - op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/collections/control_collection/shards", null), + op -> + op.create() + .withMode(CreateMode.PERSISTENT) + .forPath("/collections/collection1", Utils.toJSON(zkProps)), + op -> + op.create() + .withMode(CreateMode.PERSISTENT) + .forPath("/collections/collection1/shards", null), + op -> + op.create() + .withMode(CreateMode.PERSISTENT) + .forPath("/collections/control_collection", Utils.toJSON(zkProps)), + op -> + op.create() + .withMode(CreateMode.PERSISTENT) + .forPath("/collections/control_collection/shards", null), op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/configs", null), - op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/configs/conf1", null) - ); + op -> op.create().withMode(CreateMode.PERSISTENT).forPath("/configs/conf1", null)); // for now, always upload the config and schema to the canonical names putConfig("conf1", chRootClient, solrhome, config, "solrconfig.xml"); 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 9d9112a5cba..ed51f2ce357 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,9 +115,7 @@ 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)); } @Test @@ -133,9 +131,7 @@ 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)); } @Test diff --git a/versions.lock b/versions.lock index 4efe961e79a..5e8528101e2 100644 --- a/versions.lock +++ b/versions.lock @@ -44,7 +44,7 @@ com.google.cloud:google-cloud-storage:2.27.0 (2 constraints: d71c8a27) com.google.code.gson:gson:2.10.1 (7 constraints: 005f69b0) com.google.errorprone:error_prone_annotations:2.22.0 (11 constraints: 6e891f5a) com.google.guava:failureaccess:1.0.1 (2 constraints: f9199e37) -com.google.guava:guava:32.1.2-jre (26 constraints: 407b586c) +com.google.guava:guava:32.1.2-jre (27 constraints: 498a9992) com.google.guava:guava-parent:32.1.2-jre (1 constraints: b80ba5eb) com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (2 constraints: 4b35b0a0) com.google.http-client:google-http-client:1.43.3 (11 constraints: 3fbf96b4) @@ -89,7 +89,7 @@ edu.ucar:netcdf4:4.5.5 (1 constraints: 650c0402) edu.ucar:udunits:4.5.5 (1 constraints: 2b06034e) edu.usc.ir:sentiment-analysis-parser:0.1 (1 constraints: fa0b50e9) io.dropwizard.metrics:metrics-annotation:4.2.20 (1 constraints: 30106db0) -io.dropwizard.metrics:metrics-core:4.2.20 (5 constraints: 3344adfc) +io.dropwizard.metrics:metrics-core:4.2.20 (6 constraints: 015254da) io.dropwizard.metrics:metrics-graphite:4.2.20 (1 constraints: 3a05413b) io.dropwizard.metrics:metrics-jetty10:4.2.20 (1 constraints: 3a05413b) io.dropwizard.metrics:metrics-jmx:4.2.20 (1 constraints: 3a05413b) @@ -257,7 +257,7 @@ org.apache.tika:tika-core:1.28.5 (2 constraints: d8118f11) org.apache.tika:tika-parsers:1.28.5 (1 constraints: 42054a3b) org.apache.tomcat:annotations-api:6.0.53 (1 constraints: 40054e3b) org.apache.xmlbeans:xmlbeans:5.0.3 (2 constraints: 72173075) -org.apache.zookeeper:zookeeper:3.9.0 (2 constraints: 9c134e5f) +org.apache.zookeeper:zookeeper:3.9.0 (1 constraints: 0e051536) org.apache.zookeeper:zookeeper-jute:3.9.0 (2 constraints: 99125f23) org.apiguardian:apiguardian-api:1.1.2 (2 constraints: 601bd5a8) org.bitbucket.b_c:jose4j:0.9.3 (1 constraints: 0e050936) From 44399c710f639350c8c635bb3458024699a9c0a5 Mon Sep 17 00:00:00 2001 From: Kevin Risden Date: Wed, 11 Oct 2023 15:16:08 -0400 Subject: [PATCH 11/14] 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()); From 784a9b2ccd077caaa30d9bb8f94dbc6804fff0d1 Mon Sep 17 00:00:00 2001 From: Kevin Risden Date: Wed, 11 Oct 2023 15:58:52 -0400 Subject: [PATCH 12/14] Fix ZkStateWriterTest --- .../org/apache/solr/cloud/overseer/ZkStateWriterTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 a1e76dd6bac..cc8bcd0e0bb 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 @@ -500,9 +500,7 @@ public void testSingleExternalCollectionCompressedState() throws Exception { writer.writePendingUpdates(); byte[] data = - zkClient - .getZooKeeper() - .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); assertNotNull(map.get("c1")); } From 5d20221022d9c8a8c80d8b506743778febac474e Mon Sep 17 00:00:00 2001 From: Kevin Risden Date: Wed, 11 Oct 2023 16:00:02 -0400 Subject: [PATCH 13/14] Fix VMParamsZkACLAndCredentialsProvidersTest --- .../AbstractDigestZkACLAndCredentialsProvidersTestBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dbbf308bad1..c2597a02692 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 @@ -336,7 +336,7 @@ public void testRepairACL() throws Exception { NoAuthException e = assertThrows( NoAuthException.class, () -> zkClient.getData("/security.json", null, null, false)); - assertEquals("/security.json", e.getPath()); + assertEquals("/solr/security.json", e.getPath()); } } From 80595c2c78c081295187f7f2226d91396a094fd3 Mon Sep 17 00:00:00 2001 From: Kevin Risden Date: Wed, 11 Oct 2023 15:36:23 -0400 Subject: [PATCH 14/14] Remove retryOnConnLoss This reverts commit 44399c710f639350c8c635bb3458024699a9c0a5. --- .../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 | 24 ++-- .../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 | 20 +-- .../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 +- .../jwt/JWTAuthPluginIntegrationTest.java | 2 +- .../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 | 41 +++--- .../solr/cloud/AbstractDistribZkTestBase.java | 1 + .../cloud/AbstractFullDistribZkTestBase.java | 10 +- .../solr/cloud/MiniSolrCloudCluster.java | 17 +-- .../apache/solr/cloud/MockSolrZkClient.java | 6 +- .../org/apache/solr/cloud/ZkTestServer.java | 8 +- ...ctCollectionsAPIDistributedZkTestBase.java | 12 +- 137 files changed, 685 insertions(+), 920 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 2afd71706b6..1f2fc2ac0dd 100644 --- a/solr/core/src/java/org/apache/solr/cli/AuthTool.java +++ b/solr/core/src/java/org/apache/solr/cli/AuthTool.java @@ -217,8 +217,7 @@ 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), true); + zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); } catch (Exception ex) { CLIO.out( "Unable to access ZooKeeper. Please add the following security.json to ZooKeeper (in case of SolrCloud):\n" @@ -384,7 +383,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), true); + zkClient.setData("/security.json", securityJson.getBytes(StandardCharsets.UTF_8)); } } @@ -452,8 +451,8 @@ private int handleBasicAuth(CommandLine cli) throws Exception { private void checkSecurityJsonExists(SolrZkClient zkClient) throws KeeperException, InterruptedException { - if (zkClient.exists("/security.json", true)) { - byte[] oldSecurityBytes = zkClient.getData("/security.json", null, null, true); + if (zkClient.exists("/security.json")) { + byte[] oldSecurityBytes = zkClient.getData("/security.json", null, null); 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" @@ -479,7 +478,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), true); + zkClient.setData("/security.json", "{}".getBytes(StandardCharsets.UTF_8)); } } } 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 e62c42d185a..64f8a9ceaca 100644 --- a/solr/core/src/java/org/apache/solr/cli/CreateTool.java +++ b/solr/core/src/java/org/apache/solr/cli/CreateTool.java @@ -243,9 +243,7 @@ protected void createCollection(CloudSolrClient cloudSolrClient, CommandLine cli boolean configExistsInZk = confName != null && !confName.trim().isEmpty() - && ZkStateReader.from(cloudSolrClient) - .getZkClient() - .exists("/configs/" + confName, true); + && ZkStateReader.from(cloudSolrClient).getZkClient().exists("/configs/" + confName); 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 dad5bdbbe94..4b106a540b5 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, true).size() != 0) { + if (!recurse && zkClient.getChildren(znode, null).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 de9181e505c..fc3d7239202 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, true); + List children = zk.getChildren("/keys/" + dir, null); for (String key : children) { if (key.endsWith(".der")) - result.put(key, zk.getData("/keys/" + dir + "/" + key, null, null, true)); + result.put(key, zk.getData("/keys/" + dir + "/" + key, null, null)); } } 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 8ebdb2ae287..6120d8ad6b2 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, true)) { - zkClient.makePath(rootNodePath, new byte[0], CreateMode.PERSISTENT, true); + if (!zkClient.exists(rootNodePath)) { + zkClient.makePath(rootNodePath, new byte[0], CreateMode.PERSISTENT); } } catch (KeeperException.NodeExistsException nee) { // Some other thread (on this or another JVM) beat us to create the node, that's ok, the @@ -329,27 +329,25 @@ void createNewInFlightTask(String asyncId) throws KeeperException, InterruptedEx zkClient.create( getPath(asyncId), State.SUBMITTED.shorthand.getBytes(StandardCharsets.UTF_8), - CreateMode.EPHEMERAL, - true); + CreateMode.EPHEMERAL); } void setTaskRunning(String asyncId) throws KeeperException, InterruptedException { - zkClient.setData( - getPath(asyncId), State.RUNNING.shorthand.getBytes(StandardCharsets.UTF_8), true); + zkClient.setData(getPath(asyncId), State.RUNNING.shorthand.getBytes(StandardCharsets.UTF_8)); } void deleteInFlightTask(String asyncId) throws KeeperException, InterruptedException { - zkClient.delete(getPath(asyncId), -1, true); + zkClient.delete(getPath(asyncId), -1); } State getInFlightState(String asyncId) throws KeeperException, InterruptedException { - if (!zkClient.exists(getPath(asyncId), true)) { + if (!zkClient.exists(getPath(asyncId))) { return State.NOT_FOUND; } final byte[] bytes; try { - bytes = zkClient.getData(getPath(asyncId), null, null, true); + bytes = zkClient.getData(getPath(asyncId), null, null); } 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 bc565ad97e8..02543e51e40 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, true); + zkStateReader.getZkClient().create(jsonPath, stateJson, CreateMode.PERSISTENT); } else { // We're updating an existing state.json if (log.isDebugEnabled()) { @@ -607,9 +607,7 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState) jsonPath, collection.getZNodeVersion()); } - zkStateReader - .getZkClient() - .setData(jsonPath, stateJson, collection.getZNodeVersion(), true); + zkStateReader.getZkClient().setData(jsonPath, stateJson, collection.getZNodeVersion()); } } } @@ -623,7 +621,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, true); + byte[] data = zkStateReader.getZkClient().getData(collectionStatePath, null, stat); // This factory method can detect a missing configName and supply it by reading it from the // old ZK location. @@ -933,7 +931,7 @@ public static void executeNodeDownStateUpdate(String nodeName, ZkStateReader zkS try { final List collectionNames = - zkStateReader.getZkClient().getChildren(COLLECTIONS_ZKNODE, null, true); + zkStateReader.getZkClient().getChildren(COLLECTIONS_ZKNODE, null); // 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 fb2347c3e82..532a782825b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java +++ b/solr/core/src/java/org/apache/solr/cloud/DistributedMap.java @@ -68,8 +68,7 @@ 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, true); + zookeeper.makePath(dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, false); } /** @@ -81,8 +80,7 @@ public boolean putIfAbsent(String trackingId, byte[] data) throws KeeperException, InterruptedException { assertKeyFormat(trackingId); try { - zookeeper.makePath( - dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, true, true); + zookeeper.makePath(dir + "/" + PREFIX + trackingId, data, CreateMode.PERSISTENT, null, true); return true; } catch (NodeExistsException e) { return false; @@ -90,16 +88,16 @@ public boolean putIfAbsent(String trackingId, byte[] data) } public byte[] get(String trackingId) throws KeeperException, InterruptedException { - return zookeeper.getData(dir + "/" + PREFIX + trackingId, null, null, true); + return zookeeper.getData(dir + "/" + PREFIX + trackingId, null, null); } public boolean contains(String trackingId) throws KeeperException, InterruptedException { - return zookeeper.exists(dir + "/" + PREFIX + trackingId, true); + return zookeeper.exists(dir + "/" + PREFIX + trackingId); } public int size() throws KeeperException, InterruptedException { Stat stat = new Stat(); - zookeeper.getData(dir, null, stat, true); + zookeeper.getData(dir, null, stat); return stat.getNumChildren(); } @@ -110,7 +108,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, true); + zookeeper.delete(path, -1); } catch (KeeperException.NoNodeException e) { return false; } catch (KeeperException.NotEmptyException hack) { @@ -123,15 +121,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, true); + List childNames = zookeeper.getChildren(dir, null); for (String childName : childNames) { - zookeeper.delete(dir + "/" + childName, -1, true); + zookeeper.delete(dir + "/" + childName, -1); } } /** Returns the keys of all the elements in the map */ public Collection keys() throws KeeperException, InterruptedException { - List childs = zookeeper.getChildren(dir, null, true); + List childs = zookeeper.getChildren(dir, null); 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 1ace066447c..e41546f24da 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, true); + zkClient.delete(leaderSeqPath, -1); } 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 1b13d470240..760d6ae04ab 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, true); + List seqs = zkClient.getChildren(holdElectionPath, null); 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, true); + zkClient.delete(toDelete, -1); } catch (KeeperException.NoNodeException e) { // ignore } @@ -148,8 +148,7 @@ private void checkIfIamLeader(final ElectionContext context, boolean replacement watcher = new ElectionWatcher( context.leaderSeqPath, watchedNode, getSeq(context.leaderSeqPath), context), - null, - true); + null); log.debug("Watching path {} to know if I could be the leader", watchedNode); } catch (KeeperException.SessionExpiredException e) { throw e; @@ -240,10 +239,7 @@ public int joinElection(ElectionContext context, boolean replacement, boolean jo if (nodes.size() < 2) { leaderSeqPath = zkClient.create( - shardsElectZkPath + "/" + id + "-n_", - null, - CreateMode.EPHEMERAL_SEQUENTIAL, - false); + shardsElectZkPath + "/" + id + "-n_", null, CreateMode.EPHEMERAL_SEQUENTIAL); } else { String firstInLine = nodes.get(1); log.debug("The current head: {}", firstInLine); @@ -252,15 +248,12 @@ 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, false); + zkClient.create(leaderSeqPath, null, CreateMode.EPHEMERAL); } } else { leaderSeqPath = zkClient.create( - shardsElectZkPath + "/" + id + "-n_", - null, - CreateMode.EPHEMERAL_SEQUENTIAL, - false); + shardsElectZkPath + "/" + id + "-n_", null, CreateMode.EPHEMERAL_SEQUENTIAL); } log.debug("Joined leadership election with path: {}", leaderSeqPath); @@ -268,7 +261,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, true); + List entries = zkClient.getChildren(shardsElectZkPath, null); boolean foundId = false; for (String entry : entries) { @@ -336,7 +329,7 @@ public void process(WatchedEvent event) { if (canceled) { log.debug("This watcher is not active anymore {}", myNode); try { - zkClient.delete(myNode, -1, true); + zkClient.delete(myNode, -1); } catch (KeeperException.NoNodeException nne) { // expected . don't do anything } catch (Exception e) { @@ -364,8 +357,7 @@ 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, (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); + ZkMaintenanceUtils.ensureExists(electZKPath, 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 b81673423d1..b37453948d5 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, true); + data = zkClient.getData(path, null, stat); } 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(), true); + zkClient.delete(path, stat.getVersion()); } 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, true)); + ZkNodeProps.load(zkClient.getData(OVERSEER_ELECT + "/leader", null, null)); 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, true); + zkClient.create("/overseer", new byte[0], CreateMode.PERSISTENT); } 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 8eb8a6d1386..270d746bc4e 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, true); + zkClient.makePath(leaderPath, Utils.toJSON(myProps), CreateMode.EPHEMERAL); 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 63dca3f1c61..0e1a0acd58e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java +++ b/solr/core/src/java/org/apache/solr/cloud/OverseerNodePrioritizer.java @@ -67,9 +67,8 @@ public OverseerNodePrioritizer( public synchronized void prioritizeOverseerNodes(String overseerId) throws Exception { SolrZkClient zk = zkStateReader.getZkClient(); List overseerDesignates = new ArrayList<>(); - if (zk.exists(ZkStateReader.ROLES, true)) { - Map m = - (Map) Utils.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat(), true)); + if (zk.exists(ZkStateReader.ROLES)) { + Map m = (Map) Utils.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat())); @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 b63afbcf0c4..9ebe8644626 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, true); + children = zk.getChildren(Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE, null); } 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, true); + children = zk.getChildren(path, null); 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(), true); + data = zkClient.getData(Overseer.OVERSEER_ELECT + "/leader", null, new Stat()); } catch (KeeperException.NoNodeException e) { return null; } @@ -480,9 +480,7 @@ protected LeaderStatus amILeader() { try { ZkNodeProps props = ZkNodeProps.load( - zkStateReader - .getZkClient() - .getData(Overseer.OVERSEER_ELECT + "/leader", null, null, true)); + zkStateReader.getZkClient().getData(Overseer.OVERSEER_ELECT + "/leader", null, null)); 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 3092dce185e..a7b81e2889e 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, true); + List childNames = zookeeper.getChildren(dir, null); stats.setQueueLength(childNames.size()); for (String childName : childNames) { if (childName != null && childName.startsWith(PREFIX)) { try { - byte[] data = zookeeper.getData(dir + "/" + childName, null, null, true); + byte[] data = zookeeper.getData(dir + "/" + childName, null, null); 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(), true); + zookeeper.setData(responsePath, event.getBytes()); } 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, true); + zookeeper.delete(path, -1); } 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, true); + return zookeeper.create(path, data, mode); } catch (KeeperException.NoNodeException e) { try { - zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT, true); + zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT); } 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, true); + Stat stat = zookeeper.exists(watchID, watcher); // 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, true); + byte[] bytes = zookeeper.getData(watchID, null, null); // 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, true); + zookeeper.delete(watchID, -1); return event; } finally { time.stop(); @@ -295,9 +295,7 @@ public String getTailId() throws KeeperException, InterruptedException { try { QueueEvent queueEvent = new QueueEvent( - dir + "/" + headNode, - zookeeper.getData(dir + "/" + headNode, null, null, true), - null); + dir + "/" + headNode, zookeeper.getData(dir + "/" + headNode, null, null), 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 fee0d32bf50..c09a38d418c 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, true); + .exists(DocCollection.getCollectionPath(collection), null); 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 c57a43980b1..743f10a4524 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, true).size(); + found = zkClient.getChildren(shardsElectZkPath, null).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 c4c8923b218..510c0f1c1f5 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, true); + List children = zookeeper.getChildren(dir, null); 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, true); + Stat stat = zookeeper.exists(dir + "/" + child, null); 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 8e058a32a9a..45e7895cc63 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), true); + zkClient.makePath(arglist.get(0)); } else if (line.getOptionValue(CMD).equalsIgnoreCase(PUT)) { List arglist = line.getArgList(); if (arglist.size() != 2) { @@ -406,16 +406,17 @@ 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, true)) { - zkClient.setData(path, data, true); + if (zkClient.exists(path)) { + zkClient.setData(path, data); } else { - zkClient.makePath(path, data, CreateMode.PERSISTENT, true); + zkClient.makePath(path, data, CreateMode.PERSISTENT); } } else if (line.getOptionValue(CMD).equalsIgnoreCase(PUT_FILE)) { List arglist = line.getArgList(); @@ -433,10 +434,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, true)) { - zkClient.setData(path, data, true); + if (zkClient.exists(path)) { + zkClient.setData(path, data); } else { - zkClient.makePath(path, data, CreateMode.PERSISTENT, true); + zkClient.makePath(path, data, CreateMode.PERSISTENT); } } else if (line.getOptionValue(CMD).equalsIgnoreCase(GET)) { List arglist = line.getArgList(); @@ -444,7 +445,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, true); + byte[] data = zkClient.getData(arglist.get(0), null, null); stdout.println(new String(data, StandardCharsets.UTF_8)); } else if (line.getOptionValue(CMD).equalsIgnoreCase(GET_FILE)) { List arglist = line.getArgList(); @@ -453,7 +454,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, true); + byte[] data = zkClient.getData(arglist.get(0), null, null); 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 1718edbf56a..fa3f1b4037b 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, true)) { + if (!zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + colName)) { // 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, true); + stat = zkClient.exists(zkPath, null); } 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, true); + return zkClient.exists(CONFIGS_ZKNODE + "/" + configName); } 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, true); + zkClient.makePath(filePath, data, CreateMode.PERSISTENT, null, !overwriteOnExists); } } catch (KeeperException.NodeExistsException nodeExistsException) { throw new SolrException( @@ -224,8 +224,7 @@ public void setConfigMetadata(String configName, Map data) throw Utils.toJSON(data), CreateMode.PERSISTENT, null, - false, - true); + false); } catch (KeeperException | InterruptedException e) { throw new IOException("Error setting config metadata", SolrZkClient.checkInterrupted(e)); } @@ -237,7 +236,7 @@ public Map getConfigMetadata(String configName) throws IOExcepti @SuppressWarnings("unchecked") Map data = (Map) - Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null, true)); + Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null)); return data; } catch (KeeperException | InterruptedException e) { throw new IOException("Error getting config metadata", SolrZkClient.checkInterrupted(e)); @@ -252,7 +251,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, true); + return zkClient.getData(CONFIGS_ZKNODE + "/" + configName + "/" + filePath, null, null); } catch (KeeperException.NoNodeException e) { return null; } catch (KeeperException | InterruptedException e) { @@ -263,7 +262,7 @@ public byte[] downloadFileFromConfig(String configName, String filePath) throws @Override public List listConfigs() throws IOException { try { - return zkClient.getChildren(CONFIGS_ZKNODE, null, true); + return zkClient.getChildren(CONFIGS_ZKNODE, null); } catch (KeeperException.NoNodeException e) { return Collections.emptyList(); } catch (KeeperException | InterruptedException e) { @@ -310,9 +309,9 @@ public List getAllConfigFiles(String configName) throws IOException { private void copyConfigDirFromZk(String fromZkPath, String toZkPath) throws IOException { try { - List files = zkClient.getChildren(fromZkPath, null, true); + List files = zkClient.getChildren(fromZkPath, null); for (String file : files) { - List children = zkClient.getChildren(fromZkPath + "/" + file, null, true); + List children = zkClient.getChildren(fromZkPath + "/" + file, null); if (children.size() == 0) { copyData(fromZkPath + "/" + file, toZkPath + "/" + file); } else { @@ -338,8 +337,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, true); - zkClient.makePath(toZkFilePath, data, true); + byte[] data = zkClient.getData(fromZkFilePath, null, null); + zkClient.makePath(toZkFilePath, data); } } 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 1770f2df748..44e72a76d84 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -526,18 +526,17 @@ private void onReconnect(Supplier> descriptorsSupplier) { */ private void checkNoOldClusterstate(final SolrZkClient zkClient) throws InterruptedException { try { - if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, true)) { + if (!zkClient.exists(ZkStateReader.UNSUPPORTED_CLUSTER_STATE)) { return; } - final byte[] data = - zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null, true); + final byte[] data = zkClient.getData(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, null, null); 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, true); + zkClient.delete(ZkStateReader.UNSUPPORTED_CLUSTER_STATE, -1); } 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. @@ -601,8 +600,7 @@ private void registerAllCoresAsDown( + "/leader_elect/" + slice + "/election", - null, - true) + null) .size(); if (children == 0) { log.debug( @@ -924,7 +922,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, true); + List securityConfAcl = zkClient.getACL(ZkStateReader.SOLR_SECURITY_CONF_PATH, null); ACLProvider aclProvider = zkClient.getZkACLProvider(); boolean tryUpdate = false; @@ -991,7 +989,7 @@ private void init() { } } - Stat stat = zkClient.exists(ZkStateReader.LIVE_NODES_ZKNODE, null, true); + Stat stat = zkClient.exists(ZkStateReader.LIVE_NODES_ZKNODE, null); if (stat != null && stat.getNumChildren() > 0) { publishAndWaitForDownStates(); } @@ -1020,7 +1018,7 @@ private void checkForExistingEphemeralNode() throws KeeperException, Interrupted String nodeName = getNodeName(); String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName; - if (!zkClient.exists(nodePath, true)) { + if (!zkClient.exists(nodePath)) { return; } @@ -1035,8 +1033,7 @@ 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 @@ -1150,10 +1147,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, true); + boolean exists = tmpClient.exists(chrootPath); if (!exists && create) { log.info("creating chroot {}", chrootPath); - tmpClient.makePath(chrootPath, false, true); + tmpClient.makePath(chrootPath, false); exists = true; } tmpClient.close(); @@ -1196,7 +1193,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, true); + zkClient.delete(nodePath, -1); } catch (NoNodeException e) { } @@ -1208,7 +1205,7 @@ public String getNodeName() { /** Returns true if the path exists */ public boolean pathExists(String path) throws KeeperException, InterruptedException { - return zkClient.exists(path, true); + return zkClient.exists(path); } /** @@ -1523,8 +1520,7 @@ public ZkCoreNodeProps getLeaderProps( while (iterCount-- > 0) { try { byte[] data = - zkClient.getData( - ZkStateReader.getShardLeadersPath(collection, slice), null, null, true); + zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null); ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(ZkNodeProps.load(data)); return leaderProps; } catch (InterruptedException e) { @@ -2190,14 +2186,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, true); + data = zkClient.getData(path, null, null); } 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, null, true); + zkClient.makePath(path, Utils.toJSON(props), CreateMode.PERSISTENT); } catch (KeeperException e2) { // it's okay if the node already exists if (e2.code() != KeeperException.Code.NODEEXISTS) { @@ -2205,7 +2201,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), true); + zkClient.setData(path, Utils.toJSON(props)); } return; } @@ -2221,7 +2217,7 @@ public static void linkConfSet(SolrZkClient zkClient, String collection, String } // TODO: we should consider using version - zkClient.setData(path, Utils.toJSON(props), true); + zkClient.setData(path, Utils.toJSON(props)); } public ZkDistributedQueue getOverseerJobQueue() { @@ -2327,9 +2323,7 @@ public void rejoinOverseerElection(String electionNode, boolean joinAtHead) { if (electionNode.startsWith(getNodeName())) { try { zkClient.delete( - Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE + "/" + electionNode, - -1, - true); + Overseer.OVERSEER_ELECT + LeaderElector.ELECTION_NODE + "/" + electionNode, -1); } catch (NoNodeException e) { // no problem } catch (InterruptedException e) { @@ -2417,7 +2411,7 @@ public void rejoinShardLeaderElection(SolrParams params) { public void checkOverseerDesignate() { try { - byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true); + byte[] data = zkClient.getData(ZkStateReader.ROLES, null, new Stat()); if (data == null) return; Map roles = (Map) Utils.fromJSON(data); if (roles == null) return; @@ -2523,7 +2517,7 @@ public static int persistConfigResourceToZooKeeper( String errMsg = "Failed to persist resource at {0} - old {1}"; try { try { - Stat stat = zkClient.setData(resourceLocation, content, znodeVersion, true); + Stat stat = zkClient.setData(resourceLocation, content, znodeVersion); // if the set succeeded, it should have incremented the version by one always latestVersion = stat.getVersion(); log.info("Persisted config data to node {} ", resourceLocation); @@ -2531,12 +2525,12 @@ public static int persistConfigResourceToZooKeeper( } catch (NoNodeException e) { if (createIfNotExists) { try { - zkClient.create(resourceLocation, content, CreateMode.PERSISTENT, true); + zkClient.create(resourceLocation, content, CreateMode.PERSISTENT); latestVersion = 0; // just created so version must be zero touchConfDir(zkLoader); } catch (KeeperException.NodeExistsException nee) { try { - Stat stat = zkClient.exists(resourceLocation, null, true); + Stat stat = zkClient.exists(resourceLocation, null); if (log.isDebugEnabled()) { log.debug( "failed to set data version in zk is {} and expected version is {} ", @@ -2559,7 +2553,7 @@ public static int persistConfigResourceToZooKeeper( } catch (KeeperException.BadVersionException bve) { try { - zkClient.exists(resourceLocation, null, true); + zkClient.exists(resourceLocation, null); } catch (Exception e) { log.error("Exception during ZooKeeper node checking ", e); } @@ -2683,7 +2677,7 @@ public void process(WatchedEvent event) { Stat stat = null; try { - stat = zkClient.exists(zkDir, null, true); + stat = zkClient.exists(zkDir, null); } catch (KeeperException e) { // ignore , it is not a big deal } catch (InterruptedException e) { @@ -2737,7 +2731,7 @@ private boolean fireEventListeners(String zkDir) { private void setConfWatcher(String zkDir, Watcher watcher, Stat stat) { try { - Stat newStat = zkClient.exists(zkDir, watcher, true); + Stat newStat = zkClient.exists(zkDir, watcher); 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 ca29d53e9d7..469986960d6 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkDistributedLock.java @@ -92,8 +92,7 @@ protected ZkDistributedLock(SolrZkClient zkClient, String lockDir, String lockNo + DistributedCollectionConfigSetCommandRunner.ZK_PATH_SEPARATOR + lockNodePrefix, null, - CreateMode.EPHEMERAL_SEQUENTIAL, - false); + CreateMode.EPHEMERAL_SEQUENTIAL); sequence = getSequenceFromNodename(lockNode); } @@ -141,7 +140,7 @@ public void waitUntilAcquired() { String nodeToWatch = nodeToWatch(); while (nodeToWatch != null) { final DeletedNodeWatcher watcher = new DeletedNodeWatcher(nodeToWatch); - if (zkClient.exists(nodeToWatch, watcher, true) != null) { + if (zkClient.exists(nodeToWatch, watcher) != null) { watcher.await(); } nodeToWatch = nodeToWatch(); @@ -157,7 +156,7 @@ public void waitUntilAcquired() { @Override public void release() { try { - zkClient.delete(lockNode, -1, true); + zkClient.delete(lockNode, -1); released = true; } catch (KeeperException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); @@ -188,7 +187,7 @@ public boolean isAcquired() { * {@code null} if the lock is ours. */ String nodeToWatch() throws KeeperException, InterruptedException { - List locks = zkClient.getChildren(lockDir, null, true); + List locks = zkClient.getChildren(lockDir, null); 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 54434c8e6bc..76696dc3942 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, true)) { - zkClient.makePath(lockNodePath, new byte[0], CreateMode.PERSISTENT, true); + if (!zkClient.exists(lockNodePath)) { + zkClient.makePath(lockNodePath, new byte[0], CreateMode.PERSISTENT); } } 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 174b782c226..c8bc80615f0 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, true); + zookeeper.delete(result.getForPath(), -1); } 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, true); + Stat stat = zookeeper.exists(dir, null); 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, true); + zookeeper.create(dir + "/" + PREFIX, data, CreateMode.PERSISTENT_SEQUENTIAL); isDirty = true; return; } catch (KeeperException.NoNodeException e) { try { - zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT, true); + zookeeper.create(dir, new byte[0], CreateMode.PERSISTENT); } 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, true); + List childNames = zookeeper.getChildren(dir, watcher); 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, true); + zookeeper.makePath(dir, false); // 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, true); + byte[] data = zookeeper.getData(dir + "/" + child, null, null); 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, true); + return zookeeper.getData(dir + "/" + firstChild, null, null); } 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, true); - zookeeper.delete(path, -1, true); + byte[] result = zookeeper.getData(path, null, null); + zookeeper.delete(path, -1); 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 74f1993dd0f..1c856b1a5d2 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(), true); + Stat stat = zkClient.setData(znodePath, znodeData, newTerms.getVersion()); 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, true); + zkClient.makePath(path, Utils.toJSON(initialTerms), CreateMode.PERSISTENT); } 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, true); + byte[] data = zkClient.getData(znodePath, null, stat); 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, true); + zkClient.exists(znodePath, watcher); } 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 4aa5990e0ea..0d9ef1c8338 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, true); + Stat stat = zkController.getZkClient().exists(file, null); 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, true); + byte[] bytes = zkController.getZkClient().getData(file, null, stat); 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 9accbf4dc69..59db03a4c73 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,9 +190,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList resu if (zkStateReader.getClusterState().getCollectionOrNull(collection) == null) { if (zkStateReader .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection, true)) { + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection)) { // 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, true)) { + if (zkStateReader.getZkClient().exists(collectionPath)) { 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 d8e7a3dea64..fc400ffb26a 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, true); + boolean nodeExists = zkClient.exists(ZkStateReader.ROLES); if (nodeExists) { @SuppressWarnings("unchecked") Map> tmp = (Map>) - Utils.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true)); + Utils.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat())); 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), true); + zkClient.setData(ZkStateReader.ROLES, Utils.toJSON(roles)); } else { - zkClient.create(ZkStateReader.ROLES, Utils.toJSON(roles), CreateMode.PERSISTENT, true); + zkClient.create(ZkStateReader.ROLES, Utils.toJSON(roles), CreateMode.PERSISTENT); } 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 0b841fe8790..d7fad3f776f 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, true); + zkStateReader.getZkClient().getData("/overseer/queue", null, stat); results.add("overseer_queue_size", stat.getNumChildren()); stat = new Stat(); - zkStateReader.getZkClient().getData("/overseer/queue-work", null, stat, true); + zkStateReader.getZkClient().getData("/overseer/queue-work", null, stat); results.add("overseer_work_queue_size", stat.getNumChildren()); stat = new Stat(); - zkStateReader.getZkClient().getData("/overseer/collection-queue-work", null, stat, true); + zkStateReader.getZkClient().getData("/overseer/collection-queue-work", null, stat); 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 0060eb676af..f849ab24d92 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,10 +212,7 @@ 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 be6a1a83c2f..968b2186a93 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, true); + zkStateReader.getZkClient().create(zkPath, arr, CreateMode.PERSISTENT); } 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, true)) { + if (!zkStateReader.getZkClient().exists(zkPath)) { // Nothing to back up return; } try (OutputStream os = repository.createOutput(dest)) { - byte[] data = zkStateReader.getZkClient().getData(zkPath, null, null, true); + byte[] data = zkStateReader.getZkClient().getData(zkPath, null, null); 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 acdbd722717..db83b2e6d11 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, true); + return zkClient.exists(zkPath); } /** @@ -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, true); + zkClient.makePath(zkPath, Utils.toJSON(meta), CreateMode.PERSISTENT); } /** @@ -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, true); + zkClient.setData(zkPath, Utils.toJSON(meta), -1); } /** @@ -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, true); + zkClient.delete(zkPath, -1); } /** @@ -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, true); + Collection snapshots = zkClient.getChildren(zkPath, null); for (String snapshot : snapshots) { String path = getSnapshotMetaDataZkPath(collectionName, Optional.of(snapshot)); try { - zkClient.delete(path, -1, true); + zkClient.delete(path, -1); } 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, true); + zkClient.delete(zkPath, -1); } 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, true)); + (Map) Utils.fromJSON(zkClient.getData(zkPath, null, null)); 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, true); + Collection snapshots = zkClient.getChildren(zkPath, null); 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 8bd0f2c71ea..c301f0d297b 100644 --- a/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java +++ b/solr/core/src/java/org/apache/solr/filestore/DistribPackageStore.java @@ -337,18 +337,14 @@ 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, true); + coreContainer.getZkController().getZkClient().makePath(ZK_PACKAGESTORE + dirName, false); coreContainer .getZkController() .getZkClient() .create( ZK_PACKAGESTORE + info.path, info.getDetails().getMetaData().sha512.getBytes(UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT); } catch (Exception e) { throw new SolrException(SERVER_ERROR, "Unable to create an entry in ZK", e); } @@ -512,7 +508,7 @@ public void delete(String path) { private void checkInZk(String path) { try { // fail if file exists - if (coreContainer.getZkController().getZkClient().exists(ZK_PACKAGESTORE + path, true)) { + if (coreContainer.getZkController().getZkClient().exists(ZK_PACKAGESTORE + path)) { throw new SolrException(BAD_REQUEST, "The path exist ZK, delete and retry"); } @@ -536,11 +532,7 @@ public void refresh(String path) { @SuppressWarnings({"rawtypes"}) List l = null; try { - l = - coreContainer - .getZkController() - .getZkClient() - .getChildren(ZK_PACKAGESTORE + path, null, true); + l = coreContainer.getZkController().getZkClient().getChildren(ZK_PACKAGESTORE + path, null); } catch (KeeperException.NoNodeException e) { // does not matter } @@ -647,7 +639,7 @@ private static Map _getKeys(Path solrHome) throws IOException { public static void deleteZKFileEntry(SolrZkClient client, String path) { try { - client.delete(ZK_PACKAGESTORE + path, -1, true); + client.delete(ZK_PACKAGESTORE + path, -1); } 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 eb87c1a8e29..ffa7f7dced4 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, true); + .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL); 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, true); + coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1); } 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, true); + .create(TMP_ZK_NODE, "true".getBytes(UTF_8), CreateMode.EPHEMERAL); 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, true); + coreContainer.getZkController().getZkClient().delete(TMP_ZK_NODE, -1); } 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 9130fcc317a..b3aea417df9 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,11 +113,10 @@ public void getClusterStatus(NamedList results) } Map roles = null; - if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES, true)) { + if (zkStateReader.getZkClient().exists(ZkStateReader.ROLES)) { roles = (Map) - Utils.fromJSON( - zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null, true)); + Utils.fromJSON(zkStateReader.getZkClient().getData(ZkStateReader.ROLES, null, null)); } ClusterState clusterState = zkStateReader.getClusterState(); @@ -197,7 +196,7 @@ public void getClusterStatus(NamedList results) } List liveNodes = - zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true); + zkStateReader.getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null); // 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 117334b6d4b..290185c7b07 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(), true)); + Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); 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 a0978c02759..09d8cbcddf6 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,8 +79,7 @@ protected boolean persistConf(SecurityConfig securityConfig) throws IOException .setData( SOLR_SECURITY_CONF_PATH, Utils.toJSON(securityConfig.getData()), - securityConfig.getVersion(), - true); + securityConfig.getVersion()); 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 e2d8b7715b8..71b2127f790 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, true); + List children = zkClient.getChildren(adminFile, null); 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, true); + List fchildren = zkClient.getChildren(adminFile + "/" + f, null); if (fchildren.size() > 0) { fileInfo.add("directory", true); } else { @@ -185,8 +185,7 @@ private void showFromZooKeeper( params.set(CommonParams.WT, "raw"); req.setParams(params); ContentStreamBase content = - new ContentStreamBase.ByteArrayStream( - zkClient.getData(adminFile, null, null, true), adminFile); + new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null), adminFile); content.setContentType(getSafeContentType(req.getParams().get(USE_CONTENT_TYPE))); rsp.add(RawResponseWriter.CONTENT, content); @@ -342,7 +341,7 @@ public static String getAdminFileFromZooKeeper( } // Make sure the file exists, is readable and is not a hidden file - if (!zkClient.exists(adminFile, true)) { + if (!zkClient.exists(adminFile)) { 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 b5a8234a321..ce1616ff901 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, true); + List fromZk = zkClient.getChildren("/collections", this); 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, true); + byte[] data = zkClient.getData(path, null, stat); 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, true); + List children = zkClient.getChildren(path, null); 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, true); + byte[] data = zkClient.getData(path, null, stat); 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 c2f244e93d8..4e958192c7a 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,20 +121,18 @@ public ListZkChildrenResponse listNodes( zkPath = sanitizeZkPath(zkPath); try { - Stat stat = coreContainer.getZkController().getZkClient().exists(zkPath, null, true); + Stat stat = coreContainer.getZkController().getZkClient().exists(zkPath, null); listResponse.stat = new AnnotatedStat(stat); if (includeChildren != null && !includeChildren.booleanValue()) { return listResponse; } - List l = - coreContainer.getZkController().getZkClient().getChildren(zkPath, null, false); + List l = coreContainer.getZkController().getZkClient().getChildren(zkPath, null); 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, false)); + stats.put(s, coreContainer.getZkController().getZkClient().exists(prefix + s, null)); } catch (Exception e) { throw new RuntimeException(e); } @@ -184,7 +182,7 @@ private ZooKeeperFileResponse readNodeAndAddToResponse(String zkPath) { private byte[] readPathFromZookeeper(String path) { byte[] d; try { - d = coreContainer.getZkController().getZkClient().getData(path, null, null, false); + d = coreContainer.getZkController().getZkClient().getData(path, null, null); } 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 a8a4b5091d4..644a48eae12 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, true); + data = zkStateReader().getZkClient().getData(filePath, null, null); } 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, true); + zkClient.setData(zkPath, data); } 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), true)) { - if (zkClient.exists(getConfigSetZkPath(configSet, null), true)) { + if (!zkClient.exists(getConfigSetZkPath(mutableId, null))) { + if (zkClient.exists(getConfigSetZkPath(configSet, null))) { 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, true); + return zkClient.exists(zkPath); } 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 db35a805c51..8c726f288ca 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, true); + Stat stat = cc.getZkController().getZkClient().exists(path, null); if (stat != null) { currentVersion = stat.getVersion(); } @@ -927,7 +927,7 @@ protected ManagedIndexSchema removeLanguageSpecificObjectsAndFiles( for (String path : toRemoveFiles) { try { - zkClient.delete(path, -1, false); + zkClient.delete(path, -1); } 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, true)) { - zkClient.makePath(copyToPath, false, true); - zkClient.setData(copyToPath, zkClient.getData(path, null, null, true), true); + if (!zkClient.exists(copyToPath)) { + zkClient.makePath(copyToPath, false); + zkClient.setData(copyToPath, zkClient.getData(path, null, null)); } } 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 bf8e3d26e93..a824e70381d 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, true); + data = cc.getZkController().getZkStateReader().getZkClient().getData(path, null, stat); } 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 79b9fa1c9c3..f518499c934 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, true)) { + if (zkClient.exists(ZkStateReader.SOLR_PKGS_PATH)) { @SuppressWarnings("unchecked") Map>> packagesZnodeMap = (Map>>) getMapper() .readValue( new String( - zkClient.getData(ZkStateReader.SOLR_PKGS_PATH, null, null, true), + zkClient.getData(ZkStateReader.SOLR_PKGS_PATH, null, null), 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, true); + List existingCollections = zkClient.getChildren("/collections", null); 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, true); + allCollections = zkClient.getChildren(ZkStateReader.COLLECTIONS_ZKNODE, null); } 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 8ef29ba5552..9ee18360c31 100644 --- a/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java +++ b/solr/core/src/java/org/apache/solr/packagemanager/RepositoryManager.java @@ -119,17 +119,15 @@ 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, true) == false) { + if (packageManager.zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH) == false) { packageManager.zkClient.create( PackageUtils.REPOSITORIES_ZK_PATH, getMapper().writeValueAsString(repos).getBytes("UTF-8"), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT); } else { packageManager.zkClient.setData( PackageUtils.REPOSITORIES_ZK_PATH, - getMapper().writeValueAsString(repos).getBytes("UTF-8"), - true); + getMapper().writeValueAsString(repos).getBytes("UTF-8")); } try (InputStream is = new URL(uri + "/publickey.der").openStream()) { @@ -153,9 +151,8 @@ 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, true)) { - return new String( - zkClient.getData(PackageUtils.REPOSITORIES_ZK_PATH, null, null, true), "UTF-8"); + if (zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH)) { + return new String(zkClient.getData(PackageUtils.REPOSITORIES_ZK_PATH, null, null), "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 0f9a8d50845..3bb8f6578d0 100644 --- a/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java +++ b/solr/core/src/java/org/apache/solr/pkg/PackageAPI.java @@ -113,18 +113,14 @@ 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, true); + coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, watcher, stat); pkgs = readPkgsFromZk(data, stat); packageLoader.refreshPackageConf(); } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) { @@ -144,8 +140,7 @@ 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, true); + data = coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, null, stat); } 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 b28f4f57c36..aed8b6090a2 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java @@ -227,7 +227,6 @@ public static class ZooKeeperStorageIO implements StorageIO { protected SolrZkClient zkClient; protected String znodeBase; - protected boolean retryOnConnLoss = true; public ZooKeeperStorageIO(SolrZkClient zkClient, String znodeBase) { this.zkClient = zkClient; @@ -239,8 +238,8 @@ public void configure(SolrResourceLoader loader, NamedList initArgs) throws SolrException { // validate connectivity and the configured znode base try { - if (!zkClient.exists(znodeBase, retryOnConnLoss)) { - zkClient.makePath(znodeBase, retryOnConnLoss); + if (!zkClient.exists(znodeBase)) { + zkClient.makePath(znodeBase); } } catch (Exception exc) { String errMsg = @@ -257,7 +256,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, retryOnConnLoss); + return zkClient.exists(znodePath); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; @@ -272,8 +271,8 @@ public InputStream openInputStream(String storedResourceId) throws IOException { final String znodePath = getZnodeForResource(storedResourceId); byte[] znodeData = null; try { - if (zkClient.exists(znodePath, retryOnConnLoss)) { - znodeData = zkClient.getData(znodePath, null, null, retryOnConnLoss); + if (zkClient.exists(znodePath)) { + znodeData = zkClient.getData(znodePath, null, null); } } catch (Exception e) { if (e instanceof IOException) { @@ -296,18 +295,17 @@ public InputStream openInputStream(String storedResourceId) throws IOException { @Override public OutputStream openOutputStream(String storedResourceId) throws IOException { final String znodePath = getZnodeForResource(storedResourceId); - final boolean retryOnConnLoss = this.retryOnConnLoss; ByteArrayOutputStream baos = new ByteArrayOutputStream() { @Override public void close() { byte[] znodeData = toByteArray(); try { - if (zkClient.exists(znodePath, retryOnConnLoss)) { - zkClient.setData(znodePath, znodeData, retryOnConnLoss); + if (zkClient.exists(znodePath)) { + zkClient.setData(znodePath, znodeData); log.info("Wrote {} bytes to existing znode {}", znodeData.length, znodePath); } else { - zkClient.makePath(znodePath, znodeData, retryOnConnLoss); + zkClient.makePath(znodePath, znodeData); log.info("Wrote {} bytes to new znode {}", znodeData.length, znodePath); } } catch (Exception e) { @@ -339,10 +337,10 @@ public boolean delete(String storedResourceId) throws IOException { // this might be overkill for a delete operation try { - if (zkClient.exists(znodePath, retryOnConnLoss)) { + if (zkClient.exists(znodePath)) { log.debug("Attempting to delete znode {}", znodePath); - zkClient.delete(znodePath, -1, retryOnConnLoss); - wasDeleted = zkClient.exists(znodePath, retryOnConnLoss); + zkClient.delete(znodePath, -1); + wasDeleted = zkClient.exists(znodePath); 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 0bcfda95823..cc6e2e01277 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, true); + zkClient.create(managedSchemaPath, data, CreateMode.PERSISTENT); 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, true); + Stat stat = zkClient.setData(managedSchemaPath, data, schemaZkVersion); 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 73187383bd8..8bf2f3d1668 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, true)) { + if (zkClient.exists(legacyManagedSchemaPath)) { 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, true); + byte[] data = zkClient.getData(managedSchemaPath, null, stat); 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, true); + byte[] data = zkClient.getData(managedSchemaPath, null, stat); 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, true); + zkClient.makePath(lockPath, null, CreateMode.EPHEMERAL, null, 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, true); + byte[] bytes = zkController.getZkClient().getData(nonManagedSchemaPath, null, null); final String upgradedSchemaPath = nonManagedSchemaPath + UPGRADED_SCHEMA_EXTENSION; ZkMaintenanceUtils.ensureExists(upgradedSchemaPath, zkController.getZkClient()); - zkController.getZkClient().setData(upgradedSchemaPath, bytes, true); + zkController.getZkClient().setData(upgradedSchemaPath, bytes); // Then delete the non-managed schema znode - if (zkController.getZkClient().exists(nonManagedSchemaPath, true)) { + if (zkController.getZkClient().exists(nonManagedSchemaPath)) { try { - zkController.getZkClient().delete(nonManagedSchemaPath, -1, true); + zkController.getZkClient().delete(nonManagedSchemaPath, -1); } 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, true); + zkClient.delete(lockPath, -1); } 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 801863fa882..e99270078a1 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, true)) { + if (!zkClient.exists(managedSchemaPath)) { String backupName = schemaResourceName + ManagedIndexSchemaFactory.UPGRADED_SCHEMA_EXTENSION; - if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + backupName, true)) { + if (!zkClient.exists(zkLoader.getConfigSetZkPath() + "/" + backupName)) { 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 d37e812a891..40be270e09e 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, true); + zkClient.exists(managedSchemaPath, watcher); } 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, true); + byte[] data = zkClient.getData(managedSchemaPath, watcher, stat); 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 ce9b1f8e6be..3dfd33ee6b9 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), true)) { + .exists(DocCollection.getCollectionPath(collectionName))) { // 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 6b54ce450cd..5b57617fa83 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(), true)); + Utils.fromJSON(zkClient.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); 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 970f4d8478f..5b4fb191dad 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, true); + final byte[] rawBytes = zkStateReader.getZkClient().getData(ALIASES, null, null); 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 0587fada196..7275293c6de 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, true); + cluster.getZkClient().delete("/collections/" + COLLECTION + "/counter", -1); clearedCounter = true; } if (deleteReplica) { @@ -115,7 +115,7 @@ private int getCounter() throws InterruptedException { byte[] data = cluster .getZkClient() - .getData("/collections/" + COLLECTION + "/counter", null, new Stat(), true); + .getData("/collections/" + COLLECTION + "/counter", null, new Stat()); 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 7d963ee6b9a..87f71cc0570 100644 --- a/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/CollectionPropsTest.java @@ -171,8 +171,7 @@ private void waitForValue(String propertyName, String expectedValue) throws Inte new String( cluster .getZkClient() - .getData( - "/collections/" + collectionName + "/collectionprops.json", null, null, true), + .getData("/collections/" + collectionName + "/collectionprops.json", null, null), StandardCharsets.UTF_8); } catch (Exception e) { collectionpropsInZk = "Could not get file from ZooKeeper: " + e.getMessage(); @@ -222,7 +221,7 @@ public void testWatcher() throws KeeperException, InterruptedException, IOExcept log.info("deleting props"); zkStateReader .getZkClient() - .delete("/collections/" + collectionName + "/collectionprops.json", -1, true); + .delete("/collections/" + collectionName + "/collectionprops.json", -1); 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 0c43b93ea80..05eb9e5c71b 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), true)); + zkClient().exists(DocCollection.getCollectionPath(collectionName))); Stat stat = new Stat(); - zkClient().getData(DocCollection.getCollectionPath(collectionName), null, stat, true); + zkClient().getData(DocCollection.getCollectionPath(collectionName), null, stat); DocCollection c = getCollectionState(collectionName); @@ -68,6 +68,6 @@ public void testZkNodeLocation() throws Exception { assertFalse( "collection state should not exist", - zkClient().exists(DocCollection.getCollectionPath(collectionName), true)); + zkClient().exists(DocCollection.getCollectionPath(collectionName))); } } 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 2ed48c9e7bd..7a5836391c8 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("/", true)) zkClient.makePath("/", false, true); - if (zkClient.exists(znodePath, true)) zkClient.clean(znodePath); - zkClient.makePath(znodePath, false, true); + if (!zkClient.exists("/")) zkClient.makePath("/", false); + if (zkClient.exists(znodePath)) zkClient.clean(znodePath); + zkClient.makePath(znodePath, false); 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 0fd64f1306c..6e0860023fd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java @@ -130,7 +130,6 @@ private List getElectionNodes(String collection, String shard, SolrZkCli throws KeeperException, InterruptedException { return client.getChildren( "/collections/" + collection + "/leader_elect/" + shard + LeaderElector.ELECTION_NODE, - null, - true); + null); } } 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 d4a61abcc60..6446a7ced54 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", true); - zkClient.makePath("/collections/collection2", true); + zkClient.makePath("/collections/collection1"); + zkClient.makePath("/collections/collection2"); } static class TestLeaderElectionContext extends ShardLeaderElectionContextBase { @@ -292,8 +292,7 @@ private String getLeaderUrl(final String collection, final String slice) while (iterCount-- > 0) { try { byte[] data = - zkClient.getData( - ZkStateReader.getShardLeadersPath(collection, slice), null, null, true); + zkClient.getData(ZkStateReader.getShardLeadersPath(collection, slice), null, null); 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 146a05388e8..064a9e5ae3c 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, true); + "/collections/" + collectionName + "/leader_elect/shard1/election", null); 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 b0188069562..b211096aae3 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, true); + zkClient.makePath("/solr", false); zkClient.close(); zkClient = @@ -85,21 +85,17 @@ public void setUp() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT); zkClient.close(); if (log.isInfoEnabled()) { @@ -152,7 +148,7 @@ public void testOpenACLUnsafeAllover() throws Exception { protected void assertOpenACLUnsafeAllover( SolrZkClient zkClient, String path, List verifiedList) throws Exception { - List acls = zkClient.getACL(path, new Stat(), true); + List acls = zkClient.getACL(path, new Stat()); if (log.isInfoEnabled()) { log.info("Verifying {}", path); } @@ -169,7 +165,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, false); + List children = zkClient.getChildren(path, null); 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 5810c50fe17..cc593562d4e 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, true); + zkClient.makePath("/solr", false); } try (SolrZkClient zkClient = @@ -100,17 +100,13 @@ public void setUp() throws Exception { "readonlyACLPassword") .getSolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) { zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT); } try (SolrZkClient zkClient = @@ -123,15 +119,9 @@ public void setUp() throws Exception { ("connectAndAllACLUsername:connectAndAllACLPassword") .getBytes(DATA_ENCODING)))) { zkClient.create( - "/unprotectedCreateNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); } 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 ac3df8b4373..a64e35a7753 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(), anyBoolean())) + when(solrZkClientMock.setData(anyString(), any(), anyInt())) .then( invocation -> { System.out.println( @@ -414,7 +414,7 @@ protected Set commonMocks(int liveNodesCount, boolean distributedCluster return null; }); - when(solrZkClientMock.getData(anyString(), any(), any(), anyBoolean())) + when(solrZkClientMock.getData(anyString(), any(), any())) .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(), anyBoolean())) + when(solrZkClientMock.create(any(), any(), any())) .thenAnswer( invocation -> { zkClientData.put(invocation.getArgument(0), invocation.getArgument(1)); return invocation.getArgument(0); }); - when(solrZkClientMock.exists(any(String.class), anyBoolean())) + when(solrZkClientMock.exists(any(String.class))) .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(), anyBoolean())) + when(solrZkClientMock.exists(any(String.class), isNull())) .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 1324ae8d6dd..573a7d0191c 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, true); + zkClient.makePath(nodePath, CreateMode.EPHEMERAL); } private void deleteNode(final String path) { try { - zkClient.delete(path, -1, true); + zkClient.delete(path, -1); } 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, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection); ZkNodeProps m = new ZkNodeProps( @@ -287,7 +287,7 @@ public String publishState( try { zkClient.makePath( - "/collections/" + collection + "/leader_elect/" + shardId + "/election", true); + "/collections/" + collection + "/leader_elect/" + shardId + "/election"); } 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, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection); 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, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); 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, true); + zkClient.makePath("/collections/perf" + i); 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, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); 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, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + testCollectionName); 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, true); + byte[] data = zkClient.getData(path, null, null); // Simulate an external modification of state.json - zkClient.setData(path, data, true); + zkClient.setData(path, data); m = new ZkNodeProps( @@ -1973,7 +1973,7 @@ public void testRemovalOfLastReplica() throws Exception { // create collection { - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION, true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + COLLECTION); 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 38f6a674dd3..a5439a1c2e0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java @@ -124,8 +124,7 @@ public void testUpconfig() throws Exception { String content = new String( - zkClient.getData("/configs/upconfig2/schema.xml", null, null, true), - StandardCharsets.UTF_8); + zkClient.getData("/configs/upconfig2/schema.xml", null, null), StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); } @@ -354,7 +353,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", true)); + zkClient.exists("/powerup/solrconfig.xml")); // copy individual file up // src and cp3 are valid @@ -374,8 +373,7 @@ 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", true)); + "Should NOT have created an intermediate node on ZK", zkClient.exists("/copyUpFile.xml")); // copy individual file down // src and cp3 are valid @@ -422,8 +420,7 @@ 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", true)); + assertTrue("Should have found znode /solrconfig.xml: ", zkClient.exists("/solrconfig.xml")); // Check that the form path/ works for copying files up. Should append the last bit of the // source path to the dst @@ -468,8 +465,7 @@ public void testCp() throws Exception { assertEquals("Copy should have succeeded.", 0, res); String content = - new String( - zkClient.getData("/cp7/conf/stopwords", null, null, true), StandardCharsets.UTF_8); + new String(zkClient.getData("/cp7/conf/stopwords", null, null), StandardCharsets.UTF_8); assertTrue("There should be content in the node! ", content.contains("{Some Arbitrary Data}")); res = @@ -514,8 +510,7 @@ public void testCp() throws Exception { assertEquals("Copy should have succeeded.", 0, res); content = - new String( - zkClient.getData("/cp9/conf/stopwords", null, null, true), StandardCharsets.UTF_8); + new String(zkClient.getData("/cp9/conf/stopwords", null, null), 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 @@ -623,7 +618,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", true)); + assertFalse("/configs/mv1 Znode should not be there: ", zkClient.exists("/configs/mv1")); // Files are in mv2 // Now fail if we specify "file:". Everything should still be in /mv2 @@ -649,7 +644,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", true)); + assertFalse("Znode /mv3 really should be gone", zkClient.exists("/mv3")); // Now does the moved directory match the original on disk? verifyZkLocalPathsMatch(srcPathCheck, "/mv4"); @@ -665,10 +660,9 @@ 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", true)); + "Should be able to move a single file", zkClient.exists("/testmvsingle/solrconfig.xml")); - zkClient.makePath("/parentNode", true); + zkClient.makePath("/parentNode"); // what happens if the destination ends with a slash? args = @@ -683,10 +677,9 @@ 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", true)); + zkClient.exists("/parentnode/schema.xml")); String content = - new String( - zkClient.getData("/parentnode/schema.xml", null, null, true), StandardCharsets.UTF_8); + new String(zkClient.getData("/parentnode/schema.xml", null, null), StandardCharsets.UTF_8); assertTrue( "There should be content in the node! ", content.contains("Apache Software Foundation")); } @@ -832,8 +825,7 @@ 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", true)); + assertFalse("Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1")); // Check that zk prefix also works. args = @@ -845,8 +837,7 @@ 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", true)); + assertFalse("Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2")); // This should silently just refuse to do anything to the / or /zookeeper args = @@ -869,14 +860,14 @@ private void verifyZkLocalPathsMatch(Path fileRoot, String zkRoot) } private static boolean isEphemeral(String zkPath) throws KeeperException, InterruptedException { - Stat znodeStat = zkClient.exists(zkPath, null, true); + Stat znodeStat = zkClient.exists(zkPath, null); return znodeStat.getEphemeralOwner() != 0; } void verifyAllZNodesAreFiles(Path fileRoot, String zkRoot) throws KeeperException, InterruptedException { - for (String child : zkClient.getChildren(zkRoot, null, true)) { + for (String child : zkClient.getChildren(zkRoot, null)) { // Skip ephemeral nodes if (zkRoot.endsWith("/") == false) zkRoot += "/"; if (isEphemeral(zkRoot + child)) continue; @@ -896,8 +887,7 @@ 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, true)); + assertTrue("Should have found " + znode + " on Zookeeper", zkClient.exists(znode)); } catch (Exception e) { fail( "Caught unexpected exception " @@ -933,10 +923,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, true)) { + for (String node : zkClient.getChildren(first, null)) { String fNode = first + "/" + node; String sNode = second + "/" + node; - assertTrue("Node " + sNode + " not found. Exists on " + fNode, zkClient.exists(sNode, true)); + assertTrue("Node " + sNode + " not found. Exists on " + fNode, zkClient.exists(sNode)); 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 868cd91e62a..3dd6948fc3f 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), true); + zkClient.makePath("solr.xml", XML_FOR_ZK.getBytes(StandardCharsets.UTF_8)); } 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 1da60d85ff9..0272ac5f806 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, true); + oldPropsData = zkClient.getData(path, null, null); } catch (KeeperException.NoNodeException e) { // okay, properties just don't exist } @@ -444,17 +444,15 @@ public void testUploadErrors() throws Exception { .build(); // Create dummy config files in zookeeper - zkClient.makePath("/configs/myconf", true); + zkClient.makePath("/configs/myconf"); zkClient.create( "/configs/myconf/firstDummyFile", "first dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT); zkClient.create( "/configs/myconf/anotherDummyFile", "second dummy content".getBytes(UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT); // Checking error when configuration name specified already exists ignoreException("already exists"); @@ -472,10 +470,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", true)); + zkClient.exists("/configs/myconf/firstDummyFile")); assertTrue( "Expected file doesnt exist in zk. It's possibly overwritten", - zkClient.exists("/configs/myconf/anotherDummyFile", true)); + zkClient.exists("/configs/myconf/anotherDummyFile")); zkClient.close(); solrClient.close(); @@ -533,7 +531,7 @@ public void testUploadLegacyManagedSchemaFile() throws Exception { assertTrue( "managed-schema file should have been uploaded", - zkClient.exists("/configs/" + configSetName + "/managed-schema", true)); + zkClient.exists("/configs/" + configSetName + "/managed-schema")); } finally { zkClient.close(); } @@ -635,20 +633,19 @@ public void testOverwriteWithCleanup(boolean v2) throws Exception { configPath + "/foo2/1", configPath + "/foo2/2"); for (String f : extraFiles) { - zkClient.makePath(f, true); + zkClient.makePath(f); } 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, true)); + "Expecting file " + f + " to exist in ConfigSet but it's gone", zkClient.exists(f)); } 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, true)); + zkClient.exists(f)); } assertConfigsetFiles(configsetName, configsetSuffix, zkClient); } @@ -680,7 +677,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, true)); + zkClient.exists(f)); } } } @@ -989,8 +986,7 @@ 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", - true)); + "/configs/" + configsetName + configsetSuffix + "/test/upload/path/solrconfig.xml")); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("ConfigSet uploads do not allow cleanup=true when filePath is used."); } @@ -1051,8 +1047,10 @@ 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", - true)); + "/configs/" + + configsetName + + configsetSuffix + + "/test/different/path/solrconfig.xml")); assertTrue(isTrusted(zkClient, configsetName, configsetSuffix)); assertConfigsetFiles(configsetName, configsetSuffix, zkClient); unIgnoreException("Trying to make an unstrusted ConfigSet update on a trusted configSet"); @@ -1125,8 +1123,7 @@ public void testSingleFileForbiddenType(boolean v2) throws Exception { + configsetName + configsetSuffix + "/test/different/path/solrconfig." - + fileType, - true)); + + fileType)); unIgnoreException("is forbidden for use in configSets"); } } @@ -1309,8 +1306,7 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { List children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixTrusted), - null, - true); + null); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); @@ -1335,8 +1331,7 @@ public void testSingleFileNewConfig(boolean v2) throws Exception { children = zkClient.getChildren( String.format(Locale.ROOT, "/configs/%s%s", configsetName, configsetSuffixUntrusted), - null, - true); + null); assertEquals("The configSet should only have one file uploaded.", 1, children.size()); assertEquals("Incorrect file uploaded.", "solrconfig.xml", children.get(0)); } @@ -1346,7 +1341,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, true); + byte[] configSetNodeContent = zkClient.getData(configSetZkPath, null, null); ; @SuppressWarnings("unchecked") @@ -1361,8 +1356,7 @@ private int getConfigZNodeVersion( zkClient.getData( String.format(Locale.ROOT, "/configs/%s%s/%s", configsetName, configsetSuffix, configFile), null, - stat, - true); + stat); return stat.getVersion(); } @@ -1488,22 +1482,20 @@ 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", true)); + zkClient.exists("/configs/" + configSetName + suffix + "/managed-schema.xml")); 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, true), + zkClient.getData("/configs/" + configSetName + suffix + "/managed-schema.xml", null, null), readFile("solr/configsets/upload/" + configSetName + "/managed-schema.xml")); assertTrue( "solrconfig.xml file should have been uploaded", - zkClient.exists("/configs/" + configSetName + suffix + "/solrconfig.xml", true)); - byte data[] = zkClient.getData("/configs/" + configSetName + suffix, null, null, true); + zkClient.exists("/configs/" + configSetName + suffix + "/solrconfig.xml")); + byte data[] = zkClient.getData("/configs/" + configSetName + suffix, null, null); // 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, true), + zkClient.getData("/configs/" + configSetName + suffix + "/solrconfig.xml", null, null), 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 2920e4ece52..4c30011b7be 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIExclusivity.java @@ -96,8 +96,7 @@ private void setupBaseConfigSet(String baseConfigSetName) throws Exception { .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8), - true); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8)); } 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 2ba85cfa437..94b7b3585d0 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java @@ -156,8 +156,7 @@ private void setupBaseConfigSet(String baseConfigSetName, Map ol .getZkClient() .setData( "/configs/" + baseConfigSetName, - "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8), - true); + "{\"trusted\": false}".getBytes(StandardCharsets.UTF_8)); } 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 aa5915f007b..7a5c12a1278 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", true)); + assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); map.put("foo", new byte[0]); - assertTrue(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); + assertTrue(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); } } @@ -79,12 +79,7 @@ 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, - true); + path + "/" + DistributedMap.PREFIX + "foo", data, CreateMode.PERSISTENT, null, false); DistributedMap map = createMap(zkClient, path); assertArrayEquals(data, map.get("foo")); } @@ -104,8 +99,7 @@ public void testContains() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false, - true); + false); assertTrue(map.contains("foo")); } } @@ -124,11 +118,10 @@ public void testRemove() throws KeeperException, InterruptedException { new byte[0], CreateMode.PERSISTENT, null, - false, - true); + false); assertTrue(map.remove("foo")); assertFalse(map.contains("foo")); - assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo", true)); + assertFalse(zkClient.exists(path + "/" + DistributedMap.PREFIX + "foo")); } } @@ -240,7 +233,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], true); + zkClient.makePath(path + "/" + DistributedMap.PREFIX + key, new byte[0]); DistributedMap map = createMap(zkClient, path); assertEquals(1, map.size()); @@ -256,7 +249,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, true); + zkClient.makePath(path, false); 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 7d7f7024953..9fa4f473d07 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestLazySolrCluster.java @@ -71,14 +71,11 @@ 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, true); + zkClient.create(ZkStateReader.CONFIGS_ZKNODE + "/conf1/a", null, CreateMode.PERSISTENT); zkClient.create( - ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa1", new byte[1024], CreateMode.PERSISTENT, true); + ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa1", new byte[1024], CreateMode.PERSISTENT); zkClient.create( - ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa2", - new byte[1024 * 2], - CreateMode.PERSISTENT, - true); + ZkStateReader.CONFIGS_ZKNODE + "/conf1/a/aa2", new byte[1024 * 2], CreateMode.PERSISTENT); 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 a5b0ee21781..96ef9151720 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplica.java @@ -192,9 +192,7 @@ public void testCreateDelete() throws Exception { cluster .getZkClient() .getChildren( - ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), - null, - true); + ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null); 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 78f165613f2..9fe42b53af0 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, true); + .getData("/collections/" + COLLECTION_NAME + "/state.json", null, null); Map> infectedState = (Map>) Utils.fromJSON(collectionState); @@ -139,8 +139,7 @@ private void downAllReplicas() throws Exception { cluster .getZkClient() - .setData( - "/collections/" + COLLECTION_NAME + "/state.json", Utils.toJSON(infectedState), true); + .setData("/collections/" + COLLECTION_NAME + "/state.json", Utils.toJSON(infectedState)); } 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 bf870ad0eb2..e891e567136 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestRebalanceLeaders.java @@ -275,8 +275,7 @@ private void checkOneQueue(DocCollection coll, Slice slice, Set liveRep + "/leader_elect/" + slice.getName() + "/election", - null, - true); + null); 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 a534e2e2a30..385c39c26d2 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], true); + zkClient.makePath(path + "/" + DistributedMap.PREFIX + "slash/test/0", new byte[0]); 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 eb3bf597e4b..3865d665e20 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, true)); + new ArrayList<>(client.getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null)); 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, true); + client.makePath(nodePath, CreateMode.EPHEMERAL); 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 937b8f1fe17..d2b772b44f7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -222,9 +222,7 @@ public void testCreateDelete() throws Exception { cluster .getZkClient() .getChildren( - ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), - null, - true); + ZkStateReader.getShardLeadersElectPath(collectionName, s.getName()), null); 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 11d9cc99711..95ca8d13ac0 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, true); + zkClient.makePath("/solr", false); 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, true)); + assertFalse(zkClient.exists(chroot)); String[] args = new String[] { @@ -138,7 +138,7 @@ public void testBootstrapWithChroot() throws Exception { ZkCLI.main(args); - assertTrue(zkClient.exists(chroot + ZkConfigSetService.CONFIGS_ZKNODE + "/collection1", true)); + assertTrue(zkClient.exists(chroot + ZkConfigSetService.CONFIGS_ZKNODE + "/collection1")); } @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", true)); + assertTrue(zkClient.exists("/path/mynewpath")); } @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, true); + zkClient.getData("/data.txt", null, null); assertArrayEquals( - zkClient.getData("/data.txt", null, null, true), data.getBytes(StandardCharsets.UTF_8)); + zkClient.getData("/data.txt", null, null), 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, true), data.getBytes(StandardCharsets.UTF_8)); + zkClient.getData("/data.txt", null, null), data.getBytes(StandardCharsets.UTF_8)); } @Test @@ -216,8 +216,7 @@ public void testPutFile() throws Exception { }; ZkCLI.main(args); - String fromZk = - new String(zkClient.getData("/solr.xml", null, null, true), StandardCharsets.UTF_8); + String fromZk = new String(zkClient.getData("/solr.xml", null, null), 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); @@ -266,7 +265,7 @@ public void testPutFileNotExists() { @Test public void testList() throws Exception { - zkClient.makePath("/test", true); + zkClient.makePath("/test"); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "list"}; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); @@ -282,7 +281,7 @@ public void testList() throws Exception { @Test public void testLs() throws Exception { - zkClient.makePath("/test/path", true); + zkClient.makePath("/test/path"); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "ls", "/test"}; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); @@ -335,7 +334,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { } ZkCLI.main(upconfigArgs); - assertTrue(zkClient.exists(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, true)); + assertTrue(zkClient.exists(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname)); // print help // ZkCLI.main(new String[0]); @@ -356,7 +355,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { ZkNodeProps collectionProps = ZkNodeProps.load( - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null, true)); + zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null)); assertTrue(collectionProps.containsKey("configName")); assertEquals(confsetname, collectionProps.getStr("configName")); @@ -381,7 +380,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { File[] files = confDir.listFiles(); List zkFiles = - zkClient.getChildren(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, null, true); + zkClient.getChildren(ZkConfigSetService.CONFIGS_ZKNODE + "/" + confsetname, null); assertEquals(files.length, zkFiles.size()); File sourceConfDir = new File(ExternalPaths.TECHPRODUCTS_CONFIGSET); @@ -421,7 +420,7 @@ public void testUpConfigLinkConfigClearZk() throws Exception { args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "clear", "/"}; ZkCLI.main(args); - assertEquals(0, zkClient.getChildren("/", null, true).size()); + assertEquals(0, zkClient.getChildren("/", null).size()); } @Test @@ -429,7 +428,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, true); + this.zkClient.create(getNode, data, CreateMode.PERSISTENT); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "get", getNode}; ZkCLI.setStdout(new PrintStream(systemOut, true, StandardCharsets.UTF_8)); ZkCLI.main(args); @@ -454,7 +453,7 @@ public void testGetCompressed() throws Exception { random().nextBoolean() ? zLibCompressor.compressBytes(data) : zLibCompressor.compressBytes(data, data.length / 10); - this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT, true); + this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT); String[] args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd", "get", getNode}; ZkCLI.setStdout(new PrintStream(systemOut, true, StandardCharsets.UTF_8)); ZkCLI.main(args); @@ -472,7 +471,7 @@ public void testGetFile() throws Exception { String getNode = "/getFileNode"; byte[] data = "getFileNode-data".getBytes(StandardCharsets.UTF_8); - this.zkClient.create(getNode, data, CreateMode.PERSISTENT, true); + this.zkClient.create(getNode, data, CreateMode.PERSISTENT); Path file = tmpDir.resolve("solrtest-getfile-" + this.getClass().getName() + "-" + System.nanoTime()); @@ -501,7 +500,7 @@ public void testGetFileCompressed() throws Exception { random().nextBoolean() ? zLibCompressor.compressBytes(data) : zLibCompressor.compressBytes(data, data.length / 10); - this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT, true); + this.zkClient.create(getNode, compressedData, CreateMode.PERSISTENT); Path file = tmpDir.resolve("solrtest-getfile-" + this.getClass().getName() + "-" + System.nanoTime()); @@ -602,7 +601,7 @@ public void testUpdateAcls() throws Exception { .withTimeout( AbstractDistribZkTestBase.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - zkClient.getData("/", null, null, true); + zkClient.getData("/", null, null); } 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 f1df3febab4..a83e5c31b1d 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java @@ -233,8 +233,7 @@ public List getCoreDescriptors() { .makePath( DocCollection.getCollectionPathRoot(collectionName), new byte[0], - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT); ZkNodeProps m = new ZkNodeProps( @@ -340,30 +339,29 @@ public void testTouchConfDir() throws Exception { // touchConfDir doesn't make the znode Stat s = new Stat(); - assertFalse(zkClient.exists(zkpath, true)); + assertFalse(zkClient.exists(zkpath)); zkClient.makePath(zkpath, true); - assertTrue(zkClient.exists(zkpath, true)); - assertNull(zkClient.getData(zkpath, null, s, true)); + assertTrue(zkClient.exists(zkpath)); + assertNull(zkClient.getData(zkpath, null, s)); assertEquals(0, s.getVersion()); // touchConfDir should only set the data to new byte[] {0} ZkController.touchConfDir(loader); - assertTrue(zkClient.exists(zkpath, true)); - assertArrayEquals( - ZkController.TOUCHED_ZNODE_DATA, zkClient.getData(zkpath, null, s, true)); + assertTrue(zkClient.exists(zkpath)); + assertArrayEquals(ZkController.TOUCHED_ZNODE_DATA, zkClient.getData(zkpath, null, s)); 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, true); + s = zkClient.setData(zkpath, data); assertEquals(2, s.getVersion()); // make sure touchConfDir doesn't overwrite existing data. // touchConfDir should update version. - assertTrue(zkClient.exists(zkpath, true)); + assertTrue(zkClient.exists(zkpath)); ZkController.touchConfDir(loader); - assertTrue(zkClient.exists(zkpath, true)); - assertArrayEquals(data, zkClient.getData(zkpath, null, s, true)); + assertTrue(zkClient.exists(zkpath)); + assertArrayEquals(data, zkClient.getData(zkpath, null, s)); assertEquals(3, s.getVersion()); } } @@ -390,10 +388,7 @@ public void testCheckNoOldClusterstate() throws Exception { server .getZkClient() .create( - "/clusterstate.json", - "{}".getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT, - true); + "/clusterstate.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); AtomicInteger idx = new AtomicInteger(); CountDownLatch latch = new CountDownLatch(nThreads); CountDownLatch done = new CountDownLatch(nThreads); @@ -420,7 +415,7 @@ public void testCheckNoOldClusterstate() throws Exception { }); } done.await(); - assertFalse(server.getZkClient().exists("/clusterstate.json", true)); + assertFalse(server.getZkClient().exists("/clusterstate.json")); 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 2ce44a8b65c..bf2f1389a30 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", true)); + assertTrue(zkClient.exists("/solr")); } } } @@ -102,14 +102,14 @@ public void testClean() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/test/path/here", true); + zkClient.makePath("/test/path/here"); - zkClient.makePath("/zz/path/here", true); + zkClient.makePath("/zz/path/here"); zkClient.clean("/"); - assertFalse(zkClient.exists("/test", true)); - assertFalse(zkClient.exists("/zz", true)); + assertFalse(zkClient.exists("/test")); + assertFalse(zkClient.exists("/zz")); } } @@ -125,7 +125,7 @@ public void testReconnect() throws Exception { .build()) { String shardsPath = "/collections/collection1/shards"; - zkClient.makePath(shardsPath, false, true); + zkClient.makePath(shardsPath, false); 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", false); + zkClient.makePath("collections/collection2"); // 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", true); + zkClient.makePath("collections/collection3"); } catch (KeeperException e) { throw new RuntimeException(e); @@ -178,8 +178,8 @@ public void run() { thread2.join(); - assertNotNull(zkClient.exists("/collections/collection3", null, true)); - assertNotNull(zkClient.exists("/collections/collection1", null, true)); + assertNotNull(zkClient.exists("/collections/collection3", null)); + assertNotNull(zkClient.exists("/collections/collection1", null)); // simulate session expiration @@ -196,7 +196,7 @@ public void run() { for (int i = 0; i < 8; i++) { try { - zkClient.makePath("collections/collection4", true); + zkClient.makePath("collections/collection4"); break; } catch (KeeperException.SessionExpiredException | KeeperException.ConnectionLossException e) { @@ -206,8 +206,7 @@ public void run() { } assertNotNull( - "Node does not exist, but it should", - zkClient.exists("/collections/collection4", null, true)); + "Node does not exist, but it should", zkClient.exists("/collections/collection4", null)); } finally { @@ -222,7 +221,7 @@ public void run() { public void testMultipleWatchesAsync() throws Exception { try (ZkConnection conn = new ZkConnection()) { final SolrZkClient zkClient = conn.getClient(); - zkClient.makePath("/collections", true); + zkClient.makePath("/collections"); final int numColls = random().nextInt(100); final CountDownLatch latch = new CountDownLatch(numColls); @@ -232,7 +231,7 @@ public void testMultipleWatchesAsync() throws Exception { for (int i = 1; i <= numColls; i++) { String collPath = "/collections/collection" + i; - zkClient.makePath(collPath, true); + zkClient.makePath(collPath); zkClient.getChildren( collPath, new Watcher() { @@ -254,13 +253,12 @@ public void process(WatchedEvent event) { } watchesDone.countDown(); } - }, - true); + }); } for (int i = 1; i <= numColls; i++) { String shardsPath = "/collections/collection" + i + "/shards"; - zkClient.makePath(shardsPath, true); + zkClient.makePath(shardsPath); } assertTrue(latch.await(10000, TimeUnit.MILLISECONDS)); @@ -284,7 +282,7 @@ public void testWatchChildren() throws Exception { final AtomicInteger cnt = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); - zkClient.makePath("/collections", true); + zkClient.makePath("/collections"); zkClient.getChildren( "/collections", @@ -295,23 +293,22 @@ public void process(WatchedEvent event) { cnt.incrementAndGet(); // remake watch try { - zkClient.getChildren("/collections", this, true); + zkClient.getChildren("/collections", this); latch.countDown(); } catch (KeeperException | InterruptedException e) { throw new RuntimeException(e); } } - }, - true); + }); - zkClient.makePath("/collections/collection99/shards", true); + zkClient.makePath("/collections/collection99/shards"); latch.await(); // wait until watch has been re-created - zkClient.makePath("collections/collection99/config=collection1", true); + zkClient.makePath("collections/collection99/config=collection1"); - zkClient.makePath("collections/collection99/config=collection3", true); + zkClient.makePath("collections/collection99/config=collection3"); - zkClient.makePath("/collections/collection97/shards", true); + zkClient.makePath("/collections/collection97/shards"); // pause for the watches to fire Thread.sleep(700); @@ -336,8 +333,7 @@ public void testSkipPathPartsOnMakePath() throws Exception { zkClient.makePath("/test", true); // should work - zkClient.makePath( - "/test/path/here", (byte[]) null, CreateMode.PERSISTENT, (Watcher) null, true, true, 1); + zkClient.makePath("/test/path/here", null, CreateMode.PERSISTENT, null, true, 1); zkClient.clean("/"); @@ -347,14 +343,7 @@ public void testSkipPathPartsOnMakePath() throws Exception { KeeperException.NoNodeException.class, "We should not be able to create this path", () -> - zkClient.makePath( - "/test/path/here", - (byte[]) null, - CreateMode.PERSISTENT, - (Watcher) null, - true, - true, - 1)); + zkClient.makePath("/test/path/here", null, CreateMode.PERSISTENT, null, true, 1)); zkClient.clean("/"); @@ -387,14 +376,14 @@ public void testSkipPathPartsOnMakePath() throws Exception { ZkMaintenanceUtils.ensureExists( "/collection/collection", bytes, CreateMode.PERSISTENT, zkClient, 2); - byte[] returnedBytes = zkClient.getData("/collection/collection", null, null, true); + byte[] returnedBytes = zkClient.getData("/collection/collection", null, null); assertNull("We skipped 2 path parts, so data won't be written", returnedBytes); zkClient.makePath("/collection/collection/leader", true); ZkMaintenanceUtils.ensureExists( - "/collection/collection/leader", (byte[]) null, CreateMode.PERSISTENT, zkClient, 2); + "/collection/collection/leader", null, CreateMode.PERSISTENT, zkClient, 2); } } @@ -403,14 +392,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, true); + zkClient.create("/test-node", null, CreateMode.PERSISTENT); - Stat stat = zkClient.exists("/test-node", null, true); + Stat stat = zkClient.exists("/test-node", null); 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, true); + stat = zkClient.exists("/test-node", null); 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 f252c23e901..22d3a51b2c1 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, true)) { + if (ZkStateReader.from(cloudClient).getZkClient().exists(path)) { 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, true)); + ZkStateReader.from(cloudClient).getZkClient().exists(path)); // 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, true)) { + if (!ZkStateReader.from(cloudClient).getZkClient().exists(path)) { 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 9d8c18f42d7..021b93a9812 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,15 +65,13 @@ public void testCreateAndDeleteThenCreateAgain() throws Exception { NamedList request = create.process(cloudClient).getResponse(); if (request.get("success") != null) { - assertTrue( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + assertTrue(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName); cloudClient.request(delete); - assertFalse( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + assertFalse(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); // currently, removing a collection does not wait for cores to be unloaded TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); @@ -119,7 +117,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, true); + getZkClient().getNode(DocCollection.getCollectionPath(collectionName), null); DocCollection c = ClusterState.createFromCollectionMap( @@ -151,26 +149,25 @@ public void testDeleteAlsoDeletesAutocreatedConfigSet() throws Exception { assertTrue( ZkStateReader.from(cloudClient) .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); 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, true)); + assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); CollectionAdminRequest.Delete delete = CollectionAdminRequest.deleteCollection(collectionName); cloudClient.request(delete); // collection has been deleted - assertFalse( - getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false)); + assertFalse(getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); // ... 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, true)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); } } @@ -186,8 +183,7 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception if (requestInitial.get("success") != null) { // collection exists now assertTrue( - getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial, false)); + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); String configName = cloudClient @@ -197,7 +193,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, true)); + assertTrue(getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); // create a second collection, sharing the same configSet String collectionNameWithSharedConfig = @@ -213,8 +209,7 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception assertTrue( "The new collection should exist after a successful creation", getZkClient() - .exists( - ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig, false)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); String configNameOfSecondCollection = cloudClient @@ -235,12 +230,11 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // initial collection has been deleted assertFalse( - getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial, false)); + getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameInitial)); // ... 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, true)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); // delete the second collection - the config set should now be deleted, since it is no longer // shared any other collection @@ -251,13 +245,12 @@ public void testDeleteDoesNotDeleteSharedAutocreatedConfigSet() throws Exception // the collection has been deleted assertFalse( getZkClient() - .exists( - ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig, false)); + .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionNameWithSharedConfig)); // ... 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, true)); + getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + configName)); } } 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 29c103cb9a3..d37017abda8 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, true); + List kids = zkClient.getChildren(node, null); for (String kid : kids) { deleteThemAll(zkClient, node + "/" + kid); } - zkClient.delete(node, -1, true); + zkClient.delete(node, -1); } 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 caa2e5f4c74..04e1fff06e7 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,9 +76,7 @@ public static void setupClass() throws Exception { cluster .getZkClient() .delete( - ZkConfigSetService.CONFIGS_ZKNODE + "/" + "confFaulty" + "/" + "solrconfig.xml", - -1, - true); + ZkConfigSetService.CONFIGS_ZKNODE + "/" + "confFaulty" + "/" + "solrconfig.xml", -1); 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 3e1ca33963c..bb5a5fc0524 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); // 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); 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", true)); + assertTrue(fixture.zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json")); 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 cc8bcd0e0bb..1ef1cb28a0c 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", true); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c3", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c3"); 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", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); // 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, true)); + ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null)); 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", true); - zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2", true); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1"); + zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c2"); 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, true); - zkClient.setData(DocCollection.getCollectionPath("c2"), data, true); + byte[] data = zkClient.getData(DocCollection.getCollectionPath("c2"), null, null); + zkClient.setData(DocCollection.getCollectionPath("c2"), data); // get the most up-to-date state reader.forceUpdateCollection("c2"); @@ -500,7 +500,7 @@ public void testSingleExternalCollectionCompressedState() throws Exception { writer.writePendingUpdates(); byte[] data = - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true); + zkClient.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 36ce1c08377..ab806d58829 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, true); + data = client.getData(resPath, null, stat); } catch (KeeperException.NoNodeException e) { data = "{}".getBytes(StandardCharsets.UTF_8); log.info("creating_node {}", resPath); - client.create(resPath, data, CreateMode.PERSISTENT, true); + client.create(resPath, data, CreateMode.PERSISTENT); } long startTime = System.nanoTime(); - Stat newStat = client.setData(resPath, data, true); - client.setData("/configs/conf1", new byte[] {1}, true); + Stat newStat = client.setData(resPath, data); + client.setData("/configs/conf1", new byte[] {1}); 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 109e27d64d9..ee4cf40ed34 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,9 +86,7 @@ public void testZkread() throws Exception { bytes[i] = (byte) random().nextInt(128); } try { - cluster - .getZkClient() - .create("/configs/_default/testdata", bytes, CreateMode.PERSISTENT, true); + cluster.getZkClient().create("/configs/_default/testdata", bytes, CreateMode.PERSISTENT); Utils.executeGET( client.getHttpClient(), basezk + "/configs/_default/testdata", @@ -101,7 +99,7 @@ public void testZkread() throws Exception { return null; }); } finally { - cluster.getZkClient().delete("/configs/_default/testdata", -1, true); + cluster.getZkClient().delete("/configs/_default/testdata", -1); } } } 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 57d5a6b47a8..42b25847d15 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, true)); + assertFalse(zkClient.exists("/configs/" + mutableId)); } @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, true)); + assertFalse(zkClient.exists("/configs/" + mutableId)); 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 979ecd9ef0b..bcb51f4217d 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,8 +180,7 @@ public void testEnableDisableOptions() throws Exception { assertTrue( cluster .getZkClient() - .exists( - SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"), true)); + .exists(SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); assertNotNull(schema.getFieldTypeByName("text_fr")); assertNotNull(schema.getFieldOrNull("*_txt_fr")); assertNull(schema.getFieldOrNull("*_txt_ga")); @@ -204,8 +203,7 @@ public void testEnableDisableOptions() throws Exception { assertTrue( cluster .getZkClient() - .exists( - SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"), true)); + .exists(SchemaDesignerAPI.getConfigSetZkPath(mutableId, "lang/stopwords_en.txt"))); 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 3e8fea806e5..7c92be25e5a 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(), true))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), 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(), true))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), 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(), true))), + cluster.getZkClient().getData(SOLR_PKGS_PATH, null, new Stat()))), 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 5c0f4f49d22..33c0f3e3952 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, true), StandardCharsets.UTF_8)); + return (new String(zkClient.getData(fileName, null, null), StandardCharsets.UTF_8)); } protected final void assertFileNotInZooKeeper( SolrZkClient zkClient, String parent, String fileName) throws Exception { - List kids = zkClient.getChildren(parent, null, true); + List kids = zkClient.getChildren(parent, null); for (String kid : kids) { if (kid.equalsIgnoreCase(fileName)) { String rawContent = - new String(zkClient.getData(fileName, null, null, true), StandardCharsets.UTF_8); + new String(zkClient.getData(fileName, null, null), 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 bd452178f63..8e84d5e5728 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, boolean retryOnConnLoss) + public byte[] getData(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException { byte[] data; try { - data = super.getData(path, watcher, stat, retryOnConnLoss); + data = super.getData(path, watcher, stat); } 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, true); + Boolean exists = client.exists(path); 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 3599a4e2ebe..12352970d2e 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), true); + zkClient().setData("/security.json", STD_CONF.replace("'", "\"").getBytes(UTF_8)); 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 8b6708fe825..b5d49a9c55f 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, false); + cluster.getZkClient().delete("/security.json", -1); 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 3fdda76715d..ee04fcf20ed 100644 --- a/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java +++ b/solr/core/src/test/org/apache/solr/security/TestAuthorizationFramework.java @@ -53,8 +53,7 @@ public void distribSetUp() throws Exception { new ZkStateReader(zkServer.getZkAddress(), TIMEOUT, TIMEOUT)) { zkStateReader .getZkClient() - .create( - ZkStateReader.SOLR_SECURITY_CONF_PATH, SECURITY_JSON, CreateMode.PERSISTENT, true); + .create(ZkStateReader.SOLR_SECURITY_CONF_PATH, SECURITY_JSON, CreateMode.PERSISTENT); } } 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 9a781215b8e..efba05bc1ca 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,8 +214,7 @@ public void test() throws Exception { + "/" + COLLECTION_PROPS_ZKNODE, null, - null, - true); + null); assertNotNull(data); assertTrue(data.length > 0); @SuppressWarnings("unchecked") @@ -1048,8 +1047,7 @@ public void process(WatchedEvent watchedEvent) { aliasUpdate.countDown(); } }, - stat, - true); + stat); } /** @@ -1272,7 +1270,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, true); + byte[] data = zkStateReader.getZkClient().getData("/aliases.json", null, null); // some tidbits for handling zk data here are swiped from Aliases.json Map aliasMap; @@ -1293,7 +1291,7 @@ private void manuallyConstructLegacyTRA() throws Exception { colAliases.put(alias, String.join(",", legacy24, legacy23)); data = Utils.toJSON(aliasMap); - zkStateReader.getZkClient().setData("/aliases.json", data, true); + zkStateReader.getZkClient().setData("/aliases.json", data); 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 318ad72e7e7..a1c211b05ad 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,8 +158,7 @@ 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, true); + zkClient.makePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT); } 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 25bd363d3ad..9a5dcff772d 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,8 +142,7 @@ 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, true); + zkClient.makePath(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, CreateMode.PERSISTENT); } 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 9cf22f51cfe..c06d8ecd420 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, true); + zkClient.makePath("/solr", false); } 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,17 +114,13 @@ protected void setupZNodes() throws Exception { new SolrZkClientWithACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT); } finally { zkClient.close(); } @@ -132,15 +128,9 @@ protected void setupZNodes() throws Exception { zkClient = new SolrZkClientNoACLs(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT); try { zkClient.create( - "/unprotectedCreateNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); } 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 0fd49a52314..60fc0e4e145 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", true)); - assertTrue(zkClient.exists("/security/token", true)); + assertTrue(zkClient.exists("/security/zkdtsm")); + assertTrue(zkClient.exists("/security/token")); } } 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 30f59222e63..1a99d543af5 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", true)); - assertTrue(zkClient.exists("/security/token", true)); + assertTrue(zkClient.exists("/security/zkdtsm")); + assertTrue(zkClient.exists("/security/token")); } } 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 9cb6c9ec25a..b1616c20b6f 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,8 +160,7 @@ public static void setupClass() throws Exception { + "confFaulty" + Path.SEPARATOR + "solrconfig.xml", - -1, - true); + -1); } @AfterClass diff --git a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java index c2613d8550c..1fea4d8319d 100644 --- a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java +++ b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java @@ -303,7 +303,7 @@ private MiniSolrCloudCluster configureClusterMockOauth( .withDefaultClusterProperty("useLegacyReplicaAssignment", "false") .build(); String securityJson = createMockOAuthSecurityJson(pemFilePath); - myCluster.zkSetData("/security.json", securityJson.getBytes(Charset.defaultCharset()), true); + myCluster.zkSetData("/security.json", securityJson.getBytes(Charset.defaultCharset())); RTimer timer = new RTimer(); do { // Wait timeoutMs time for the security.json change to take effect Thread.sleep(200); 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 075c1e4d3de..4e74981a661 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, true); + byte[] data = zkClient.getData(path, null, null); 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 0d9f99f0c6d..15d3ebc2651 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, true); + return zkClient.exists(path); } 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, true); + return zkClient.getChildren(path, watcher); } 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, true); + byte[] bytes = zkClient.getData(path, watcher, stat); 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, true); + zkClient.makePath(path); } 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, true); + zkClient.makePath(path, data, createMode, null, failOnExists); } 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, true); + return zkClient.create(path, data, mode); } 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, true); + zkClient.delete(path, version); } 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, true); + zkClient.setData(path, data, version); } 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 811a0b4e2e8..6baac9554d0 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, true); + .getData(DocCollection.getCollectionPathRoot(coll.getName()), null, null); 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 39051da857c..5848831fd76 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, true), fun); + recursiveRead("", zkStateReader.getZkClient().getChildren(basePath, null), fun); } catch (KeeperException | InterruptedException e) { throwZkExp(e); } @@ -84,8 +84,7 @@ public String name() { @Override public void get(Consumer consumer) throws SolrException { try { - byte[] data = - zkStateReader.getZkClient().getData(basePath + "/" + path, null, null, true); + byte[] data = zkStateReader.getZkClient().getData(basePath + "/" + path, null, null); if (data != null && data.length > 0) { consumer.read(new ByteArrayInputStream(data)); } else { @@ -109,7 +108,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, true); + zkStateReader.getZkClient().getChildren(basePath + "/" + relativePath, null); 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 84e5cf462e4..9373d8825ae 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(), true)); + Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, new Stat())); return convertCollectionDefaultsToNestedFormat(properties); } catch (KeeperException.NoNodeException e) { return Collections.emptyMap(); @@ -197,23 +197,21 @@ public void setClusterProperty(String propertyName, Object propertyValue) throws for (; ; ) { Stat s = new Stat(); try { - if (client.exists(ZkStateReader.CLUSTER_PROPS, true)) { + if (client.exists(ZkStateReader.CLUSTER_PROPS)) { @SuppressWarnings({"rawtypes"}) Map properties = - (Map) Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, s, true)); + (Map) Utils.fromJSON(client.getData(ZkStateReader.CLUSTER_PROPS, null, s)); 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(), true); + client.setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion()); } } 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(), true); + client.setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), s.getVersion()); } } } else { @@ -221,7 +219,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, true); + ZkStateReader.CLUSTER_PROPS, Utils.toJSON(properties), CreateMode.PERSISTENT); } } 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 e036ac76217..25b13086267 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,8 +67,7 @@ public Map getCollectionProperties(String collection) throws IOE try { return (Map) Utils.fromJSON( - client.getData( - ZkStateReader.getCollectionPropsPath(collection), null, new Stat(), true)); + client.getData(ZkStateReader.getCollectionPropsPath(collection), null, new Stat())); } catch (KeeperException.NoNodeException e) { return Collections.emptyMap(); } catch (KeeperException | InterruptedException e) { @@ -94,25 +93,25 @@ public void setCollectionProperty(String collection, String propertyName, String while (true) { Stat s = new Stat(); try { - if (client.exists(znodePath, true)) { + if (client.exists(znodePath)) { Map properties = - (Map) Utils.fromJSON(client.getData(znodePath, null, s, true)); + (Map) Utils.fromJSON(client.getData(znodePath, null, s)); if (propertyValue == null) { if (properties.remove(propertyName) != null) { // Don't update ZK unless absolutely necessary. - client.setData(znodePath, Utils.toJSON(properties), s.getVersion(), true); + client.setData(znodePath, Utils.toJSON(properties), s.getVersion()); } } else { if (!propertyValue.equals( properties.put( propertyName, propertyValue))) { // Don't update ZK unless absolutely necessary. - client.setData(znodePath, Utils.toJSON(properties), s.getVersion(), true); + client.setData(znodePath, Utils.toJSON(properties), s.getVersion()); } } } else { Map properties = new LinkedHashMap<>(); properties.put(propertyName, propertyValue); - client.create(znodePath, Utils.toJSON(properties), CreateMode.PERSISTENT, true); + client.create(znodePath, Utils.toJSON(properties), CreateMode.PERSISTENT); } } 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 85fcef00e83..2194defcdde 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, true); + Stat stat = zkClient.exists(current.path, null); 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, true); + List children = zkClient.getChildren(path, null, stat); 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, true)); + log.error("Multi-op exception: {}", zkClient.getChildren(znode, null)); 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 487fa6b427b..0a35bad37e5 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,12 +71,9 @@ 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, true); + zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); } else { - data = - zkStateReader - .getZkClient() - .getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, this, true); + data = zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); } try { callback.call(data); @@ -97,7 +94,7 @@ public void process(WatchedEvent event) { } void register() throws InterruptedException, KeeperException { - zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this, true); + zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, this); securityData = getSecurityProps(true); } @@ -108,9 +105,9 @@ ZkStateReader.ConfigData getSecurityProps(boolean getFresh) { return new ZkStateReader.ConfigData(securityData.data, securityData.version); } try { - if (zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH, true)) { + if (zkStateReader.getZkClient().exists(ZkStateReader.SOLR_SECURITY_CONF_PATH)) { SolrZkClient.NodeData d = - zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, null, true); + zkStateReader.getZkClient().getNode(ZkStateReader.SOLR_SECURITY_CONF_PATH, null); 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 64c8b523343..c87be19e421 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, boolean retryOnConnLoss) + public void delete(final String path, final int version) throws InterruptedException, KeeperException { runWithCorrectThrows( "deleting znode", () -> client.delete().withVersion(version).forPath(path)); @@ -338,9 +338,8 @@ public void delete(final String path, final int version, boolean retryOnConnLoss /** * 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, org.apache.zookeeper.Watcher, - * boolean)} or {@link #getData(String, org.apache.zookeeper.Watcher, - * org.apache.zookeeper.data.Stat, boolean)}. + * watcher using this method before calling {@link #exists(String, Watcher)} or {@link + * #getData(String, Watcher, Stat)}. */ public Watcher wrapWatcher(final Watcher watcher) { if (watcher == null || watcher instanceof ProcessWatchWithExecutor) return watcher; @@ -361,7 +360,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, boolean retryOnConnLoss) + public Stat exists(final String path, final Watcher watcher) throws KeeperException, InterruptedException { Stat result = runWithCorrectThrows( @@ -372,8 +371,7 @@ public Stat exists(final String path, final Watcher watcher, boolean retryOnConn } /** Returns true if path exists */ - public Boolean exists(final String path, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { + public Boolean exists(final String path) throws KeeperException, InterruptedException { Boolean result = runWithCorrectThrows("checking exists", () -> client.checkExists().forPath(path) != null); metrics.existsChecks.increment(); @@ -381,7 +379,7 @@ public Boolean exists(final String path, boolean retryOnConnLoss) } /** Returns children of the node at the path */ - public List getChildren(final String path, final Watcher watcher, boolean retryOnConnLoss) + public List getChildren(final String path, final Watcher watcher) throws KeeperException, InterruptedException { List result = runWithCorrectThrows( @@ -396,8 +394,7 @@ public List getChildren(final String path, final Watcher watcher, boolea } /** Returns children of the node at the path */ - public List getChildren( - final String path, final Watcher watcher, Stat stat, boolean retryOnConnLoss) + public List getChildren(final String path, final Watcher watcher, Stat stat) throws KeeperException, InterruptedException { List result = runWithCorrectThrows( @@ -417,8 +414,7 @@ public List getChildren( } /** Returns node's data */ - public byte[] getData( - final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) + public byte[] getData(final String path, final Watcher watcher, final Stat stat) throws KeeperException, InterruptedException { byte[] result = runWithCorrectThrows( @@ -448,15 +444,14 @@ public byte[] getData( return result; } - public NodeData getNode(final String path, Watcher watcher, boolean retryOnConnLoss) + public NodeData getNode(final String path, Watcher watcher) throws KeeperException, InterruptedException { Stat stat = new Stat(); - return new NodeData(stat, getData(path, watcher, stat, retryOnConnLoss)); + return new NodeData(stat, getData(path, watcher, stat)); } /** Returns node's state */ - public Stat setData( - final String path, final byte data[], final int version, boolean retryOnConnLoss) + public Stat setData(final String path, final byte data[], final int version) throws KeeperException, InterruptedException { Stat result = runWithCorrectThrows( @@ -480,14 +475,14 @@ public void atomicUpdate(String path, BiFunction editor) byte[] zkData = null; Stat s = new Stat(); try { - if (exists(path, true)) { - zkData = getData(path, null, s, true); + if (exists(path)) { + zkData = getData(path, null, s); modified = editor.apply(s, zkData); if (modified == null) { // no change , no need to persist return; } - setData(path, modified, s.getVersion(), true); + setData(path, modified, s.getVersion()); break; } else { modified = editor.apply(s, null); @@ -495,7 +490,7 @@ public void atomicUpdate(String path, BiFunction editor) // no change , no need to persist return; } - create(path, modified, CreateMode.PERSISTENT, true); + create(path, modified, CreateMode.PERSISTENT); break; } } catch (KeeperException.BadVersionException | KeeperException.NodeExistsException e) { @@ -505,8 +500,7 @@ public void atomicUpdate(String path, BiFunction editor) } /** Returns path of created node */ - public String create( - final String path, final byte[] data, final CreateMode createMode, boolean retryOnConnLoss) + public String create(final String path, final byte[] data, final CreateMode createMode) throws KeeperException, InterruptedException { String result = runWithCorrectThrows( @@ -524,36 +518,28 @@ public String create( *

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, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { - makePath(path, null, CreateMode.PERSISTENT, retryOnConnLoss); + public void makePath(String path) throws KeeperException, InterruptedException { + makePath(path, null, CreateMode.PERSISTENT); } - public void makePath(String path, boolean failOnExists, boolean retryOnConnLoss) + public void makePath(String path, boolean failOnExists) throws KeeperException, InterruptedException { - makePath(path, null, CreateMode.PERSISTENT, null, failOnExists, retryOnConnLoss, 0); + makePath(path, null, CreateMode.PERSISTENT, null, failOnExists, 0); } - public void makePath(String path, Path data, boolean failOnExists, boolean retryOnConnLoss) + public void makePath(String path, Path data, boolean failOnExists) throws IOException, KeeperException, InterruptedException { - makePath( - path, - Files.readAllBytes(data), - CreateMode.PERSISTENT, - null, - failOnExists, - retryOnConnLoss, - 0); + makePath(path, Files.readAllBytes(data), CreateMode.PERSISTENT, null, failOnExists, 0); } - public void makePath(String path, Path data, boolean retryOnConnLoss) + public void makePath(String path, Path data) throws IOException, KeeperException, InterruptedException { - makePath(path, Files.readAllBytes(data), retryOnConnLoss); + makePath(path, Files.readAllBytes(data)); } - public void makePath(String path, CreateMode createMode, boolean retryOnConnLoss) + public void makePath(String path, CreateMode createMode) throws KeeperException, InterruptedException { - makePath(path, null, createMode, retryOnConnLoss); + makePath(path, null, createMode); } /** @@ -561,9 +547,8 @@ public void makePath(String path, CreateMode createMode, boolean retryOnConnLoss * * @param data to set on the last zkNode */ - public void makePath(String path, byte[] data, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { - makePath(path, data, CreateMode.PERSISTENT, retryOnConnLoss); + public void makePath(String path, byte[] data) throws KeeperException, InterruptedException { + makePath(path, data, CreateMode.PERSISTENT); } /** @@ -574,9 +559,14 @@ public void makePath(String path, byte[] data, boolean retryOnConnLoss) * * @param data to set on the last zkNode */ - public void makePath(String path, byte[] data, CreateMode createMode, boolean retryOnConnLoss) + 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) throws KeeperException, InterruptedException { - makePath(path, data, createMode, null, retryOnConnLoss); + makePath(zkPath, null, createMode, watcher, true, 0); } /** @@ -587,10 +577,9 @@ public void makePath(String path, byte[] data, CreateMode createMode, boolean re * * @param data to set on the last zkNode */ - public void makePath( - String path, byte[] data, CreateMode createMode, Watcher watcher, boolean retryOnConnLoss) + public void makePath(String path, byte[] data, CreateMode createMode, Watcher watcher) throws KeeperException, InterruptedException { - makePath(path, data, createMode, watcher, true, retryOnConnLoss, 0); + makePath(path, data, createMode, watcher, true, 0); } /** @@ -602,14 +591,9 @@ public void makePath( * @param data to set on the last zkNode */ public void makePath( - String path, - byte[] data, - CreateMode createMode, - Watcher watcher, - boolean failOnExists, - boolean retryOnConnLoss) + String path, byte[] data, CreateMode createMode, Watcher watcher, boolean failOnExists) throws KeeperException, InterruptedException { - makePath(path, data, createMode, watcher, failOnExists, retryOnConnLoss, 0); + makePath(path, data, createMode, watcher, failOnExists, 0); } /** @@ -620,8 +604,6 @@ 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 */ @@ -631,7 +613,6 @@ public void makePath( CreateMode createMode, Watcher watcher, boolean failOnExists, - boolean retryOnConnLoss, int skipPathParts) throws KeeperException, InterruptedException { log.debug("makePath: {}", path); @@ -687,12 +668,6 @@ 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 * @@ -736,7 +711,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, true)) { + if (exists(path)) { return; } try { @@ -749,20 +724,19 @@ public void ensureExists( throw new KeeperException.NoNodeException(path); } String startingPath = path.substring(0, endingIndex); - if (!exists(startingPath, true)) { + if (!exists(startingPath)) { throw new KeeperException.NoNodeException(startingPath); } } - makePath(path, data, createMode, null, true, true, skipPathParts); + makePath(path, data, createMode, null, 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, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { - return setData(path, data, -1, retryOnConnLoss); + public Stat setData(String path, byte[] data) throws KeeperException, InterruptedException { + return setData(path, data, -1); } /** @@ -771,12 +745,12 @@ public Stat setData(String path, byte[] data, boolean retryOnConnLoss) * @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, boolean retryOnConnLoss) + public Stat setData(String path, Path data) throws IOException, KeeperException, InterruptedException { if (log.isDebugEnabled()) { log.debug("Write to ZooKeeper: {} to {}", data.toAbsolutePath(), path); } - return setData(path, Files.readAllBytes(data), retryOnConnLoss); + return setData(path, Files.readAllBytes(data)); } @FunctionalInterface @@ -822,8 +796,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, true); - List children = getChildren(path, null, true); + byte[] data = getData(path, null, null); + List children = getChildren(path, null); StringBuilder dent = new StringBuilder(); dent.append(" ".repeat(Math.max(0, indent))); string.append(dent).append(path).append(" (").append(children.size()).append(")").append(NEWL); @@ -985,8 +959,7 @@ public ACLProvider getZkACLProvider() { /** * @return the ACLs on a single node in ZooKeeper. */ - public List getACL(String path, Stat stat, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { + public List getACL(String path, Stat stat) 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 34d770c7a12..658281dd09c 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, true)) { + for (String node : zkClient.getChildren(root, null)) { 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, true).size() != 0) { + if (zkClient.getChildren(src, null).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, true).size() > 0) { + if (zkClient.getChildren(src, null).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, true); + byte[] data = zkClient.getData(src, null, null); 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, true).size() == 0) { - zkClient.makePath(destName, false, true); - zkClient.setData(destName, zkClient.getData(src, null, null, true), true); + if (zkClient.getChildren(src, null).size() == 0) { + zkClient.makePath(destName, false); + zkClient.setData(destName, zkClient.getData(src, null, null)); } 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, true)) { - if (zkClient.exists(dst + "/" + node, true) == false) { + for (String node : zkClient.getChildren(src, null)) { + if (zkClient.exists(dst + "/" + node) == 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, true); + zkClient.delete(znode, -1); } 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, true); + zkClient.delete(subpath, -1); } catch (KeeperException.NotEmptyException | KeeperException.NoNodeException e) { // expected } @@ -324,11 +324,9 @@ 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 { @@ -350,24 +348,11 @@ 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, true)) { - zkClient.setData(zkNode, file, true); - } else if (file == rootPath) { - // We are only uploading a single file, preVisitDirectory was never called - zkClient.makePath(zkNode, file, false, true); + if (file.toFile().getName().equals(ZKNODE_DATA_FILE) && zkClient.exists(zkNode)) { + zkClient.setData(zkNode, file); } 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); + // We are only uploading a single file, preVisitDirectory was never called + zkClient.makePath(zkNode, file, false); } } catch (KeeperException | InterruptedException e) { throw new IOException( @@ -386,11 +371,9 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) try { if (dir.equals(rootPath)) { // Make sure the root path exists, including potential parents - zkClient.makePath(zkNode, true); + zkClient.makePath(zkNode); } 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); + zkClient.makePath(zkNode, true); } } catch (KeeperException.NodeExistsException ignored) { // Using fail-on-exists == false has side effect of makePath attempting to setData on @@ -409,13 +392,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, true); + Stat znodeStat = zkClient.exists(zkPath, null); 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, true); + byte[] data = zkClient.getData(zkPath, null, null); if (data != null && data.length > 0) { // There are apparently basically empty ZNodes. log.info("Writing file {}", file); Files.write(file, data); @@ -427,7 +410,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, true); + List children = zkClient.getChildren(zkPath, null); // 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) { @@ -498,7 +481,7 @@ public static void traverseZkTree( } List children; try { - children = zkClient.getChildren(path, null, true); + children = zkClient.getChildren(path, null); } catch (KeeperException.NoNodeException r) { return; } @@ -639,11 +622,11 @@ public static void ensureExists( int skipPathParts) throws KeeperException, InterruptedException { - if (zkClient.exists(path, true)) { + if (zkClient.exists(path)) { return; } try { - zkClient.makePath(path, data, createMode, null, true, true, skipPathParts); + zkClient.makePath(path, data, createMode, null, true, skipPathParts); } catch (NodeExistsException ignored) { // it's okay if another beats us creating the node } @@ -669,8 +652,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, true); - zkClient.setData(finalDestination, zkClient.getData(path, null, null, true), true); + zkClient.makePath(finalDestination, false); + zkClient.setData(finalDestination, zkClient.getData(path, null, null)); } } } 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 604779839fb..f16360a34be 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, true); + children = zkClient.getChildren(COLLECTIONS_ZKNODE, watcher); } 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, true); + freshStats = zkClient.exists(DocCollection.getCollectionPath(collName), null); } 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, true); + List nodeList = zkClient.getChildren(LIVE_NODES_ZKNODE, watcher); newLiveNodes = new TreeSet<>(nodeList); } catch (KeeperException.NoNodeException e) { newLiveNodes = emptySortedSet(); @@ -1144,8 +1144,7 @@ private void loadClusterProperties() { while (true) { try { byte[] data = - zkClient.getData( - ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat(), true); + zkClient.getData(ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher, new Stat()); @SuppressWarnings("unchecked") Map properties = (Map) Utils.fromJSON(data); this.clusterProperties = @@ -1161,7 +1160,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, true) == null) + if (zkClient.exists(ZkStateReader.CLUSTER_PROPS, clusterPropertiesWatcher) == null) return; } } @@ -1274,7 +1273,7 @@ private VersionedCollectionProps fetchCollectionProperties(String collection, Wa while (true) { try { Stat stat = new Stat(); - byte[] data = zkClient.getData(znodePath, watcher, stat, true); + byte[] data = zkClient.getData(znodePath, watcher, stat); @SuppressWarnings("unchecked") Map props = (Map) Utils.fromJSON(data); return new VersionedCollectionProps(stat.getVersion(), props); @@ -1286,7 +1285,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, true); + Stat exists = zkClient.exists(znodePath, watcher); 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. @@ -1393,7 +1392,7 @@ private void refreshAndWatchChildren() throws KeeperException, InterruptedExcept Stat stat = new Stat(); List replicaStates = null; try { - replicaStates = zkClient.getChildren(collectionPath, this, stat, true); + replicaStates = zkClient.getChildren(collectionPath, this, stat); PerReplicaStates newStates = new PerReplicaStates(collectionPath, stat.getCversion(), replicaStates); DocCollection oldState = collectionWatches.getDocCollection(coll); @@ -1608,7 +1607,7 @@ private DocCollection fetchCollectionState(String coll, Watcher watcher) while (true) { try { Stat stat = new Stat(); - byte[] data = zkClient.getData(collectionPath, watcher, stat, true); + byte[] data = zkClient.getData(collectionPath, watcher, stat); // This factory method can detect a missing configName and supply it by reading it from the // old ZK location. @@ -1622,7 +1621,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, true); + Stat exists = zkClient.exists(collectionPath, watcher); 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. @@ -1635,7 +1634,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, true); + Stat exists = zkClient.exists(collectionPath, watcher); 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.", @@ -2142,7 +2141,7 @@ public AliasesManager getAliasesManager() { private void refreshAliases(AliasesManager watcher) throws KeeperException, InterruptedException { synchronized (getUpdateLock()) { constructState(Collections.emptySet()); - zkClient.exists(ALIASES, watcher, true); + zkClient.exists(ALIASES, watcher); } aliasesManager.update(); } @@ -2201,7 +2200,7 @@ public void applyModificationAndExportToZk(UnaryOperator op) { try { try { final Stat stat = - getZkClient().setData(ALIASES, modAliasesJson, curAliases.getZNodeVersion(), true); + getZkClient().setData(ALIASES, modAliasesJson, curAliases.getZNodeVersion()); setIfNewer(new SolrZkClient.NodeData(stat, modAliasesJson)); return; } catch (KeeperException.BadVersionException e) { @@ -2245,7 +2244,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, true)); + return setIfNewer(zkClient.getNode(ALIASES, null)); } // ZK Watcher interface @@ -2259,7 +2258,7 @@ public void process(WatchedEvent event) { log.debug("Aliases: updating"); // re-register the watch - setIfNewer(zkClient.getNode(ALIASES, this, true)); + setIfNewer(zkClient.getNode(ALIASES, this)); } 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 38f13860389..cb8723c6e68 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, true); + client.makePath("/solr", false); } defaultClient = @@ -94,7 +94,7 @@ public void setUp() throws Exception { .withUrl(zkServer.getZkAddress()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); - defaultClient.makePath(PATH, true); + defaultClient.makePath(PATH); aclClient = new SolrZkClient( @@ -216,12 +216,10 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null, true); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null, true); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped2A, null); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bam") .process(solrClient); @@ -235,12 +233,10 @@ public void process(WatchedEvent event) { ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null, true); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrapped1A, null); ZkStateReader.from(solrClient) .getZkClient() - .getData( - "/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null, true); + .getData("/collections/" + getSaferTestName() + "/collectionprops.json", wrappedB, null); CollectionAdminRequest.setCollectionProperty(getSaferTestName(), "baz", "bang") .process(solrClient); @@ -257,7 +253,7 @@ public void process(WatchedEvent event) { private static boolean canRead(SolrZkClient zkClient, String path) throws KeeperException, InterruptedException { try { - zkClient.getData(path, null, null, true); + zkClient.getData(path, null, null); 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 ab650bdc608..52ee6ff7d7e 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, true); + cluster.getZkClient().create(root, null, CreateMode.PERSISTENT); 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, true); + cluster.getZkClient().create(root + "/" + state, null, CreateMode.PERSISTENT); } 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, true).size()); + assertEquals(6, cluster.getZkClient().getChildren(root, null).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 9f726035691..50df39f1156 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, true); + zkClient.makePath("/solr", false); 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 89677753f76..bbdd7de8cf3 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,18 +81,17 @@ 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, true); - zkClient.create(path, null, CreateMode.PERSISTENT, true); + zkClient.create("/myPath", null, CreateMode.PERSISTENT); + zkClient.create(path, null, CreateMode.PERSISTENT); zkClient.create( - path + "/file1.txt", data1.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); - zkClient.create(path + "/nothing.txt", null, CreateMode.PERSISTENT, true); + path + "/file1.txt", data1.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); + zkClient.create(path + "/nothing.txt", null, CreateMode.PERSISTENT); zkClient.create( - path + "/file2.txt", data2.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); + path + "/file2.txt", data2.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); zkClient.create( path + "/some_longer_file2.txt", longData.getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT); /* RUN */ // delete all nodes that contain "file" @@ -138,9 +137,9 @@ public void testTraverseZkTree() throws Exception { .withUrl(zkServer.getZkHost()) .withTimeout(10000, TimeUnit.MILLISECONDS) .build()) { - zkClient.makePath("/testTraverseZkTree/1/1", true, true); - zkClient.makePath("/testTraverseZkTree/1/2", false, true); - zkClient.makePath("/testTraverseZkTree/2", false, true); + zkClient.makePath("/testTraverseZkTree/1/1", true); + zkClient.makePath("/testTraverseZkTree/1/2", false); + zkClient.makePath("/testTraverseZkTree/2", false); assertEquals( Arrays.asList( "/testTraverseZkTree", @@ -172,7 +171,7 @@ public void testOneByteFile() throws Exception { .build()) { byte[] oneByte = new byte[1]; oneByte[0] = 0x30; - zkClient.makePath("/test1byte/one", oneByte, true); + zkClient.makePath("/test1byte/one", oneByte); 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 db385e26b83..79398676f3d 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,9 +66,7 @@ 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, true); + cluster.getZkClient().getData(DocCollection.getCollectionPath(collectionId), null, null); 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 d678106f873..36ded773992 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", true)); + cluster.getZkClient().exists(ZkStateReader.CONFIGS_ZKNODE + "/" + "testconfig")); } 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 e75100f1a50..aa9b5427c99 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(NONPRS_COLL), null); 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // +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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // 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, true); + stat = cluster.getZkClient().exists(DocCollection.getCollectionPath(PRS_COLL), null); // 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 dbdbbc39449..71f95b23c4b 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, true); + zkClient.create(path, compressedData, CreateMode.PERSISTENT); byte[] data = - zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true); + zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null); 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 ee3141e412d..d7590f6c257 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("/", false); + cc.getZkController().getZkClient().exists("/"); } 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 899efc03dcb..9fc1417cdc4 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, true) + .getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null) .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 c2597a02692..02935f94b96 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, true); + zkClient.makePath("/solr", false); zkClient.close(); zkClient = @@ -111,15 +111,14 @@ public void setUp() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build(); zkClient.create( - "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.create( SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + CreateMode.PERSISTENT); zkClient.close(); clearSecuritySystemProperties(); @@ -138,12 +137,9 @@ public void setUp() throws Exception { .addAuthInfo( "digest", (ALL_USERNAME + ":" + ALL_PASSWORD).getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false); + "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.makePath( - "/unprotectedMakePathNode", - "content".getBytes(DATA_ENCODING), - CreateMode.PERSISTENT, - false); + "/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT); zkClient.close(); setDigestZkSystemProps(); @@ -312,8 +308,8 @@ public void testRepairACL() throws Exception { .getBytes(StandardCharsets.UTF_8)); zkClient.create( - "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, false); - assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); + "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT); + assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); } setSecuritySystemProperties(); @@ -323,7 +319,7 @@ public void testRepairACL() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { ZkController.createClusterZkNodes(zkClient); - assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false)); + assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null)); } useZkCredentialsInjector(ConnectWithReadonlyCredsInjector.class); @@ -334,8 +330,7 @@ public void testRepairACL() throws Exception { .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { NoAuthException e = - assertThrows( - NoAuthException.class, () -> zkClient.getData("/security.json", null, null, false)); + assertThrows(NoAuthException.class, () -> zkClient.getData("/security.json", null, null)); assertEquals("/solr/security.json", e.getPath()); } } @@ -401,27 +396,27 @@ protected static void doTest( boolean setData, boolean delete) throws Exception { - doTest(getData, () -> zkClient.getData(path, null, null, false)); - doTest(list, () -> zkClient.getChildren(path, null, false)); + doTest(getData, () -> zkClient.getData(path, null, null)); + doTest(list, () -> zkClient.getChildren(path, null)); doTest( create, () -> { - zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT, false); - zkClient.delete(path + "/subnode", -1, false); + zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT); + zkClient.delete(path + "/subnode", -1); }); doTest( create, () -> { zkClient.makePath(path + "/subnode/subsubnode", false); - zkClient.delete(path + "/subnode/subsubnode", -1, false); - zkClient.delete(path + "/subnode", -1, false); + zkClient.delete(path + "/subnode/subsubnode", -1); + zkClient.delete(path + "/subnode", -1); }); - doTest(setData, () -> zkClient.setData(path, (byte[]) null, false)); + doTest(setData, () -> zkClient.setData(path, (byte[]) null)); // Actually about the ACLs on /solr, but that is protected - doTest(delete, () -> zkClient.delete(path, -1, false)); + doTest(delete, () -> zkClient.delete(path, -1)); } 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 435a2a931ba..e8b104f9fcf 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,6 +395,7 @@ 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 e2f2074873d..c0f4ce77a69 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,18 +262,14 @@ public void distribSetUp() throws Exception { .create( ZkStateReader.CLUSTER_PROPS, Utils.toJSON(Collections.singletonMap(URL_SCHEME, HTTPS)), - CreateMode.PERSISTENT, - true); + CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException e) { ZkNodeProps props = ZkNodeProps.load( - zkStateReader - .getZkClient() - .getData(ZkStateReader.CLUSTER_PROPS, null, null, true)); + zkStateReader.getZkClient().getData(ZkStateReader.CLUSTER_PROPS, null, null)); zkStateReader .getZkClient() - .setData( - ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS)), true); + .setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS))); } } } 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 03b8877e8c0..84ed008a2a1 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,17 +301,16 @@ public MiniSolrCloudCluster( .withUrl(zkServer.getZkHost()) .withTimeout(AbstractZkTestCase.TIMEOUT, TimeUnit.MILLISECONDS) .build()) { - if (!zkClient.exists("/solr/solr.xml", true)) { - zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset()), true); + if (!zkClient.exists("/solr/solr.xml")) { + zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset())); if (jettyConfig.sslConfig != null && jettyConfig.sslConfig.isSSLMode()) { zkClient.makePath( "/solr" + ZkStateReader.CLUSTER_PROPS, - "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8), - true); + "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8)); } if (securityJson.isPresent()) { // configure Solr security zkClient.makePath( - "/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset()), true); + "/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset())); } } } @@ -646,9 +645,7 @@ public void deleteAllConfigSets() throws Exception { // cleanup any property before removing the configset getZkClient() .delete( - ZkConfigSetService.CONFIGS_ZKNODE + "/" + configSet + "/" + DEFAULT_FILENAME, - -1, - true); + ZkConfigSetService.CONFIGS_ZKNODE + "/" + configSet + "/" + DEFAULT_FILENAME, -1); } catch (KeeperException.NoNodeException nne) { } new ConfigSetAdminRequest.Delete().setConfigSetName(configSet).process(solrClient); @@ -737,10 +734,10 @@ public SolrZkClient getZkClient() { * Set data in zk without exposing caller to the ZK API, i.e. tests won't need to include * Zookeeper dependencies */ - public void zkSetData(String path, byte[] data, boolean retryOnConnLoss) + public void zkSetData(String path, byte[] data) throws InterruptedException { try { - getZkClient().setData(path, data, -1, retryOnConnLoss); + getZkClient().setData(path, data, -1); } 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 c1c73fb853a..e9bd640d101 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,15 +29,13 @@ public MockSolrZkClient() { } @Override - public Boolean exists(final String path, boolean retryOnConnLoss) - throws KeeperException, InterruptedException { + public Boolean exists(final String path) throws KeeperException, InterruptedException { return false; } @Override - public byte[] getData( - final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss) + public byte[] getData(final String path, final Watcher watcher, final Stat stat) 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 0043b75a236..2cfd01b67a0 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, true, 0); + client.makePath(path, null, CreateMode.PERSISTENT, null, false); } 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, true); + zkClient.makePath(destPath, file, false); } // 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, true); + rootClient.makePath("/solr", false); } public void tryCleanSolrZkNode() throws Exception { @@ -840,7 +840,7 @@ public void tryCleanSolrZkNode() throws Exception { } void tryCleanPath(String path) throws Exception { - if (rootClient.exists(path, true)) { + if (rootClient.exists(path)) { 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 a414eb5fdbe..ed51f2ce357 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,9 +115,7 @@ public void testCreationAndDeletion() throws Exception { CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName)); assertFalse( - cluster - .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true)); + cluster.getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); } @Test @@ -125,7 +123,7 @@ public void deleteCollectionRemovesStaleZkCollectionsNode() throws Exception { String collectionName = "out_of_sync_collection"; // manually create a collections zknode - cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true); + cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName); CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient()); @@ -133,9 +131,7 @@ public void deleteCollectionRemovesStaleZkCollectionsNode() throws Exception { CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName)); assertFalse( - cluster - .getZkClient() - .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true)); + cluster.getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName)); } @Test @@ -173,7 +169,7 @@ public void deleteCollectionOnlyInZk() throws Exception { final String collectionName = "onlyinzk"; // create the collections node, but nothing else - cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true); + cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName); // delete via API - should remove collections node CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());