From 21be96d8134f40a10500af2cf082a14c2574bd50 Mon Sep 17 00:00:00 2001 From: noblepaul Date: Fri, 22 Jan 2021 13:54:16 +1100 Subject: [PATCH 1/3] SOLR-15094: Replace all code references of coreNodeName to replicaName --- gradle/maven/defaults-maven.gradle | 1 + settings.gradle | 1 + solr/CHANGES.txt | 3 + .../apache/solr/cloud/CloudDescriptor.java | 22 +- .../java/org/apache/solr/cloud/CloudUtil.java | 6 +- .../apache/solr/cloud/ElectionContext.java | 4 +- .../solr/cloud/RecoveringCoreTermWatcher.java | 10 +- .../apache/solr/cloud/RecoveryStrategy.java | 8 +- .../cloud/ShardLeaderElectionContext.java | 30 +- .../cloud/ShardLeaderElectionContextBase.java | 4 +- .../org/apache/solr/cloud/SyncStrategy.java | 4 +- .../apache/solr/cloud/ZkCollectionTerms.java | 4 +- .../org/apache/solr/cloud/ZkController.java | 134 ++--- .../org/apache/solr/cloud/ZkShardTerms.java | 62 +- .../cloud/api/collections/AddReplicaCmd.java | 27 +- .../solr/cloud/api/collections/Assign.java | 12 +- .../collections/LeaderRecoveryWatcher.java | 2 +- .../cloud/api/collections/MigrateCmd.java | 8 +- .../OverseerCollectionMessageHandler.java | 4 +- .../cloud/api/collections/RestoreCmd.java | 6 +- .../cloud/api/collections/SplitShardCmd.java | 4 +- .../cloud/overseer/ClusterStateMutator.java | 2 +- .../solr/cloud/overseer/ReplicaMutator.java | 32 +- .../solr/cloud/overseer/SliceMutator.java | 12 +- .../org/apache/solr/core/CloudConfig.java | 2 +- .../org/apache/solr/core/CoreContainer.java | 8 +- .../org/apache/solr/core/CoreDescriptor.java | 8 +- .../solr/core/HdfsDirectoryFactory.java | 2 +- .../org/apache/solr/handler/IndexFetcher.java | 2 +- .../solr/handler/admin/CoreAdminHandler.java | 8 +- .../handler/admin/CoreAdminOperation.java | 2 +- .../solr/handler/admin/PrepRecoveryOp.java | 17 +- .../component/RealTimeGetComponent.java | 2 +- .../solr/logging/MDCLoggingContext.java | 2 +- .../solr/metrics/SolrCoreMetricManager.java | 4 +- .../reporters/solr/SolrShardReporter.java | 4 +- .../solr/schema/ManagedIndexSchema.java | 10 +- .../org/apache/solr/schema/SchemaManager.java | 2 +- .../DistributedZkUpdateProcessor.java | 74 +-- .../DocExpirationUpdateProcessorFactory.java | 4 +- .../processor/ScriptEngineCustomizer.java | 28 - ...StatelessScriptUpdateProcessorFactory.java | 529 ------------------ .../org/apache/solr/util/SolrLogLayout.java | 2 +- .../conf/addfields.updateprocessor.js | 26 - ...bad-solrconfig-bogus-scriptengine-name.xml | 34 -- .../bad-solrconfig-invalid-scriptfile.xml | 35 -- .../bad-solrconfig-missing-scriptfile.xml | 33 -- .../conf/conditional.updateprocessor.js | 25 - .../solr/collection1/conf/cross-compatible.js | 53 -- .../test-files/solr/collection1/conf/evil.js | 21 - .../conf/missing.functions.updateprocessor.js | 3 - ...ssleading.extension.updateprocessor.js.txt | 23 - .../solrconfig-script-updateprocessor.xml | 126 ----- .../throw.error.on.add.updateprocessor.js | 21 - .../conf/trivial.updateprocessor0.js | 59 -- .../conf/trivial.updateprocessor1.js | 25 - ...ssleading.extension.updateprocessor.js.txt | 23 - .../with-script-processor/solrconfig.xml | 10 +- .../AssignBackwardCompatibilityTest.java | 8 +- .../solr/cloud/BasicDistributedZkTest.java | 2 +- .../solr/cloud/DeleteInactiveReplicaTest.java | 4 +- .../apache/solr/cloud/DeleteReplicaTest.java | 2 +- ...stribDocExpirationUpdateProcessorTest.java | 2 +- .../apache/solr/cloud/HttpPartitionTest.java | 6 +- .../cloud/LeaderElectionContextKeyTest.java | 2 +- .../apache/solr/cloud/LeaderElectionTest.java | 4 +- .../LeaderFailureAfterFreshStartTest.java | 6 +- .../org/apache/solr/cloud/OverseerTest.java | 20 +- .../solr/cloud/PeerSyncReplicationTest.java | 2 +- .../solr/cloud/TestCloudSearcherWarming.java | 48 +- .../apache/solr/cloud/TestTlogReplica.java | 4 +- .../apache/solr/cloud/ZkControllerTest.java | 8 +- .../org/apache/solr/core/CoreSorterTest.java | 3 +- .../org/apache/solr/core/TestBadConfig.java | 30 +- .../handler/admin/HealthCheckHandlerTest.java | 2 +- .../reporters/solr/SolrShardReporterTest.java | 2 +- .../update/processor/ScriptEngineTest.java | 110 ---- ...elessScriptUpdateProcessorFactoryTest.java | 272 --------- solr/packaging/build.gradle | 1 + .../conf/solrconfig.xml | 37 +- .../conf/update-script.js | 4 +- solr/solr-ref-guide/src/configsets-api.adoc | 2 +- .../src/configuring-solrconfig-xml.adoc | 1 + .../src/major-changes-in-solr-9.adoc | 3 + .../src/update-request-processors.adoc | 2 +- .../solr/client/solrj/cloud/ShardTerms.java | 112 ++-- .../solrj/request/CoreAdminRequest.java | 28 +- .../solr/common/cloud/ClusterStateUtil.java | 12 +- .../solr/common/cloud/DocCollection.java | 6 +- .../org/apache/solr/common/cloud/Replica.java | 2 +- .../org/apache/solr/common/cloud/Slice.java | 2 +- .../solr/common/cloud/ZkStateReader.java | 20 +- .../solr/common/params/CommonParams.java | 2 + .../solr/common/params/CoreAdminParams.java | 3 +- .../solrj/impl/CloudHttp2SolrClientTest.java | 2 +- .../solrj/impl/CloudSolrClientTest.java | 2 +- .../solr/BaseDistributedSearchTestCase.java | 7 +- .../solr/cloud/AbstractDistribZkTestBase.java | 8 +- .../cloud/AbstractFullDistribZkTestBase.java | 4 +- .../org/apache/solr/cloud/ChaosMonkey.java | 12 +- .../processor/UpdateProcessorTestBase.java | 4 +- 101 files changed, 510 insertions(+), 1932 deletions(-) delete mode 100644 solr/core/src/java/org/apache/solr/update/processor/ScriptEngineCustomizer.java delete mode 100644 solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java delete mode 100644 solr/core/src/test-files/solr/collection1/conf/addfields.updateprocessor.js delete mode 100644 solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-bogus-scriptengine-name.xml delete mode 100644 solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-invalid-scriptfile.xml delete mode 100644 solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-missing-scriptfile.xml delete mode 100644 solr/core/src/test-files/solr/collection1/conf/conditional.updateprocessor.js delete mode 100644 solr/core/src/test-files/solr/collection1/conf/cross-compatible.js delete mode 100644 solr/core/src/test-files/solr/collection1/conf/evil.js delete mode 100644 solr/core/src/test-files/solr/collection1/conf/missing.functions.updateprocessor.js delete mode 100644 solr/core/src/test-files/solr/collection1/conf/missleading.extension.updateprocessor.js.txt delete mode 100644 solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml delete mode 100644 solr/core/src/test-files/solr/collection1/conf/throw.error.on.add.updateprocessor.js delete mode 100644 solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js delete mode 100644 solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor1.js delete mode 100644 solr/core/src/test-files/solr/configsets/upload/with-script-processor/missleading.extension.updateprocessor.js.txt delete mode 100644 solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java delete mode 100644 solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java diff --git a/gradle/maven/defaults-maven.gradle b/gradle/maven/defaults-maven.gradle index 2662a69a25d3..443d6904f0a4 100644 --- a/gradle/maven/defaults-maven.gradle +++ b/gradle/maven/defaults-maven.gradle @@ -66,6 +66,7 @@ configure(rootProject) { ":solr:contrib:langid", ":solr:contrib:jaegertracer-configurator", ":solr:contrib:prometheus-exporter", + ":solr:contrib:scripting", ":solr:test-framework", ] diff --git a/settings.gradle b/settings.gradle index be2c09cc2354..494c7102de25 100644 --- a/settings.gradle +++ b/settings.gradle @@ -65,6 +65,7 @@ include "solr:contrib:extraction" include "solr:contrib:langid" include "solr:contrib:jaegertracer-configurator" include "solr:contrib:prometheus-exporter" +include "solr:contrib:scripting" include "solr:contrib:ltr" include "solr:webapp" include "solr:test-framework" diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 4ce0332d68e9..7a17a75f75fa 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -188,6 +188,9 @@ Other Changes * SOLR-14297: Replace commons-codec Base64 with JDK8 Base64 (Andras Salamon via Houston Putman) +* SOLR-14067: StatelessScriptUpdateProcessorFactory moved to it's own /contrib/scripting/ package instead + of shipping as part of Solr due to security concerns. Renamed to ScriptUpdateProcessorFactory for simpler name. (Eric Pugh) + Bug Fixes --------------------- * SOLR-14546: Fix for a relatively hard to hit issue in OverseerTaskProcessor that could lead to out of order execution diff --git a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java index b00ca523dd15..ffd004d7a6ee 100644 --- a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java +++ b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java @@ -26,6 +26,8 @@ import org.apache.solr.common.util.PropertiesUtil; import org.apache.solr.core.CoreDescriptor; +import static org.apache.solr.common.params.CommonParams.REPLICA_NAME; + /** * SolrCloud metadata attached to a {@link CoreDescriptor}. */ @@ -64,7 +66,7 @@ public CloudDescriptor(CoreDescriptor cd, String coreName, Properties props) { // If no collection name is specified, we default to the core name this.collectionName = props.getProperty(CoreDescriptor.CORE_COLLECTION, coreName); this.roles = props.getProperty(CoreDescriptor.CORE_ROLES, null); - this.nodeName = props.getProperty(CoreDescriptor.CORE_NODE_NAME); + this.nodeName = props.getProperty(REPLICA_NAME); if (Strings.isNullOrEmpty(nodeName)) this.nodeName = null; this.numShards = PropertiesUtil.toInteger(props.getProperty(CloudDescriptor.NUM_SHARDS), null); @@ -146,15 +148,27 @@ public Integer getNumShards() { public void setNumShards(int numShards) { this.numShards = numShards; } - + + @Deprecated public String getCoreNodeName() { return nodeName; } + public String getReplicaName() { + return nodeName; + } + + public void setReplicaName(String nodeName) { + this.nodeName = nodeName; + if(nodeName==null) cd.getPersistableStandardProperties().remove(REPLICA_NAME); + else cd.getPersistableStandardProperties().setProperty(REPLICA_NAME, nodeName); + } + + @Deprecated public void setCoreNodeName(String nodeName) { this.nodeName = nodeName; - if(nodeName==null) cd.getPersistableStandardProperties().remove(CoreDescriptor.CORE_NODE_NAME); - else cd.getPersistableStandardProperties().setProperty(CoreDescriptor.CORE_NODE_NAME, nodeName); + if(nodeName==null) cd.getPersistableStandardProperties().remove(REPLICA_NAME); + else cd.getPersistableStandardProperties().setProperty(REPLICA_NAME, nodeName); } public void reload(CloudDescriptor reloadFrom) { 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 3dffb724a4fd..2d6b79826b4a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java +++ b/solr/core/src/java/org/apache/solr/cloud/CloudUtil.java @@ -56,7 +56,7 @@ public class CloudUtil { public static final int DEFAULT_TIMEOUT = 90; /** - * See if coreNodeName has been taken over by another baseUrl and unload core + * See if replicaName has been taken over by another baseUrl and unload core * + throw exception if it has been. */ public static void checkSharedFSFailoverReplaced(CoreContainer cc, CoreDescriptor desc) { @@ -103,12 +103,12 @@ public static void checkSharedFSFailoverReplaced(CoreContainer cc, CoreDescripto } } - public static boolean replicaExists(ClusterState clusterState, String collection, String shard, String coreNodeName) { + public static boolean replicaExists(ClusterState clusterState, String collection, String shard, String replicaName) { DocCollection docCollection = clusterState.getCollectionOrNull(collection); if (docCollection != null) { Slice slice = docCollection.getSlice(shard); if (slice != null) { - return slice.getReplica(coreNodeName) != null; + return slice.getReplica(replicaName) != null; } } return false; 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 13985709a7bf..72e20b3a0790 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java @@ -35,10 +35,10 @@ public abstract class ElectionContext implements Closeable { volatile String leaderSeqPath; private SolrZkClient zkClient; - public ElectionContext(final String coreNodeName, + public ElectionContext(final String relicaName, final String electionPath, final String leaderPath, final ZkNodeProps leaderProps, final SolrZkClient zkClient) { assert zkClient != null; - this.id = coreNodeName; + this.id = relicaName; this.electionPath = electionPath; this.leaderPath = leaderPath; this.leaderProps = leaderProps; diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveringCoreTermWatcher.java b/solr/core/src/java/org/apache/solr/cloud/RecoveringCoreTermWatcher.java index 1fa31ad28ec7..4ca95c8a21fa 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RecoveringCoreTermWatcher.java +++ b/solr/core/src/java/org/apache/solr/cloud/RecoveringCoreTermWatcher.java @@ -54,11 +54,11 @@ public boolean onTermChanged(ShardTerms terms) { } if (solrCore.getCoreDescriptor() == null || solrCore.getCoreDescriptor().getCloudDescriptor() == null) return true; - String coreNodeName = solrCore.getCoreDescriptor().getCloudDescriptor().getCoreNodeName(); - if (terms.haveHighestTermValue(coreNodeName)) return true; - if (lastTermDoRecovery.get() < terms.getTerm(coreNodeName)) { - log.info("Start recovery on {} because core's term is less than leader's term", coreNodeName); - lastTermDoRecovery.set(terms.getTerm(coreNodeName)); + String replicaName = solrCore.getCoreDescriptor().getCloudDescriptor().getReplicaName(); + if (terms.haveHighestTermValue(replicaName)) return true; + if (lastTermDoRecovery.get() < terms.getTerm(replicaName)) { + log.info("Start recovery on {} because core's term is less than leader's term", replicaName); + lastTermDoRecovery.set(terms.getTerm(replicaName)); solrCore.getUpdateHandler().getSolrCoreState().doRecovery(solrCore.getCoreContainer(), solrCore.getCoreDescriptor()); } } catch (Exception e) { diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java index eaeba2d099b5..4cc8b3f9aa21 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java @@ -119,7 +119,7 @@ public static interface RecoveryListener { private RecoveryListener recoveryListener; private ZkController zkController; private String baseUrl; - private String coreZkNodeName; + private String replicaName; private ZkStateReader zkStateReader; private volatile String coreName; private int retries; @@ -137,7 +137,7 @@ protected RecoveryStrategy(CoreContainer cc, CoreDescriptor cd, RecoveryListener zkController = cc.getZkController(); zkStateReader = zkController.getZkStateReader(); baseUrl = zkController.getBaseUrl(); - coreZkNodeName = cd.getCloudDescriptor().getCoreNodeName(); + replicaName = cd.getCloudDescriptor().getCoreNodeName(); replicaType = cd.getCloudDescriptor().getReplicaType(); } @@ -193,7 +193,7 @@ final public void close() { if (prevSendPreRecoveryHttpUriRequest != null) { prevSendPreRecoveryHttpUriRequest.abort(); } - log.warn("Stopping recovery for core=[{}] coreNodeName=[{}]", coreName, coreZkNodeName); + log.warn("Stopping recovery for core=[{}] replicaName=[{}]", coreName, replicaName); } final private void recoveryFailed(final ZkController zkController, @@ -847,7 +847,7 @@ final private void sendPrepRecoveryCmd(String leaderBaseUrl, String leaderCoreNa WaitForState prepCmd = new WaitForState(); prepCmd.setCoreName(leaderCoreName); prepCmd.setNodeName(zkController.getNodeName()); - prepCmd.setCoreNodeName(coreZkNodeName); + prepCmd.setCoreNodeName(replicaName); prepCmd.setState(Replica.State.RECOVERING); prepCmd.setCheckLive(true); prepCmd.setOnlyIfLeader(true); 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 68b062ed876e..8fd74e2def21 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java @@ -56,8 +56,8 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase { public ShardLeaderElectionContext(LeaderElector leaderElector, final String shardId, final String collection, - final String coreNodeName, ZkNodeProps props, ZkController zkController, CoreContainer cc) { - super(leaderElector, shardId, collection, coreNodeName, props, + final String replicaName, ZkNodeProps props, ZkController zkController, CoreContainer cc) { + super(leaderElector, shardId, collection, replicaName, props, zkController); this.cc = cc; syncStrategy = new SyncStrategy(cc); @@ -133,7 +133,7 @@ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws Kee } Replica.Type replicaType; - String coreNodeName; + String replicaName; boolean setTermToMax = false; try (SolrCore core = cc.getCore(coreName)) { @@ -142,11 +142,11 @@ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws Kee } replicaType = core.getCoreDescriptor().getCloudDescriptor().getReplicaType(); - coreNodeName = core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName(); + replicaName = core.getCoreDescriptor().getCloudDescriptor().getReplicaName(); // should I be leader? ZkShardTerms zkShardTerms = zkController.getShardTerms(collection, shardId); - if (zkShardTerms.registered(coreNodeName) && !zkShardTerms.canBecomeLeader(coreNodeName)) { - if (!waitForEligibleBecomeLeaderAfterTimeout(zkShardTerms, coreNodeName, leaderVoteWait)) { + if (zkShardTerms.registered(replicaName) && !zkShardTerms.canBecomeLeader(replicaName)) { + if (!waitForEligibleBecomeLeaderAfterTimeout(zkShardTerms, replicaName, leaderVoteWait)) { rejoinLeaderElection(core); return; } else { @@ -255,8 +255,8 @@ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws Kee // in case of leaderVoteWait timeout, a replica with lower term can win the election if (setTermToMax) { log.error("WARNING: Potential data loss -- Replica {} became leader after timeout (leaderVoteWait) {}" - , "without being up-to-date with the previous leader", coreNodeName); - zkController.getShardTerms(collection, shardId).setTermEqualsToLeader(coreNodeName); + , "without being up-to-date with the previous leader", replicaName); + zkController.getShardTerms(collection, shardId).setTermEqualsToLeader(replicaName); } super.runLeaderProcess(weAreReplacement, 0); try (SolrCore core = cc.getCore(coreName)) { @@ -314,15 +314,15 @@ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws Kee * @return true if after {@code timeout} there are no other replicas with higher term participate in the election, * false if otherwise */ - private boolean waitForEligibleBecomeLeaderAfterTimeout(ZkShardTerms zkShardTerms, String coreNodeName, int timeout) throws InterruptedException { + private boolean waitForEligibleBecomeLeaderAfterTimeout(ZkShardTerms zkShardTerms, String replicaName, int timeout) throws InterruptedException { long timeoutAt = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS); while (!isClosed && !cc.isShutDown()) { if (System.nanoTime() > timeoutAt) { log.warn("After waiting for {}ms, no other potential leader was found, {} try to become leader anyway (core_term:{}, highest_term:{})", - timeout, coreNodeName, zkShardTerms.getTerm(coreNodeName), zkShardTerms.getHighestTerm()); + timeout, replicaName, zkShardTerms.getTerm(replicaName), zkShardTerms.getHighestTerm()); return true; } - if (replicasWithHigherTermParticipated(zkShardTerms, coreNodeName)) { + if (replicasWithHigherTermParticipated(zkShardTerms, replicaName)) { log.info("Can't become leader, other replicas with higher term participated in leader election"); return false; } @@ -336,17 +336,17 @@ private boolean waitForEligibleBecomeLeaderAfterTimeout(ZkShardTerms zkShardTerm * * @return true if other replicas with higher term participated in the election, false if otherwise */ - private boolean replicasWithHigherTermParticipated(ZkShardTerms zkShardTerms, String coreNodeName) { + private boolean replicasWithHigherTermParticipated(ZkShardTerms zkShardTerms, String replicaName) { ClusterState clusterState = zkController.getClusterState(); DocCollection docCollection = clusterState.getCollectionOrNull(collection); Slice slices = (docCollection == null) ? null : docCollection.getSlice(shardId); if (slices == null) return false; - long replicaTerm = zkShardTerms.getTerm(coreNodeName); - boolean isRecovering = zkShardTerms.isRecovering(coreNodeName); + long replicaTerm = zkShardTerms.getTerm(replicaName); + boolean isRecovering = zkShardTerms.isRecovering(replicaName); for (Replica replica : slices.getReplicas()) { - if (replica.getName().equals(coreNodeName)) continue; + if (replica.getName().equals(replicaName)) continue; if (clusterState.getLiveNodes().contains(replica.getNodeName())) { long otherTerm = zkShardTerms.getTerm(replica.getName()); 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 531294a83906..f58e0df9f88e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContextBase.java @@ -54,9 +54,9 @@ class ShardLeaderElectionContextBase extends ElectionContext { private final Object lock = new Object(); public ShardLeaderElectionContextBase(LeaderElector leaderElector, - final String shardId, final String collection, final String coreNodeName, + final String shardId, final String collection, final String replicaName, ZkNodeProps props, ZkController zkController) { - super(coreNodeName, ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + super(replicaName, ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + "/leader_elect/" + shardId, ZkStateReader.getShardLeadersPath( collection, shardId), props, zkController.getZkClient()); this.leaderElector = leaderElector; diff --git a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java index c73e57ba6b8b..bb23f33333ea 100644 --- a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java @@ -155,7 +155,7 @@ private PeerSync.PeerSyncResult syncReplicas(ZkController zkController, SolrCore private PeerSync.PeerSyncResult syncWithReplicas(ZkController zkController, SolrCore core, ZkNodeProps props, String collection, String shardId, boolean peerSyncOnlyWithActive) throws Exception { List nodes = zkController.getZkStateReader() - .getReplicaProps(collection, shardId,core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName()); + .getReplicaProps(collection, shardId,core.getCoreDescriptor().getCloudDescriptor().getReplicaName()); if (isClosed) { log.info("We have been closed, won't sync with replicas"); @@ -197,7 +197,7 @@ private void syncToMe(ZkController zkController, String collection, List nodes = zkController .getZkStateReader() .getReplicaProps(collection, shardId, - cd.getCloudDescriptor().getCoreNodeName()); + cd.getCloudDescriptor().getReplicaName()); if (nodes == null) { if (log.isInfoEnabled()) { log.info("{} has no replicas", ZkCoreNodeProps.getCoreUrl(leaderProps)); diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkCollectionTerms.java b/solr/core/src/java/org/apache/solr/cloud/ZkCollectionTerms.java index 671bb469e6ec..99a908946093 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkCollectionTerms.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkCollectionTerms.java @@ -47,9 +47,9 @@ public ZkShardTerms getShard(String shardId) { } } - public void register(String shardId, String coreNodeName) { + public void register(String shardId, String replicaName) { synchronized (terms) { - getShard(shardId).registerTerm(coreNodeName); + getShard(shardId).registerTerm(replicaName); } } 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 0e573ad2dfc4..f52d843baef6 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -139,11 +139,11 @@ public class ZkController implements Closeable { static class ContextKey { private String collection; - private String coreNodeName; + private String replicaName; - public ContextKey(String collection, String coreNodeName) { + public ContextKey(String collection, String replicaName) { this.collection = collection; - this.coreNodeName = coreNodeName; + this.replicaName = replicaName; } @Override @@ -153,7 +153,7 @@ public int hashCode() { result = prime * result + ((collection == null) ? 0 : collection.hashCode()); result = prime * result - + ((coreNodeName == null) ? 0 : coreNodeName.hashCode()); + + ((replicaName == null) ? 0 : replicaName.hashCode()); return result; } @@ -166,15 +166,15 @@ public boolean equals(Object obj) { if (collection == null) { if (other.collection != null) return false; } else if (!collection.equals(other.collection)) return false; - if (coreNodeName == null) { - if (other.coreNodeName != null) return false; - } else if (!coreNodeName.equals(other.coreNodeName)) return false; + if (replicaName == null) { + if (other.replicaName != null) return false; + } else if (!replicaName.equals(other.replicaName)) return false; return true; } @Override public String toString() { - return collection + ':' + coreNodeName; + return collection + ':' + replicaName; } } @@ -209,7 +209,7 @@ public String toString() { private int leaderVoteWait; private int leaderConflictResolveWait; - private boolean genericCoreNodeNames; + private boolean genericReplicaNames; private int clientTimeout; @@ -284,7 +284,7 @@ public ZkController(final CoreContainer cc, String zkServerAddress, int zkClient this.cloudConfig = cloudConfig; - this.genericCoreNodeNames = cloudConfig.getGenericCoreNodeNames(); + this.genericReplicaNames = cloudConfig.getGenericReplicaNames(); // be forgiving and strip this off leading/trailing slashes // this allows us to support users specifying hostContext="/" in @@ -554,10 +554,10 @@ private void registerAllCoresAsDown( Thread.currentThread().interrupt(); } - final String coreZkNodeName = descriptor.getCloudDescriptor().getCoreNodeName(); + final String replicaName = descriptor.getCloudDescriptor().getReplicaName(); try { - log.debug("calling waitForLeaderToSeeDownState for coreZkNodeName={} collection={} shard={}", new Object[]{coreZkNodeName, collection, slice}); - waitForLeaderToSeeDownState(descriptor, coreZkNodeName); + log.debug("calling waitForLeaderToSeeDownState for replicaName={} collection={} shard={}", new Object[]{replicaName, collection, slice}); + waitForLeaderToSeeDownState(descriptor, replicaName); } catch (Exception e) { log.warn("There was a problem while making a best effort to ensure the leader has seen us as down, this is not unexpected as Zookeeper has just reconnected after a session expiration", e); if (isClosed) { @@ -584,9 +584,9 @@ private void closeOutstandingElections(final Supplier> regi private ContextKey closeExistingElectionContext(CoreDescriptor cd) { // look for old context - if we find it, cancel it String collection = cd.getCloudDescriptor().getCollectionName(); - final String coreNodeName = cd.getCloudDescriptor().getCoreNodeName(); + final String replicaName = cd.getCloudDescriptor().getReplicaName(); - ContextKey contextKey = new ContextKey(collection, coreNodeName); + ContextKey contextKey = new ContextKey(collection, replicaName); ElectionContext prevContext = electionContexts.get(contextKey); if (prevContext != null) { @@ -709,7 +709,7 @@ public void giveupLeadership(CoreDescriptor cd) { if (shard == null) return; // if this replica is not a leader, it will be put in recovery state by the leader - String leader = cd.getCloudDescriptor().getCoreNodeName(); + String leader = cd.getCloudDescriptor().getReplicaName(); if (shard.getReplica(leader) != shard.getLeader()) return; Set liveNodes = getClusterState().getLiveNodes(); @@ -1041,7 +1041,7 @@ public void publishAndWaitForDownStates(int timeoutSeconds) throws KeeperExcepti boolean foundStates = true; for (CoreDescriptor coreDescriptor : cc.getCoreDescriptors()) { if (coreDescriptor.getCloudDescriptor().getCollectionName().equals(collectionWithLocalReplica)) { - Replica replica = collectionState.getReplica(coreDescriptor.getCloudDescriptor().getCoreNodeName()); + Replica replica = collectionState.getReplica(coreDescriptor.getCloudDescriptor().getReplicaName()); if (replica == null || replica.getState() != Replica.State.DOWN) { foundStates = false; } @@ -1160,24 +1160,24 @@ public String register(String coreName, final CoreDescriptor desc, boolean recov final CloudDescriptor cloudDesc = desc.getCloudDescriptor(); final String collection = cloudDesc.getCollectionName(); final String shardId = cloudDesc.getShardId(); - final String coreZkNodeName = cloudDesc.getCoreNodeName(); - assert coreZkNodeName != null : "we should have a coreNodeName by now"; + final String replicaName = cloudDesc.getReplicaName(); + assert replicaName != null : "we should have a replicaName by now"; // check replica's existence in clusterstate first try { zkStateReader.waitForState(collection, 100, TimeUnit.MILLISECONDS, - (collectionState) -> getReplicaOrNull(collectionState, shardId, coreZkNodeName) != null); + (collectionState) -> getReplicaOrNull(collectionState, shardId, replicaName) != null); } catch (TimeoutException e) { throw new SolrException(ErrorCode.SERVER_ERROR, "Error registering SolrCore, timeout waiting for replica present in clusterstate"); } - Replica replica = getReplicaOrNull(zkStateReader.getClusterState().getCollectionOrNull(collection), shardId, coreZkNodeName); + Replica replica = getReplicaOrNull(zkStateReader.getClusterState().getCollectionOrNull(collection), shardId, replicaName); if (replica == null) { throw new SolrException(ErrorCode.SERVER_ERROR, "Error registering SolrCore, replica is removed from clusterstate"); } if (replica.getType() != Type.PULL) { - getCollectionTerms(collection).register(cloudDesc.getShardId(), coreZkNodeName); + getCollectionTerms(collection).register(cloudDesc.getShardId(), replicaName); } ZkShardTerms shardTerms = getShardTerms(collection, cloudDesc.getShardId()); @@ -1192,9 +1192,9 @@ public String register(String coreName, final CoreDescriptor desc, boolean recov joinElection(desc, afterExpiration, joinAtHead); } else if (replica.getType() == Type.PULL) { if (joinAtHead) { - log.warn("Replica {} was designated as preferred leader but it's type is {}, It won't join election", coreZkNodeName, Type.PULL); + log.warn("Replica {} was designated as preferred leader but it's type is {}, It won't join election", replicaName, Type.PULL); } - log.debug("Replica {} skipping election because it's type is {}", coreZkNodeName, Type.PULL); + log.debug("Replica {} skipping election because it's type is {}", replicaName, Type.PULL); startReplicationFromLeader(coreName, false); } } catch (InterruptedException e) { @@ -1255,7 +1255,7 @@ public String register(String coreName, final CoreDescriptor desc, boolean recov } } boolean didRecovery - = checkRecovery(recoverReloadedCores, isLeader, skipRecovery, collection, coreZkNodeName, shardId, core, cc, afterExpiration); + = checkRecovery(recoverReloadedCores, isLeader, skipRecovery, collection, replicaName, shardId, core, cc, afterExpiration); if (!didRecovery) { if (isTlogReplicaAndNotLeader) { startReplicationFromLeader(coreName, true); @@ -1277,20 +1277,20 @@ public String register(String coreName, final CoreDescriptor desc, boolean recov zkStateReader.forceUpdateCollection(collection); // the watcher is added to a set so multiple calls of this method will left only one watcher zkStateReader.registerDocCollectionWatcher(cloudDesc.getCollectionName(), - new UnloadCoreOnDeletedWatcher(coreZkNodeName, shardId, desc.getName())); + new UnloadCoreOnDeletedWatcher(replicaName, shardId, desc.getName())); return shardId; } finally { MDCLoggingContext.clear(); } } - private Replica getReplicaOrNull(DocCollection docCollection, String shard, String coreNodeName) { + private Replica getReplicaOrNull(DocCollection docCollection, String shard, String replicaName) { if (docCollection == null) return null; Slice slice = docCollection.getSlice(shard); if (slice == null) return null; - Replica replica = slice.getReplica(coreNodeName); + Replica replica = slice.getReplica(replicaName); if (replica == null) return null; if (!getNodeName().equals(replica.getNodeName())) return null; @@ -1422,9 +1422,9 @@ private void joinElection(CoreDescriptor cd, boolean afterExpiration, boolean jo throws InterruptedException, KeeperException, IOException { // look for old context - if we find it, cancel it String collection = cd.getCloudDescriptor().getCollectionName(); - final String coreNodeName = cd.getCloudDescriptor().getCoreNodeName(); + final String replicaName = cd.getCloudDescriptor().getCoreNodeName(); - ContextKey contextKey = new ContextKey(collection, coreNodeName); + ContextKey contextKey = new ContextKey(collection, replicaName); ElectionContext prevContext = electionContexts.get(contextKey); @@ -1438,14 +1438,14 @@ private void joinElection(CoreDescriptor cd, boolean afterExpiration, boolean jo // we only put a subset of props into the leader node props.put(ZkStateReader.CORE_NAME_PROP, cd.getName()); props.put(ZkStateReader.NODE_NAME_PROP, getNodeName()); - props.put(ZkStateReader.CORE_NODE_NAME_PROP, coreNodeName); + props.put(ZkStateReader.CORE_NODE_NAME_PROP, replicaName); ZkNodeProps ourProps = new ZkNodeProps(props); LeaderElector leaderElector = new LeaderElector(zkClient, contextKey, electionContexts); ElectionContext context = new ShardLeaderElectionContext(leaderElector, shardId, - collection, coreNodeName, ourProps, this, cc); + collection, replicaName, ourProps, this, cc); leaderElector.setup(context); electionContexts.put(contextKey, context); @@ -1529,7 +1529,7 @@ public void publish(final CoreDescriptor cd, final Replica.State state, boolean String shardId = cd.getCloudDescriptor().getShardId(); - String coreNodeName = cd.getCloudDescriptor().getCoreNodeName(); + String replicaName = cd.getCloudDescriptor().getReplicaName(); Map props = new HashMap<>(); props.put(Overseer.QUEUE_OPERATION, "state"); @@ -1544,8 +1544,8 @@ public void publish(final CoreDescriptor cd, final Replica.State state, boolean if (numShards != null) { props.put(ZkStateReader.NUM_SHARDS_PROP, numShards.toString()); } - if (coreNodeName != null) { - props.put(ZkStateReader.CORE_NODE_NAME_PROP, coreNodeName); + if (replicaName != null) { + props.put(CommonParams.REPLICA_NAME, replicaName); } try (SolrCore core = cc.getCore(cd.getName())) { if (core != null && state == Replica.State.ACTIVE) { @@ -1572,10 +1572,10 @@ public void publish(final CoreDescriptor cd, final Replica.State state, boolean if (state == Replica.State.RECOVERING && cd.getCloudDescriptor().getReplicaType() != Type.PULL) { // state is used by client, state of replica can change from RECOVERING to DOWN without needed to finish recovery // by calling this we will know that a replica actually finished recovery or not - getShardTerms(collection, shardId).startRecovering(coreNodeName); + getShardTerms(collection, shardId).startRecovering(replicaName); } if (state == Replica.State.ACTIVE && cd.getCloudDescriptor().getReplicaType() != Type.PULL) { - getShardTerms(collection, shardId).doneRecovering(coreNodeName); + getShardTerms(collection, shardId).doneRecovering(replicaName); } ZkNodeProps m = new ZkNodeProps(props); @@ -1584,14 +1584,14 @@ public void publish(final CoreDescriptor cd, final Replica.State state, boolean cd.getCloudDescriptor().setLastPublished(state); } DocCollection coll = zkStateReader.getCollection(collection); - if (forcePublish || sendToOverseer(coll, coreNodeName)) { + if (forcePublish || sendToOverseer(coll, replicaName)) { overseerJobQueue.offer(Utils.toJSON(m)); } else { if (log.isDebugEnabled()) { log.debug("bypassed overseer for message : {}", Utils.toJSONString(m)); } PerReplicaStates perReplicaStates = PerReplicaStates.fetch(coll.getZNode(), zkClient, coll.getPerReplicaStates()); - PerReplicaStatesOps.flipState(coreNodeName, state, perReplicaStates) + PerReplicaStatesOps.flipState(replicaName, state, perReplicaStates) .persist(coll.getZNode(), zkClient); } } finally { @@ -1640,10 +1640,10 @@ public void unregister(String coreName, CoreDescriptor cd) throws Exception { } public void unregister(String coreName, CoreDescriptor cd, boolean removeCoreFromZk) throws Exception { - final String coreNodeName = cd.getCloudDescriptor().getCoreNodeName(); + final String replicaName = cd.getCloudDescriptor().getReplicaName(); final String collection = cd.getCloudDescriptor().getCollectionName(); getCollectionTerms(collection).remove(cd.getCloudDescriptor().getShardId(), cd); - replicasMetTragicEvent.remove(collection+":"+coreNodeName); + replicasMetTragicEvent.remove(collection+":"+replicaName); if (Strings.isNullOrEmpty(collection)) { log.error("No collection was specified."); @@ -1651,10 +1651,10 @@ public void unregister(String coreName, CoreDescriptor cd, boolean removeCoreFro return; } final DocCollection docCollection = zkStateReader.getClusterState().getCollectionOrNull(collection); - Replica replica = (docCollection == null) ? null : docCollection.getReplica(coreNodeName); + Replica replica = (docCollection == null) ? null : docCollection.getReplica(replicaName); if (replica == null || replica.getType() != Type.PULL) { - ElectionContext context = electionContexts.remove(new ContextKey(collection, coreNodeName)); + ElectionContext context = electionContexts.remove(new ContextKey(collection, replicaName)); if (context != null) { context.cancelElection(); @@ -1666,7 +1666,7 @@ public void unregister(String coreName, CoreDescriptor cd, boolean removeCoreFro OverseerAction.DELETECORE.toLower(), ZkStateReader.CORE_NAME_PROP, coreName, ZkStateReader.NODE_NAME_PROP, getNodeName(), ZkStateReader.COLLECTION_PROP, cloudDescriptor.getCollectionName(), - ZkStateReader.CORE_NODE_NAME_PROP, coreNodeName); + ZkStateReader.CORE_NODE_NAME_PROP, replicaName); overseerJobQueue.offer(Utils.toJSON(m)); } } @@ -1683,18 +1683,18 @@ public ZkStateReader getZkStateReader() { } private void doGetShardIdAndNodeNameProcess(CoreDescriptor cd) { - final String coreNodeName = cd.getCloudDescriptor().getCoreNodeName(); + final String replicaName = cd.getCloudDescriptor().getReplicaName(); - if (coreNodeName != null) { + if (replicaName != null) { waitForShardId(cd); } else { - // if no explicit coreNodeName, we want to match by base url and core name - waitForCoreNodeName(cd); + // if no explicit replicaName, we want to match by base url and core name + waitForReplica(cd); waitForShardId(cd); } } - private void waitForCoreNodeName(CoreDescriptor descriptor) { + private void waitForReplica(CoreDescriptor descriptor) { int retryCount = 320; log.debug("look for our core node name"); while (retryCount-- > 0) { @@ -1714,7 +1714,7 @@ private void waitForCoreNodeName(CoreDescriptor descriptor) { if (msgNodeName.equals(nodeName) && core.equals(msgCore)) { descriptor.getCloudDescriptor() - .setCoreNodeName(replica.getName()); + .setReplicaName(replica.getName()); getCoreContainer().getCoresLocator().persist(getCoreContainer(), descriptor); return; } @@ -1751,20 +1751,24 @@ private void waitForShardId(CoreDescriptor cd) { "Could not get shard id for core: " + cd.getName()); } - - public String getCoreNodeName(CoreDescriptor descriptor) { - String coreNodeName = descriptor.getCloudDescriptor().getCoreNodeName(); - if (coreNodeName == null && !genericCoreNodeNames) { + public String getReplicaName(CoreDescriptor descriptor) { + String replicaName = descriptor.getCloudDescriptor().getReplicaName(); + if (replicaName == null && !genericReplicaNames) { // it's the default return getNodeName() + "_" + descriptor.getName(); } + return replicaName; + } - return coreNodeName; + + @Deprecated + public String getCoreNodeName(CoreDescriptor descriptor) { + return getReplicaName(descriptor); } public void preRegister(CoreDescriptor cd, boolean publishState) { - String coreNodeName = getCoreNodeName(cd); + String replicaName = getReplicaName(cd); // before becoming available, make sure we are not live and active // this also gets us our assigned shard id if it was not specified @@ -1774,8 +1778,8 @@ public void preRegister(CoreDescriptor cd, boolean publishState) { CloudDescriptor cloudDesc = cd.getCloudDescriptor(); // make sure the node name is set on the descriptor - if (cloudDesc.getCoreNodeName() == null) { - cloudDesc.setCoreNodeName(coreNodeName); + if (cloudDesc.getReplicaName() == null) { + cloudDesc.setReplicaName(replicaName); } // publishState == false on startup @@ -1823,11 +1827,11 @@ private boolean isPublishAsDownOnStartup(CloudDescriptor cloudDesc) { private void checkStateInZk(CoreDescriptor cd) throws InterruptedException, NotInClusterStateException { CloudDescriptor cloudDesc = cd.getCloudDescriptor(); - String nodeName = cloudDesc.getCoreNodeName(); + String nodeName = cloudDesc.getReplicaName(); if (nodeName == null) { - throw new SolrException(ErrorCode.SERVER_ERROR, "No coreNodeName for " + cd); + throw new SolrException(ErrorCode.SERVER_ERROR, "No replicaName for " + cd); } - final String coreNodeName = nodeName; + final String replicaName = nodeName; if (cloudDesc.getShardId() == null) { throw new SolrException(ErrorCode.SERVER_ERROR, "No shard id for " + cd); @@ -1845,9 +1849,9 @@ private void checkStateInZk(CoreDescriptor cd) throws InterruptedException, NotI errorMessage.set("Invalid shard: " + cloudDesc.getShardId()); return false; } - Replica replica = slice.getReplica(coreNodeName); + Replica replica = slice.getReplica(replicaName); if (replica == null) { - errorMessage.set("coreNodeName " + coreNodeName + " does not exist in shard " + cloudDesc.getShardId() + + errorMessage.set("replicaName " + replicaName + " does not exist in shard " + cloudDesc.getShardId() + ", ignore the exception if the replica was deleted"); return false; } @@ -1856,7 +1860,7 @@ private void checkStateInZk(CoreDescriptor cd) throws InterruptedException, NotI } catch (TimeoutException e) { String error = errorMessage.get(); if (error == null) - error = "coreNodeName " + coreNodeName + " does not exist in shard " + cloudDesc.getShardId() + + error = "replicaName " + replicaName + " does not exist in shard " + cloudDesc.getShardId() + ", ignore the exception if the replica was deleted"; throw new NotInClusterStateException(ErrorCode.SERVER_ERROR, error); } @@ -2636,7 +2640,7 @@ public NotInClusterStateException(ErrorCode code, String msg) { } } - public boolean checkIfCoreNodeNameAlreadyExists(CoreDescriptor dcore) { + public boolean checkIfReplicaNameAlreadyExists(CoreDescriptor dcore) { DocCollection collection = zkStateReader.getClusterState().getCollectionOrNull(dcore.getCollectionName()); if (collection != null) { Collection slices = collection.getSlices(); 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 6b4799f21b89..a55ed256dc23 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkShardTerms.java @@ -110,7 +110,7 @@ public ZkShardTerms(String collection, String shard, SolrZkClient zkClient) { * Ensure that terms are higher than some replica's terms. If the current leader is attempting to give up * leadership and included in replicasNeedingRecovery, then other replicas that are in sync will have higher * terms, while the leader will stay where it is. - * @param leader coreNodeName of leader + * @param leader replicaName of leader * @param replicasNeedingRecovery set of replicas in which their terms should be lower than leader's term */ public void ensureTermsIsHigher(String leader, Set replicasNeedingRecovery) { @@ -123,29 +123,29 @@ public ShardTerms getShardTerms() { } /** * Can this replica become leader? - * @param coreNodeName of the replica + * @param replicaName of the replica * @return true if this replica can become leader, false if otherwise */ - public boolean canBecomeLeader(String coreNodeName) { - return terms.get().canBecomeLeader(coreNodeName); + public boolean canBecomeLeader(String replicaName) { + return terms.get().canBecomeLeader(replicaName); } /** * Should leader skip sending updates to this replica? - * @param coreNodeName of the replica + * @param replicaName of the replica * @return true if this replica has term equals to leader's term, false if otherwise */ - public boolean skipSendingUpdatesTo(String coreNodeName) { - return !terms.get().haveHighestTermValue(coreNodeName); + public boolean skipSendingUpdatesTo(String replicaName) { + return !terms.get().haveHighestTermValue(replicaName); } /** * Did this replica registered its term? This is a sign to check f - * @param coreNodeName of the replica + * @param replicaName of the replica * @return true if this replica registered its term, false if otherwise */ - public boolean registered(String coreNodeName) { - return terms.get().getTerm(coreNodeName) != null; + public boolean registered(String replicaName) { + return terms.get().getTerm(replicaName) != null; } public void close() { @@ -172,7 +172,7 @@ void addListener(CoreTermWatcher listener) { } /** - * Remove the coreNodeName from terms map and also remove any expired listeners + * Remove the replicaName from terms map and also remove any expired listeners * @return Return true if this object should not be reused */ boolean removeTerm(CoreDescriptor cd) { @@ -182,14 +182,14 @@ boolean removeTerm(CoreDescriptor cd) { listeners.removeIf(coreTermWatcher -> !coreTermWatcher.onTermChanged(terms.get())); numListeners = listeners.size(); } - return removeTerm(cd.getCloudDescriptor().getCoreNodeName()) || numListeners == 0; + return removeTerm(cd.getCloudDescriptor().getReplicaName()) || numListeners == 0; } // package private for testing, only used by tests // return true if this object should not be reused - boolean removeTerm(String coreNodeName) { + boolean removeTerm(String replicaName) { ShardTerms newTerms; - while ( (newTerms = terms.get().removeTerm(coreNodeName)) != null) { + while ( (newTerms = terms.get().removeTerm(replicaName)) != null) { try { if (saveTerms(newTerms, "removeTerm")) return false; } catch (KeeperException.NoNodeException e) { @@ -202,41 +202,41 @@ boolean removeTerm(String coreNodeName) { /** * Register a replica's term (term value will be 0). * If a term is already associate with this replica do nothing - * @param coreNodeName of the replica + * @param replicaName of the replica */ - void registerTerm(String coreNodeName) { - mutate(terms -> terms.registerTerm(coreNodeName)); + void registerTerm(String replicaName) { + mutate(terms -> terms.registerTerm(replicaName)); } /** * Set a replica's term equals to leader's term, and remove recovering flag of a replica. * This call should only be used by {@link org.apache.solr.common.params.CollectionParams.CollectionAction#FORCELEADER} - * @param coreNodeName of the replica + * @param replicaName of the replica */ - public void setTermEqualsToLeader(String coreNodeName) { - mutate(terms -> terms.setTermEqualsToLeader(coreNodeName)); + public void setTermEqualsToLeader(String replicaName) { + mutate(terms -> terms.setTermEqualsToLeader(replicaName)); } /** * Set a replica's term to 0. If the term does not exist, create it. - * @param coreNodeName of the replica + * @param replicaName of the replica */ - public void setTermToZero(String coreNodeName) { - mutate(terms -> terms.setTermToZero(coreNodeName)); + public void setTermToZero(String replicaName) { + mutate(terms -> terms.setTermToZero(replicaName)); } /** - * Mark {@code coreNodeName} as recovering + * Mark {@code replicaName} as recovering */ - public void startRecovering(String coreNodeName) { - mutate(terms -> terms.startRecovering(coreNodeName)); + public void startRecovering(String replicaName) { + mutate(terms -> terms.startRecovering(replicaName)); } /** - * Mark {@code coreNodeName} as finished recovering + * Mark {@code replicaName} as finished recovering */ - public void doneRecovering(String coreNodeName) { - mutate(terms -> terms.doneRecovering(coreNodeName)); + public void doneRecovering(String replicaName) { + mutate(terms -> terms.doneRecovering(replicaName)); } public boolean isRecovering(String name) { @@ -269,8 +269,8 @@ public long getHighestTerm() { return terms.get().getMaxTerm(); } - public long getTerm(String coreNodeName) { - Long term = terms.get().getTerm(coreNodeName); + public long getTerm(String replicaName) { + Long term = terms.get().getTerm(replicaName); return term == null? -1 : term; } diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java index b24e442b1eca..a1b77564e84d 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/AddReplicaCmd.java @@ -55,10 +55,7 @@ import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.cloud.ZkNodeProps; import org.apache.solr.common.cloud.ZkStateReader; -import org.apache.solr.common.params.CollectionAdminParams; -import org.apache.solr.common.params.CoreAdminParams; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.params.ShardParams; +import org.apache.solr.common.params.*; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.Utils; import org.apache.solr.handler.component.ShardHandler; @@ -135,7 +132,7 @@ List addReplica(ClusterState clusterState, ZkNodeProps message, @Su if (node != null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot create " + totalReplicas + " replicas if 'name' parameter is specified"); } - if (message.getStr(CoreAdminParams.CORE_NODE_NAME) != null) { + if (message.getStr(CommonParams.REPLICA_NAME) != null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot create " + totalReplicas + " replicas if 'coreNodeName' parameter is specified"); } } @@ -160,7 +157,7 @@ List addReplica(ClusterState clusterState, ZkNodeProps message, @Su Runnable runnable = () -> { shardRequestTracker.processResponses(results, shardHandler, true, "ADDREPLICA failed to create replica"); for (CreateReplica replica : createReplicas) { - ocmh.waitForCoreNodeName(collectionName, replica.node, replica.coreName); + ocmh.waitForReplica(collectionName, replica.node, replica.coreName); } if (onComplete != null) onComplete.run(); }; @@ -209,8 +206,8 @@ private ModifiableSolrParams getReplicaParams(ClusterState clusterState, ZkNodeP ZkStateReader.STATE_PROP, Replica.State.DOWN.toString(), ZkStateReader.NODE_NAME_PROP, createReplica.node, ZkStateReader.REPLICA_TYPE, createReplica.replicaType.name()); - if (createReplica.coreNodeName != null) { - props = props.plus(ZkStateReader.CORE_NODE_NAME_PROP, createReplica.coreNodeName); + if (createReplica.replicaName != null) { + props = props.plus(ZkStateReader.CORE_NODE_NAME_PROP, createReplica.replicaName); } try { ocmh.overseer.offerStateUpdate(Utils.toJSON(props)); @@ -253,8 +250,8 @@ private ModifiableSolrParams getReplicaParams(ClusterState clusterState, ZkNodeP if (instanceDir != null) { params.set(CoreAdminParams.INSTANCE_DIR, instanceDir); } - if (createReplica.coreNodeName != null) { - params.set(CoreAdminParams.CORE_NODE_NAME, createReplica.coreNodeName); + if (createReplica.replicaName != null) { + params.set(CoreAdminParams.CORE_NODE_NAME, createReplica.replicaName); } ocmh.addPropertyParams(message, params); @@ -269,7 +266,7 @@ public static CreateReplica assignReplicaDetails(SolrCloudManager cloudManager, String node = replicaPosition.node; String shard = message.getStr(SHARD_ID_PROP); String coreName = message.getStr(CoreAdminParams.NAME); - String coreNodeName = message.getStr(CoreAdminParams.CORE_NODE_NAME); + String replicaName = message.getStr(CoreAdminParams.CORE_NODE_NAME); Replica.Type replicaType = replicaPosition.type; if (StringUtils.isBlank(coreName)) { @@ -296,7 +293,7 @@ public static CreateReplica assignReplicaDetails(SolrCloudManager cloudManager, } } log.info("Returning CreateReplica command."); - return new CreateReplica(collection, shard, node, replicaType, coreName, coreNodeName); + return new CreateReplica(collection, shard, node, replicaType, coreName, replicaName); } public static List buildReplicaPositions(SolrCloudManager cloudManager, ClusterState clusterState, @@ -361,15 +358,15 @@ public static class CreateReplica { public final String node; public final Replica.Type replicaType; public String coreName; - public String coreNodeName; + public String replicaName; - CreateReplica(String collectionName, String sliceName, String node, Replica.Type replicaType, String coreName, String coreNodeName) { + CreateReplica(String collectionName, String sliceName, String node, Replica.Type replicaType, String coreName, String replicaName) { this.collectionName = collectionName; this.sliceName = sliceName; this.node = node; this.replicaType = replicaType; this.coreName = coreName; - this.coreNodeName = coreNodeName; + this.replicaName = replicaName; } } diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java index 786bfa9ae59b..01d4ec1c2b27 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/Assign.java @@ -114,16 +114,16 @@ public static int incAndGetId(DistribStateManager stateManager, String collectio } } - public static String assignCoreNodeName(DistribStateManager stateManager, DocCollection collection) { + public static String assignReplicaName(DistribStateManager stateManager, DocCollection collection) { // for backward compatibility; int defaultValue = defaultCounterValue(collection, false); - String coreNodeName = "core_node" + incAndGetId(stateManager, collection.getName(), defaultValue); - while (collection.getReplica(coreNodeName) != null) { - // there is wee chance that, the new coreNodeName id not totally unique, + String replicaName = "core_node" + incAndGetId(stateManager, collection.getName(), defaultValue); + while (collection.getReplica(replicaName) != null) { + // there is wee chance that, the new replicaName is not totally unique, // but this will be guaranteed unique for new collections - coreNodeName = "core_node" + incAndGetId(stateManager, collection.getName(), defaultValue); + replicaName = "core_node" + incAndGetId(stateManager, collection.getName(), defaultValue); } - return coreNodeName; + return replicaName; } /** diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/LeaderRecoveryWatcher.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/LeaderRecoveryWatcher.java index a80fdc0a3d05..1f3fbc3a0218 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/LeaderRecoveryWatcher.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/LeaderRecoveryWatcher.java @@ -40,7 +40,7 @@ public class LeaderRecoveryWatcher implements CollectionStateWatcher { * * @param collectionId collection name * @param shardId shard id - * @param replicaId source replica name (coreNodeName) + * @param replicaId source replica name * @param targetCore specific target core name - if null then any active replica will do * @param latch countdown when recovered */ diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java index 85bac4bfffd0..20ec262470ab 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/MigrateCmd.java @@ -251,7 +251,7 @@ private void migrateKey(ClusterState clusterState, DocCollection sourceCollectio Replica tempSourceLeader = zkStateReader.getLeaderRetry(tempSourceCollectionName, tempSourceSlice.getName(), 120000); String tempCollectionReplica1 = tempSourceLeader.getCoreName(); - String coreNodeName = ocmh.waitForCoreNodeName(tempSourceCollectionName, + String replicaName = ocmh.waitForReplica(tempSourceCollectionName, sourceLeader.getNodeName(), tempCollectionReplica1); // wait for the replicas to be seen as active on temp source leader if (log.isInfoEnabled()) { @@ -260,7 +260,7 @@ private void migrateKey(ClusterState clusterState, DocCollection sourceCollectio CoreAdminRequest.WaitForState cmd = new CoreAdminRequest.WaitForState(); cmd.setCoreName(tempCollectionReplica1); cmd.setNodeName(sourceLeader.getNodeName()); - cmd.setCoreNodeName(coreNodeName); + cmd.setReplicaName(replicaName); cmd.setState(Replica.State.ACTIVE); cmd.setCheckLive(true); cmd.setOnlyIfLeader(true); @@ -319,7 +319,7 @@ private void migrateKey(ClusterState clusterState, DocCollection sourceCollectio syncRequestTracker.processResponses(results, shardHandler, true, "MIGRATE failed to create replica of " + "temporary collection in target leader node."); } - coreNodeName = ocmh.waitForCoreNodeName(tempSourceCollectionName, + replicaName = ocmh.waitForReplica(tempSourceCollectionName, targetLeader.getNodeName(), tempCollectionReplica2); // wait for the replicas to be seen as active on temp source leader if (log.isInfoEnabled()) { @@ -328,7 +328,7 @@ private void migrateKey(ClusterState clusterState, DocCollection sourceCollectio cmd = new CoreAdminRequest.WaitForState(); cmd.setCoreName(tempSourceLeader.getStr("core")); cmd.setNodeName(targetLeader.getNodeName()); - cmd.setCoreNodeName(coreNodeName); + cmd.setCoreNodeName(replicaName); cmd.setState(Replica.State.ACTIVE); cmd.setCheckLive(true); cmd.setOnlyIfLeader(true); diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java index b69d4d433767..8c55fd3c4f60 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/OverseerCollectionMessageHandler.java @@ -488,7 +488,7 @@ static UpdateResponse softCommit(String url) throws SolrServerException, IOExcep } } - String waitForCoreNodeName(String collectionName, String msgNodeName, String msgCore) { + String waitForReplica(String collectionName, String msgNodeName, String msgCore) { int retryCount = 320; while (retryCount-- > 0) { final DocCollection docCollection = zkStateReader.getClusterState().getCollectionOrNull(collectionName); @@ -513,7 +513,7 @@ String waitForCoreNodeName(String collectionName, String msgNodeName, String msg Thread.currentThread().interrupt(); } } - throw new SolrException(ErrorCode.SERVER_ERROR, "Could not find coreNodeName"); + throw new SolrException(ErrorCode.SERVER_ERROR, "Could not find replicaName"); } ClusterState waitForNewShard(String collectionName, String sliceName) throws KeeperException, InterruptedException { diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java index c7c941a904d5..0b6dffcdf61a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java +++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/RestoreCmd.java @@ -327,17 +327,17 @@ public void call(ClusterState state, ZkNodeProps message, NamedList results) thr for (Slice s : restoreCollection.getSlices()) { for (Replica r : s.getReplicas()) { String nodeName = r.getNodeName(); - String coreNodeName = r.getCoreName(); + String replicaName = r.getCoreName(); Replica.State stateRep = r.getState(); if (log.isDebugEnabled()) { - log.debug("Calling REQUESTAPPLYUPDATES on: nodeName={}, coreNodeName={}, state={}", nodeName, coreNodeName, + log.debug("Calling REQUESTAPPLYUPDATES on: nodeName={}, replicaName={}, state={}", nodeName, replicaName, stateRep.name()); } ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.REQUESTAPPLYUPDATES.toString()); - params.set(CoreAdminParams.NAME, coreNodeName); + params.set(CoreAdminParams.NAME, replicaName); shardRequestTracker.sendShardRequest(nodeName, params, shardHandler); } 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 770dfacfb4c4..d4d06322b27c 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 @@ -329,11 +329,11 @@ public boolean split(ClusterState clusterState, ZkNodeProps message, NamedList slices = collection != null ? collection.getSlices() : null; if (slices != null) { for (Slice slice : slices) { diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/ReplicaMutator.java b/solr/core/src/java/org/apache/solr/cloud/overseer/ReplicaMutator.java index ecf06e4ed59c..78857afbee7a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/overseer/ReplicaMutator.java +++ b/solr/core/src/java/org/apache/solr/cloud/overseer/ReplicaMutator.java @@ -258,38 +258,38 @@ protected ZkWriteCommand updateState(final ClusterState prevState, ZkNodeProps m private ZkWriteCommand updateState(final ClusterState prevState, ZkNodeProps message, String collectionName, Integer numShards, boolean collectionExists) { String sliceName = message.getStr(ZkStateReader.SHARD_ID_PROP); - String coreNodeName = message.getStr(ZkStateReader.CORE_NODE_NAME_PROP); + String replicaName = message.getStr(ZkStateReader.CORE_NODE_NAME_PROP); boolean forceSetState = message.getBool(ZkStateReader.FORCE_SET_STATE_PROP, true); DocCollection collection = prevState.getCollectionOrNull(collectionName); - if (!forceSetState && !CloudUtil.replicaExists(prevState, collectionName, sliceName, coreNodeName)) { + if (!forceSetState && !CloudUtil.replicaExists(prevState, collectionName, sliceName, replicaName)) { log.info("Failed to update state because the replica does not exist, {}", message); return ZkStateWriter.NO_OP; } boolean persistCollectionState = collection != null && collection.isPerReplicaState(); - if (coreNodeName == null) { - coreNodeName = ClusterStateMutator.getAssignedCoreNodeName(collection, + if (replicaName == null) { + replicaName = ClusterStateMutator.getAssignedReplicaName(collection, message.getStr(ZkStateReader.NODE_NAME_PROP), message.getStr(ZkStateReader.CORE_NAME_PROP)); - if (coreNodeName != null) { - log.debug("node={} is already registered", coreNodeName); + if (replicaName != null) { + log.debug("node={} is already registered", replicaName); } else { if (!forceSetState) { log.info("Failed to update state because the replica does not exist, {}", message); return ZkStateWriter.NO_OP; } persistCollectionState = true; - // if coreNodeName is null, auto assign one - coreNodeName = Assign.assignCoreNodeName(stateManager, collection); + // if replicaName is null, auto assign one + replicaName = Assign.assignReplicaName(stateManager, collection); } message.getProperties().put(ZkStateReader.CORE_NODE_NAME_PROP, - coreNodeName); + replicaName); } // use the provided non null shardId if (sliceName == null) { //get shardId from ClusterState - sliceName = ClusterStateMutator.getAssignedId(collection, coreNodeName); + sliceName = ClusterStateMutator.getAssignedId(collection, replicaName); if (sliceName != null) { log.debug("shard={} is already registered", sliceName); } @@ -311,7 +311,7 @@ private ZkWriteCommand updateState(final ClusterState prevState, ZkNodeProps mes Map replicaProps = new LinkedHashMap<>(message.getProperties()); if (slice != null) { - Replica oldReplica = slice.getReplica(coreNodeName); + Replica oldReplica = slice.getReplica(replicaName); if (oldReplica != null) { if (oldReplica.containsKey(ZkStateReader.LEADER_PROP)) { replicaProps.put(ZkStateReader.LEADER_PROP, oldReplica.get(ZkStateReader.LEADER_PROP)); @@ -351,7 +351,7 @@ private ZkWriteCommand updateState(final ClusterState prevState, ZkNodeProps mes String shardParent = (String) replicaProps.remove(ZkStateReader.SHARD_PARENT_PROP); - Replica replica = new Replica(coreNodeName, replicaProps, collectionName, sliceName); + Replica replica = new Replica(replicaName, replicaProps, collectionName, sliceName); log.debug("Will update state for replica: {}", replica); @@ -359,7 +359,7 @@ private ZkWriteCommand updateState(final ClusterState prevState, ZkNodeProps mes Map replicas; if (slice != null) { - collection = checkAndCompleteShardSplit(prevState, collection, coreNodeName, sliceName, replica); + collection = checkAndCompleteShardSplit(prevState, collection, replicaName, sliceName, replica); // get the current slice again because it may have been updated due to checkAndCompleteShardSplit method slice = collection.getSlice(sliceName); sliceProps = slice.getProperties(); @@ -384,18 +384,18 @@ private ZkWriteCommand updateState(final ClusterState prevState, ZkNodeProps mes } } - private DocCollection checkAndCompleteShardSplit(ClusterState prevState, DocCollection collection, String coreNodeName, String sliceName, Replica replica) { + private DocCollection checkAndCompleteShardSplit(ClusterState prevState, DocCollection collection, String replicaName, String sliceName, Replica replica) { Slice slice = collection.getSlice(sliceName); Map sliceProps = slice.getProperties(); if (slice.getState() == Slice.State.RECOVERY) { log.info("Shard: {} is in recovery state", sliceName); // is this replica active? if (replica.getState() == Replica.State.ACTIVE) { - log.info("Shard: {} is in recovery state and coreNodeName: {} is active", sliceName, coreNodeName); + log.info("Shard: {} is in recovery state and replicaName: {} is active", sliceName, replicaName); // are all other replicas also active? boolean allActive = true; for (Map.Entry entry : slice.getReplicasMap().entrySet()) { - if (coreNodeName.equals(entry.getKey())) continue; + if (replicaName.equals(entry.getKey())) continue; if (entry.getValue().getState() != Replica.State.ACTIVE) { allActive = false; break; diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/SliceMutator.java b/solr/core/src/java/org/apache/solr/cloud/overseer/SliceMutator.java index 019339e197cd..b5bf5124236e 100644 --- a/solr/core/src/java/org/apache/solr/cloud/overseer/SliceMutator.java +++ b/solr/core/src/java/org/apache/solr/cloud/overseer/SliceMutator.java @@ -83,13 +83,13 @@ public ZkWriteCommand addReplica(ClusterState clusterState, ZkNodeProps message) log.error("Invalid Collection/Slice {}/{} ", coll, slice); return ZkStateWriter.NO_OP; } - String coreNodeName; + String replicaName; if (message.getStr(ZkStateReader.CORE_NODE_NAME_PROP) != null) { - coreNodeName = message.getStr(ZkStateReader.CORE_NODE_NAME_PROP); + replicaName = message.getStr(ZkStateReader.CORE_NODE_NAME_PROP); } else { - coreNodeName = Assign.assignCoreNodeName(stateManager, collection); + replicaName = Assign.assignReplicaName(stateManager, collection); } - Replica replica = new Replica(coreNodeName, + Replica replica = new Replica(replicaName, makeMap( ZkStateReader.CORE_NAME_PROP, message.getStr(ZkStateReader.CORE_NAME_PROP), ZkStateReader.STATE_PROP, message.getStr(ZkStateReader.STATE_PROP), @@ -287,10 +287,10 @@ public ZkWriteCommand removeRoutingRule(final ClusterState clusterState, ZkNodeP return ZkStateWriter.NO_OP; } - public static DocCollection updateReplica(DocCollection collection, final Slice slice, String coreNodeName, final Replica replica) { + public static DocCollection updateReplica(DocCollection collection, final Slice slice, String replicaName, final Replica replica) { Map replicasCopy = slice.getReplicasCopy(); if (replica == null) { - replicasCopy.remove(coreNodeName); + replicasCopy.remove(replicaName); } else { replicasCopy.put(replica.getName(), replica); } diff --git a/solr/core/src/java/org/apache/solr/core/CloudConfig.java b/solr/core/src/java/org/apache/solr/core/CloudConfig.java index c8efbbb04614..3af488873a65 100644 --- a/solr/core/src/java/org/apache/solr/core/CloudConfig.java +++ b/solr/core/src/java/org/apache/solr/core/CloudConfig.java @@ -109,7 +109,7 @@ public int getLeaderConflictResolveWait() { return leaderConflictResolveWait; } - public boolean getGenericCoreNodeNames() { + public boolean getGenericReplicaNames() { return useGenericCoreNames; } diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index d8a6a33ed43f..94650d6c56a7 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -1306,10 +1306,10 @@ public SolrCore create(String coreName, Path instancePath, Map p boolean preExisitingZkEntry = false; try { if (getZkController() != null) { - if (cd.getCloudDescriptor().getCoreNodeName() == null) { + if (cd.getCloudDescriptor().getReplicaName() == null) { throw new SolrException(ErrorCode.SERVER_ERROR, "coreNodeName missing " + parameters.toString()); } - preExisitingZkEntry = getZkController().checkIfCoreNodeNameAlreadyExists(cd); + preExisitingZkEntry = getZkController().checkIfReplicaNameAlreadyExists(cd); } // Much of the logic in core handling pre-supposes that the core.properties file already exists, so create it @@ -1527,7 +1527,7 @@ private SolrCore processCoreCreateException(SolrException original, CoreDescript log.info("Found active leader, will attempt to create fresh core and recover."); resetIndexDirectory(dcore, coreConfig); // the index of this core is emptied, its term should be set to 0 - getZkController().getShardTerms(desc.getCollectionName(), desc.getShardId()).setTermToZero(desc.getCoreNodeName()); + getZkController().getShardTerms(desc.getCollectionName(), desc.getShardId()).setTermToZero(desc.getReplicaName()); return new SolrCore(this, dcore, coreConfig); } } catch (SolrException se) { @@ -1739,7 +1739,7 @@ public void reload(String name, UUID coreId) { if (docCollection != null) { - Replica replica = docCollection.getReplica(cd.getCloudDescriptor().getCoreNodeName()); + Replica replica = docCollection.getReplica(cd.getCloudDescriptor().getReplicaName()); assert replica != null; if (replica.getType() == Replica.Type.TLOG) { // TODO: needed here? getZkController().stopReplicationFromLeader(core.getName()); diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java index 033f2590bd4a..35f0dff3ed15 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java +++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java @@ -35,10 +35,13 @@ import org.apache.solr.cloud.CloudDescriptor; import org.apache.solr.cloud.ZkController; import org.apache.solr.common.SolrException; +import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.util.PropertiesUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.solr.common.params.CommonParams.REPLICA_NAME; + /** * Metadata about a {@link SolrCore}. * It's mostly loaded from a file on disk at the very beginning of loading a core. @@ -61,7 +64,8 @@ public class CoreDescriptor { public static final String CORE_PROPERTIES = "properties"; public static final String CORE_LOADONSTARTUP = "loadOnStartup"; public static final String CORE_TRANSIENT = "transient"; - public static final String CORE_NODE_NAME = "coreNodeName"; + @Deprecated + public static final String CORE_NODE_NAME = REPLICA_NAME; public static final String CORE_CONFIGSET = "configSet"; public static final String CORE_CONFIGSET_PROPERTIES = "configSetProperties"; public static final String SOLR_CORE_PROP_PREFIX = "solr.core."; @@ -120,7 +124,7 @@ public Properties getPersistableUserProperties() { CORE_SHARD, CORE_COLLECTION, CORE_ROLES, - CORE_NODE_NAME, + REPLICA_NAME, CloudDescriptor.NUM_SHARDS ); diff --git a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java index 6b776177d47a..688f1cedff90 100644 --- a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java @@ -413,7 +413,7 @@ public String getDataHome(CoreDescriptor cd) throws IOException { path = URLEncoder.encode(cd.getCloudDescriptor().getCollectionName(), "UTF-8") + "/" - + URLEncoder.encode(cd.getCloudDescriptor().getCoreNodeName(), + + URLEncoder.encode(cd.getCloudDescriptor().getReplicaName(), "UTF-8"); } else { path = cd.getName(); diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java index 66d195c0a122..f9af65128dd6 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -372,7 +372,7 @@ IndexFetchResult fetchLatestIndex(boolean forceReplication, boolean forceCoreRel assert !solrCore.isClosed(): "Replication should be stopped before closing the core"; Replica replica = getLeaderReplica(); CloudDescriptor cd = solrCore.getCoreDescriptor().getCloudDescriptor(); - if (cd.getCoreNodeName().equals(replica.getName())) { + if (cd.getReplicaName().equals(replica.getName())) { return IndexFetchResult.EXPECTING_NON_LEADER; } if (replica.getState() != Replica.State.ACTIVE) { diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java index 0ef3ebbd999d..96e78cef5159 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java @@ -35,10 +35,7 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.ZkStateReader; -import org.apache.solr.common.params.CommonAdminParams; -import org.apache.solr.common.params.CoreAdminParams; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.common.params.SolrParams; +import org.apache.solr.common.params.*; import org.apache.solr.common.util.ExecutorUtil; import org.apache.solr.common.util.NamedList; import org.apache.solr.core.CoreContainer; @@ -57,6 +54,7 @@ import org.slf4j.LoggerFactory; import org.slf4j.MDC; +import static org.apache.solr.common.params.CommonParams.REPLICA_NAME; import static org.apache.solr.common.params.CoreAdminParams.ACTION; import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.STATUS; import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM; @@ -233,7 +231,7 @@ protected void handleCustomAction(SolrQueryRequest req, SolrQueryResponse rsp) { .put(CoreAdminParams.SHARD, CoreDescriptor.CORE_SHARD) .put(CoreAdminParams.COLLECTION, CoreDescriptor.CORE_COLLECTION) .put(CoreAdminParams.ROLES, CoreDescriptor.CORE_ROLES) - .put(CoreAdminParams.CORE_NODE_NAME, CoreDescriptor.CORE_NODE_NAME) + .put(REPLICA_NAME, REPLICA_NAME) .put(ZkStateReader.NUM_SHARDS_PROP, CloudDescriptor.NUM_SHARDS) .put(CoreAdminParams.REPLICA_TYPE, CloudDescriptor.REPLICA_TYPE) .build(); diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java index 4f09c8513da6..fc5e6a90295f 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java @@ -338,7 +338,7 @@ static NamedList getCoreStatus(CoreContainer cores, String cname, boolea SimpleOrderedMap cloudInfo = new SimpleOrderedMap<>(); cloudInfo.add(COLLECTION, core.getCoreDescriptor().getCloudDescriptor().getCollectionName()); cloudInfo.add(SHARD, core.getCoreDescriptor().getCloudDescriptor().getShardId()); - cloudInfo.add(REPLICA, core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName()); + cloudInfo.add(REPLICA, core.getCoreDescriptor().getCloudDescriptor().getReplicaName()); cloudInfo.add(REPLICA_TYPE, core.getCoreDescriptor().getCloudDescriptor().getReplicaType().name()); info.add("cloud", cloudInfo); } diff --git a/solr/core/src/java/org/apache/solr/handler/admin/PrepRecoveryOp.java b/solr/core/src/java/org/apache/solr/handler/admin/PrepRecoveryOp.java index 15be7463369b..2f5ef74a55b1 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/PrepRecoveryOp.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/PrepRecoveryOp.java @@ -30,6 +30,7 @@ import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; import org.apache.solr.common.cloud.ZkStateReader; +import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CoreAdminParams; import org.apache.solr.common.params.SolrParams; import org.apache.solr.core.CoreContainer; @@ -39,6 +40,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.solr.common.params.CommonParams.REPLICA_NAME; + class PrepRecoveryOp implements CoreAdminHandler.CoreAdminOp { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -52,7 +55,7 @@ public void execute(CallInfo it) throws Exception { String cname = params.get(CoreAdminParams.CORE, ""); String nodeName = params.get("nodeName"); - String coreNodeName = params.get("coreNodeName"); + String replicaName = params.get(REPLICA_NAME); Replica.State waitForState = Replica.State.getState(params.get(ZkStateReader.STATE_PROP)); Boolean checkLive = params.getBool("checkLive"); Boolean onlyIfLeader = params.getBool("onlyIfLeader"); @@ -62,8 +65,8 @@ public void execute(CallInfo it) throws Exception { // wait long enough for the leader conflict to work itself out plus a little extra int conflictWaitMs = coreContainer.getZkController().getLeaderConflictResolveWait(); log.info( - "Going to wait for coreNodeName: {}, state: {}, checkLive: {}, onlyIfLeader: {}, onlyIfLeaderActive: {}", - coreNodeName, waitForState, checkLive, onlyIfLeader, onlyIfLeaderActive); + "Going to wait for replicaName: {}, state: {}, checkLive: {}, onlyIfLeader: {}, onlyIfLeaderActive: {}", + replicaName, waitForState, checkLive, onlyIfLeader, onlyIfLeaderActive); String collectionName; CloudDescriptor cloudDescriptor; @@ -94,7 +97,7 @@ public void execute(CallInfo it) throws Exception { boolean live = false; Slice slice = c.getSlice(cloudDescriptor.getShardId()); if (slice != null) { - final Replica replica = slice.getReplicasMap().get(coreNodeName); + final Replica replica = slice.getReplicasMap().get(replicaName); if (replica != null) { state = replica.getState(); live = n.contains(nodeName); @@ -117,8 +120,8 @@ public void execute(CallInfo it) throws Exception { ZkShardTerms shardTerms = coreContainer.getZkController().getShardTerms(collectionName, slice.getName()); // if the replica is waiting for leader to see recovery state, the leader should refresh its terms - if (waitForState == Replica.State.RECOVERING && shardTerms.registered(coreNodeName) - && shardTerms.skipSendingUpdatesTo(coreNodeName)) { + if (waitForState == Replica.State.RECOVERING && shardTerms.registered(replicaName) + && shardTerms.skipSendingUpdatesTo(replicaName)) { // The replica changed it term, then published itself as RECOVERING. // This core already see replica as RECOVERING // so it is guarantees that a live-fetch will be enough for this core to see max term published @@ -134,7 +137,7 @@ public void execute(CallInfo it) throws Exception { ", isLeader? " + cloudDescriptor.isLeader() + ", live=" + live + ", checkLive=" + checkLive + ", currentState=" + state + ", localState=" + localState + ", nodeName=" + nodeName + - ", coreNodeName=" + coreNodeName + ", onlyIfActiveCheckResult=" + onlyIfActiveCheckResult + ", replicaName=" + replicaName + ", onlyIfActiveCheckResult=" + onlyIfActiveCheckResult + ", nodeProps: " + replica); //nowarn } if (!onlyIfActiveCheckResult && replica != null && (state == waitForState || leaderDoesNotNeedRecovery)) { diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java index ad1483726f8d..d44eabb1b0b3 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java @@ -126,7 +126,7 @@ public void process(ResponseBuilder rb) throws IOException if (replicaType == Replica.Type.PULL) { throw new SolrException(ErrorCode.BAD_REQUEST, String.format(Locale.ROOT, "%s can't handle realtime get requests. Replicas of type %s do not support these type of requests", - cloudDesc.getCoreNodeName(), + cloudDesc.getReplicaName(), Replica.Type.PULL)); } // non-leader TLOG replicas should not respond to distrib /get requests, but internal requests are OK diff --git a/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java b/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java index 492735be6e7a..677d8c6b902c 100644 --- a/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java +++ b/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java @@ -138,7 +138,7 @@ public static void setCoreDescriptor(CoreContainer coreContainer, CoreDescriptor if (ccd != null) { setCollection(ccd.getCollectionName()); setShard(ccd.getShardId()); - setReplica(ccd.getCoreNodeName()); + setReplica(ccd.getReplicaName()); } } } diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java b/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java index f05889c88031..39b460a7f8b3 100644 --- a/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java +++ b/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java @@ -63,11 +63,11 @@ private void initCloudMode() { cloudMode = true; collectionName = core.getCoreDescriptor().getCollectionName(); shardName = cd.getShardId(); - //replicaName = cd.getCoreNodeName(); + //replicaName = cd.getReplicaName(); String coreName = core.getName(); replicaName = Utils.parseMetricsReplicaName(collectionName, coreName); if (replicaName == null) { - replicaName = cd.getCoreNodeName(); + replicaName = cd.getReplicaName(); } } } diff --git a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java index 8791160e9663..734258f821fe 100644 --- a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java +++ b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java @@ -136,8 +136,8 @@ public void init(PluginInfo pluginInfo, SolrCore core) { log.warn("period={}, not starting shard reporter ", period); return; } - // our id is coreNodeName - String id = core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName(); + // our id is replicaName + String id = core.getCoreDescriptor().getCloudDescriptor().getReplicaName(); // target registry is the leaderRegistryName String groupId = core.getCoreMetricManager().getLeaderRegistryName(); if (groupId == null) { 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 ddabd2523635..72a06ddcc36b 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java @@ -222,14 +222,14 @@ boolean persistManagedSchemaToZooKeeper(boolean createOnly) { * Block up to a specified maximum time until we see agreement on the schema * version in ZooKeeper across all replicas for a collection. */ - public static void waitForSchemaZkVersionAgreement(String collection, String localCoreNodeName, + public static void waitForSchemaZkVersionAgreement(String collection, String localReplicaName, int schemaZkVersion, ZkController zkController, int maxWaitSecs) { RTimer timer = new RTimer(); // get a list of active replica cores to query for the schema zk version (skipping this core of course) List concurrentTasks = new ArrayList<>(); - for (String coreUrl : getActiveReplicaCoreUrls(zkController, collection, localCoreNodeName)) + for (String coreUrl : getActiveReplicaCoreUrls(zkController, collection, localReplicaName)) concurrentTasks.add(new GetZkSchemaVersionCallable(coreUrl, schemaZkVersion)); if (concurrentTasks.isEmpty()) return; // nothing to wait for ... @@ -278,7 +278,7 @@ public static void waitForSchemaZkVersionAgreement(String collection, String loc } catch (InterruptedException ie) { log.warn("Core {} was interrupted waiting for schema version {} to propagate to {} replicas for collection {}" - , localCoreNodeName, schemaZkVersion, concurrentTasks.size(), collection); + , localReplicaName, schemaZkVersion, concurrentTasks.size(), collection); Thread.currentThread().interrupt(); } finally { if (!parallelExecutor.isShutdown()) @@ -291,7 +291,7 @@ public static void waitForSchemaZkVersionAgreement(String collection, String loc } } - protected static List getActiveReplicaCoreUrls(ZkController zkController, String collection, String localCoreNodeName) { + protected static List getActiveReplicaCoreUrls(ZkController zkController, String collection, String localReplicaName) { List activeReplicaCoreUrls = new ArrayList<>(); ZkStateReader zkStateReader = zkController.getZkStateReader(); ClusterState clusterState = zkStateReader.getClusterState(); @@ -304,7 +304,7 @@ protected static List getActiveReplicaCoreUrls(ZkController zkController if (replicasMap != null) { for (Map.Entry entry : replicasMap.entrySet()) { Replica replica = entry.getValue(); - if (!localCoreNodeName.equals(replica.getName()) && + if (!localReplicaName.equals(replica.getName()) && replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) { ZkCoreNodeProps replicaCoreProps = new ZkCoreNodeProps(replica); 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 fe2db9a62eb8..c0f6d3c8583e 100644 --- a/solr/core/src/java/org/apache/solr/schema/SchemaManager.java +++ b/solr/core/src/java/org/apache/solr/schema/SchemaManager.java @@ -172,7 +172,7 @@ private void waitForOtherReplicasToUpdate(TimeOut timeOut, int latestVersion) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Not enough time left to update replicas. However, the schema is updated already."); } - ManagedIndexSchema.waitForSchemaZkVersionAgreement(collection, cd.getCloudDescriptor().getCoreNodeName(), + ManagedIndexSchema.waitForSchemaZkVersionAgreement(collection, cd.getCloudDescriptor().getReplicaName(), latestVersion, core.getCoreContainer().getZkController(), (int) timeOut.timeLeft(TimeUnit.SECONDS)); } } 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 aa7c61e58626..88cb404a554b 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 @@ -79,7 +79,7 @@ public class DistributedZkUpdateProcessor extends DistributedUpdateProcessor { private final ZkController zkController; private final SolrCmdDistributor cmdDistrib; protected List nodes; - private Set skippedCoreNodeNames; + private Set skippedReplicaNames; private final String collection; private boolean readOnlyCollection = false; @@ -168,7 +168,7 @@ public void processCommit(CommitUpdateCommand cmd) throws IOException { Thread.interrupted(); throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Exception finding leader for shard " + cloudDesc.getShardId(), e); } - isLeader = leaderReplica.getName().equals(cloudDesc.getCoreNodeName()); + isLeader = leaderReplica.getName().equals(cloudDesc.getReplicaName()); nodes = getCollectionUrls(collection, EnumSet.of(Replica.Type.TLOG,Replica.Type.NRT), true); if (nodes == null) { @@ -405,9 +405,9 @@ protected void doDeleteByQuery(DeleteUpdateCommand cmd) throws IOException { // Am I the leader for this slice? ZkCoreNodeProps coreLeaderProps = new ZkCoreNodeProps(leader); - String leaderCoreNodeName = leader.getName(); - String coreNodeName = cloudDesc.getCoreNodeName(); - isLeader = coreNodeName.equals(leaderCoreNodeName); + String leaderReplicaName = leader.getName(); + String replicaName = cloudDesc.getReplicaName(); + isLeader = replicaName.equals(leaderReplicaName); if (isLeader) { // don't forward to ourself @@ -516,7 +516,7 @@ private List setupRequestForDBQ() { try { Replica leaderReplica = zkController.getZkStateReader().getLeaderRetry(collection, shardId); - isLeader = leaderReplica.getName().equals(cloudDesc.getCoreNodeName()); + isLeader = leaderReplica.getName().equals(cloudDesc.getReplicaName()); // TODO: what if we are no longer the leader? @@ -628,7 +628,7 @@ protected List setupRequest(String id, SolrInputDocumen // Not equivalent to getLeaderProps, which retries to find a leader. // Replica leader = slice.getLeader(); Replica leaderReplica = zkController.getZkStateReader().getLeaderRetry(collection, shardId); - isLeader = leaderReplica.getName().equals(cloudDesc.getCoreNodeName()); + isLeader = leaderReplica.getName().equals(cloudDesc.getReplicaName()); if (!isLeader) { isSubShardLeader = amISubShardLeader(coll, slice, id, doc); @@ -652,11 +652,11 @@ protected List setupRequest(String id, SolrInputDocumen // that means I want to forward onto my replicas... // so get the replicas... forwardToLeader = false; - String leaderCoreNodeName = leaderReplica.getName(); + String leaderReplicaName = leaderReplica.getName(); List replicas = clusterState.getCollection(collection) .getSlice(shardId) .getReplicas(EnumSet.of(Replica.Type.NRT, Replica.Type.TLOG)); - replicas.removeIf((replica) -> replica.getName().equals(leaderCoreNodeName)); + replicas.removeIf((replica) -> replica.getName().equals(leaderReplicaName)); if (replicas.isEmpty()) { return null; } @@ -671,21 +671,21 @@ protected List setupRequest(String id, SolrInputDocumen } List nodes = new ArrayList<>(replicas.size()); - skippedCoreNodeNames = new HashSet<>(); + skippedReplicaNames = new HashSet<>(); ZkShardTerms zkShardTerms = zkController.getShardTerms(collection, shardId); for (Replica replica: replicas) { - String coreNodeName = replica.getName(); + String replicaName = replica.getName(); if (skipList != null && skipListSet.contains(replica.getCoreUrl())) { if (log.isInfoEnabled()) { log.info("check url:{} against:{} result:true", replica.getCoreUrl(), skipListSet); } - } else if(zkShardTerms.registered(coreNodeName) && zkShardTerms.skipSendingUpdatesTo(coreNodeName)) { + } else if(zkShardTerms.registered(replicaName) && zkShardTerms.skipSendingUpdatesTo(replicaName)) { if (log.isDebugEnabled()) { log.debug("skip url:{} cause its term is less than leader", replica.getCoreUrl()); } - skippedCoreNodeNames.add(replica.getName()); + skippedReplicaNames.add(replica.getName()); } else if (!clusterState.getLiveNodes().contains(replica.getNodeName()) || replica.getState() == Replica.State.DOWN) { - skippedCoreNodeNames.add(replica.getName()); + skippedReplicaNames.add(replica.getName()); } else { nodes.add(new SolrCmdDistributor.StdNode(new ZkCoreNodeProps(replica), collection, shardId, maxRetriesToFollowers)); } @@ -790,7 +790,7 @@ protected boolean amISubShardLeader(DocCollection coll, Slice parentSlice, Strin final Slice.State state = mySlice.getState(); if (state == Slice.State.CONSTRUCTION || state == Slice.State.RECOVERY) { Replica myLeader = zkController.getZkStateReader().getLeaderRetry(collection, myShardId); - boolean amILeader = myLeader.getName().equals(cloudDesc.getCoreNodeName()); + boolean amILeader = myLeader.getName().equals(cloudDesc.getReplicaName()); if (amILeader) { // Does the document belong to my hash range as well? DocRouter.Range myRange = mySlice.getRange(); @@ -808,11 +808,11 @@ protected boolean amISubShardLeader(DocCollection coll, Slice parentSlice, Strin } protected List getReplicaNodesForLeader(String shardId, Replica leaderReplica) { - String leaderCoreNodeName = leaderReplica.getName(); + String leaderReplicaName = leaderReplica.getName(); List replicas = clusterState.getCollection(collection) .getSlice(shardId) .getReplicas(EnumSet.of(Replica.Type.NRT, Replica.Type.TLOG)); - replicas.removeIf((replica) -> replica.getName().equals(leaderCoreNodeName)); + replicas.removeIf((replica) -> replica.getName().equals(leaderReplicaName)); if (replicas.isEmpty()) { return null; } @@ -827,22 +827,22 @@ protected List getReplicaNodesForLeader(String shardId, } List nodes = new ArrayList<>(replicas.size()); - skippedCoreNodeNames = new HashSet<>(); + skippedReplicaNames = new HashSet<>(); ZkShardTerms zkShardTerms = zkController.getShardTerms(collection, shardId); for (Replica replica : replicas) { - String coreNodeName = replica.getName(); + String replicaName = replica.getName(); if (skipList != null && skipListSet.contains(replica.getCoreUrl())) { if (log.isInfoEnabled()) { log.info("check url:{} against:{} result:true", replica.getCoreUrl(), skipListSet); } - } else if (zkShardTerms.registered(coreNodeName) && zkShardTerms.skipSendingUpdatesTo(coreNodeName)) { + } else if (zkShardTerms.registered(replicaName) && zkShardTerms.skipSendingUpdatesTo(replicaName)) { if (log.isDebugEnabled()) { log.debug("skip url:{} cause its term is less than leader", replica.getCoreUrl()); } - skippedCoreNodeNames.add(replica.getName()); + skippedReplicaNames.add(replica.getName()); } else if (!clusterState.getLiveNodes().contains(replica.getNodeName()) || replica.getState() == Replica.State.DOWN) { - skippedCoreNodeNames.add(replica.getName()); + skippedReplicaNames.add(replica.getName()); } else { nodes.add(new SolrCmdDistributor.StdNode(new ZkCoreNodeProps(replica), collection, shardId)); } @@ -1046,8 +1046,8 @@ protected void doDistribFinish() { boolean shouldUpdateTerms = isLeader && isIndexChanged; if (shouldUpdateTerms) { ZkShardTerms zkShardTerms = zkController.getShardTerms(cloudDesc.getCollectionName(), cloudDesc.getShardId()); - if (skippedCoreNodeNames != null) { - zkShardTerms.ensureTermsIsHigher(cloudDesc.getCoreNodeName(), skippedCoreNodeNames); + if (skippedReplicaNames != null) { + zkShardTerms.ensureTermsIsHigher(cloudDesc.getReplicaName(), skippedReplicaNames); } zkController.getShardTerms(collection, cloudDesc.getShardId()).ensureHighestTermsAreNotZero(); } @@ -1096,7 +1096,7 @@ protected void doDistribFinish() { if ("LeaderChanged".equals(cause)) { // let's just fail this request and let the client retry? or just call processAdd again? log.error("On {}, replica {} now thinks it is the leader! Failing the request to let the client retry!" - , cloudDesc.getCoreNodeName(), replicaUrl, error.e); + , cloudDesc.getReplicaName(), replicaUrl, error.e); errorsForClient.add(error); continue; } @@ -1110,24 +1110,24 @@ protected void doDistribFinish() { shardId = stdNode.getShardId(); // before we go setting other replicas to down, make sure we're still the leader! - String leaderCoreNodeName = null; + String leaderReplicaName = null; Exception getLeaderExc = null; Replica leaderProps = null; try { leaderProps = zkController.getZkStateReader().getLeader(collection, shardId); if (leaderProps != null) { - leaderCoreNodeName = leaderProps.getName(); + leaderReplicaName = leaderProps.getName(); } } catch (Exception exc) { getLeaderExc = exc; } - if (leaderCoreNodeName == null) { + if (leaderReplicaName == null) { log.warn("Failed to determine if {} is still the leader for collection={} shardId={} before putting {} into leader-initiated recovery", - cloudDesc.getCoreNodeName(), collection, shardId, replicaUrl, getLeaderExc); + cloudDesc.getReplicaName(), collection, shardId, replicaUrl, getLeaderExc); } List myReplicas = zkController.getZkStateReader().getReplicaProps(collection, - cloudDesc.getShardId(), cloudDesc.getCoreNodeName()); + cloudDesc.getShardId(), cloudDesc.getReplicaName()); boolean foundErrorNodeInReplicaList = false; if (myReplicas != null) { for (ZkCoreNodeProps replicaProp : myReplicas) { @@ -1138,16 +1138,16 @@ protected void doDistribFinish() { } } - if (leaderCoreNodeName != null && cloudDesc.getCoreNodeName().equals(leaderCoreNodeName) // we are still same leader + if (leaderReplicaName != null && cloudDesc.getCoreNodeName().equals(leaderReplicaName) // we are still same leader && foundErrorNodeInReplicaList // we found an error for one of replicas && !stdNode.getNodeProps().getCoreUrl().equals(leaderProps.getCoreUrl())) { // we do not want to put ourself into LIR try { - String coreNodeName = ((Replica) stdNode.getNodeProps().getNodeProps()).getName(); + String replicaName = ((Replica) stdNode.getNodeProps().getNodeProps()).getName(); // if false, then the node is probably not "live" anymore // and we do not need to send a recovery message Throwable rootCause = SolrException.getRootCause(error.e); - log.error("Setting up to try to start recovery on replica {} with url {} by increasing leader term", coreNodeName, replicaUrl, rootCause); - replicasShouldBeInLowerTerms.add(coreNodeName); + log.error("Setting up to try to start recovery on replica {} with url {} by increasing leader term", replicaName, replicaUrl, rootCause); + replicasShouldBeInLowerTerms.add(replicaName); } catch (Exception exc) { Throwable setLirZnodeFailedCause = SolrException.getRootCause(exc); log.error("Leader failed to set replica {} state to DOWN due to: {}" @@ -1157,7 +1157,7 @@ protected void doDistribFinish() { // not the leader anymore maybe or the error'd node is not my replica? if (!foundErrorNodeInReplicaList) { log.warn("Core {} belonging to {} {}, does not have error'd node {} as a replica. No request recovery command will be sent!" - , cloudDesc.getCoreNodeName(), collection, cloudDesc.getShardId(), stdNode.getNodeProps().getCoreUrl()); + , cloudDesc.getReplicaName(), collection, cloudDesc.getShardId(), stdNode.getNodeProps().getCoreUrl()); if (!shardId.equals(cloudDesc.getShardId())) { // some replicas on other shard did not receive the updates (ex: during splitshard), // exception must be notified to clients @@ -1165,14 +1165,14 @@ protected void doDistribFinish() { } } else { log.warn("Core {} is no longer the leader for {} {} or we tried to put ourself into LIR, no request recovery command will be sent!" - , cloudDesc.getCoreNodeName(), collection, shardId); + , cloudDesc.getReplicaName(), collection, shardId); } } } } if (!replicasShouldBeInLowerTerms.isEmpty()) { zkController.getShardTerms(cloudDesc.getCollectionName(), cloudDesc.getShardId()) - .ensureTermsIsHigher(cloudDesc.getCoreNodeName(), replicasShouldBeInLowerTerms); + .ensureTermsIsHigher(cloudDesc.getReplicaName(), replicasShouldBeInLowerTerms); } handleReplicationFactor(); if (0 < errorsForClient.size()) { diff --git a/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java index 90edc57081a4..e7c69eb3c6c0 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java @@ -492,9 +492,9 @@ private boolean iAmInChargeOfPeriodicDeletes() { return false; } String leaderInCharge = firstSliceLeader.getName(); - String myCoreNodeName = desc.getCoreNodeName(); + String myReplicaName = desc.getReplicaName(); - boolean inChargeOfDeletesRightNow = leaderInCharge.equals(myCoreNodeName); + boolean inChargeOfDeletesRightNow = leaderInCharge.equals(myReplicaName); if (previouslyInChargeOfDeletes && ! inChargeOfDeletesRightNow) { // don't spam the logs constantly, just log when we know that we're not the guy diff --git a/solr/core/src/java/org/apache/solr/update/processor/ScriptEngineCustomizer.java b/solr/core/src/java/org/apache/solr/update/processor/ScriptEngineCustomizer.java deleted file mode 100644 index f230526b624a..000000000000 --- a/solr/core/src/java/org/apache/solr/update/processor/ScriptEngineCustomizer.java +++ /dev/null @@ -1,28 +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.update.processor; - -import javax.script.ScriptEngine; - -/** - * Enables customization of a script engine. Will mostly be used to register engine scoped variables. - */ -public interface ScriptEngineCustomizer { - - void customize(ScriptEngine engine); - -} diff --git a/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java deleted file mode 100644 index d2f5a07173fb..000000000000 --- a/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java +++ /dev/null @@ -1,529 +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.update.processor; - -import org.apache.solr.common.SolrException; -import org.apache.solr.common.SolrException.ErrorCode; -import org.apache.solr.common.util.NamedList; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.core.SolrCore; -import org.apache.solr.core.SolrResourceLoader; -import org.apache.solr.request.SolrQueryRequest; -import org.apache.solr.request.LocalSolrQueryRequest; -import org.apache.solr.response.SolrQueryResponse; -import org.apache.solr.update.*; -import org.apache.solr.util.plugin.SolrCoreAware; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.FilenameUtils; - -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptEngineFactory; -import javax.script.ScriptException; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.lang.invoke.MethodHandles; -import java.nio.charset.StandardCharsets; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.security.ProtectionDomain; -import java.util.Set; -import java.util.LinkedHashSet; -import java.util.ArrayList; -import java.util.List; -import java.util.Collection; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - *

- * An update request processor factory that enables the use of update - * processors implemented as scripts which can be loaded by the - * {@link SolrResourceLoader} (usually via the conf dir for - * the SolrCore). - *

- *

- * This factory requires at least one configuration parameter named - * script which may be the name of a script file as a string, - * or an array of multiple script files. If multiple script files are - * specified, they are executed sequentially in the order specified in the - * configuration -- as if multiple factories were configured sequentially - *

- *

- * Each script file is expected to declare functions with the same name - * as each method in {@link UpdateRequestProcessor}, using the same - * arguments. One slight deviation is in the optional return value from - * these functions: If a script function has a boolean return - * value, and that value is false then the processor will - * cleanly terminate processing of the command and return, without forwarding - * the command on to the next script or processor in the chain. - * Due to limitations in the {@link ScriptEngine} API used by - * this factory, it can not enforce that all functions exist on initialization, - * so errors from missing functions will only be generated at runtime when - * the chain attempts to use them. - *

- *

- * The factory may also be configured with an optional "params" argument, - * which can be an {@link NamedList} (or array, or any other simple Java - * object) which will be put into the global scope for each script. - *

- *

- * The following variables are define as global variables for each script: - *

    - *
  • req - The {@link SolrQueryRequest}
  • - *
  • rsp - The {@link SolrQueryResponse}
  • - *
  • logger - A {@link Logger} that can be used for logging purposes in the script
  • - *
  • params - The "params" init argument in the factory configuration (if any)
  • - *
- *

- * Internally this update processor uses JDK 6 scripting engine support, - * and any {@link Invocable} implementations of ScriptEngine - * that can be loaded using the Solr Plugin ClassLoader may be used. - * By default, the engine used for each script is determined by the filed - * extension (ie: a *.js file will be treated as a JavaScript script) but - * this can be overridden by specifying an explicit "engine" name init - * param for the factory, which identifies a registered name of a - * {@link ScriptEngineFactory}. - * (This may be particularly useful if multiple engines are available for - * the same scripting language, and you wish to force the usage of a - * particular engine because of known quirks) - *

- *

- * A new {@link ScriptEngineManager} is created for each - * SolrQueryRequest defining a "global" scope for the script(s) - * which is request specific. Separate ScriptEngine instances - * are then used to evaluate the script files, resulting in an "engine" scope - * that is specific to each script. - *

- *

- * A simple example... - *

- *
- * <processor class="solr.StatelessScriptUpdateProcessorFactory">
- *   <str name="script">updateProcessor.js</str>
- * </processor>
- * 
- *

- * A more complex example involving multiple scripts in different languages, - * and a "params" NamedList that will be put into the global - * scope of each script... - *

- *
- * <processor class="solr.StatelessScriptUpdateProcessorFactory">
- *   <arr name="script">
- *     <str name="script">first-processor.js</str>
- *     <str name="script">second-processor.py</str>
- *   </arr>
- *   <lst name="params">
- *     <bool name="a_bool_value">true</bool>
- *     <int name="and_int_value">3</int>
- *   </lst>
- * </processor>
- * 
- *

- * An example where the script file extensions are ignored, and an - * explicit script engine is used.... - *

- *
- * <processor class="solr.StatelessScriptUpdateProcessorFactory">
- *   <arr name="script">
- *     <str name="script">first-processor.txt</str>
- *     <str name="script">second-processor.txt</str>
- *   </arr>
- *   <str name="engine">rhino</str>
- * </processor>
- * 
- * - * @since 4.0.0 - */ -public class StatelessScriptUpdateProcessorFactory extends UpdateRequestProcessorFactory implements SolrCoreAware { - - private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - private final static String SCRIPT_ARG = "script"; - private final static String PARAMS_ARG = "params"; - private final static String ENGINE_NAME_ARG = "engine"; - - private List scriptFiles; - - /** if non null, this is an override for the engine for all scripts */ - private String engineName = null; - - private Object params = null; - - private SolrResourceLoader resourceLoader; - - private ScriptEngineCustomizer scriptEngineCustomizer; - - @Override - public void init(@SuppressWarnings({"rawtypes"})NamedList args) { - @SuppressWarnings({"unchecked"}) - Collection scripts = - args.removeConfigArgs(SCRIPT_ARG); - if (scripts.isEmpty()) { - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, - "StatelessScriptUpdateProcessorFactory must be " + - "initialized with at least one " + SCRIPT_ARG); - } - scriptFiles = new ArrayList<>(); - for (String script : scripts) { - scriptFiles.add(new ScriptFile(script)); - } - - params = args.remove(PARAMS_ARG); - - Object engine = args.remove(ENGINE_NAME_ARG); - if (engine != null) { - if (engine instanceof String) { - engineName = (String)engine; - } else { - throw new SolrException - (SolrException.ErrorCode.SERVER_ERROR, - "'" + ENGINE_NAME_ARG + "' init param must be a String (found: " + - engine.getClass() + ")"); - } - } - - super.init(args); - - } - - @Override - public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) { - List scriptEngines = null; - - scriptEngines = initEngines(req, rsp); - - return new ScriptUpdateProcessor(req, rsp, scriptEngines, next); - } - - // TODO: Make this useful outside of tests, such that a ScriptEngineCustomizer could be looked up through the resource loader - void setScriptEngineCustomizer(ScriptEngineCustomizer scriptEngineCustomizer) { - this.scriptEngineCustomizer = scriptEngineCustomizer; - } - - @Override - public void inform(SolrCore core) { - if (!core.getCoreDescriptor().isConfigSetTrusted()) { - throw new SolrException(ErrorCode.UNAUTHORIZED, "The configset for this collection was uploaded without any authentication in place," - + " and this operation is not available for collections with untrusted configsets. To use this component, re-upload the configset" - + " after enabling authentication and authorization."); - } - resourceLoader = core.getResourceLoader(); - - // test that our engines & scripts are valid - - SolrQueryResponse rsp = new SolrQueryResponse(); - SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams()); - try { - initEngines(req, rsp); - } catch (Exception e) { - String msg = "Unable to initialize scripts: " + e.getMessage(); - log.error(msg, e); - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg, e); - } finally { - req.close(); - } - - - } - - - //================================================ Helper Methods ================================================== - - /** - * Initializes a list of script engines - an engine per script file. - * - * @param req The solr request. - * @param rsp The solr response - * @return The list of initialized script engines. - */ - private List initEngines(SolrQueryRequest req, - SolrQueryResponse rsp) - throws SolrException { - - List scriptEngines = new ArrayList<>(); - - ScriptEngineManager scriptEngineManager - = new ScriptEngineManager(resourceLoader.getClassLoader()); - - scriptEngineManager.put("logger", log); - scriptEngineManager.put("req", req); - scriptEngineManager.put("rsp", rsp); - if (params != null) { - scriptEngineManager.put("params", params); - } - - for (ScriptFile scriptFile : scriptFiles) { - final ScriptEngine engine; - if (null != engineName) { - engine = scriptEngineManager.getEngineByName(engineName); - if (engine == null) { - String details = getSupportedEngines(scriptEngineManager, false); - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, - "No ScriptEngine found by name: " - + engineName + - (null != details ? - " -- supported names: " + details : "")); - } - } else { - engine = scriptEngineManager.getEngineByExtension - (scriptFile.getExtension()); - if (engine == null) { - String details = getSupportedEngines(scriptEngineManager, true); - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, - "No ScriptEngine found by file extension: " - + scriptFile.getFileName() + - (null != details ? - " -- supported extensions: " + details : "")); - - } - } - - if (! (engine instanceof Invocable)) { - String msg = - "Engine " + ((null != engineName) ? engineName : - ("for script " + scriptFile.getFileName())) + - " does not support function invocation (via Invocable): " + - engine.getClass().toString() + " (" + - engine.getFactory().getEngineName() + ")"; - log.error(msg); - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg); - } - - if (scriptEngineCustomizer != null) { - scriptEngineCustomizer.customize(engine); - } - - scriptEngines.add(new EngineInfo((Invocable)engine, scriptFile)); - try { - Reader scriptSrc = scriptFile.openReader(resourceLoader); - - try { - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Void run() throws ScriptException { - engine.eval(scriptSrc); - return null; - } - }, SCRIPT_SANDBOX); - } catch (PrivilegedActionException e) { - throw (ScriptException) e.getException(); - } - } catch (ScriptException e) { - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, - "Unable to evaluate script: " + - scriptFile.getFileName(), e); - } finally { - IOUtils.closeQuietly(scriptSrc); - } - } catch (IOException ioe) { - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, - "Unable to evaluate script: " + - scriptFile.getFileName(), ioe); - } - } - return scriptEngines; - } - - /** - * For error messages - returns null if there are any exceptions of any - * kind building the string (or of the list is empty for some unknown reason). - * @param ext - if true, list of extensions, otherwise a list of engine names - */ - private static String getSupportedEngines(ScriptEngineManager mgr, - boolean ext) { - String result = null; - try { - List factories = mgr.getEngineFactories(); - if (null == factories) return result; - - Set engines = new LinkedHashSet<>(factories.size()); - for (ScriptEngineFactory f : factories) { - if (ext) { - engines.addAll(f.getExtensions()); - } else { - engines.addAll(f.getNames()); - } - } - result = String.join(", ", engines); - } catch (RuntimeException e) { - /* :NOOP: */ - } - return result; - } - - - - //================================================= Inner Classes ================================================== - - /** - * The actual update processor. All methods delegate to scripts. - */ - private static class ScriptUpdateProcessor extends UpdateRequestProcessor { - - private List engines; - - private ScriptUpdateProcessor(SolrQueryRequest req, SolrQueryResponse res, List engines, UpdateRequestProcessor next) { - super(next); - this.engines = engines; - } - - @Override - public void processAdd(AddUpdateCommand cmd) throws IOException { - if (invokeFunction("processAdd", cmd)) { - super.processAdd(cmd); - } - } - - @Override - public void processDelete(DeleteUpdateCommand cmd) throws IOException { - if (invokeFunction("processDelete", cmd)) { - super.processDelete(cmd); - } - - } - - @Override - public void processMergeIndexes(MergeIndexesCommand cmd) throws IOException { - if (invokeFunction("processMergeIndexes", cmd)) { - super.processMergeIndexes(cmd); - } - } - - @Override - public void processCommit(CommitUpdateCommand cmd) throws IOException { - if (invokeFunction("processCommit", cmd)) { - super.processCommit(cmd); - } - } - - @Override - public void processRollback(RollbackUpdateCommand cmd) throws IOException { - if (invokeFunction("processRollback", cmd)) { - super.processRollback(cmd); - } - } - - @Override - public void finish() throws IOException { - if (invokeFunction("finish")) { - super.finish(); - } - } - - /** - * returns true if processing should continue, or false if the - * request should be ended now. Result value is computed from the return - * value of the script function if: it exists, is non-null, and can be - * cast to a java Boolean. - */ - private boolean invokeFunction(String name, Object... cmd) { - return AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Boolean run() { - return invokeFunctionUnsafe(name, cmd); - } - }, SCRIPT_SANDBOX); - } - - private boolean invokeFunctionUnsafe(String name, Object... cmd) { - - for (EngineInfo engine : engines) { - try { - Object result = engine.getEngine().invokeFunction(name, cmd); - if (null != result && result instanceof Boolean) { - if (! ((Boolean)result).booleanValue() ) { - return false; - } - } - - } catch (ScriptException | NoSuchMethodException e) { - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, - "Unable to invoke function " + name + - " in script: " + - engine.getScriptFile().getFileName() + - ": " + e.getMessage(), e); - } - } - - return true; - } - } - - /** - * Holds the script engine and its associated script file. - */ - private static class EngineInfo { - - private final Invocable engine; - private final ScriptFile scriptFile; - - private EngineInfo(Invocable engine, ScriptFile scriptFile) { - this.engine = engine; - this.scriptFile = scriptFile; - } - - public Invocable getEngine() { - return engine; - } - - public ScriptFile getScriptFile() { - return scriptFile; - } - } - - /** - * Represents a script file. - */ - private static class ScriptFile { - - private final String fileName; - private final String extension; - - private ScriptFile(String fileName) { - this.fileName = fileName; - this.extension = FilenameUtils.getExtension(fileName); - } - - public String getFileName() { - return fileName; - } - - public String getExtension() { - return extension; - } - - public Reader openReader(SolrResourceLoader resourceLoader) throws IOException { - InputStream input = resourceLoader.openResource(fileName); - return org.apache.lucene.util.IOUtils.getDecodingReader - (input, StandardCharsets.UTF_8); - } - } - - // sandbox for script code: zero permissions - private static final AccessControlContext SCRIPT_SANDBOX = - new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, null) }); -} diff --git a/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java b/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java index 0280eee45337..f60bb05ee050 100644 --- a/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java +++ b/solr/core/src/java/org/apache/solr/util/SolrLogLayout.java @@ -241,7 +241,7 @@ public String _format(LogEvent event) { private Map getReplicaProps(ZkController zkController, SolrCore core) { final String collectionName = core.getCoreDescriptor().getCloudDescriptor().getCollectionName(); DocCollection collection = zkController.getClusterState().getCollectionOrNull(collectionName); - Replica replica = collection.getReplica(zkController.getCoreNodeName(core.getCoreDescriptor())); + Replica replica = collection.getReplica(zkController.getReplicaName(core.getCoreDescriptor())); if (replica != null) { return replica.getProperties(); } diff --git a/solr/core/src/test-files/solr/collection1/conf/addfields.updateprocessor.js b/solr/core/src/test-files/solr/collection1/conf/addfields.updateprocessor.js deleted file mode 100644 index 1b3c9fc2d6e4..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/addfields.updateprocessor.js +++ /dev/null @@ -1,26 +0,0 @@ -function processAdd(cmd) { - // Integer.valueOf is needed here to get a tru java object, because - // all javascript numbers are floating point (ie: java.lang.Double) - cmd.getSolrInputDocument().addField("script_added_i", - java.lang.Integer.valueOf(42)); - cmd.getSolrInputDocument().addField("script_added_d", 42.3); - -} - -// // // - -function processDelete() { - // NOOP -} -function processCommit() { - // NOOP -} -function processRollback() { - // NOOP -} -function processMergeIndexes() { - // NOOP -} -function finish() { - // NOOP -} diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-bogus-scriptengine-name.xml b/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-bogus-scriptengine-name.xml deleted file mode 100644 index ded7416f1adc..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-bogus-scriptengine-name.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - ${tests.luceneMatchVersion:LATEST} - - - - giberish - missleading.extension.updateprocessor.js.txt - - - - - - - diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-invalid-scriptfile.xml b/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-invalid-scriptfile.xml deleted file mode 100644 index 709774d6a22e..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-invalid-scriptfile.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - ${tests.luceneMatchVersion:LATEST} - - - - javascript - - currency.xml - - - - - - - diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-missing-scriptfile.xml b/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-missing-scriptfile.xml deleted file mode 100644 index d13ba0b0ad6c..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/bad-solrconfig-missing-scriptfile.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - ${tests.luceneMatchVersion:LATEST} - - - - a-file-name-that-does-not-exist.js - - - - - - - diff --git a/solr/core/src/test-files/solr/collection1/conf/conditional.updateprocessor.js b/solr/core/src/test-files/solr/collection1/conf/conditional.updateprocessor.js deleted file mode 100644 index 5ec9487c1502..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/conditional.updateprocessor.js +++ /dev/null @@ -1,25 +0,0 @@ -function processAdd(cmd) { - if (req.getParams().getBool("go-for-it",false)) { - cmd.getSolrInputDocument().addField("script_added_s", "i went for it"); - return true; - } - return false; -} - -// // // - -function processDelete() { - // NOOP -} -function processCommit() { - // NOOP -} -function processRollback() { - // NOOP -} -function processMergeIndexes() { - // NOOP -} -function finish() { - // NOOP -} diff --git a/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js b/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js deleted file mode 100644 index 2fcd6c3baf69..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js +++ /dev/null @@ -1,53 +0,0 @@ -function get_class(name) { - var clazz; - try { - // Java8 Nashorn - clazz = eval("Java.type(name).class"); - } catch(e) { - // Java7 Rhino - clazz = eval("Packages."+name); - } - - return clazz; -} - -function processAdd(cmd) { - var doc = cmd.getSolrInputDocument(); - - var analyzer = - req.getCore().getLatestSchema() - .getFieldTypeByName("text") - .getIndexAnalyzer(); - - var token_stream = - analyzer.tokenStream("subject", doc.getFieldValue("subject")); - - var cta_class = get_class("org.apache.lucene.analysis.tokenattributes.CharTermAttribute"); - var term_att = token_stream.getAttribute(cta_class); - token_stream.reset(); - while (token_stream.incrementToken()) { - doc.addField("term_s", term_att.toString()); - } - token_stream.end(); - token_stream.close(); - - return true; -} - -// // // - -function processDelete() { - // NOOP -} -function processCommit() { - // NOOP -} -function processRollback() { - // NOOP -} -function processMergeIndexes() { - // NOOP -} -function finish() { - // NOOP -} diff --git a/solr/core/src/test-files/solr/collection1/conf/evil.js b/solr/core/src/test-files/solr/collection1/conf/evil.js deleted file mode 100644 index d49481481196..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/evil.js +++ /dev/null @@ -1,21 +0,0 @@ -var sys = Packages.java.lang.System; - -function processAdd(cmd) { - sys.getProperty("os.name"); -} - -function processDelete(cmd) { -} - -function processMergeIndexes(cmd) { -} - -function processCommit(cmd) { -} - -function processRollback(cmd) { -} - -function finish() { -} - diff --git a/solr/core/src/test-files/solr/collection1/conf/missing.functions.updateprocessor.js b/solr/core/src/test-files/solr/collection1/conf/missing.functions.updateprocessor.js deleted file mode 100644 index 6e8728a0d771..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/missing.functions.updateprocessor.js +++ /dev/null @@ -1,3 +0,0 @@ -function doSomeStuff() { - return "This script doesn't contain any update processor functions"; -} diff --git a/solr/core/src/test-files/solr/collection1/conf/missleading.extension.updateprocessor.js.txt b/solr/core/src/test-files/solr/collection1/conf/missleading.extension.updateprocessor.js.txt deleted file mode 100644 index 984e1d82f100..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/missleading.extension.updateprocessor.js.txt +++ /dev/null @@ -1,23 +0,0 @@ -function processAdd(cmd) { - // Integer.valueOf is needed here to get a tru java object, because - // all javascript numbers are floating point (ie: java.lang.Double) - cmd.getSolrInputDocument().addField("script_added_i", - java.lang.Integer.valueOf(42)); - cmd.getSolrInputDocument().addField("script_added_d", 42.3); - -} -function processDelete() { - // NOOP -} -function processCommit() { - // NOOP -} -function processRollback() { - // NOOP -} -function processMergeIndexes() { - // NOOP -} -function finish() { - // NOOP -} diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml deleted file mode 100644 index 74f00fd4ef62..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - ${tests.luceneMatchVersion:LATEST} - - - - - - - - javascript - missleading.extension.updateprocessor.js.txt - - - - - - - - - - - - trivial.updateprocessor0.js - - true - 1 - - - - - - - - - trivial.updateprocessor0.js - trivial.updateprocessor1.js - - - true - 1 - - - - - - - - trivial.updateprocessor0.js - trivial.updateprocessor1.js - - true - 1 - - - - - - - - - conditional.updateprocessor.js - addfields.updateprocessor.js - - - - - - - conditional.updateprocessor.js - - - addfields.updateprocessor.js - - - - - - throw.error.on.add.updateprocessor.js - - - - - - missing.functions.updateprocessor.js - - - - - - cross-compatible.js - - - - - - evil.js - - - - diff --git a/solr/core/src/test-files/solr/collection1/conf/throw.error.on.add.updateprocessor.js b/solr/core/src/test-files/solr/collection1/conf/throw.error.on.add.updateprocessor.js deleted file mode 100644 index ca56fe35cfe2..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/throw.error.on.add.updateprocessor.js +++ /dev/null @@ -1,21 +0,0 @@ -function processAdd() { - throw "guess what? no-soup-fo-you !!!"; -} - -// // // - -function processDelete() { - // NOOP -} -function processCommit() { - // NOOP -} -function processRollback() { - // NOOP -} -function processMergeIndexes() { - // NOOP -} -function finish() { - // NOOP -} diff --git a/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js b/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js deleted file mode 100644 index b1856b15d855..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor0.js +++ /dev/null @@ -1,59 +0,0 @@ -var Assert = Packages.org.junit.Assert; - -function processAdd(cmd) { - functionMessages.add("processAdd0"); - Assert.assertNotNull(req); - Assert.assertNotNull(rsp); - Assert.assertNotNull(logger); - Assert.assertNotNull(cmd); - Assert.assertNotNull(params); - Assert.assertTrue(1 == params.get('intValue').intValue()); // had issues with assertTrue(1, params.get('intValue').intValue()) casting to wrong variant - Assert.assertTrue(params.get('boolValue').booleanValue()); - - // Integer.valueOf is needed here to get a tru java object, because - // all javascript numbers are floating point (ie: java.lang.Double) - cmd.getSolrInputDocument().addField("script_added_i", - java.lang.Integer.valueOf(42)); - cmd.getSolrInputDocument().addField("script_added_d", 42.3); - -} - -function processDelete(cmd) { - functionMessages.add("processDelete0"); - Assert.assertNotNull(req); - Assert.assertNotNull(rsp); - Assert.assertNotNull(logger); - Assert.assertNotNull(cmd); -} - -function processMergeIndexes(cmd) { - functionMessages.add("processMergeIndexes0"); - Assert.assertNotNull(req); - Assert.assertNotNull(rsp); - Assert.assertNotNull(logger); - Assert.assertNotNull(cmd); -} - -function processCommit(cmd) { - functionMessages.add("processCommit0"); - Assert.assertNotNull(req); - Assert.assertNotNull(rsp); - Assert.assertNotNull(logger); - Assert.assertNotNull(cmd); -} - -function processRollback(cmd) { - functionMessages.add("processRollback0"); - Assert.assertNotNull(req); - Assert.assertNotNull(rsp); - Assert.assertNotNull(logger); - Assert.assertNotNull(cmd); -} - -function finish() { - functionMessages.add("finish0"); - Assert.assertNotNull(req); - Assert.assertNotNull(rsp); - Assert.assertNotNull(logger); -} - diff --git a/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor1.js b/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor1.js deleted file mode 100644 index 98bdf2ab0604..000000000000 --- a/solr/core/src/test-files/solr/collection1/conf/trivial.updateprocessor1.js +++ /dev/null @@ -1,25 +0,0 @@ -function processAdd(cmd) { - functionMessages.add("processAdd1"); - -} - -function processDelete(cmd) { - functionMessages.add("processDelete1"); -} - -function processMergeIndexes(cmd) { - functionMessages.add("processMergeIndexes1"); -} - -function processCommit(cmd) { - functionMessages.add("processCommit1"); -} - -function processRollback(cmd) { - functionMessages.add("processRollback1"); -} - -function finish() { - functionMessages.add("finish1"); -} - diff --git a/solr/core/src/test-files/solr/configsets/upload/with-script-processor/missleading.extension.updateprocessor.js.txt b/solr/core/src/test-files/solr/configsets/upload/with-script-processor/missleading.extension.updateprocessor.js.txt deleted file mode 100644 index 984e1d82f100..000000000000 --- a/solr/core/src/test-files/solr/configsets/upload/with-script-processor/missleading.extension.updateprocessor.js.txt +++ /dev/null @@ -1,23 +0,0 @@ -function processAdd(cmd) { - // Integer.valueOf is needed here to get a tru java object, because - // all javascript numbers are floating point (ie: java.lang.Double) - cmd.getSolrInputDocument().addField("script_added_i", - java.lang.Integer.valueOf(42)); - cmd.getSolrInputDocument().addField("script_added_d", 42.3); - -} -function processDelete() { - // NOOP -} -function processCommit() { - // NOOP -} -function processRollback() { - // NOOP -} -function processMergeIndexes() { - // NOOP -} -function finish() { - // NOOP -} diff --git a/solr/core/src/test-files/solr/configsets/upload/with-script-processor/solrconfig.xml b/solr/core/src/test-files/solr/configsets/upload/with-script-processor/solrconfig.xml index 1c62889d19ee..affccbfa6f80 100644 --- a/solr/core/src/test-files/solr/configsets/upload/with-script-processor/solrconfig.xml +++ b/solr/core/src/test-files/solr/configsets/upload/with-script-processor/solrconfig.xml @@ -37,12 +37,9 @@ ${tests.luceneMatchVersion:LATEST} - - - ${solr.commitwithin.softcommit:true} - + + - explicit @@ -55,11 +52,10 @@ javascript - missleading.extension.updateprocessor.js.txt + trivial.updateprocessor.js - 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 37062e639272..5480eff72d8e 100644 --- a/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/AssignBackwardCompatibilityTest.java @@ -58,7 +58,7 @@ public static void setupCluster() throws Exception { @Test public void test() throws IOException, SolrServerException, KeeperException, InterruptedException { Set coreNames = new HashSet<>(); - Set coreNodeNames = new HashSet<>(); + Set replicaNames = new HashSet<>(); int numOperations = random().nextInt(15) + 15; int numLiveReplicas = 4; @@ -97,9 +97,9 @@ public void test() throws IOException, SolrServerException, KeeperException, Int Replica newReplica = getCollectionState(COLLECTION).getReplicas().stream() .filter(r -> r.getCoreName().equals(coreName)) .findAny().get(); - String coreNodeName = newReplica.getName(); - assertFalse("Core node name is not unique", coreNodeNames.contains(coreName)); - coreNodeNames.add(coreNodeName); + String replicaName = newReplica.getName(); + assertFalse("Core node name is not unique", replicaNames.contains(coreName)); + replicaNames.add(replicaName); } } } diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java index 227e50e14aa6..a7d4c1de534b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -1167,7 +1167,7 @@ private void createSolrCore(final String collection, if (random().nextBoolean()) { // sometimes we use an explicit core node name - createCmd.setCoreNodeName("anode" + nodeCounter.incrementAndGet()); + createCmd.setReplicaName("anode" + nodeCounter.incrementAndGet()); } if (shardId == null) { diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java index 325c5fbf486d..667ecfe0949a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java @@ -92,7 +92,7 @@ public void deleteInactiveReplicaTest() throws Exception { timeOut.waitFor("Expected data dir and instance dir of " + replica.getName() + " is deleted", () -> !Files.exists(replicaCd.getInstanceDir()) && !FileUtils.fileExists(replicaCd.getDataDir())); - // Check that we can't create a core with no coreNodeName + // Check that we can't create a core with no replicaName try (SolrClient queryClient = getHttpSolrClient(jetty.getBaseUrl().toString())) { Exception e = expectThrows(Exception.class, () -> { CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create(); @@ -101,7 +101,7 @@ public void deleteInactiveReplicaTest() throws Exception { createRequest.setShardId("shard2"); queryClient.request(createRequest); }); - assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("coreNodeName missing")); + assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("replicaName missing")); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java index e7215177bf4e..c47a480e19e9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java @@ -293,7 +293,7 @@ public void raceConditionOnDeleteAndRegisterReplica() throws Exception { AtomicInteger times = new AtomicInteger(0); ZkContainer.testing_beforeRegisterInZk = cd -> { if (cd.getCloudDescriptor() == null) return false; - if (replica1.getName().equals(cd.getCloudDescriptor().getCoreNodeName()) + if (replica1.getName().equals(cd.getCloudDescriptor().getReplicaName()) && collectionName.equals(cd.getCloudDescriptor().getCollectionName())) { if (times.incrementAndGet() > 1) { return false; diff --git a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java index 027af1177cbc..0bd5efdf9c3d 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java @@ -269,7 +269,7 @@ private void runTest() throws Exception { } /** - * returns a map whose key is the coreNodeName and whose value is data about that core needed for the test + * returns a map whose key is the replicaName and whose value is data about that core needed for the test */ private Map getTestDataForAllReplicas() throws IOException, SolrServerException { Map results = new HashMap<>(); diff --git a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java index 081ed5213816..559712b060f9 100644 --- a/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/HttpPartitionTest.java @@ -412,7 +412,7 @@ protected void testLeaderZkSessionLoss() throws Exception { // cause leader migration by expiring the current leader's zk session chaosMonkey.expireSession(leaderJetty); - String expectedNewLeaderCoreNodeName = notLeaders.get(0).getName(); + String expectedNewLeaderReplicaName = notLeaders.get(0).getName(); long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(60, TimeUnit.SECONDS); while (System.nanoTime() < timeout) { String currentLeaderName = null; @@ -422,7 +422,7 @@ protected void testLeaderZkSessionLoss() throws Exception { currentLeaderName = currentLeader.getName(); } catch (Exception exc) {} - if (expectedNewLeaderCoreNodeName.equals(currentLeaderName)) + if (expectedNewLeaderReplicaName.equals(currentLeaderName)) break; // new leader was elected after zk session expiration Thread.sleep(500); @@ -430,7 +430,7 @@ protected void testLeaderZkSessionLoss() throws Exception { Replica currentLeader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard1"); - assertEquals(expectedNewLeaderCoreNodeName, currentLeader.getName()); + assertEquals(expectedNewLeaderReplicaName, currentLeader.getName()); // TODO: This test logic seems to be timing dependent and fails on Jenkins // need to come up with a better approach 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 ee74f680ee60..3f55aa11d7a3 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionContextKeyTest.java @@ -49,7 +49,7 @@ public static void setupCluster() throws Exception { for (int i = 1; i <= 2; i++) { // Create two collections with same order of requests, no parallel - // therefore Assign.buildCoreNodeName will create same coreNodeName + // therefore Assign.buildReplicaName will create same coreNodeName CollectionAdminRequest .createCollection("testCollection"+i, "config", 2, 1) .setCreateNodeSet("") 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 294f7c2a2187..97925bd1f3e7 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java @@ -89,9 +89,9 @@ class TestLeaderElectionContext extends ShardLeaderElectionContextBase { private long runLeaderDelay = 0; public TestLeaderElectionContext(LeaderElector leaderElector, - String shardId, String collection, String coreNodeName, ZkNodeProps props, + String shardId, String collection, String replicaName, ZkNodeProps props, ZkController zkController, long runLeaderDelay) { - super (leaderElector, shardId, collection, coreNodeName, props, zkController); + super (leaderElector, shardId, collection, replicaName, props, zkController); this.runLeaderDelay = runLeaderDelay; } diff --git a/solr/core/src/test/org/apache/solr/cloud/LeaderFailureAfterFreshStartTest.java b/solr/core/src/test/org/apache/solr/cloud/LeaderFailureAfterFreshStartTest.java index 8cb40ddfbbfd..a2c7e106bf18 100644 --- a/solr/core/src/test/org/apache/solr/cloud/LeaderFailureAfterFreshStartTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/LeaderFailureAfterFreshStartTest.java @@ -106,9 +106,9 @@ public void test() throws Exception { CloudJettyRunner initialLeaderJetty = shardToLeaderJetty.get("shard1"); List otherJetties = getOtherAvailableJetties(initialLeaderJetty); - log.info("Leader node_name: {}, url: {}", initialLeaderJetty.coreNodeName, initialLeaderJetty.url); + log.info("Leader node_name: {}, url: {}", initialLeaderJetty.replicaName, initialLeaderJetty.url); for (CloudJettyRunner cloudJettyRunner : otherJetties) { - log.info("Nonleader node_name: {}, url: {}", cloudJettyRunner.coreNodeName, cloudJettyRunner.url); + log.info("Nonleader node_name: {}, url: {}", cloudJettyRunner.replicaName, cloudJettyRunner.url); } CloudJettyRunner secondNode = otherJetties.get(0); @@ -212,7 +212,7 @@ private void waitTillNodesActive() throws Exception { boolean allActive = true; Collection nodesDownNames = nodesDown.stream() - .map(n -> n.coreNodeName) + .map(n -> n.replicaName) .collect(Collectors.toList()); Collection replicasToCheck = null; 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 16326177b73d..c57caa4b2a1a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/OverseerTest.java @@ -192,7 +192,7 @@ public void createCollection(String collection, int numShards) throws Exception q.offer(Utils.toJSON(m)); } - public String publishState(String collection, String coreName, String coreNodeName, String shard, Replica.State stateName, int numShards, boolean startElection, Overseer overseer) + public String publishState(String collection, String coreName, String replicaName, String shard, Replica.State stateName, int numShards, boolean startElection, Overseer overseer) throws Exception { if (stateName == null) { ElectionContext ec = electionContext.remove(coreName); @@ -202,7 +202,7 @@ public String publishState(String collection, String coreName, String coreNodeNa ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.DELETECORE.toLower(), ZkStateReader.NODE_NAME_PROP, nodeName, ZkStateReader.CORE_NAME_PROP, coreName, - ZkStateReader.CORE_NODE_NAME_PROP, coreNodeName, + ZkStateReader.CORE_NODE_NAME_PROP, replicaName, ZkStateReader.COLLECTION_PROP, collection); ZkDistributedQueue q = overseer.getStateUpdateQueue(); q.offer(Utils.toJSON(m)); @@ -212,7 +212,7 @@ public String publishState(String collection, String coreName, String coreNodeNa ZkStateReader.STATE_PROP, stateName.toString(), ZkStateReader.NODE_NAME_PROP, nodeName, ZkStateReader.CORE_NAME_PROP, coreName, - ZkStateReader.CORE_NODE_NAME_PROP, coreNodeName, + ZkStateReader.CORE_NODE_NAME_PROP, replicaName, ZkStateReader.COLLECTION_PROP, collection, ZkStateReader.SHARD_ID_PROP, shard, ZkStateReader.NUM_SHARDS_PROP, Integer.toString(numShards)); @@ -222,8 +222,8 @@ public String publishState(String collection, String coreName, String coreNodeNa if (startElection && collection.length() > 0) { zkStateReader.waitForState(collection, 45000, TimeUnit.MILLISECONDS, - (liveNodes, collectionState) -> getShardId(collectionState, coreNodeName) != null); - String shardId = getShardId(collection, coreNodeName); + (liveNodes, collectionState) -> getShardId(collectionState, replicaName) != null); + String shardId = getShardId(collection, replicaName); if (shardId != null) { ElectionContext prevContext = electionContext.get(coreName); if (prevContext != null) { @@ -238,7 +238,7 @@ public String publishState(String collection, String coreName, String coreNodeNa ZkStateReader.CORE_NAME_PROP, coreName, ZkStateReader.SHARD_ID_PROP, shardId, ZkStateReader.COLLECTION_PROP, collection, - ZkStateReader.CORE_NODE_NAME_PROP, coreNodeName); + ZkStateReader.CORE_NODE_NAME_PROP, replicaName); LeaderElector elector = new LeaderElector(zkClient); ShardLeaderElectionContextBase ctx = new ShardLeaderElectionContextBase( elector, shardId, collection, nodeName + coreName, props, @@ -252,19 +252,19 @@ public String publishState(String collection, String coreName, String coreNodeNa return null; } - private String getShardId(String collection, String coreNodeName) { + private String getShardId(String collection, String replicaName) { DocCollection dc = zkStateReader.getClusterState().getCollectionOrNull(collection); - return getShardId(dc, coreNodeName); + return getShardId(dc, replicaName); } - private String getShardId(DocCollection collection, String coreNodeName) { + private String getShardId(DocCollection collection, String replicaName) { if (collection == null) return null; Map slices = collection.getSlicesMap(); if (slices != null) { for (Slice slice : slices.values()) { for (Replica replica : slice.getReplicas()) { String cnn = replica.getName(); - if (coreNodeName.equals(cnn)) { + if (replicaName.equals(cnn)) { return slice.getName(); } } diff --git a/solr/core/src/test/org/apache/solr/cloud/PeerSyncReplicationTest.java b/solr/core/src/test/org/apache/solr/cloud/PeerSyncReplicationTest.java index c20e3eb127a8..0155de25aeca 100644 --- a/solr/core/src/test/org/apache/solr/cloud/PeerSyncReplicationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/PeerSyncReplicationTest.java @@ -345,7 +345,7 @@ private void waitTillNodesActive() throws Exception { Collection nodesDownNames = nodesDown.stream() - .map(n -> n.coreNodeName) + .map(n -> n.replicaName) .collect(Collectors.toList()); Collection replicasToCheck = diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java index 247313e5bb4b..5a4511006e6b 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudSearcherWarming.java @@ -52,7 +52,7 @@ */ @LogLevel("org.apache.solr.cloud.overseer.*=DEBUG,org.apache.solr.cloud.Overseer=DEBUG,org.apache.solr.cloud.ZkController=DEBUG") public class TestCloudSearcherWarming extends SolrCloudTestCase { - public static final AtomicReference coreNodeNameRef = new AtomicReference<>(null), + public static final AtomicReference replicaNameRef = new AtomicReference<>(null), coreNameRef = new AtomicReference<>(null); private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final AtomicInteger sleepTime = new AtomicInteger(-1); @@ -72,7 +72,7 @@ public void setUp() throws Exception { @Override public void tearDown() throws Exception { coreNameRef.set(null); - coreNodeNameRef.set(null); + replicaNameRef.set(null); sleepTime.set(-1); if (null != cluster) { @@ -112,8 +112,8 @@ public void testRepFactor1LeaderStartup() throws Exception { solrClient.commit(); AtomicInteger expectedDocs = new AtomicInteger(1); - AtomicReference failingCoreNodeName = new AtomicReference<>(); - CollectionStateWatcher stateWatcher = createActiveReplicaSearcherWatcher(expectedDocs, failingCoreNodeName); + AtomicReference failingReplicaName = new AtomicReference<>(); + CollectionStateWatcher stateWatcher = createActiveReplicaSearcherWatcher(expectedDocs, failingReplicaName); JettySolrRunner runner = cluster.getJettySolrRunner(0); runner.stop(); @@ -130,7 +130,7 @@ public void testRepFactor1LeaderStartup() throws Exception { cluster.waitForAllNodes(30); cluster.getSolrClient().getZkStateReader().registerCollectionStateWatcher(collectionName, stateWatcher); cluster.waitForActiveCollection(collectionName, 1, 1); - assertNull("No replica should have been active without registering a searcher, found: " + failingCoreNodeName.get(), failingCoreNodeName.get()); + assertNull("No replica should have been active without registering a searcher, found: " + failingReplicaName.get(), failingReplicaName.get()); cluster.getSolrClient().getZkStateReader().removeCollectionStateWatcher(collectionName, stateWatcher); } @@ -160,18 +160,18 @@ public void testPeersyncFailureReplicationSuccess() throws Exception { solrClient.commit(); AtomicInteger expectedDocs = new AtomicInteger(1); - AtomicReference failingCoreNodeName = new AtomicReference<>(); + AtomicReference failingReplicaName = new AtomicReference<>(); QueryResponse response = solrClient.query(new SolrQuery("*:*")); assertEquals(1, response.getResults().getNumFound()); // reset coreNameRef.set(null); - coreNodeNameRef.set(null); - failingCoreNodeName.set(null); + replicaNameRef.set(null); + failingReplicaName.set(null); sleepTime.set(5000); - CollectionStateWatcher stateWatcher = createActiveReplicaSearcherWatcher(expectedDocs, failingCoreNodeName); + CollectionStateWatcher stateWatcher = createActiveReplicaSearcherWatcher(expectedDocs, failingReplicaName); cluster.getSolrClient().getZkStateReader().registerCollectionStateWatcher(collectionName, stateWatcher); JettySolrRunner newNode = cluster.startJettySolrRunner(); @@ -181,7 +181,7 @@ public void testPeersyncFailureReplicationSuccess() throws Exception { .process(solrClient); waitForState("The collection should have 1 shard and 2 replica", collectionName, clusterShape(1, 2)); - assertNull("No replica should have been active without registering a searcher, found: " + failingCoreNodeName.get(), failingCoreNodeName.get()); + assertNull("No replica should have been active without registering a searcher, found: " + failingReplicaName.get(), failingReplicaName.get()); // stop the old node log.info("Stopping old node 1"); @@ -206,8 +206,8 @@ public void testPeersyncFailureReplicationSuccess() throws Exception { // reset coreNameRef.set(null); - coreNodeNameRef.set(null); - failingCoreNodeName.set(null); + replicaNameRef.set(null); + failingReplicaName.set(null); sleepTime.set(5000); // inject wrong signature output @@ -218,7 +218,7 @@ public void testPeersyncFailureReplicationSuccess() throws Exception { waitForState("", collectionName, clusterShape(1, 2)); // invoke statewatcher explicitly to avoid race condition where the assert happens before the state watcher is invoked by ZkStateReader cluster.getSolrClient().getZkStateReader().registerCollectionStateWatcher(collectionName, stateWatcher); - assertNull("No replica should have been active without registering a searcher, found: " + failingCoreNodeName.get(), failingCoreNodeName.get()); + assertNull("No replica should have been active without registering a searcher, found: " + failingReplicaName.get(), failingReplicaName.get()); oldNodeName.set(cluster.getJettySolrRunner(1).getNodeName()); assertSame(oldNode, cluster.stopJettySolrRunner(1)); // old node is now at 1 @@ -228,8 +228,8 @@ public void testPeersyncFailureReplicationSuccess() throws Exception { // reset coreNameRef.set(null); - coreNodeNameRef.set(null); - failingCoreNodeName.set(null); + replicaNameRef.set(null); + failingReplicaName.set(null); sleepTime.set(14000); // has to be higher than the twice the recovery wait pause between attempts plus some margin // inject failure @@ -240,23 +240,23 @@ public void testPeersyncFailureReplicationSuccess() throws Exception { waitForState("", collectionName, clusterShape(1, 2)); // invoke statewatcher explicitly to avoid race condition where the assert happens before the state watcher is invoked by ZkStateReader cluster.getSolrClient().getZkStateReader().registerCollectionStateWatcher(collectionName, stateWatcher); - assertNull("No replica should have been active without registering a searcher, found: " + failingCoreNodeName.get(), failingCoreNodeName.get()); + assertNull("No replica should have been active without registering a searcher, found: " + failingReplicaName.get(), failingReplicaName.get()); cluster.getSolrClient().getZkStateReader().removeCollectionStateWatcher(collectionName, stateWatcher); } - private CollectionStateWatcher createActiveReplicaSearcherWatcher(AtomicInteger expectedDocs, AtomicReference failingCoreNodeName) { + private CollectionStateWatcher createActiveReplicaSearcherWatcher(AtomicInteger expectedDocs, AtomicReference failingReplicaName) { return new CollectionStateWatcher() { @Override public boolean onStateChanged(Set liveNodes, DocCollection collectionState) { try { - String coreNodeName = coreNodeNameRef.get(); + String replicaName = replicaNameRef.get(); String coreName = coreNameRef.get(); - if (coreNodeName == null || coreName == null) return false; - Replica replica = collectionState.getReplica(coreNodeName); + if (replicaName == null || coreName == null) return false; + Replica replica = collectionState.getReplica(replicaName); if (replica == null) return false; log.info("Collection state: {}", collectionState); if (replica.isActive(liveNodes)) { - log.info("Active replica: {}", coreNodeName); + log.info("Active replica: {}", replicaName); for (int i = 0; i < cluster.getJettySolrRunners().size(); i++) { JettySolrRunner jettySolrRunner = cluster.getJettySolrRunner(i); if (log.isInfoEnabled()) { @@ -277,7 +277,7 @@ public boolean onStateChanged(Set liveNodes, DocCollection collectionSta if (registeredSearcher != null) { log.error("registered searcher not null, maxdocs = {}", registeredSearcher.get().maxDoc()); if (registeredSearcher.get().maxDoc() != expectedDocs.get()) { - failingCoreNodeName.set(coreNodeName); + failingReplicaName.set(replicaName); registeredSearcher.decref(); return false; } else { @@ -295,7 +295,7 @@ public boolean onStateChanged(Set liveNodes, DocCollection collectionSta log.error("newest searcher was also null!"); } // no registered searcher but replica is active! - failingCoreNodeName.set(coreNodeName); + failingReplicaName.set(replicaName); } } } @@ -328,7 +328,7 @@ public void postSoftCommit() { @Override public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) { if (sleepTime.get() > 0) { - TestCloudSearcherWarming.coreNodeNameRef.set(newSearcher.getCore().getCoreDescriptor().getCloudDescriptor().getCoreNodeName()); + TestCloudSearcherWarming.replicaNameRef.set(newSearcher.getCore().getCoreDescriptor().getCloudDescriptor().getCoreNodeName()); TestCloudSearcherWarming.coreNameRef.set(newSearcher.getCore().getName()); if (log.isInfoEnabled()) { log.info("Sleeping for {} on newSearcher: {}, currentSearcher: {} belonging to (newest) core: {}, id: {}" 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 8ffff31cc14f..5230c8bc1153 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestTlogReplica.java @@ -957,7 +957,7 @@ private List getSolrCore(boolean isLeader) { for (SolrCore solrCore : solrRunner.getCoreContainer().getCores()) { CloudDescriptor cloudDescriptor = solrCore.getCoreDescriptor().getCloudDescriptor(); Slice slice = docCollection.getSlice(cloudDescriptor.getShardId()); - Replica replica = docCollection.getReplica(cloudDescriptor.getCoreNodeName()); + Replica replica = docCollection.getReplica(cloudDescriptor.getReplicaName()); if (slice.getLeader().equals(replica) && isLeader) { rs.add(solrCore); } else if (!slice.getLeader().equals(replica) && !isLeader) { @@ -992,7 +992,7 @@ private List getSolrRunner(boolean isLeader) { for (SolrCore solrCore : solrRunner.getCoreContainer().getCores()) { CloudDescriptor cloudDescriptor = solrCore.getCoreDescriptor().getCloudDescriptor(); Slice slice = docCollection.getSlice(cloudDescriptor.getShardId()); - Replica replica = docCollection.getReplica(cloudDescriptor.getCoreNodeName()); + Replica replica = docCollection.getReplica(cloudDescriptor.getReplicaName()); if (slice.getLeader() == replica && isLeader) { rs.add(solrRunner); } else if (slice.getLeader() != replica && !isLeader) { 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 8018e782f60f..18be7150748a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java @@ -247,7 +247,7 @@ public void testPublishAndWaitForDownStates() throws Exception { /* This test asserts that if zkController.publishAndWaitForDownStates uses only core name to check if all local - cores are down then the method will return immediately but if it uses coreNodeName (as it does after SOLR-6665 then + cores are down then the method will return immediately but if it uses replicaName (as it does after SOLR-6665 then the method will timeout). We setup the cluster state in such a way that two replicas with same core name exist on non-existent nodes and core container also has a dummy core that has the same core name. The publishAndWaitForDownStates before SOLR-6665 @@ -270,9 +270,9 @@ cores are down then the method will return immediately but if it uses coreNodeNa @Override public List getCoreDescriptors() { CoreDescriptor descriptor = new CoreDescriptor(collectionName, TEST_PATH(), Collections.emptyMap(), new Properties(), zkControllerRef.get()); - // non-existent coreNodeName, this will cause zkController.publishAndWaitForDownStates to wait indefinitely - // when using coreNodeName but usage of core name alone will return immediately - descriptor.getCloudDescriptor().setCoreNodeName("core_node0"); + // non-existent replicaName, this will cause zkController.publishAndWaitForDownStates to wait indefinitely + // when using replicaName but usage of core name alone will return immediately + descriptor.getCloudDescriptor().setReplicaName("core_node0"); return Collections.singletonList(descriptor); } }; diff --git a/solr/core/src/test/org/apache/solr/core/CoreSorterTest.java b/solr/core/src/test/org/apache/solr/core/CoreSorterTest.java index fd7b5c4f56e5..9bc5af45277e 100644 --- a/solr/core/src/test/org/apache/solr/core/CoreSorterTest.java +++ b/solr/core/src/test/org/apache/solr/core/CoreSorterTest.java @@ -34,6 +34,7 @@ import org.apache.solr.common.cloud.DocRouter; import org.apache.solr.common.cloud.Replica; import org.apache.solr.common.cloud.Slice; +import org.apache.solr.common.params.CommonParams; import org.apache.solr.core.CoreSorter.CountsForEachShard; import org.junit.Test; @@ -187,7 +188,7 @@ private CoreDescriptor newCoreDescriptor(Replica r) { Map props = map( CoreDescriptor.CORE_SHARD, r.getShard(), CoreDescriptor.CORE_COLLECTION, r.getCollection(), - CoreDescriptor.CORE_NODE_NAME, r.getNodeName() + CommonParams.REPLICA_NAME, r.getNodeName() ); return new CoreDescriptor(r.getCoreName(), TEST_PATH(), props , null, mock(ZkController.class)); } diff --git a/solr/core/src/test/org/apache/solr/core/TestBadConfig.java b/solr/core/src/test/org/apache/solr/core/TestBadConfig.java index 1dfad85f3273..91fd9ae3fde5 100644 --- a/solr/core/src/test/org/apache/solr/core/TestBadConfig.java +++ b/solr/core/src/test/org/apache/solr/core/TestBadConfig.java @@ -16,10 +16,6 @@ */ package org.apache.solr.core; -import javax.script.ScriptEngineManager; - -import org.junit.Assume; - public class TestBadConfig extends AbstractBadConfigTestBase { public void testUnsetSysProperty() throws Exception { @@ -44,7 +40,7 @@ public void testMultipleCFS() throws Exception { } public void testUpdateLogButNoVersionField() throws Exception { - + System.setProperty("enable.update.log", "true"); try { assertConfigs("solrconfig.xml", "schema12.xml", "_version_"); @@ -53,28 +49,6 @@ public void testUpdateLogButNoVersionField() throws Exception { } } - public void testBogusScriptEngine() throws Exception { - // sanity check - Assume.assumeTrue(null == (new ScriptEngineManager()).getEngineByName("giberish")); - - assertConfigs("bad-solrconfig-bogus-scriptengine-name.xml", - "schema.xml","giberish"); - } - - public void testMissingScriptFile() throws Exception { - // sanity check - Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js")); - assertConfigs("bad-solrconfig-missing-scriptfile.xml", - "schema.xml","a-file-name-that-does-not-exist.js"); - } - - public void testInvalidScriptFile() throws Exception { - // sanity check - Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("javascript")); - assertConfigs("bad-solrconfig-invalid-scriptfile.xml", - "schema.xml","currency.xml"); - } - public void testBogusMergePolicy() throws Exception { assertConfigs("bad-mpf-solrconfig.xml", "schema-minimal.xml", "DummyMergePolicyFactory"); @@ -89,7 +63,7 @@ public void testManagedSchemaCannotBeNamedSchemaDotXml() throws Exception { assertConfigs("bad-solrconfig-managed-schema-named-schema.xml.xml", "schema-minimal.xml", "managedSchemaResourceName can't be 'schema.xml'"); } - + public void testUnknownSchemaAttribute() throws Exception { assertConfigs("bad-solrconfig-unexpected-schema-attribute.xml", "schema-minimal.xml", "Unexpected arg(s): {bogusParam=bogusValue}"); diff --git a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java index 25b66939f2f9..2bcb214a8261 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/HealthCheckHandlerTest.java @@ -229,7 +229,7 @@ private CloudDescriptor mockCD(String collection, String name, String shardId, b Properties props = new Properties(); props.put(CoreDescriptor.CORE_SHARD, shardId); props.put(CoreDescriptor.CORE_COLLECTION, collection); - props.put(CoreDescriptor.CORE_NODE_NAME, name); + props.put(CommonParams.REPLICA_NAME, name); CloudDescriptor cd = new CloudDescriptor(null, name, props); cd.setHasRegistered(registered); cd.setLastPublished(state); diff --git a/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrShardReporterTest.java b/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrShardReporterTest.java index 3d8669acf0e3..60d765073b3d 100644 --- a/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrShardReporterTest.java +++ b/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrShardReporterTest.java @@ -85,7 +85,7 @@ public void test() throws Exception { DocCollection docCollection = state.getCollection(cloudDesc.getCollectionName()); String replicaName = Utils.parseMetricsReplicaName(cloudDesc.getCollectionName(), coreName); if (replicaName == null) { - replicaName = cloudDesc.getCoreNodeName(); + replicaName = cloudDesc.getReplicaName(); } String registryName = SolrCoreMetricManager.createRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId(), replicaName, null); diff --git a/solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java b/solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java deleted file mode 100644 index 8a913e16426f..000000000000 --- a/solr/core/src/test/org/apache/solr/update/processor/ScriptEngineTest.java +++ /dev/null @@ -1,110 +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.update.processor; - -import org.apache.lucene.util.Constants; - -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; -import java.io.StringReader; - -import org.apache.solr.SolrTestCase; -import org.junit.Assume; -import org.junit.BeforeClass; - -/** - * Sanity tests basic functionality of {@link ScriptEngineManager} and - * {@link ScriptEngine} w/o exercising any Lucene specific code. - */ -public class ScriptEngineTest extends SolrTestCase { - - private ScriptEngineManager manager; - - @BeforeClass - public static void beforeClass() throws Exception { - assumeFalse("https://twitter.com/UweSays/status/260487231880433664 / SOLR-4233: OS X bogusly starts AWT!", - Constants.MAC_OS_X); - Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js")); - Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("JavaScript")); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - manager = new ScriptEngineManager(); - } - - public void testGetEngineByName() { - ScriptEngine engine = manager.getEngineByName("JavaScript"); - assertNotNull(engine); - engine = manager.getEngineByName("DummyScript"); - assertNull(engine); - } - - public void testGetEngineByExtension() { - ScriptEngine engine = manager.getEngineByExtension("js"); - assertNotNull(engine); - engine = manager.getEngineByExtension("foobar"); - assertNull(engine); - } - - public void testEvalText() throws ScriptException, NoSuchMethodException { - ScriptEngine engine = manager.getEngineByName("JavaScript"); - assertNotNull(engine); - engine.eval("function add(a,b) { return a + b }"); - Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2); - assertNotNull(result); - assertEquals(3, result.intValue()); - } - - public void testEvalReader() throws ScriptException, NoSuchMethodException { - ScriptEngine engine = manager.getEngineByName("JavaScript"); - assertNotNull(engine); - StringReader reader = new StringReader("function add(a,b) { return a + b }"); - engine.eval(reader); - Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2); - assertNotNull(result); - assertEquals(3, result.intValue()); - } - - public void testPut() throws ScriptException, NoSuchMethodException { - manager.put("a", 1); - ScriptEngine engine = manager.getEngineByName("JavaScript"); - engine.put("b", 2); - assertNotNull(engine); - engine.eval("function add() { return a + b }"); - Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2); - assertNotNull(result); - assertEquals(3, result.intValue()); - } - - public void testJRuby() throws ScriptException, NoSuchMethodException { - // Simply adding jruby.jar to Solr's lib/ directory gets this test passing - ScriptEngine engine = manager.getEngineByName("jruby"); - - Assume.assumeNotNull(engine); - - assertNotNull(engine); - engine.eval("def add(a,b); a + b; end"); - Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2); - assertNotNull(result); - assertEquals(3, result.intValue()); - } - -} diff --git a/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java b/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java deleted file mode 100644 index 09dd78399954..000000000000 --- a/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java +++ /dev/null @@ -1,272 +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.update.processor; - -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import java.util.ArrayList; -import java.util.List; - -import org.apache.solr.common.SolrException; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.ModifiableSolrParams; -import org.apache.solr.core.SolrCore; -import org.junit.Assume; -import org.junit.BeforeClass; - -/** - * Tests {@link StatelessScriptUpdateProcessorFactory}. - * - * TODO: This test, to run from an IDE, requires a working directory of <path-to>/solr/core/src/test-files. Fix! - */ -public class StatelessScriptUpdateProcessorFactoryTest extends UpdateProcessorTestBase { - - @BeforeClass - public static void beforeClass() throws Exception { - Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js")); - initCore("solrconfig-script-updateprocessor.xml", "schema12.xml"); - } - - /** - * simple test of a basic script processor chain using the full - * RequestHandler + UpdateProcessorChain flow - */ - public void testFullRequestHandlerFlow() throws Exception { - - assertU("Simple assertion that adding a document works", - adoc("id", "4055", - "subject", "Hoss")); - assertU(commit()); - - assertQ("couldn't find hoss using script added field", - req("q","script_added_i:[40 TO 45]", - "fq","id:4055") - ,"//result[@numFound=1]" - ,"//str[@name='id'][.='4055']" - ); - - // clean up - processDeleteById("run-no-scripts","4055"); - processCommit("run-no-scripts"); - - } - - public void testSingleScript() throws Exception { - SolrCore core = h.getCore(); - UpdateRequestProcessorChain chained = core.getUpdateProcessingChain("single-script"); - final StatelessScriptUpdateProcessorFactory factory = ((StatelessScriptUpdateProcessorFactory) chained.getProcessors().get(0)); - final List functionMessages = new ArrayList<>(); - factory.setScriptEngineCustomizer(new ScriptEngineCustomizer() { - @Override - public void customize(ScriptEngine engine) { - engine.put("functionMessages", functionMessages); - } - }); - assertNotNull(chained); - - SolrInputDocument d = processAdd("single-script", - doc(f("id", "1"), - f("name", " foo "), - f("subject", "bar"))); - - processCommit("run-no-scripts"); - - assertQ("couldn't find doc by id", - req("q","id:1") - , "//result[@numFound=1]"); - - processDeleteById("single-script","1"); - processCommit("single-script"); - - assertQ("found deleted doc", - req("q","id:1") - , "//result[@numFound=0]"); - - - assertEquals(3, functionMessages.size()); - - assertTrue(functionMessages.contains("processAdd0")); - assertTrue(functionMessages.contains("processDelete0")); - assertTrue(functionMessages.contains("processCommit0")); - - } - - public void testMultipleScripts() throws Exception { - SolrCore core = h.getCore(); - - for (final String chain : new String[] {"dual-scripts-arr", - "dual-scripts-strs"}) { - - UpdateRequestProcessorChain chained = core.getUpdateProcessingChain(chain); - final StatelessScriptUpdateProcessorFactory factory = - ((StatelessScriptUpdateProcessorFactory) chained.getProcessors().get(0)); - final List functionMessages = new ArrayList<>(); - ScriptEngineCustomizer customizer = new ScriptEngineCustomizer() { - @Override - public void customize(ScriptEngine engine) { - engine.put("functionMessages", functionMessages); - } - }; - factory.setScriptEngineCustomizer(customizer); - assertNotNull(chained); - - SolrInputDocument d = processAdd(chain, - doc(f("id", "2"), - f("name", " foo "), - f("subject", "bar"))); - - assertEquals(chain + " didn't add Double field", - 42.3d, d.getFieldValue("script_added_d")); - assertEquals(chain + " didn't add integer field", - 42, d.getFieldValue("script_added_i")); - - processCommit("run-no-scripts"); - - assertQ(chain + ": couldn't find doc by id", - req("q","id:2") - , "//result[@numFound=1]"); - - processDeleteById(chain, "2"); - processCommit(chain); - - assertEquals(chain, 6, functionMessages.size()); - assertTrue(chain, functionMessages.contains("processAdd0")); - assertTrue(chain, functionMessages.contains("processAdd1")); - assertTrue(chain + ": script order doesn't match conf order", - functionMessages.indexOf("processAdd0") - < functionMessages.indexOf("processAdd1")); - - assertTrue(chain, functionMessages.contains("processDelete0")); - assertTrue(chain, functionMessages.contains("processDelete1")); - assertTrue(chain + ": script order doesn't match conf order", - functionMessages.indexOf("processDelete0") - < functionMessages.indexOf("processDelete1")); - - assertTrue(chain, functionMessages.contains("processCommit0")); - assertTrue(chain, functionMessages.contains("processCommit1")); - assertTrue(chain + ": script order doesn't match conf order", - functionMessages.indexOf("processCommit0") - < functionMessages.indexOf("processCommit1")); - - finish(chain); - - assertEquals(chain, 8, functionMessages.size()); - - assertTrue(chain, functionMessages.contains("finish0")); - assertTrue(chain, functionMessages.contains("finish1")); - assertTrue(chain + ": script order doesn't match conf order", - functionMessages.indexOf("finish0") - < functionMessages.indexOf("finish1")); - - assertQ(chain + ": found deleted doc", - req("q","id:2") - , "//result[@numFound=0]"); - - } - } - - - public void testConditionalExecution() throws Exception { - for (String chain : new String[] {"conditional-script", - "conditional-scripts"}) { - - ModifiableSolrParams reqParams = new ModifiableSolrParams(); - - SolrInputDocument d = processAdd(chain, - reqParams, - doc(f("id", "3"), - f("name", " foo "), - f("subject", "bar"))); - - assertFalse(chain + " added String field despite condition", - d.containsKey("script_added_s")); - assertFalse(chain + " added Double field despite condition", - d.containsKey("script_added_d")); - - reqParams.add("go-for-it", "true"); - - d = processAdd(chain, - reqParams, - doc(f("id", "4"), - f("name", " foo "), - f("subject", "bar"))); - - assertEquals(chain + " didn't add String field", - "i went for it", d.getFieldValue("script_added_s")); - assertEquals(chain +" didn't add Double field", - 42.3d, d.getFieldValue("script_added_d")); - assertEquals(chain + " didn't add integer field", - 42, d.getFieldValue("script_added_i")); - } - } - - public void testForceEngine() throws Exception { - Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("javascript")); - - final String chain = "force-script-engine"; - SolrInputDocument d = processAdd(chain, - doc(f("id", "5"), - f("name", " foo "), - f("subject", "bar"))); - - assertEquals(chain +" didn't add Double field", - 42.3d, d.getFieldValue("script_added_d")); - assertEquals(chain + " didn't add integer field", - 42, d.getFieldValue("script_added_i")); - } - - public void testPropogatedException() throws Exception { - final String chain = "error-on-add"; - SolrException e = expectThrows(SolrException.class, () -> - processAdd(chain, doc(f("id", "5"), f("name", " foo "), - f("subject", "bar"))) - ); - assertTrue("Exception doesn't contain script error string: " + e.getMessage(), - 0 < e.getMessage().indexOf("no-soup-fo-you")); - } - - public void testMissingFunctions() throws Exception { - final String chain = "missing-functions"; - SolrException e = expectThrows(SolrException.class, () -> - processAdd(chain, doc(f("id", "5"), - f("name", " foo "), f("subject", "bar"))) - ); - assertTrue("Exception doesn't contain expected error: " + e.getMessage(), - 0 < e.getMessage().indexOf("processAdd")); - } - - public void testJavaScriptCompatibility() throws Exception { - final String chain = "javascript-compatibility"; - SolrInputDocument d = processAdd(chain, - doc(f("id", "5"), - f("name", " foo "), - f("subject", "BAR"))); - assertEquals("bar", d.getFieldValue("term_s")); - - } - - public void testScriptSandbox() throws Exception { - assumeTrue("This test only works with security manager", System.getSecurityManager() != null); - expectThrows(SecurityException.class, () -> { - processAdd("evil", - doc(f("id", "5"), - f("name", " foo "), - f("subject", "BAR"))); - }); - } - -} diff --git a/solr/packaging/build.gradle b/solr/packaging/build.gradle index 27e8e3ad7f6f..3b242ad7199b 100644 --- a/solr/packaging/build.gradle +++ b/solr/packaging/build.gradle @@ -52,6 +52,7 @@ dependencies { ":solr:contrib:langid", ":solr:contrib:ltr", ":solr:contrib:prometheus-exporter", + ":solr:contrib:scripting" ].each { contribName -> distSolr project(contribName) contrib project(path: contribName, configuration: "packaging") diff --git a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml index 8fea9ca8d49b..14f094dc24cc 100644 --- a/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml +++ b/solr/server/solr/configsets/sample_techproducts_configs/conf/solrconfig.xml @@ -83,6 +83,8 @@ + + + - --> - + + + update-script.js + + example config parameter + + + +