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


##########
pinot-common/src/main/java/org/apache/pinot/common/minion/TaskGeneratorMostRecentRunInfo.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.common.minion;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.TreeMap;
+import javax.annotation.Nonnull;
+import org.apache.helix.ZNRecord;
+
+
+/**
+ * a task generator running history which keeps the most recent several 
success run timestamp and the most recent
+ * several error run
+ * message.
+ */
+public class TaskGeneratorMostRecentRunInfo extends BaseTaskGeneratorInfo {
+  @VisibleForTesting
+  static final int MAX_NUM_OF_HISTORY_TO_KEEP = 5;
+  @VisibleForTesting
+  static final String MOST_RECENT_SUCCESS_RUN_TS = "mostRecentSuccessRunTs";
+  @VisibleForTesting
+  static final String MOST_RECENT_ERROR_RUN_MESSAGE = 
"mostRecentErrorRunMessage";

Review Comment:
   Seems not used?



##########
pinot-common/src/main/java/org/apache/pinot/common/minion/InMemoryTaskManagerStatusCache.java:
##########
@@ -0,0 +1,82 @@
+/**
+ * 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.common.minion;
+
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+
+public class InMemoryTaskManagerStatusCache extends 
TaskManagerStatusCache<TaskGeneratorMostRecentRunInfo> {
+
+  private static class TaskGeneratorCacheKey {
+    String _tableNameWithType;

Review Comment:
   (minor) make them `final`



##########
pinot-common/src/main/java/org/apache/pinot/common/minion/TaskGeneratorMostRecentRunInfo.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.common.minion;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.TreeMap;
+import javax.annotation.Nonnull;
+import org.apache.helix.ZNRecord;
+
+
+/**
+ * a task generator running history which keeps the most recent several 
success run timestamp and the most recent
+ * several error run
+ * message.
+ */
+public class TaskGeneratorMostRecentRunInfo extends BaseTaskGeneratorInfo {
+  @VisibleForTesting
+  static final int MAX_NUM_OF_HISTORY_TO_KEEP = 5;
+  @VisibleForTesting
+  static final String MOST_RECENT_SUCCESS_RUN_TS = "mostRecentSuccessRunTs";
+  @VisibleForTesting
+  static final String MOST_RECENT_ERROR_RUN_MESSAGE = 
"mostRecentErrorRunMessage";
+
+  private final String _taskType;
+  private final String _tableNameWithType;
+  // the timestamp to error message map of the most recent several error runs
+  @Nonnull
+  private final TreeMap<Long, String> _mostRecentErrorRunMessage;
+  // the timestamp of the most recent several success runs
+  @Nonnull
+  private final List<Long> _mostRecentSuccessRunTS;
+  private final int _version;
+
+  private TaskGeneratorMostRecentRunInfo(String tableNameWithType, String 
taskType,
+      Map<Long, String> mostRecentErrorRunMessage, List<Long> 
mostRecentSuccessRunTS, int version) {
+    _tableNameWithType = tableNameWithType;
+    _taskType = taskType;
+    // sort and keep the most recent several error messages
+    _mostRecentErrorRunMessage = new TreeMap<>();

Review Comment:
   Since we decided to not use ZNode to store the information, suggest 
simplifying it to only take `tableNameWithType` and `taskType`. We may change 
it when we decide to persist the info in the future.



##########
pinot-common/src/main/java/org/apache/pinot/common/minion/TaskGeneratorMostRecentRunInfo.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.common.minion;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.TreeMap;
+import javax.annotation.Nonnull;
+import org.apache.helix.ZNRecord;
+
+
+/**
+ * a task generator running history which keeps the most recent several 
success run timestamp and the most recent
+ * several error run
+ * message.

Review Comment:
   (minor)
   ```suggestion
    * several error run messages.
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/minion/TaskGeneratorMostRecentRunInfo.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.common.minion;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.TreeMap;
+import javax.annotation.Nonnull;
+import org.apache.helix.ZNRecord;
+
+
+/**
+ * a task generator running history which keeps the most recent several 
success run timestamp and the most recent
+ * several error run
+ * message.
+ */
+public class TaskGeneratorMostRecentRunInfo extends BaseTaskGeneratorInfo {
+  @VisibleForTesting
+  static final int MAX_NUM_OF_HISTORY_TO_KEEP = 5;
+  @VisibleForTesting
+  static final String MOST_RECENT_SUCCESS_RUN_TS = "mostRecentSuccessRunTs";
+  @VisibleForTesting
+  static final String MOST_RECENT_ERROR_RUN_MESSAGE = 
"mostRecentErrorRunMessage";
+
+  private final String _taskType;
+  private final String _tableNameWithType;
+  // the timestamp to error message map of the most recent several error runs
+  @Nonnull
+  private final TreeMap<Long, String> _mostRecentErrorRunMessage;

Review Comment:
   Consider storing timestamp as `java.sql.Timestamp` so that the response can 
show human readable time



##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTaskRestletResource.java:
##########
@@ -231,6 +260,55 @@ public Map<String, 
PinotHelixTaskResourceManager.TaskDebugInfo> getTasksDebugInf
     return _pinotHelixTaskResourceManager.getTasksDebugInfoByTable(taskType, 
tableNameWithType, verbosity);
   }
 
+  @GET
+  @Produces(MediaType.APPLICATION_JSON)
+  @Path("/tasks/generator/{tableNameWithType}/{taskType}/debug")
+  @ApiOperation("Fetch task generation information for the recent runs of the 
given task for the given table")
+  public String getTaskGenerationDebugInto(
+      @ApiParam(value = "Task type", required = true) @PathParam("taskType") 
String taskType,
+      @ApiParam(value = "Table name with type", required = true) 
@PathParam("tableNameWithType")
+          String tableNameWithType,
+      @ApiParam(value = "Whether to only lookup local cache for logs", 
defaultValue = "false") @QueryParam("localOnly")
+          boolean localOnly)
+      throws JsonProcessingException {
+    if (localOnly) {
+      BaseTaskGeneratorInfo taskGeneratorMostRecentRunInfo =
+          _taskManagerStatusCache.fetchTaskGeneratorInfo(tableNameWithType, 
taskType);
+      if (taskGeneratorMostRecentRunInfo == null) {
+        throw new ControllerApplicationException(LOGGER, "Task generation 
information not found",
+            Response.Status.NOT_FOUND);
+      }
+
+      return JsonUtils.objectToString(taskGeneratorMostRecentRunInfo);
+    }
+
+    // Call all controllers
+    List<InstanceConfig> controllers = 
_pinotHelixResourceManager.getAllControllerInstanceConfigs();
+    // Relying on original schema that was used to query the controller
+    URI uri = _uriInfo.getRequestUri();
+    String scheme = uri.getScheme();
+    List<String> controllerUrls = controllers.stream().map(controller -> {
+      return 
String.format("%s://%s:%d/tasks/generator/%s/%s/debug?localOnly=true", scheme, 
controller.getHostName(),
+          Integer.parseInt(controller.getPort()), tableNameWithType, taskType);
+    }).collect(Collectors.toList());
+
+    CompletionServiceHelper completionServiceHelper =
+        new CompletionServiceHelper(_executor, _connectionManager, 
HashBiMap.create(0));
+    CompletionServiceHelper.CompletionServiceResponse serviceResponse =
+        completionServiceHelper.doMultiGetRequest(controllerUrls, null, true, 
10000);
+
+    List<JsonNode> result = new ArrayList<>();
+    serviceResponse._httpResponses.values().forEach(resp -> {
+      try {
+        result.add(JsonUtils.stringToJsonNode(resp));
+      } catch (IOException e) {
+        LOGGER.error("Failed to parse ");

Review Comment:
   Incomplete



##########
pinot-common/src/main/java/org/apache/pinot/common/minion/TaskGeneratorMostRecentRunInfo.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.common.minion;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.TreeMap;
+import javax.annotation.Nonnull;
+import org.apache.helix.ZNRecord;
+
+
+/**
+ * a task generator running history which keeps the most recent several 
success run timestamp and the most recent
+ * several error run
+ * message.
+ */
+public class TaskGeneratorMostRecentRunInfo extends BaseTaskGeneratorInfo {
+  @VisibleForTesting
+  static final int MAX_NUM_OF_HISTORY_TO_KEEP = 5;
+  @VisibleForTesting
+  static final String MOST_RECENT_SUCCESS_RUN_TS = "mostRecentSuccessRunTs";
+  @VisibleForTesting
+  static final String MOST_RECENT_ERROR_RUN_MESSAGE = 
"mostRecentErrorRunMessage";
+
+  private final String _taskType;
+  private final String _tableNameWithType;
+  // the timestamp to error message map of the most recent several error runs
+  @Nonnull
+  private final TreeMap<Long, String> _mostRecentErrorRunMessage;

Review Comment:
   ```suggestion
     private final TreeMap<Long, String> _mostRecentErrorRunMessages;
   ```



##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/minion/PinotTaskManager.java:
##########
@@ -517,7 +526,34 @@ private synchronized Map<String, String> 
scheduleTasks(List<String> tableNamesWi
   private String scheduleTask(PinotTaskGenerator taskGenerator, 
List<TableConfig> enabledTableConfigs,
       boolean isLeader) {
     LOGGER.info("Trying to schedule task type: {}, isLeader: {}", 
taskGenerator.getTaskType(), isLeader);
-    List<PinotTaskConfig> pinotTaskConfigs = 
taskGenerator.generateTasks(enabledTableConfigs);
+    List<PinotTaskConfig> pinotTaskConfigs;
+    try {
+      pinotTaskConfigs = taskGenerator.generateTasks(enabledTableConfigs);
+      for (TableConfig tableConfig : enabledTableConfigs) {

Review Comment:
   Let's add a `TODO` here to separate the generated task/exception for each 
table. Currently even though some table doesn't have anything scheduled (e.g. 
enough tasks are scheduled from previous tables), we will still put success TS 
for it



##########
pinot-common/src/main/java/org/apache/pinot/common/minion/TaskGeneratorMostRecentRunInfo.java:
##########
@@ -0,0 +1,151 @@
+/**
+ * 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.common.minion;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+import java.util.Queue;
+import java.util.TreeMap;
+import javax.annotation.Nonnull;
+import org.apache.helix.ZNRecord;
+
+
+/**
+ * a task generator running history which keeps the most recent several 
success run timestamp and the most recent
+ * several error run
+ * message.
+ */
+public class TaskGeneratorMostRecentRunInfo extends BaseTaskGeneratorInfo {
+  @VisibleForTesting
+  static final int MAX_NUM_OF_HISTORY_TO_KEEP = 5;
+  @VisibleForTesting
+  static final String MOST_RECENT_SUCCESS_RUN_TS = "mostRecentSuccessRunTs";
+  @VisibleForTesting
+  static final String MOST_RECENT_ERROR_RUN_MESSAGE = 
"mostRecentErrorRunMessage";
+
+  private final String _taskType;
+  private final String _tableNameWithType;
+  // the timestamp to error message map of the most recent several error runs
+  @Nonnull

Review Comment:
   (minor) We don't usually use `Nonnull`. Everything without annotation are 
treated non-null



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

Reply via email to