Jackie-Jiang commented on code in PR #13488: URL: https://github.com/apache/pinot/pull/13488#discussion_r1663306183
########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java: ########## @@ -677,14 +678,30 @@ public RebalanceResult rebalance( if (dryRunResult.getStatus() == RebalanceResult.Status.DONE) { // If dry-run succeeded, run rebalance asynchronously rebalanceConfig.setDryRun(false); - _executorService.submit(() -> { + Future<RebalanceResult> rebalanceResultFuture = _executorService.submit(() -> { try { - _pinotHelixResourceManager.rebalanceTable(tableNameWithType, rebalanceConfig, rebalanceJobId, true); + return _pinotHelixResourceManager.rebalanceTable( + tableNameWithType, rebalanceConfig, rebalanceJobId, true); } catch (Throwable t) { - LOGGER.error("Caught exception/error while rebalancing table: {}", tableNameWithType, t); + String errorMsg = String.format("Caught exception/error while rebalancing table: %s", tableNameWithType); + LOGGER.error(errorMsg, t); + return new RebalanceResult(rebalanceJobId, RebalanceResult.Status.FAILED, errorMsg, null, null, null); } }); - waitForJobIdToPersist(dryRunResult.getJobId(), tableNameWithType); + boolean isJobIdPersisted = waitForJobIdToPersist(dryRunResult.getJobId(), tableNameWithType); + + // It's possible the dryRun indicates a rebalance is needed, but next rebalance is not. + // In that case, we never persist the jobId, but will already have a rebalanceResult. + // Return the actual rebalanceResult in this case. + if (!isJobIdPersisted && rebalanceResultFuture.isDone()) { Review Comment: Should we consider always return `rebalanceResultFuture.get()` if it is already done? ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java: ########## @@ -677,14 +678,30 @@ public RebalanceResult rebalance( if (dryRunResult.getStatus() == RebalanceResult.Status.DONE) { // If dry-run succeeded, run rebalance asynchronously rebalanceConfig.setDryRun(false); - _executorService.submit(() -> { + Future<RebalanceResult> rebalanceResultFuture = _executorService.submit(() -> { try { - _pinotHelixResourceManager.rebalanceTable(tableNameWithType, rebalanceConfig, rebalanceJobId, true); + return _pinotHelixResourceManager.rebalanceTable( + tableNameWithType, rebalanceConfig, rebalanceJobId, true); Review Comment: (minor) This reformat seems unnecessary ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java: ########## @@ -677,14 +678,30 @@ public RebalanceResult rebalance( if (dryRunResult.getStatus() == RebalanceResult.Status.DONE) { // If dry-run succeeded, run rebalance asynchronously rebalanceConfig.setDryRun(false); - _executorService.submit(() -> { + Future<RebalanceResult> rebalanceResultFuture = _executorService.submit(() -> { try { - _pinotHelixResourceManager.rebalanceTable(tableNameWithType, rebalanceConfig, rebalanceJobId, true); + return _pinotHelixResourceManager.rebalanceTable( + tableNameWithType, rebalanceConfig, rebalanceJobId, true); } catch (Throwable t) { - LOGGER.error("Caught exception/error while rebalancing table: {}", tableNameWithType, t); + String errorMsg = String.format("Caught exception/error while rebalancing table: %s", tableNameWithType); + LOGGER.error(errorMsg, t); + return new RebalanceResult(rebalanceJobId, RebalanceResult.Status.FAILED, errorMsg, null, null, null); } }); - waitForJobIdToPersist(dryRunResult.getJobId(), tableNameWithType); + boolean isJobIdPersisted = waitForJobIdToPersist(dryRunResult.getJobId(), tableNameWithType); + + // It's possible the dryRun indicates a rebalance is needed, but next rebalance is not. + // In that case, we never persist the jobId, but will already have a rebalanceResult. + // Return the actual rebalanceResult in this case. + if (!isJobIdPersisted && rebalanceResultFuture.isDone()) { + try { + return rebalanceResultFuture.get(); + } catch (Throwable ignored) { + // Ignore any errors here. Errors will have already been logged + // in the submitted future. Review Comment: (minor) Wrong formatting -- 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