Skip to content

Commit

Permalink
Ignore node exists exception (#161)
Browse files Browse the repository at this point in the history
* Ignore node exists exception

* change multi op to individual operation so that we can ignore node exists exception for each of the node
  • Loading branch information
noblepaul authored Nov 1, 2023
1 parent aaea448 commit 05572c7
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions solr/core/src/java/org/apache/solr/cloud/ZkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1237,25 +1237,24 @@ private void createEphemeralLiveNode() throws KeeperException, InterruptedExcept
String nodePath = ZkStateReader.LIVE_NODES_ZKNODE + "/" + nodeName;
log.info("Register node as live in ZooKeeper:{}", nodePath);
Map<NodeRoles.Role, String> roles = cc.nodeRoles.getRoles();
List<Op> ops = new ArrayList<>(roles.size() + 1);
ops.add(
Op.create(
nodePath,

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,
zkClient.getZkACLProvider().getACLsToAdd(nodePath),
CreateMode.EPHEMERAL));

// Create the roles node as well
roles.forEach(
(role, mode) ->
ops.add(
Op.create(
NodeRoles.getZNodeForRoleMode(role, mode) + "/" + nodeName,
null,
zkClient.getZkACLProvider().getACLsToAdd(nodePath),
CreateMode.EPHEMERAL)));

zkClient.multi(ops, true);
CreateMode.EPHEMERAL,
true);
} catch (KeeperException.NodeExistsException ex) {
// ignore , it already exists
}
}
}

public void removeEphemeralLiveNode() throws KeeperException, InterruptedException {
Expand Down

0 comments on commit 05572c7

Please sign in to comment.