Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-16593 : Redundant fields are present in the replica object of state.json #1293

Merged
merged 4 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
package org.apache.solr.cloud.api.collections;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
import org.apache.solr.cloud.OverseerCollectionConfigSetProcessor;
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.embedded.JettySolrRunner;
Expand Down Expand Up @@ -104,6 +109,29 @@ public void testCreateAndDeleteThenCreateAgain() throws Exception {
}
}

@Test
@SuppressWarnings("unchecked")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add the test where it verifies all the expected properties. If test sees new property then it fails. So that person can justify any change in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it is a good idea

public void testPropertiesOfReplica() throws Exception {
String collectionName = "testPropertiesOfReplica_coll";
CollectionAdminRequest.Create create =
CollectionAdminRequest.createCollection(collectionName, 2, 1);
NamedList<Object> request = create.process(cloudClient).getResponse();
assertNotNull(request.get("success"));
SolrZkClient.NodeData node =
getZkClient().getNode(DocCollection.getCollectionPath(collectionName), null, true);

DocCollection c =
ClusterState.createFromCollectionMap(
0, (Map<String, Object>) Utils.fromJSON(node.data), Collections.emptySet())
.getCollection(collectionName);

c.forEachReplica(
(s, replica) -> {
assertFalse(replica.getProperties().containsKey("collection"));
assertFalse(replica.getProperties().containsKey("shard"));
});
}

@Test
@ShardsFixed(num = 1)
public void testDeleteAlsoDeletesAutocreatedConfigSet() throws Exception {
Expand Down
5 changes: 0 additions & 5 deletions solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ private final void validate() {
Objects.requireNonNull(baseUrl, "'base_url' must not be null");

// make sure all declared props are in the propMap
propMap.put(ReplicaStateProps.COLLECTION, collection);
propMap.put(ReplicaStateProps.SHARD_ID, shard);
propMap.put(ReplicaStateProps.CORE_NODE_NAME, name);
propMap.put(ReplicaStateProps.NODE_NAME, node);
propMap.put(ReplicaStateProps.CORE_NAME, core);
propMap.put(ReplicaStateProps.TYPE, type.toString());
Expand Down Expand Up @@ -398,8 +395,6 @@ private MapWriter _allPropsWriter() {

writer
.put(ReplicaStateProps.CORE_NAME, core, p)
.put(ReplicaStateProps.SHARD_ID, shard, p)
.put(ReplicaStateProps.COLLECTION, collection, p)
.put(ReplicaStateProps.NODE_NAME, node, p)
.put(ReplicaStateProps.TYPE, type.toString(), p)
.put(ReplicaStateProps.STATE, state.toString(), p);
Expand Down