choubenson commented on code in PR #7621: URL: https://github.com/apache/iotdb/pull/7621#discussion_r1005212231
########## server/src/main/java/org/apache/iotdb/db/engine/compaction/cross/rewrite/task/NonAlignedFastCompactionPerformerSubTask.java: ########## @@ -0,0 +1,200 @@ +/* + * 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.rewrite.task; + +import org.apache.iotdb.commons.exception.IllegalPathException; +import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.db.engine.compaction.cross.utils.ChunkMetadataElement; +import org.apache.iotdb.db.engine.compaction.cross.utils.FileElement; +import org.apache.iotdb.db.engine.compaction.cross.utils.PageElement; +import org.apache.iotdb.db.engine.compaction.writer.FastCrossCompactionWriter; +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.db.utils.QueryUtils; +import org.apache.iotdb.tsfile.exception.write.PageException; +import org.apache.iotdb.tsfile.file.MetaMarker; +import org.apache.iotdb.tsfile.file.header.ChunkHeader; +import org.apache.iotdb.tsfile.file.header.PageHeader; +import org.apache.iotdb.tsfile.file.metadata.ChunkMetadata; +import org.apache.iotdb.tsfile.file.metadata.IChunkMetadata; +import org.apache.iotdb.tsfile.read.TsFileSequenceReader; +import org.apache.iotdb.tsfile.read.common.Chunk; +import org.apache.iotdb.tsfile.read.reader.chunk.ChunkReader; +import org.apache.iotdb.tsfile.utils.Pair; +import org.apache.iotdb.tsfile.write.schema.MeasurementSchema; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class NonAlignedFastCompactionPerformerSubTask extends FastCompactionPerformerSubTask { + // measurements of the current device to be compacted, which is assigned to the current sub thread + private final List<String> measurements; + + private String currentMeasurement; + + boolean hasStartMeasurement = false; + + public NonAlignedFastCompactionPerformerSubTask( + FastCrossCompactionWriter compactionWriter, + Map<String, Map<TsFileResource, Pair<Long, Long>>> timeseriesMetadataOffsetMap, + List<String> measurements, + Map<TsFileResource, TsFileSequenceReader> readerCacheMap, + Map<TsFileResource, List<Modification>> modificationCacheMap, + List<TsFileResource> sortedSourceFiles, + String deviceId, + int subTaskId) { + super( + compactionWriter, + timeseriesMetadataOffsetMap, + readerCacheMap, + modificationCacheMap, + sortedSourceFiles, + deviceId, + false, + subTaskId); + this.measurements = measurements; + } + + @Override + public Void call() + throws IOException, PageException, WriteProcessException, IllegalPathException { + for (String measurement : measurements) { + // get source files which are sorted by the startTime of current device from old to new, files + // that do not contain the current device have been filtered out as well. + sortedSourceFiles.forEach(x -> fileList.add(new FileElement(x))); + currentMeasurement = measurement; + hasStartMeasurement = false; + + compactFiles(); + + if (hasStartMeasurement) { + compactionWriter.endMeasurement(subTaskId); + } + } + + return null; + } + + protected void startMeasurement() throws IOException { + if (!hasStartMeasurement && !chunkMetadataQueue.isEmpty()) { + ChunkMetadataElement firstChunkMetadataElement = chunkMetadataQueue.peek(); + MeasurementSchema measurementSchema = + readerCacheMap + .get(firstChunkMetadataElement.fileElement.resource) + .getMeasurementSchema( + Collections.singletonList(firstChunkMetadataElement.chunkMetadata)); + compactionWriter.startMeasurement(Collections.singletonList(measurementSchema), subTaskId); + hasStartMeasurement = true; + } + } + + /** Deserialize files into chunk metadatas and put them into the chunk metadata queue. */ + void deserializeFileIntoQueue(List<FileElement> fileElements) + throws IOException, IllegalPathException { + for (FileElement fileElement : fileElements) { + TsFileResource resource = fileElement.resource; + Pair<Long, Long> timeseriesMetadataOffset = + timeseriesMetadataOffsetMap.get(currentMeasurement).get(resource); + if (timeseriesMetadataOffset == null) { + // tsfile does not contain this timeseries + removeFile(fileElement); + continue; Review Comment: Sorry I don't understand. If the first file does not contain this timeseries, it doesn't mean the remaining overlapped files do not contain this timeseries. ########## server/src/main/java/org/apache/iotdb/db/engine/compaction/cross/rewrite/task/NonAlignedFastCompactionPerformerSubTask.java: ########## @@ -0,0 +1,200 @@ +/* + * 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.rewrite.task; + +import org.apache.iotdb.commons.exception.IllegalPathException; +import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.db.engine.compaction.cross.utils.ChunkMetadataElement; +import org.apache.iotdb.db.engine.compaction.cross.utils.FileElement; +import org.apache.iotdb.db.engine.compaction.cross.utils.PageElement; +import org.apache.iotdb.db.engine.compaction.writer.FastCrossCompactionWriter; +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.db.utils.QueryUtils; +import org.apache.iotdb.tsfile.exception.write.PageException; +import org.apache.iotdb.tsfile.file.MetaMarker; +import org.apache.iotdb.tsfile.file.header.ChunkHeader; +import org.apache.iotdb.tsfile.file.header.PageHeader; +import org.apache.iotdb.tsfile.file.metadata.ChunkMetadata; +import org.apache.iotdb.tsfile.file.metadata.IChunkMetadata; +import org.apache.iotdb.tsfile.read.TsFileSequenceReader; +import org.apache.iotdb.tsfile.read.common.Chunk; +import org.apache.iotdb.tsfile.read.reader.chunk.ChunkReader; +import org.apache.iotdb.tsfile.utils.Pair; +import org.apache.iotdb.tsfile.write.schema.MeasurementSchema; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class NonAlignedFastCompactionPerformerSubTask extends FastCompactionPerformerSubTask { + // measurements of the current device to be compacted, which is assigned to the current sub thread + private final List<String> measurements; + + private String currentMeasurement; + + boolean hasStartMeasurement = false; + + public NonAlignedFastCompactionPerformerSubTask( + FastCrossCompactionWriter compactionWriter, + Map<String, Map<TsFileResource, Pair<Long, Long>>> timeseriesMetadataOffsetMap, + List<String> measurements, + Map<TsFileResource, TsFileSequenceReader> readerCacheMap, + Map<TsFileResource, List<Modification>> modificationCacheMap, + List<TsFileResource> sortedSourceFiles, + String deviceId, + int subTaskId) { + super( + compactionWriter, + timeseriesMetadataOffsetMap, + readerCacheMap, + modificationCacheMap, + sortedSourceFiles, + deviceId, + false, + subTaskId); + this.measurements = measurements; + } + + @Override + public Void call() + throws IOException, PageException, WriteProcessException, IllegalPathException { + for (String measurement : measurements) { + // get source files which are sorted by the startTime of current device from old to new, files + // that do not contain the current device have been filtered out as well. + sortedSourceFiles.forEach(x -> fileList.add(new FileElement(x))); + currentMeasurement = measurement; + hasStartMeasurement = false; + + compactFiles(); + + if (hasStartMeasurement) { + compactionWriter.endMeasurement(subTaskId); + } + } + + return null; + } + + protected void startMeasurement() throws IOException { + if (!hasStartMeasurement && !chunkMetadataQueue.isEmpty()) { + ChunkMetadataElement firstChunkMetadataElement = chunkMetadataQueue.peek(); + MeasurementSchema measurementSchema = + readerCacheMap + .get(firstChunkMetadataElement.fileElement.resource) + .getMeasurementSchema( + Collections.singletonList(firstChunkMetadataElement.chunkMetadata)); + compactionWriter.startMeasurement(Collections.singletonList(measurementSchema), subTaskId); + hasStartMeasurement = true; + } + } + + /** Deserialize files into chunk metadatas and put them into the chunk metadata queue. */ + void deserializeFileIntoQueue(List<FileElement> fileElements) + throws IOException, IllegalPathException { + for (FileElement fileElement : fileElements) { + TsFileResource resource = fileElement.resource; + Pair<Long, Long> timeseriesMetadataOffset = + timeseriesMetadataOffsetMap.get(currentMeasurement).get(resource); + if (timeseriesMetadataOffset == null) { + // tsfile does not contain this timeseries + removeFile(fileElement); + continue; + } + List<IChunkMetadata> iChunkMetadataList = + readerCacheMap + .get(resource) + .getChunkMetadataListByTimeseriesMetadataOffset( + timeseriesMetadataOffset.left, timeseriesMetadataOffset.right); + + if (iChunkMetadataList.size() > 0) { + // modify chunk metadatas + QueryUtils.modifyChunkMetaData( + iChunkMetadataList, + getModificationsFromCache( + resource, + new PartialPath(deviceId, iChunkMetadataList.get(0).getMeasurementUid()))); + if (iChunkMetadataList.size() == 0) { + // all chunks has been deleted in this file, just remove it + removeFile(fileElement); + } Review Comment: Sorry I don't understand. If the first file does not contain this timeseries, it doesn't mean the remaining overlapped files do not contain this timeseries. -- 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]
