jt2594838 commented on a change in pull request #258: [IOTDB-143]Development of 
merge
URL: https://github.com/apache/incubator-iotdb/pull/258#discussion_r314572600
 
 

 ##########
 File path: 
server/src/main/java/org/apache/iotdb/db/engine/merge/task/MergeTask.java
 ##########
 @@ -0,0 +1,158 @@
+/**
+ * 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.iotdb.db.engine.merge.task;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+import org.apache.iotdb.db.engine.merge.manage.MergeContext;
+import org.apache.iotdb.db.engine.merge.manage.MergeResource;
+import org.apache.iotdb.db.engine.merge.recover.MergeLogger;
+import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.utils.MergeUtils;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * MergeTask merges given seqFiles and unseqFiles into a new one, which 
basically consists of three
+ * steps: 1. rewrite overflowed, modified or small-sized chunks into temp 
merge files
+ *        2. move the merged chunks in the temp files back to the seqFiles or 
move the unmerged
+ *        chunks in the seqFiles int temp files and replace the seqFiles with 
the temp files.
+ *        3. remove unseqFiles
+ */
+public class MergeTask implements Callable<Void> {
+
+  public static final String MERGE_SUFFIX = ".merge";
+  private static final Logger logger = 
LoggerFactory.getLogger(MergeTask.class);
+
+  MergeResource resource;
+  String storageGroupDir;
+  MergeLogger mergeLogger;
+  MergeContext mergeContext = new MergeContext();
+
+  private MergeCallback callback;
+  int concurrentMergeSeriesNum;
+  String taskName;
+  boolean fullMerge;
+
+  MergeTask(List<TsFileResource> seqFiles,
+      List<TsFileResource> unseqFiles, String storageGroupDir, MergeCallback 
callback,
+      String taskName, boolean fullMerge) {
+    this.resource = new MergeResource(seqFiles, unseqFiles);
+    this.storageGroupDir = storageGroupDir;
+    this.callback = callback;
+    this.taskName = taskName;
+    this.fullMerge = fullMerge;
+    this.concurrentMergeSeriesNum = 1;
+  }
+
+  public MergeTask(MergeResource mergeResource, String storageGroupDir, 
MergeCallback callback,
+      String taskName, boolean fullMerge, int concurrentMergeSeriesNum) {
+    this.resource = mergeResource;
+    this.storageGroupDir = storageGroupDir;
+    this.callback = callback;
+    this.taskName = taskName;
+    this.fullMerge = fullMerge;
+    this.concurrentMergeSeriesNum = concurrentMergeSeriesNum;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    try  {
+      doMerge();
+    } catch (Exception e) {
+      logger.error("Runtime exception in merge {}", taskName, e);
+      cleanUp(false);
+      // call the callback to make sure the StorageGroup exit merging status, 
but passing 2
+      // empty file lists to avoid files being deleted.
+      callback.call(Collections.emptyList(), Collections.emptyList(), new 
File(storageGroupDir, MergeLogger.MERGE_LOG_NAME));
 
 Review comment:
   When such situation emerges, the MergeLogger cannot be closed correctly and 
some fatal error must have happened. In such situation, further merges should 
not proceed thus not calling the callback may be better.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to