Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17272: PerReplicaState: Replica "state" and "leader" are still in state.json (#2458)

Noble Paul71160170a4d4
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java b/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java
index e9c41df8c51..b3019edc794 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java
@@ -249,7 +249,9 @@ public class Replica extends ZkNodeProps implements MapWriter {
Objects.requireNonNull(this.collection, "'collection' must not be null");
Objects.requireNonNull(this.shard, "'shard' must not be null");
Objects.requireNonNull(this.type, "'type' must not be null");
- Objects.requireNonNull(this.state, "'state' must not be null");
+ if (perReplicaStatesRef == null) { // PRS collection
+ Objects.requireNonNull(this.state, "'state' must not be null");
+ }
Objects.requireNonNull(this.node, "'node' must not be null");
String baseUrl = (String) propMap.get(ReplicaStateProps.BASE_URL);
@@ -259,7 +261,9 @@ public class Replica extends ZkNodeProps implements MapWriter {
propMap.put(ReplicaStateProps.NODE_NAME, node);
propMap.put(ReplicaStateProps.CORE_NAME, core);
propMap.put(ReplicaStateProps.TYPE, type.toString());
- propMap.put(ReplicaStateProps.STATE, state.toString());
+ if (perReplicaStatesRef == null) { // PRS collection
+ propMap.put(ReplicaStateProps.STATE, state.toString());
+ }
}
public String getCollection() {
@@ -418,8 +422,12 @@ public class Replica extends ZkNodeProps implements MapWriter {
ew.putIfNotNull(ReplicaStateProps.CORE_NAME, core)
.putIfNotNull(ReplicaStateProps.NODE_NAME, node)
.putIfNotNull(ReplicaStateProps.TYPE, type.toString())
- .putIfNotNull(ReplicaStateProps.STATE, getState().toString())
- .putIfNotNull(ReplicaStateProps.LEADER, () -> isLeader() ? "true" : null)
+ .putIfNotNull(
+ ReplicaStateProps.STATE,
+ () -> perReplicaStatesRef == null ? getState().toString() : null)
+ .putIfNotNull(
+ ReplicaStateProps.LEADER,
+ () -> perReplicaStatesRef != null || !isLeader() ? null : "true")
.putIfNotNull(
ReplicaStateProps.FORCE_SET_STATE, propMap.get(ReplicaStateProps.FORCE_SET_STATE))
.putIfNotNull(ReplicaStateProps.BASE_URL, propMap.get(ReplicaStateProps.BASE_URL));
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
index 3512e74c6f3..334851ca985 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
@@ -22,6 +22,7 @@ import static org.apache.solr.common.params.CollectionAdminParams.PER_REPLICA_ST
import java.lang.invoke.MethodHandles;
import java.util.Collections;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.solr.client.solrj.SolrClient;
@@ -31,6 +32,9 @@ import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.MapWriterMap;
+import org.apache.solr.common.NavigableObject;
+import org.apache.solr.common.util.Utils;
import org.apache.solr.embedded.JettySolrRunner;
import org.apache.solr.util.LogLevel;
import org.apache.zookeeper.data.Stat;
@@ -186,17 +190,24 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
collectionPath, SolrCloudTestCase.cluster.getZkClient(), null);
PerReplicaStates.State st = prs.get(replicaName);
assertNotEquals(Replica.State.ACTIVE, st.state);
- CollectionAdminResponse rsp =
- new CollectionAdminRequest.ClusterStatus()
- .setCollectionName(testCollection)
- .process(cluster.getSolrClient());
- assertEquals(
- "true",
+ @SuppressWarnings("unchecked")
+ NavigableObject rsp =
+ new MapWriterMap(
+ (Map<String, Object>)
+ Utils.fromJSON(
+ SolrCloudTestCase.cluster
+ .getZkClient()
+ .getData(
+ DocCollection.getCollectionPath(testCollection),
+ null,
+ null,
+ true)));
+
+ assertNull(
rsp._get(
"cluster/collections/prs_restart_test/shards/shard1/replicas/core_node2/leader",
null));
- assertEquals(
- "active",
+ assertNull(
rsp._get(
"cluster/collections/prs_restart_test/shards/shard1/replicas/core_node2/state",
null));
@@ -204,8 +215,7 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
rsp._get(
"cluster/collections/prs_restart_test/shards/shard1/replicas/core_node4/leader",
null));
- assertEquals(
- "down",
+ assertNull(
rsp._get(
"cluster/collections/prs_restart_test/shards/shard1/replicas/core_node4/state",
null));