Jackie-Jiang commented on a change in pull request #8305: URL: https://github.com/apache/pinot/pull/8305#discussion_r821131260
########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java ########## @@ -1539,7 +1539,11 @@ public ZNRecord readZKData(String path) { return _helixDataAccessor.getBaseDataAccessor().get(path, null, -1); } - public List<String> getZKChildren(String path) { + public List<ZNRecord> getZKChildren(String path) { + return _helixDataAccessor.getBaseDataAccessor().getChildren(path, null, -1, 1, 1); Review comment: ```suggestion return _helixDataAccessor.getBaseDataAccessor().getChildren(path, null, -1, CommonConstants.Helix.ZkClient.RETRY_COUNT, CommonConstants.Helix.ZkClient.RETRY_INTERVAL_MS); ``` ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java ########## @@ -187,14 +181,47 @@ public String ls( path = validateAndNormalizeZKPath(path, true); - List<String> children = _pinotHelixResourceManager.getZKChildren(path); + List<String> children = _pinotHelixResourceManager.getZKChildNames(path); Review comment: (minor) ```suggestion List<String> childNames = _pinotHelixResourceManager.getZKChildNames(path); ``` ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java ########## @@ -84,14 +85,7 @@ public String getData( ZNRecord znRecord = _pinotHelixResourceManager.readZKData(path); if (znRecord != null) { - byte[] serializeBytes = _znRecordSerializer.serialize(znRecord); - if (GZipCompressionUtil.isCompressed(serializeBytes)) { - try { - serializeBytes = GZipCompressionUtil.uncompress(new ByteArrayInputStream(serializeBytes)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + byte[] serializeBytes = serialize(znRecord); Review comment: Not introduced in this PR, but we should be able to directly use `JsonUtils.objectToPrettyString(znRecord)` instead of using the `ZNRecordSerializer`, compressing and then decompressing again ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java ########## @@ -187,14 +181,47 @@ public String ls( path = validateAndNormalizeZKPath(path, true); - List<String> children = _pinotHelixResourceManager.getZKChildren(path); + List<String> children = _pinotHelixResourceManager.getZKChildNames(path); try { return JsonUtils.objectToString(children); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } + @GET + @Path("/zk/getChildren") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Get all child znodes") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Success"), + @ApiResponse(code = 404, message = "ZK Path not found"), + @ApiResponse(code = 204, message = "No Content"), + @ApiResponse(code = 500, message = "Internal server error") + }) + public String getChildren( + @ApiParam(value = "Zookeeper Path, must start with /", required = true) @QueryParam("path") String path) { + + path = validateAndNormalizeZKPath(path, true); + + List<ZNRecord> znRecords = _pinotHelixResourceManager.getZKChildren(path); + if (znRecords != null) { + List<String> resp = new ArrayList<>(); + for (ZNRecord znRecord : znRecords) { + if (znRecord != null) { + byte[] serializeBytes = serialize(znRecord); + resp.add(new String(serializeBytes, StandardCharsets.UTF_8)); + } + } + try { + return JsonUtils.objectToString(resp); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + return null; Review comment: Throw `NOT_FOUND` ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java ########## @@ -84,14 +85,7 @@ public String getData( ZNRecord znRecord = _pinotHelixResourceManager.readZKData(path); if (znRecord != null) { - byte[] serializeBytes = _znRecordSerializer.serialize(znRecord); - if (GZipCompressionUtil.isCompressed(serializeBytes)) { - try { - serializeBytes = GZipCompressionUtil.uncompress(new ByteArrayInputStream(serializeBytes)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + byte[] serializeBytes = serialize(znRecord); return new String(serializeBytes, StandardCharsets.UTF_8); } return null; Review comment: Should throw `NOT_FOUND` instead of returning `null` ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/ZookeeperResource.java ########## @@ -187,14 +181,47 @@ public String ls( path = validateAndNormalizeZKPath(path, true); - List<String> children = _pinotHelixResourceManager.getZKChildren(path); + List<String> children = _pinotHelixResourceManager.getZKChildNames(path); try { return JsonUtils.objectToString(children); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } + @GET + @Path("/zk/getChildren") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Get all child znodes") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Success"), + @ApiResponse(code = 404, message = "ZK Path not found"), + @ApiResponse(code = 204, message = "No Content"), + @ApiResponse(code = 500, message = "Internal server error") + }) + public String getChildren( + @ApiParam(value = "Zookeeper Path, must start with /", required = true) @QueryParam("path") String path) { + + path = validateAndNormalizeZKPath(path, true); + + List<ZNRecord> znRecords = _pinotHelixResourceManager.getZKChildren(path); + if (znRecords != null) { + List<String> resp = new ArrayList<>(); + for (ZNRecord znRecord : znRecords) { + if (znRecord != null) { + byte[] serializeBytes = serialize(znRecord); + resp.add(new String(serializeBytes, StandardCharsets.UTF_8)); + } + } + try { + return JsonUtils.objectToString(resp); Review comment: This will cause `ZNRecord` encoded as escaped string. Try `JsonUtils.objectToPrettyString(znRecords)` -- 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