Jackie-Jiang commented on code in PR #8663:
URL: https://github.com/apache/pinot/pull/8663#discussion_r878650869


##########
pinot-common/src/main/java/org/apache/pinot/common/messages/RunPeriodicTaskMessage.java:
##########
@@ -32,20 +32,23 @@ public class RunPeriodicTaskMessage extends Message {
   private static final String PERIODIC_TASK_REQUEST_ID = "requestId";
   private static final String PERIODIC_TASK_NAME_KEY = "taskName";
   private static final String TABLE_NAME_WITH_TYPE_KEY = "tableNameWithType";
+  private static final String TASK_PARAMS = "taskParams";
 
   /**
    * @param taskRequestId Request Id that will be appended to log messages.
    * @param periodicTaskName Name of the task that will be run.
    * @param tableNameWithType Table (names with type suffix) on which task 
will run.
    */
-  public RunPeriodicTaskMessage(String taskRequestId, String periodicTaskName, 
String tableNameWithType) {
+  public RunPeriodicTaskMessage(String taskRequestId, String periodicTaskName, 
String tableNameWithType,
+      String taskParamsJson) {

Review Comment:
   We may take a `Map<String, String>` here and use the map field from the 
ZNRecord



##########
pinot-common/src/main/java/org/apache/pinot/common/messages/RunPeriodicTaskMessage.java:
##########
@@ -32,20 +32,23 @@ public class RunPeriodicTaskMessage extends Message {
   private static final String PERIODIC_TASK_REQUEST_ID = "requestId";
   private static final String PERIODIC_TASK_NAME_KEY = "taskName";
   private static final String TABLE_NAME_WITH_TYPE_KEY = "tableNameWithType";
+  private static final String TASK_PARAMS = "taskParams";

Review Comment:
   Suggest naming it "properties" to be consistent with the name in 
`RunPeriodicTaskMessageHandler`



##########
pinot-controller/src/main/java/org/apache/pinot/controller/ControllerUserDefinedMessageHandlerFactory.java:
##########
@@ -109,6 +113,10 @@ private static Properties createTaskProperties(String 
periodicTaskRequestId, Str
         
periodicTaskParameters.setProperty(PeriodicTask.PROPERTY_KEY_TABLE_NAME, 
tableNameWithType);
       }
 
+      if (taskParamsJson != null) {

Review Comment:
   Here we can write the key-value pairs of the map into the `Properties`



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotRealtimeTableResource.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.api.resources;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import java.util.UUID;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.helix.ClusterMessagingService;
+import org.apache.helix.Criteria;
+import org.apache.helix.InstanceType;
+import org.apache.pinot.common.messages.RunPeriodicTaskMessage;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.validation.RealtimeSegmentValidationManager;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@Api(tags = Constants.TABLE_TAG)
+@Path("/")
+public class PinotRealtimeTableResource {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PinotRealtimeTableResource.class);
+
+  @Inject
+  PinotHelixResourceManager _pinotHelixResourceManager;
+
+  @POST
+  @Path("/tables/{tableName}/resumeConsumption")
+  @Produces(MediaType.APPLICATION_JSON)
+  @Consumes(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Resume the consumption of a realtime table",
+      notes = "Resume the consumption of a realtime table")
+  public String resumeConsumption(
+      @ApiParam(value = "Name of the table", required = true)
+      @PathParam("tableName") String tableName) throws JsonProcessingException 
{
+    String tableNameWithType = 
TableNameBuilder.REALTIME.tableNameWithType(tableName);
+    // Generate an id for this request by taking first eight characters of a 
randomly generated UUID. This request id
+    // is returned to the user and also appended to log messages so that user 
can locate all log messages associated
+    // with this PeriodicTask's execution.
+    String periodicTaskRequestId = "api-" + 
UUID.randomUUID().toString().substring(0, 8);
+
+    LOGGER.info("[TaskRequestId: {}] Sending periodic task message to all 
controllers for running task {} against {}.",

Review Comment:
   Suggest making it more explicit that this is a resume consumption request



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/periodictask/ControllerPeriodicTask.java:
##########
@@ -103,10 +105,16 @@ public final ControllerMetrics getControllerMetrics() {
    * <p>
    * Override one of this method, {@link #processTable(String)} or {@link 
#processTable(String, C)}.
    */
-  protected void processTables(List<String> tableNamesWithType) {
+  protected void processTables(List<String> tableNamesWithType, String 
taskParamsJson) {
     int numTables = tableNamesWithType.size();
     LOGGER.info("Processing {} tables in task: {}", numTables, _taskName);
-    C context = preprocess();
+    C context;
+    try {
+      context = preprocess(taskParamsJson);

Review Comment:
   Same here, passing the whole `Properties` into `preprocess`



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotRealtimeTableResource.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.api.resources;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import java.util.UUID;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.helix.ClusterMessagingService;
+import org.apache.helix.Criteria;
+import org.apache.helix.InstanceType;
+import org.apache.pinot.common.messages.RunPeriodicTaskMessage;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.validation.RealtimeSegmentValidationManager;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@Api(tags = Constants.TABLE_TAG)
+@Path("/")
+public class PinotRealtimeTableResource {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PinotRealtimeTableResource.class);
+
+  @Inject
+  PinotHelixResourceManager _pinotHelixResourceManager;
+
+  @POST
+  @Path("/tables/{tableName}/resumeConsumption")
+  @Produces(MediaType.APPLICATION_JSON)
+  @Consumes(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Resume the consumption of a realtime table",
+      notes = "Resume the consumption of a realtime table")
+  public String resumeConsumption(
+      @ApiParam(value = "Name of the table", required = true)
+      @PathParam("tableName") String tableName) throws JsonProcessingException 
{
+    String tableNameWithType = 
TableNameBuilder.REALTIME.tableNameWithType(tableName);
+    // Generate an id for this request by taking first eight characters of a 
randomly generated UUID. This request id
+    // is returned to the user and also appended to log messages so that user 
can locate all log messages associated
+    // with this PeriodicTask's execution.
+    String periodicTaskRequestId = "api-" + 
UUID.randomUUID().toString().substring(0, 8);
+
+    LOGGER.info("[TaskRequestId: {}] Sending periodic task message to all 
controllers for running task {} against {}.",
+        periodicTaskRequestId, "RealtimeSegmentValidationManager", " table '" 
+ tableNameWithType + "'");

Review Comment:
   (minor) Make `"RealtimeSegmentValidationManager"` a constant



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/periodictask/ControllerPeriodicTask.java:
##########
@@ -83,7 +85,7 @@ protected final void runTask(Properties 
periodicTaskProperties) {
       }
 
       if (!tablesToProcess.isEmpty()) {
-        processTables(tablesToProcess);
+        processTables(tablesToProcess, taskParamsJson);

Review Comment:
   Suggest passing the whole `Properties` into the `processTables` to be more 
flexible



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/periodictask/ControllerPeriodicTask.java:
##########
@@ -103,10 +105,16 @@ public final ControllerMetrics getControllerMetrics() {
    * <p>
    * Override one of this method, {@link #processTable(String)} or {@link 
#processTable(String, C)}.
    */
-  protected void processTables(List<String> tableNamesWithType) {
+  protected void processTables(List<String> tableNamesWithType, String 
taskParamsJson) {
     int numTables = tableNamesWithType.size();
     LOGGER.info("Processing {} tables in task: {}", numTables, _taskName);
-    C context = preprocess();
+    C context;
+    try {
+      context = preprocess(taskParamsJson);
+    } catch (IOException e) {

Review Comment:
   We shouldn't need to catch this exception when the key-values are already 
put into the properties



##########
pinot-controller/src/main/java/org/apache/pinot/controller/validation/RealtimeSegmentValidationManager.java:
##########
@@ -172,8 +183,13 @@ public void cleanUpTask() {
     _validationMetrics.unregisterAllMetrics();
   }
 
+  public static final class RealtimeSegmentValidationTaskParameters {

Review Comment:
   This is already an inner class of `RealtimeSegmentValidationManager`, so no 
need to have a separate wrapper class for the parameters. Suggest directly 
adding `_recreateDeletedConsumingSegment` into the `Context` class



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotRealtimeTableResource.java:
##########
@@ -0,0 +1,99 @@
+/**
+ * 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.api.resources;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import java.util.UUID;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.helix.ClusterMessagingService;
+import org.apache.helix.Criteria;
+import org.apache.helix.InstanceType;
+import org.apache.pinot.common.messages.RunPeriodicTaskMessage;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.controller.validation.RealtimeSegmentValidationManager;
+import org.apache.pinot.spi.utils.CommonConstants;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@Api(tags = Constants.TABLE_TAG)
+@Path("/")
+public class PinotRealtimeTableResource {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PinotRealtimeTableResource.class);
+
+  @Inject
+  PinotHelixResourceManager _pinotHelixResourceManager;
+
+  @POST
+  @Path("/tables/{tableName}/resumeConsumption")
+  @Produces(MediaType.APPLICATION_JSON)
+  @Consumes(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Resume the consumption of a realtime table",
+      notes = "Resume the consumption of a realtime table")
+  public String resumeConsumption(
+      @ApiParam(value = "Name of the table", required = true)
+      @PathParam("tableName") String tableName) throws JsonProcessingException 
{
+    String tableNameWithType = 
TableNameBuilder.REALTIME.tableNameWithType(tableName);
+    // Generate an id for this request by taking first eight characters of a 
randomly generated UUID. This request id
+    // is returned to the user and also appended to log messages so that user 
can locate all log messages associated
+    // with this PeriodicTask's execution.
+    String periodicTaskRequestId = "api-" + 
UUID.randomUUID().toString().substring(0, 8);

Review Comment:
   This part is almost identical to the 
`PinotControllerPeriodicTaskRestletResource`, let's add a TODO here to extract 
the common part in the future



-- 
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

Reply via email to