You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/03/30 09:28:38 UTC

[GitHub] [iotdb] THUMarkLau commented on a change in pull request #5363: [IOTDB-2811] Fix compaction exception handle failure cause by deletion of storage group

THUMarkLau commented on a change in pull request #5363:
URL: https://github.com/apache/iotdb/pull/5363#discussion_r838326414



##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/CompactionTaskManager.java
##########
@@ -290,35 +292,34 @@ public synchronized void removeRunningTaskFromList(AbstractCompactionTask task)
    *
    * @throws RejectedExecutionException
    */
-  public synchronized void submitTask(Callable<Void> compactionMergeTask)
+  public synchronized Future<Void> submitTask(AbstractCompactionTask compactionTask)
       throws RejectedExecutionException {
     if (taskExecutionPool != null && !taskExecutionPool.isTerminated()) {
-      taskExecutionPool.submit(compactionMergeTask);
-      return;
+      Future<Void> future = taskExecutionPool.submit(compactionTask);
+      runningCompactionTaskList.add(compactionTask);
+      futureList.add(new Pair<>(compactionTask, future));
+      return future;
     }
     logger.warn(
         "A CompactionTask failed to be submitted to CompactionTaskManager because {}",
         taskExecutionPool == null
             ? "taskExecutionPool is null"
             : "taskExecutionPool is terminated");
+    return null;
   }
 
   /**
    * Abort all compactions of a storage group. The caller must acquire the write lock of the
    * corresponding storage group.
    */
-  public void abortCompaction(String fullStorageGroupName) {
-    Set<Future<Void>> subTasks =
-        storageGroupTasks.getOrDefault(fullStorageGroupName, Collections.emptySet());
-    candidateCompactionTaskQueue.clear();
-    Iterator<Future<Void>> subIterator = subTasks.iterator();
-    while (subIterator.hasNext()) {
-      Future<Void> next = subIterator.next();
-      if (!next.isDone() && !next.isCancelled()) {
-        next.cancel(true);
+  public synchronized void abortCompaction(String storageGroupName) {
+    for (Pair<AbstractCompactionTask, Future<Void>> futurePair : futureList) {
+      if (futurePair.left.getFullStorageGroupName().contains(storageGroupName)) {
+        futurePair.right.cancel(true);
       }
-      subIterator.remove();
     }
+
+    candidateCompactionTaskQueue.clear();

Review comment:
       When the compaction task finish, it will remove from the `futureList` and `runningCompactionTaskList` itself 

##########
File path: server/src/main/java/org/apache/iotdb/db/engine/compaction/CompactionTaskManager.java
##########
@@ -290,35 +292,34 @@ public synchronized void removeRunningTaskFromList(AbstractCompactionTask task)
    *
    * @throws RejectedExecutionException
    */
-  public synchronized void submitTask(Callable<Void> compactionMergeTask)
+  public synchronized Future<Void> submitTask(AbstractCompactionTask compactionTask)
       throws RejectedExecutionException {
     if (taskExecutionPool != null && !taskExecutionPool.isTerminated()) {
-      taskExecutionPool.submit(compactionMergeTask);
-      return;
+      Future<Void> future = taskExecutionPool.submit(compactionTask);
+      runningCompactionTaskList.add(compactionTask);
+      futureList.add(new Pair<>(compactionTask, future));
+      return future;
     }
     logger.warn(
         "A CompactionTask failed to be submitted to CompactionTaskManager because {}",
         taskExecutionPool == null
             ? "taskExecutionPool is null"
             : "taskExecutionPool is terminated");
+    return null;
   }
 
   /**
    * Abort all compactions of a storage group. The caller must acquire the write lock of the
    * corresponding storage group.
    */
-  public void abortCompaction(String fullStorageGroupName) {
-    Set<Future<Void>> subTasks =
-        storageGroupTasks.getOrDefault(fullStorageGroupName, Collections.emptySet());
-    candidateCompactionTaskQueue.clear();
-    Iterator<Future<Void>> subIterator = subTasks.iterator();
-    while (subIterator.hasNext()) {
-      Future<Void> next = subIterator.next();
-      if (!next.isDone() && !next.isCancelled()) {
-        next.cancel(true);
+  public synchronized void abortCompaction(String storageGroupName) {
+    for (Pair<AbstractCompactionTask, Future<Void>> futurePair : futureList) {
+      if (futurePair.left.getFullStorageGroupName().contains(storageGroupName)) {
+        futurePair.right.cancel(true);
       }
-      subIterator.remove();
     }
+
+    candidateCompactionTaskQueue.clear();

Review comment:
       When the compaction task finish, it will remove from the `futureList` and `runningCompactionTaskList` by itself 




-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org