suddendust commented on code in PR #12497: URL: https://github.com/apache/pinot/pull/12497#discussion_r1505373850
########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java: ########## @@ -256,6 +258,71 @@ public SuccessResponse putData( } } + @POST + @Path("/zk/create") + @Authorize(targetType = TargetType.CLUSTER, action = Actions.Cluster.UPDATE_ZNODE) + @Authenticate(AccessType.CREATE) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Create a node at a given path") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 204, message = "No Content"), + @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 500, message = "Internal server error") + }) + public SuccessResponse createNode( + @ApiParam(value = "Zookeeper Path, must start with /", required = true) @QueryParam("path") String path, + @ApiParam(value = "Content") @QueryParam("data") @Nullable String data, + @ApiParam(value = "TTL of the node. TTL are only honoured for persistent znodes (access option = 0x40 or 0x80)," + + " in which case TTL should be > 0. If access option is not 0x40 or 0x80, it will be ignored, and we can " + + "set it to any value, or be ignored", defaultValue = "-1") + @QueryParam("ttl") @DefaultValue("-1") int ttl, + @ApiParam(value = "accessOption", defaultValue = "1") @QueryParam("accessOption") @DefaultValue("1") + int accessOption, @Nullable String payload) { + + path = validateAndNormalizeZKPath(path, false); + +// validate ttl range + if ((accessOption == AccessOption.PERSISTENT_WITH_TTL + || accessOption == AccessOption.PERSISTENT_SEQUENTIAL_WITH_TTL) && ttl <= 0) { + throw new ControllerApplicationException(LOGGER, "TTL for persistent nodes should be > 0", + Response.Status.BAD_REQUEST); + } + //check if node already exists + if (_pinotHelixResourceManager.getZKStat(path) != null) { Review Comment: This was put in to explicitly detect if a path already exists. ZK does not return any error codes to detect it. Yes, a race condition exists, but that should be fine. Two cases: 1. This check passes but node exists by the time ZK tries to create this node: It'll fail anyway transparently to the user (with an ISE instead of Bad Request though, which should be okay as the user would retry). 2. This check fails but node is deleted by another process before user receives a response: This is possible even if we leave this check to ZK. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org