You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ma...@apache.org on 2022/11/03 07:53:42 UTC
[iotdb] 01/01: fix compaction task selection bug
This is an automated email from the ASF dual-hosted git repository.
marklau99 pushed a commit to branch IOTDB-4835
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 903314710215a15ec676e9950714876976178a6e
Author: Liu Xuxin <li...@outlook.com>
AuthorDate: Thu Nov 3 15:53:26 2022 +0800
fix compaction task selection bug
---
.../sizetiered/SizeTieredCompactionSelector.java | 76 ++++++++++++----------
1 file changed, 41 insertions(+), 35 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/compaction/inner/sizetiered/SizeTieredCompactionSelector.java b/server/src/main/java/org/apache/iotdb/db/engine/compaction/inner/sizetiered/SizeTieredCompactionSelector.java
index 6261787398..13a1157ae3 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/compaction/inner/sizetiered/SizeTieredCompactionSelector.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/compaction/inner/sizetiered/SizeTieredCompactionSelector.java
@@ -78,38 +78,6 @@ public class SizeTieredCompactionSelector
hasNextTimePartition = tsFileManager.hasNextTimePartition(timePartition, sequence);
}
- /**
- * This method searches for a batch of files to be compacted from layer 0 to the highest layer. If
- * there are more than a batch of files to be merged on a certain layer, it does not search to
- * higher layers. It creates a compaction thread for each batch of files and put it into the
- * candidateCompactionTaskQueue of the {@link CompactionTaskManager}.
- *
- * @return Returns whether the file was found and submits the merge task
- */
- @Override
- public List<List<TsFileResource>> selectInnerSpaceTask(List<TsFileResource> tsFileResources) {
- this.tsFileResources = tsFileResources;
- PriorityQueue<Pair<List<TsFileResource>, Long>> taskPriorityQueue =
- new PriorityQueue<>(new SizeTieredCompactionTaskComparator());
- try {
- int maxLevel = searchMaxFileLevel();
- for (int currentLevel = 0; currentLevel <= maxLevel; currentLevel++) {
- if (!selectLevelTask(currentLevel, taskPriorityQueue)) {
- break;
- }
- }
- List<List<TsFileResource>> taskList = new LinkedList<>();
- while (taskPriorityQueue.size() > 0) {
- List<TsFileResource> resources = taskPriorityQueue.poll().left;
- taskList.add(resources);
- }
- return taskList;
- } catch (Exception e) {
- LOGGER.error("Exception occurs while selecting files", e);
- }
- return Collections.emptyList();
- }
-
/**
* This method searches for all files on the given level. If there are consecutive files on the
* level that meet the system preset conditions (the number exceeds 10 or the total file size
@@ -135,8 +103,14 @@ public class SizeTieredCompactionSelector
for (TsFileResource currentFile : tsFileResources) {
TsFileNameGenerator.TsFileName currentName =
TsFileNameGenerator.getTsFileName(currentFile.getTsFile().getName());
- if (currentName.getInnerCompactionCnt() != level
- || currentFile.getStatus() != TsFileResourceStatus.CLOSED) {
+ if (currentName.getInnerCompactionCnt() != level) {
+ if (selectedFileList.size() > 1) {
+ taskPriorityQueue.add(new Pair<>(new ArrayList<>(selectedFileList), selectedFileSize));
+ }
+ selectedFileList = new ArrayList<>();
+ selectedFileSize = 0L;
+ shouldContinueToSearch = false;
+ } else if (currentFile.getStatus() != TsFileResourceStatus.CLOSED) {
selectedFileList.clear();
selectedFileSize = 0L;
continue;
@@ -155,10 +129,10 @@ public class SizeTieredCompactionSelector
// submit the task
if (selectedFileList.size() > 1) {
taskPriorityQueue.add(new Pair<>(new ArrayList<>(selectedFileList), selectedFileSize));
+ shouldContinueToSearch = false;
}
selectedFileList = new ArrayList<>();
selectedFileSize = 0L;
- shouldContinueToSearch = false;
}
}
@@ -171,6 +145,38 @@ public class SizeTieredCompactionSelector
return shouldContinueToSearch;
}
+ /**
+ * This method searches for a batch of files to be compacted from layer 0 to the highest layer. If
+ * there are more than a batch of files to be merged on a certain layer, it does not search to
+ * higher layers. It creates a compaction thread for each batch of files and put it into the
+ * candidateCompactionTaskQueue of the {@link CompactionTaskManager}.
+ *
+ * @return Returns whether the file was found and submits the merge task
+ */
+ @Override
+ public List<List<TsFileResource>> selectInnerSpaceTask(List<TsFileResource> tsFileResources) {
+ this.tsFileResources = tsFileResources;
+ PriorityQueue<Pair<List<TsFileResource>, Long>> taskPriorityQueue =
+ new PriorityQueue<>(new SizeTieredCompactionTaskComparator());
+ try {
+ int maxLevel = searchMaxFileLevel();
+ for (int currentLevel = 0; currentLevel <= maxLevel; currentLevel++) {
+ if (!selectLevelTask(currentLevel, taskPriorityQueue)) {
+ break;
+ }
+ }
+ List<List<TsFileResource>> taskList = new LinkedList<>();
+ while (taskPriorityQueue.size() > 0) {
+ List<TsFileResource> resources = taskPriorityQueue.poll().left;
+ taskList.add(resources);
+ }
+ return taskList;
+ } catch (Exception e) {
+ LOGGER.error("Exception occurs while selecting files", e);
+ }
+ return Collections.emptyList();
+ }
+
private int searchMaxFileLevel() throws IOException {
int maxLevel = -1;
for (TsFileResource currentFile : tsFileResources) {