choubenson commented on code in PR #7621: URL: https://github.com/apache/iotdb/pull/7621#discussion_r1030072395
########## server/src/main/java/org/apache/iotdb/db/engine/compaction/cross/utils/SeriesCompactionExecutor.java: ########## @@ -0,0 +1,601 @@ +/* + * 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.compaction.cross.utils; + +import org.apache.iotdb.commons.exception.IllegalPathException; +import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.db.engine.compaction.reader.PointPriorityReader; +import org.apache.iotdb.db.engine.compaction.task.SubCompactionTaskSummary; +import org.apache.iotdb.db.engine.compaction.writer.AbstractCompactionWriter; +import org.apache.iotdb.db.engine.modification.Modification; +import org.apache.iotdb.db.engine.storagegroup.TsFileResource; +import org.apache.iotdb.db.exception.WriteProcessException; +import org.apache.iotdb.tsfile.exception.write.PageException; +import org.apache.iotdb.tsfile.file.metadata.AlignedChunkMetadata; +import org.apache.iotdb.tsfile.file.metadata.ChunkMetadata; +import org.apache.iotdb.tsfile.read.TsFileSequenceReader; +import org.apache.iotdb.tsfile.read.common.TimeRange; +import org.apache.iotdb.tsfile.read.reader.chunk.AlignedChunkReader; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; + +public abstract class SeriesCompactionExecutor { + protected enum ModifiedStatus { + ALL_DELETED, + PARTIAL_DELETED, + NONE_DELETED; + } + + @FunctionalInterface + public interface RemovePage { + void call(PageElement pageElement) + throws WriteProcessException, IOException, IllegalPathException; + } + + private final SubCompactionTaskSummary summary; + + // source files which are sorted by the start time of current device from old to new. Notice: If + // the type of timeIndex is FileTimeIndex, it may contain resources in which the current device + // does not exist. + protected List<FileElement> fileList = new ArrayList<>();; + + protected final PriorityQueue<ChunkMetadataElement> chunkMetadataQueue; + + protected final PriorityQueue<PageElement> pageQueue; + + protected AbstractCompactionWriter compactionWriter; + + protected int subTaskId; + + protected Map<TsFileResource, TsFileSequenceReader> readerCacheMap; + + private final Map<TsFileResource, List<Modification>> modificationCacheMap; + + private final PointPriorityReader pointPriorityReader = new PointPriorityReader(this::removePage); + + protected String deviceId; + + // Pages in this list will be sequentially judged whether there is a real overlap to choose + // whether to put them in the point priority reader to deserialize or directly flush to chunk + // writer. During the process of compacting overlapped page, there may be new overlapped pages + // added into this list. + private final List<PageElement> candidateOverlappedPages = new ArrayList<>(); + + public SeriesCompactionExecutor( + AbstractCompactionWriter compactionWriter, + Map<TsFileResource, TsFileSequenceReader> readerCacheMap, + Map<TsFileResource, List<Modification>> modificationCacheMap, + String deviceId, + int subTaskId, + SubCompactionTaskSummary summary) { + this.compactionWriter = compactionWriter; + this.subTaskId = subTaskId; + this.deviceId = deviceId; + this.readerCacheMap = readerCacheMap; + this.modificationCacheMap = modificationCacheMap; + this.summary = summary; + + chunkMetadataQueue = + new PriorityQueue<>( + (o1, o2) -> { + int timeCompare = Long.compare(o1.startTime, o2.startTime); + return timeCompare != 0 ? timeCompare : Long.compare(o2.priority, o1.priority); + }); + + pageQueue = + new PriorityQueue<>( + (o1, o2) -> { + int timeCompare = Long.compare(o1.startTime, o2.startTime); + return timeCompare != 0 ? timeCompare : Long.compare(o2.priority, o1.priority); + }); + } + + public abstract void excute() + throws PageException, IllegalPathException, IOException, WriteProcessException; + + protected abstract void compactFiles() + throws PageException, IOException, WriteProcessException, IllegalPathException; + + /** Compact chunks in chunk metadata queue. */ + protected void compactChunks() + throws IOException, PageException, WriteProcessException, IllegalPathException { + while (!chunkMetadataQueue.isEmpty()) { + ChunkMetadataElement firstChunkMetadataElement = chunkMetadataQueue.peek(); + List<ChunkMetadataElement> overlappedChunkMetadatas = Review Comment: Resolved. -- 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]
