klsince commented on code in PR #11740:
URL: https://github.com/apache/pinot/pull/11740#discussion_r1361214644
##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java:
##########
@@ -666,6 +678,92 @@ public RebalanceResult rebalance(
}
}
+ @DELETE
+ @Produces(MediaType.APPLICATION_JSON)
+ @Authenticate(AccessType.UPDATE)
+ @Path("/tables/{tableName}/rebalance")
+ @Authorize(targetType = TargetType.TABLE, paramName = "tableName", action =
Actions.Table.ABORT_REBALANCE)
+ @ApiOperation(value = "Abort all rebalance jobs for the given table, and
noop if no rebalance is running", notes =
+ "Abort all rebalance jobs for the given table, and noop if no rebalance
is running")
+ public List<String> abortRebalance(
+ @ApiParam(value = "Name of the table to rebalance", required = true)
@PathParam("tableName") String tableName,
+ @ApiParam(value = "OFFLINE|REALTIME", required = true)
@QueryParam("type") String tableTypeStr) {
+ String tableNameWithType = constructTableNameWithType(tableName,
tableTypeStr);
+ String zkPath =
ZKMetadataProvider.constructPropertyStorePathForControllerJob(ControllerJobType.TABLE_REBALANCE);
+ List<String> abortedJobIds = new ArrayList<>();
+ // The rebalance job updates progress status kept in ZK regularly. If it
sees ABORTED status, it aborts itself.
+ boolean updated =
_pinotHelixResourceManager.updateAllJobsForTable(tableNameWithType, zkPath,
jobMetadata -> {
+ String jobId = jobMetadata.get(CommonConstants.ControllerJob.JOB_ID);
+ try {
+ String jobStatsInStr =
jobMetadata.get(RebalanceJobConstants.JOB_METADATA_KEY_REBALANCE_PROGRESS_STATS);
+ TableRebalanceProgressStats jobStats =
+ JsonUtils.stringToObject(jobStatsInStr,
TableRebalanceProgressStats.class);
+ if (jobStats.getStatus() != RebalanceResult.Status.IN_PROGRESS) {
+ return;
+ }
+ abortedJobIds.add(jobId);
+ LOGGER.info("Abort rebalance job: {} for table: {}", jobId,
tableNameWithType);
+ jobStats.setStatus(RebalanceResult.Status.ABORTED);
+
jobMetadata.put(RebalanceJobConstants.JOB_METADATA_KEY_REBALANCE_PROGRESS_STATS,
+ JsonUtils.objectToString(jobStats));
+
+ // Also cancel following retries for the rebalance job.
+ String jobCtxInStr =
jobMetadata.get(RebalanceJobConstants.JOB_METADATA_KEY_REBALANCE_ATTEMPT_CONTEXT);
+ if (StringUtils.isEmpty(jobCtxInStr)) {
+ // In case the job is submitted by older code, it may not have job
ctx field.
+ return;
+ }
+ TableRebalanceAttemptContext jobCtx =
JsonUtils.stringToObject(jobCtxInStr, TableRebalanceAttemptContext.class);
+ jobCtx.setCancelRetry(true);
Review Comment:
ABORTED is used in two places: 1) here, we want to stop all future retries
as well; 2) when next retry aborts previous ones, where we want retry continues
until maxAttempts. I'm +1 to add CANCELLED for clarity.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]