2828import org .apache .iotdb .commons .consensus .ConfigRegionId ;
2929import org .apache .iotdb .commons .exception .IllegalPathException ;
3030import org .apache .iotdb .commons .path .PartialPath ;
31+ import org .apache .iotdb .commons .path .PatternTreeMap ;
3132import org .apache .iotdb .commons .schema .SchemaConstant ;
3233import org .apache .iotdb .commons .service .metric .PerformanceOverviewMetrics ;
3334import org .apache .iotdb .confignode .rpc .thrift .TGetDatabaseReq ;
5859import org .apache .iotdb .db .queryengine .plan .statement .crud .LoadTsFileStatement ;
5960import org .apache .iotdb .db .queryengine .plan .statement .metadata .DatabaseSchemaStatement ;
6061import org .apache .iotdb .db .queryengine .plan .statement .metadata .ShowDatabaseStatement ;
61- import org .apache .iotdb .db .storageengine .dataregion .modification .Deletion ;
6262import org .apache .iotdb .db .storageengine .dataregion .modification .Modification ;
6363import org .apache .iotdb .db .storageengine .dataregion .tsfile .TsFileResource ;
6464import org .apache .iotdb .db .storageengine .dataregion .tsfile .TsFileResourceStatus ;
7373import org .apache .iotdb .db .utils .ModificationUtils ;
7474import org .apache .iotdb .db .utils .TimestampPrecisionUtils ;
7575import org .apache .iotdb .db .utils .constant .SqlConstant ;
76+ import org .apache .iotdb .db .utils .datastructure .PatternTreeMapFactory ;
7677import org .apache .iotdb .rpc .RpcUtils ;
7778import org .apache .iotdb .rpc .TSStatusCode ;
7879
9798import java .io .IOException ;
9899import java .util .ArrayList ;
99100import java .util .Arrays ;
100- import java .util .Collection ;
101101import java .util .Collections ;
102102import java .util .HashMap ;
103103import java .util .HashSet ;
@@ -527,10 +527,10 @@ public void setCurrentTimeIndex(final ITimeIndex timeIndex) {
527527
528528 public void autoCreateAndVerify (
529529 TsFileSequenceReader reader ,
530- Map <IDeviceID , List <TimeseriesMetadata >> device2TimeseriesMetadataList )
530+ Map <IDeviceID , List <TimeseriesMetadata >> device2TimeSeriesMetadataList )
531531 throws IOException , AuthException , LoadAnalyzeTypeMismatchException {
532532 for (final Map .Entry <IDeviceID , List <TimeseriesMetadata >> entry :
533- device2TimeseriesMetadataList .entrySet ()) {
533+ device2TimeSeriesMetadataList .entrySet ()) {
534534 final IDeviceID device = entry .getKey ();
535535
536536 try {
@@ -546,15 +546,15 @@ public void autoCreateAndVerify(
546546
547547 for (final TimeseriesMetadata timeseriesMetadata : entry .getValue ()) {
548548 try {
549- if (schemaCache .isTimeseriesDeletedByMods (device , timeseriesMetadata )) {
549+ if (schemaCache .isTimeSeriesDeletedByMods (device , timeseriesMetadata )) {
550550 continue ;
551551 }
552552 } catch (IllegalPathException e ) {
553553 // In aligned devices, there may be empty measurements which will cause
554554 // IllegalPathException.
555555 if (!timeseriesMetadata .getMeasurementId ().isEmpty ()) {
556556 LOGGER .warn (
557- "Failed to check if device {}, timeseries {} is deleted by mods. Will see it as not deleted." ,
557+ "Failed to check if device {}, timeSeries {} is deleted by mods. Will see it as not deleted." ,
558558 device ,
559559 timeseriesMetadata .getMeasurementId (),
560560 e );
@@ -926,7 +926,7 @@ private static class LoadTsFileAnalyzeSchemaCache {
926926 private Map <IDeviceID , Boolean > tsFileDevice2IsAligned ;
927927 private Set <PartialPath > alreadySetDatabases ;
928928
929- private Collection <Modification > currentModifications ;
929+ private PatternTreeMap <Modification , PatternTreeMapFactory . ModsSerializer > currentModifications ;
930930 private ITimeIndex currentTimeIndex ;
931931
932932 private long batchDevice2TimeSeriesSchemasMemoryUsageSizeInBytes = 0 ;
@@ -944,7 +944,7 @@ public LoadTsFileAnalyzeSchemaCache() throws LoadRuntimeOutOfMemoryException {
944944 this .currentBatchDevice2TimeSeriesSchemas = new HashMap <>();
945945 this .tsFileDevice2IsAligned = new HashMap <>();
946946 this .alreadySetDatabases = new HashSet <>();
947- this .currentModifications = new ArrayList <> ();
947+ this .currentModifications = PatternTreeMapFactory . getModsPatternTreeMap ();
948948 }
949949
950950 public Map <IDeviceID , Set <MeasurementSchema >> getDevice2TimeSeries () {
@@ -1003,10 +1003,13 @@ public void addIsAlignedCache(IDeviceID device, boolean isAligned, boolean addIf
10031003 public void setCurrentModificationsAndTimeIndex (TsFileResource resource ) throws IOException {
10041004 clearModificationsAndTimeIndex ();
10051005
1006- currentModifications = resource .getModFile ().getModifications ();
1007- for (final Modification modification : currentModifications ) {
1008- currentModificationsMemoryUsageSizeInBytes += ((Deletion ) modification ).getSerializedSize ();
1009- }
1006+ resource
1007+ .getModFile ()
1008+ .getModifications ()
1009+ .forEach (
1010+ modification -> currentModifications .append (modification .getPath (), modification ));
1011+
1012+ currentModificationsMemoryUsageSizeInBytes = currentModifications .ramBytesUsed ();
10101013 block .addMemoryUsage (currentModificationsMemoryUsageSizeInBytes );
10111014
10121015 if (resource .resourceFileExists ()) {
@@ -1028,9 +1031,9 @@ public boolean isDeviceDeletedByMods(IDeviceID device) throws IllegalPathExcepti
10281031 currentModifications , currentTimeIndex , device );
10291032 }
10301033
1031- public boolean isTimeseriesDeletedByMods (
1034+ public boolean isTimeSeriesDeletedByMods (
10321035 IDeviceID device , TimeseriesMetadata timeseriesMetadata ) throws IllegalPathException {
1033- return ModificationUtils .isTimeseriesDeletedByMods (
1036+ return ModificationUtils .isTimeSeriesDeletedByMods (
10341037 currentModifications ,
10351038 device ,
10361039 timeseriesMetadata .getMeasurementId (),
@@ -1068,7 +1071,7 @@ public void clearTimeSeries() {
10681071 }
10691072
10701073 public void clearModificationsAndTimeIndex () {
1071- currentModifications . clear ();
1074+ currentModifications = PatternTreeMapFactory . getModsPatternTreeMap ();
10721075 currentTimeIndex = null ;
10731076 block .reduceMemoryUsage (currentModificationsMemoryUsageSizeInBytes );
10741077 block .reduceMemoryUsage (currentTimeIndexMemoryUsageSizeInBytes );
0 commit comments