mayankshriv commented on code in PR #10359: URL: https://github.com/apache/pinot/pull/10359#discussion_r1128488598
########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/DefaultTableRebalanceObserver.java: ########## @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.controller.helix.core.rebalance; + +import java.util.Map; + +/** + * Default No-op TableRebalanceObserver. Review Comment: Why do we need this? ########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/TableRebalanceObserver.java: ########## @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.controller.helix.core.rebalance; + +import java.util.Map; + +/** + * The <code>TableRebalanceObserver</code> interface provides callbacks to take actions + * during critical triggers. The 3 main triggers during a rebalance operation are show below. + * For example, we can track stats + status of rebalance during these triggers. + */ + +public interface TableRebalanceObserver { + enum Trigger { + // Start of rebalance Trigger + START_TRIGGER, + // Waiting for external view to converge towards ideal state + EXTERNAL_VIEW_TO_IDEAL_CONVERGENCE_TRIGGER, Review Comment: IDEAL_STATE? ########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java: ########## @@ -2126,13 +2141,15 @@ public boolean addNewReloadAllSegmentsJob(String tableNameWithType, String jobId jobMetadata.put(CommonConstants.ControllerJob.JOB_TYPE, ControllerJobType.RELOAD_ALL_SEGMENTS.toString()); jobMetadata.put(CommonConstants.ControllerJob.SUBMISSION_TIME_MS, Long.toString(System.currentTimeMillis())); jobMetadata.put(CommonConstants.ControllerJob.MESSAGE_COUNT, Integer.toString(numberOfMessagesSent)); - return addControllerJobToZK(jobId, jobMetadata); + return addControllerJobToZK(jobId, jobMetadata, Review Comment: When does this znode get cleaned up? ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java: ########## @@ -712,6 +719,37 @@ public String getTableState( } } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Authenticate(AccessType.UPDATE) + @Path("/rebalanceStatus/{jobId}") + @ApiOperation(value = "Gets detailed stats of a rebalance operation", + notes = "Gets detailed stats of a rebalance operation") + public ServerRebalanceJobStatusResponse rebalanceStatus(@ApiParam(value = "Rebalance Job Id", required = true) + @PathParam("jobId") String jobId) + throws JsonProcessingException { + Map<String, String> controllerJobZKMetadata = + _pinotHelixResourceManager.getControllerJobZKMetadataResource(jobId, + CommonConstants.Helix.ZkClient.ZK_REBALANCE_RESOURCE); + if (controllerJobZKMetadata == null) { + throw new ControllerApplicationException(LOGGER, "Failed to find controller job id: " + jobId, + Response.Status.NOT_FOUND); + } + TableRebalanceProgressStats tableRebalanceProgressStats = JsonUtils.stringToObject( + controllerJobZKMetadata.get(RebalanceConfigConstants.REBALANCE_PROGRESS_STATS), + TableRebalanceProgressStats.class); + Long timeSinceStartInSecs = 0L; + if (!tableRebalanceProgressStats.getStatus().toString().equals(RebalanceResult.Status.DONE.toString())) { + timeSinceStartInSecs = (long) (System.currentTimeMillis() + - tableRebalanceProgressStats.getStartTimeInMilliseconds()) / 1000; + } + ServerRebalanceJobStatusResponse serverRebalanceJobStatusResponse = new ServerRebalanceJobStatusResponse(); + serverRebalanceJobStatusResponse.setTableRebalanceProgressStats(tableRebalanceProgressStats); + serverRebalanceJobStatusResponse.setTimeElapsedSinceStartInSeconds(timeSinceStartInSecs); + return serverRebalanceJobStatusResponse; Review Comment: Does this include a response code (eg 200 ok)? ########## pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/rebalance/ZkBasedTableRebalanceObserver.java: ########## @@ -0,0 +1,156 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.controller.helix.core.rebalance; + +import com.google.common.base.Preconditions; +import java.util.Map; +import org.apache.helix.store.zk.ZkHelixPropertyStore; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.pinot.controller.helix.core.PinotHelixResourceManager; +import org.apache.pinot.spi.utils.CommonConstants; +/** + * <code>ZkBasedTableRebalanceObserver</code> observes rebalance progress and tracks rebalance status, + * stats in Zookeeper. This will be used to show the progress of rebalance to users via rebalanceStatus API. + */ +public class ZkBasedTableRebalanceObserver implements TableRebalanceObserver { + private final String _tableNameWithType; + private final String _rebalanceJobId; + private final ZkHelixPropertyStore<ZNRecord> _propertyStore; + TableRebalanceProgressStats _tableRebalanceProgressStats; + + public ZkBasedTableRebalanceObserver(String tableNameWithType, + String rebalanceJobId, + ZkHelixPropertyStore<ZNRecord> propertyStore) { + Preconditions.checkState(tableNameWithType != null, "Table name cannot be null"); + Preconditions.checkState(rebalanceJobId != null, "rebalanceId cannot be null"); + Preconditions.checkState(propertyStore != null, "propertyStore cannot be null"); + _tableNameWithType = tableNameWithType; + _rebalanceJobId = rebalanceJobId; + _propertyStore = propertyStore; + _tableRebalanceProgressStats = new TableRebalanceProgressStats(); + } + + @Override + public void onTrigger(Trigger trigger, Map<String, Map<String, String>> currentState, + Map<String, Map<String, String>> targetState) { + switch (trigger) { + case START_TRIGGER: Review Comment: I could not find where these are being set. -- 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]
