jt2594838 commented on code in PR #12744: URL: https://github.com/apache/iotdb/pull/12744#discussion_r1683728142
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/executor/batch/utils/AlignedSeriesBatchCompactionUtils.java: ########## @@ -0,0 +1,175 @@ +/* + * 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.storageengine.dataregion.compaction.execute.utils.executor.batch.utils; + +import org.apache.iotdb.db.storageengine.dataregion.compaction.execute.utils.executor.ModifiedStatus; + +import org.apache.tsfile.enums.TSDataType; +import org.apache.tsfile.file.metadata.AlignedChunkMetadata; +import org.apache.tsfile.file.metadata.IChunkMetadata; +import org.apache.tsfile.read.TsFileSequenceReader; +import org.apache.tsfile.read.common.TimeRange; +import org.apache.tsfile.utils.Pair; +import org.apache.tsfile.write.schema.IMeasurementSchema; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class AlignedSeriesBatchCompactionUtils { + + private AlignedSeriesBatchCompactionUtils() {} + + public static List<IMeasurementSchema> selectColumnBatchToCompact( + List<IMeasurementSchema> schemaList, Set<String> compactedMeasurements, int batchSize) { + List<IMeasurementSchema> selectedColumnBatch = new ArrayList<>(batchSize); + for (IMeasurementSchema schema : schemaList) { + if (!isLargeDataType(schema.getType())) { + continue; + } + if (compactedMeasurements.contains(schema.getMeasurementId())) { + continue; + } + compactedMeasurements.add(schema.getMeasurementId()); + selectedColumnBatch.add(schema); + if (selectedColumnBatch.size() >= batchSize) { + return selectedColumnBatch; + } + if (compactedMeasurements.size() == schemaList.size()) { + return selectedColumnBatch; + } + } + for (IMeasurementSchema schema : schemaList) { + if (compactedMeasurements.contains(schema.getMeasurementId())) { + continue; + } + selectedColumnBatch.add(schema); + compactedMeasurements.add(schema.getMeasurementId()); + if (selectedColumnBatch.size() >= batchSize) { + break; + } + if (compactedMeasurements.size() == schemaList.size()) { + break; + } + } + return selectedColumnBatch; + } + + private static boolean isLargeDataType(TSDataType dataType) { + return dataType.equals(TSDataType.BLOB) + || dataType.equals(TSDataType.TEXT) + || dataType.equals(TSDataType.STRING); + } + + public static void markAlignedChunkHasDeletion( + LinkedList<Pair<TsFileSequenceReader, List<AlignedChunkMetadata>>> + readerAndChunkMetadataList) { + for (Pair<TsFileSequenceReader, List<AlignedChunkMetadata>> pair : readerAndChunkMetadataList) { + List<AlignedChunkMetadata> alignedChunkMetadataList = pair.getRight(); + markAlignedChunkHasDeletion(alignedChunkMetadataList); + } + } + + public static void markAlignedChunkHasDeletion( + List<AlignedChunkMetadata> alignedChunkMetadataList) { + for (AlignedChunkMetadata alignedChunkMetadata : alignedChunkMetadataList) { + IChunkMetadata timeChunkMetadata = alignedChunkMetadata.getTimeChunkMetadata(); + for (IChunkMetadata iChunkMetadata : alignedChunkMetadata.getValueChunkMetadataList()) { + if (iChunkMetadata != null && iChunkMetadata.isModified()) { + timeChunkMetadata.setModified(true); + break; + } + } + } + } + + public static AlignedChunkMetadata filterAlignedChunkMetadata( + AlignedChunkMetadata alignedChunkMetadata, List<String> selectedMeasurements) { + List<IChunkMetadata> valueChunkMetadataList = + Arrays.asList(new IChunkMetadata[selectedMeasurements.size()]); + + Map<String, Integer> measurementIndex = new HashMap<>(); + for (int i = 0; i < selectedMeasurements.size(); i++) { + measurementIndex.put(selectedMeasurements.get(i), i); + } + + for (IChunkMetadata chunkMetadata : alignedChunkMetadata.getValueChunkMetadataList()) { + if (chunkMetadata == null) { + continue; + } + if (measurementIndex.containsKey(chunkMetadata.getMeasurementUid())) { + valueChunkMetadataList.set( + measurementIndex.get(chunkMetadata.getMeasurementUid()), chunkMetadata); + } Review Comment: Not modifying measurementIndex , just to avoid accessing the map twice. ```suggestion chunkMetadataMap.computeIfPresent(chunkMetadata.getMeasurementUid(), (k, v) -> { valueChunkMetadataList.add(v); return v; } ); ``` -- 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]
