Skip to content

Commit

Permalink
Resolve reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Borjianamin98 committed Dec 19, 2021
1 parent a72ddfa commit 286bebc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/ir/sahab/zk/client/ZkClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ public String addSequentiallyNamedNode(String parentPath, String namePrefix, byt
*/
public void addPersistentNode(String path, byte[] data, boolean createParent)
throws ZkClientException, InterruptedException {
// There is a corner case where Curator throws a ConnectionLoss but actually we added
// the ZK node. In order to be sure that the logic used for the exceptional case is correct,
// There is a corner case where Curator throws a ConnectionLoss but the ZK node is actually added.
// In order to be sure that the logic used for the exceptional case is correct,
// it is necessary to first check the existence of the path and if it exists, skip the rest
// of the operations.
if (exists(path)) {
throw new ZkClientException("Failed to add ZK node because node exists: path = " + path);
throw new ZkClientException("Failed to add ZK node because node exists: " + path);
}

try {
Expand All @@ -328,13 +328,13 @@ public void addPersistentNode(String path, byte[] data, boolean createParent)
} catch (InterruptedException ex) {
throw ex;
} catch (Exception ex) {
// There is a corner case where Curator throws a ConnectionLoss but actually we added
// the ZK node, so when we retry we get NodeExists exception. In here, we check whether
// node created or not and ignore error if exists.
// There is a corner case where Curator throws a ConnectionLoss but the ZK node is actually
// added, so when we retry we get NodeExists exception. In here, we check whether the node
// is created or not and ignore the exception if the node exists.
if (exists(path) && Arrays.equals(getData(path), data)) {
logger.warn("Retrieve error in creating ZK path but node created anyway: path = {}", path);
logger.warn("Retrieve error in creating ZK path but node created anyway: {}", path);
} else {
throw new ZkClientException("Failed to add a persistent ZK node: path = {}" + path);
throw new ZkClientException("Failed to add a persistent ZK node: " + path, ex);
}
}
}
Expand Down

0 comments on commit 286bebc

Please sign in to comment.