saurabhd336 commented on code in PR #8828:
URL: https://github.com/apache/pinot/pull/8828#discussion_r899984959


##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java:
##########
@@ -1975,6 +1977,105 @@ private Set<String> getAllInstancesForTable(String 
tableNameWithType) {
     return instanceSet;
   }
 
+  public Map<String, String> getTaskZKMetadata(String tableNameWithType, 
String taskId) {
+    String taskResourcePath = 
ZKMetadataProvider.constructPropertyStorePathForTask(tableNameWithType);
+    if (_propertyStore.exists(taskResourcePath, AccessOption.PERSISTENT)) {
+      ZNRecord taskResourceZnRecord = _propertyStore.get(taskResourcePath, 
null, -1);
+      return taskResourceZnRecord.getMapFields().get(taskId);
+    } else {
+      return null;
+    }
+  }
+
+  public Map<String, Map<String, String>> getAllTasksForTable(String 
tableNameWithType) {
+    String taskResourcePath = 
ZKMetadataProvider.constructPropertyStorePathForTask(tableNameWithType);
+    if (_propertyStore.exists(taskResourcePath, AccessOption.PERSISTENT)) {
+      ZNRecord tableTaskRecord = _propertyStore.get(taskResourcePath, null, 
-1);
+      return tableTaskRecord.getMapFields();
+    } else {
+      return Collections.emptyMap();
+    }
+  }
+
+  public void addNewReloadSegmentTask(String tableNameWithType, String 
segmentName, String taskId,
+      int numberOfMessagesSent) {
+    Map<String, String> taskMetadata = new HashMap<>();
+    taskMetadata.put(CommonConstants.Task.TASK_ID, taskId);
+    taskMetadata.put(CommonConstants.Task.TASK_TYPE, 
TaskType.RELOAD_SEGMENT.toString());
+    taskMetadata.put(CommonConstants.Task.TASK_SUBMISSION_TIME, 
Long.toString(System.currentTimeMillis()));
+    taskMetadata.put(CommonConstants.Task.TASK_MESSAGE_COUNT, 
Integer.toString(numberOfMessagesSent));
+    taskMetadata.put(CommonConstants.Task.SEGMENT_RELOAD_TASK_SEGMENT_NAME, 
segmentName);
+
+    String taskResourcePath = 
ZKMetadataProvider.constructPropertyStorePathForTask(tableNameWithType);
+    ZNRecord tableTaskZnRecord;
+
+    if (_propertyStore.exists(taskResourcePath, AccessOption.PERSISTENT)) {
+      tableTaskZnRecord = _propertyStore.get(taskResourcePath, null, -1);
+      Map<String, Map<String, String>> tasks = 
tableTaskZnRecord.getMapFields();
+      tasks.put(taskId, taskMetadata);
+      if (tasks.size() > CommonConstants.Task.MAXIMUM_RELOAD_TASKS_IN_ZK) {
+        tasks = tasks.
+            entrySet()
+            .stream()
+            .sorted(new Comparator<Map.Entry<String, Map<String, String>>>() {
+          @Override
+          public int compare(Map.Entry<String, Map<String, String>> v1, 
Map.Entry<String, Map<String, String>> v2) {
+            return 
Long.compare(Long.parseLong(v2.getValue().get(CommonConstants.Task.TASK_SUBMISSION_TIME)),
+                
Long.parseLong(v1.getValue().get(CommonConstants.Task.TASK_SUBMISSION_TIME)));
+          }
+        })
+            .collect(Collectors.toList())
+            .subList(0, CommonConstants.Task.MAXIMUM_RELOAD_TASKS_IN_ZK)
+            .stream()
+            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+      }
+      tableTaskZnRecord.setMapFields(tasks);
+    } else {
+      tableTaskZnRecord = new ZNRecord(taskResourcePath);
+      tableTaskZnRecord.setMapField(taskId, taskMetadata);
+    }
+
+    _propertyStore.set(taskResourcePath, tableTaskZnRecord, 
AccessOption.PERSISTENT);
+  }
+
+  public void addNewReloadAllSegmentsTask(String tableNameWithType, String 
taskId, int numberOfMessagesSent) {
+    Map<String, String> taskMetadata = new HashMap<>();
+    taskMetadata.put(CommonConstants.Task.TASK_ID, taskId);
+    taskMetadata.put(CommonConstants.Task.TASK_TYPE, 
TaskType.RELOAD_ALL_SEGMENTS.toString());
+    taskMetadata.put(CommonConstants.Task.TASK_SUBMISSION_TIME, 
Long.toString(System.currentTimeMillis()));
+    taskMetadata.put(CommonConstants.Task.TASK_MESSAGE_COUNT, 
Integer.toString(numberOfMessagesSent));
+
+    String taskResourcePath = 
ZKMetadataProvider.constructPropertyStorePathForTask(tableNameWithType);
+    ZNRecord tableTaskZnRecord;
+
+    if (_propertyStore.exists(taskResourcePath, AccessOption.PERSISTENT)) {
+      tableTaskZnRecord = _propertyStore.get(taskResourcePath, null, -1);
+      Map<String, Map<String, String>> tasks = 
tableTaskZnRecord.getMapFields();
+      tasks.put(taskId, taskMetadata);
+      if (tasks.size() > CommonConstants.Task.MAXIMUM_RELOAD_TASKS_IN_ZK) {
+        tasks = tasks.

Review Comment:
   Ack



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