Skip to content

Commit

Permalink
SOLR-15694, 15715: Create ephemeral roles properly (missed backportin…
Browse files Browse the repository at this point in the history
…g these changes last time)
  • Loading branch information
noblepaul authored and Ishan Chattopadhyaya committed Oct 30, 2023
1 parent 002b3ce commit ace7641
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 31 additions & 1 deletion solr/core/src/java/org/apache/solr/cloud/ZkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import org.apache.solr.core.CloudConfig;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.NodeRoles;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrCoreInitializationException;
import org.apache.solr.handler.admin.ConfigSetsHandler;
Expand Down Expand Up @@ -700,7 +701,7 @@ public void giveupLeadership(CoreDescriptor cd) {

// if this replica is not a leader, it will be put in recovery state by the leader
String leader = cd.getCloudDescriptor().getCoreNodeName();
if (shard.getReplica(leader) != shard.getLeader()) return;
if (!Objects.equals(shard.getReplica(leader), shard.getLeader())) return;

Set<String> liveNodes = getClusterState().getLiveNodes();
int numActiveReplicas = shard.getReplicas(
Expand Down Expand Up @@ -858,6 +859,14 @@ public static void createClusterZkNodes(SolrZkClient zkClient)
throws KeeperException, InterruptedException, IOException {
ZkCmdExecutor cmdExecutor = new ZkCmdExecutor(zkClient.getZkClientTimeout());
cmdExecutor.ensureExists(ZkStateReader.LIVE_NODES_ZKNODE, zkClient);
cmdExecutor.ensureExists(ZkStateReader.NODE_ROLES, zkClient);
for (NodeRoles.Role role : NodeRoles.Role.values()) {
cmdExecutor.ensureExists(NodeRoles.getZNodeForRole(role), zkClient);
for (String mode : role.supportedModes()) {
cmdExecutor.ensureExists(NodeRoles.getZNodeForRoleMode(role, mode), zkClient);
}
}

cmdExecutor.ensureExists(ZkStateReader.COLLECTIONS_ZKNODE, zkClient);
cmdExecutor.ensureExists(ZkStateReader.ALIASES, zkClient);
cmdExecutor.ensureExists(ZkStateReader.SOLR_AUTOSCALING_EVENTS_PATH, zkClient);
Expand Down Expand Up @@ -1171,6 +1180,27 @@ private void createEphemeralLiveNode() throws KeeperException,
ops.add(Op.create(nodeAddedPath, json, zkClient.getZkACLProvider().getACLsToAdd(nodeAddedPath), CreateMode.EPHEMERAL));
}
zkClient.multi(ops, true);
Map<NodeRoles.Role, String> roles = cc.nodeRoles.getRoles();

try {
zkClient.create(nodePath, null, CreateMode.EPHEMERAL, true);
} catch (KeeperException.NodeExistsException e) {
// ignore , it's already there
}

for (Map.Entry<NodeRoles.Role, String> e : roles.entrySet()) {
try {
zkClient.create(
NodeRoles.getZNodeForRoleMode(e.getKey(), e.getValue()) + "/" + nodeName,
null,
CreateMode.EPHEMERAL,
true);
} catch (KeeperException.NodeExistsException ex) {
// ignore , it already exists
}
}

log.info("non-data nodes now {}", zkClient.getChildren("/node_roles/data/off", null,true));
}

public void removeEphemeralLiveNode() throws KeeperException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,9 @@ public void testWatch() throws Exception {
assertTrue(zkWatchAccessor.getWatchedCollections().contains(TEST_COLLECTION_1));

// add another collection
CollectionAdminRequest.createCollection(TEST_COLLECTION_2, "conf1", 1, 2).process(client);
CollectionAdminRequest.createCollection(TEST_COLLECTION_2, "conf1", 1, 2)
.setMaxShardsPerNode(10)
.process(client);
cluster.waitForActiveCollection(TEST_COLLECTION_2, 1, 2);
new QueryRequest(new SolrQuery("*:*"))
.setPreferredNodes(ImmutableList.of(coordinatorJetty.getNodeName()))
Expand Down

0 comments on commit ace7641

Please sign in to comment.