Skip to content

Commit 91476b0

Browse files
authored
Compatibility changes for internal settle compaction API (#18230)
1 parent 5405623 commit 91476b0

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

  • iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/SettleSelectorImpl.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class SettleSelectorImpl implements ISettleSelector {
7171
private final TsFileManager tsFileManager;
7272
private boolean isSeq;
7373
private final CompactionScheduleContext context;
74+
private final boolean ttlAuditEnabled;
7475

7576
public SettleSelectorImpl(
7677
boolean heavySelect,
@@ -85,19 +86,28 @@ public SettleSelectorImpl(
8586
this.timePartition = timePartition;
8687
this.tsFileManager = tsFileManager;
8788
this.context = context;
89+
// this will be enabled in other branches
90+
this.ttlAuditEnabled = false;
8891
}
8992

9093
static class FileDirtyInfo {
9194
DirtyStatus status;
9295
long dirtyDataSize = 0;
96+
Set<String> ttlTables = Collections.emptySet();
9397

9498
public FileDirtyInfo(DirtyStatus status) {
9599
this.status = status;
96100
}
97101

98-
public FileDirtyInfo(DirtyStatus status, long dirtyDataSize) {
102+
public FileDirtyInfo(DirtyStatus status, Set<String> ttlTables) {
103+
this.status = status;
104+
this.ttlTables = ttlTables;
105+
}
106+
107+
public FileDirtyInfo(DirtyStatus status, long dirtyDataSize, Set<String> ttlTables) {
99108
this.status = status;
100109
this.dirtyDataSize = dirtyDataSize;
110+
this.ttlTables = ttlTables;
101111
}
102112
}
103113

@@ -106,15 +116,19 @@ static class SettleTaskResource {
106116
List<TsFileResource> fullyDirtyResources = new ArrayList<>();
107117
List<TsFileResource> partiallyDirtyResources = new ArrayList<>();
108118
long totalPartiallyDirtyFileSize = 0;
119+
final Set<String> ttlTables = new HashSet<>();
109120

110-
public void addFullyDirtyResource(TsFileResource resource) {
121+
public void addFullyDirtyResource(TsFileResource resource, Set<String> fileTTLTables) {
111122
fullyDirtyResources.add(resource);
123+
ttlTables.addAll(fileTTLTables);
112124
}
113125

114-
public boolean addPartiallyDirtyResource(TsFileResource resource, long dirtyDataSize) {
126+
public boolean addPartiallyDirtyResource(
127+
TsFileResource resource, long dirtyDataSize, Set<String> fileTTLTables) {
115128
partiallyDirtyResources.add(resource);
116129
totalPartiallyDirtyFileSize += resource.getTsFileSize();
117130
totalPartiallyDirtyFileSize -= dirtyDataSize;
131+
ttlTables.addAll(fileTTLTables);
118132
return checkHasReachedThreshold();
119133
}
120134

@@ -126,6 +140,10 @@ public List<TsFileResource> getPartiallyDirtyResources() {
126140
return partiallyDirtyResources;
127141
}
128142

143+
public Set<String> getTTLTables() {
144+
return ttlTables;
145+
}
146+
129147
public boolean checkHasReachedThreshold() {
130148
return partiallyDirtyResources.size() >= config.getInnerCompactionCandidateFileNum()
131149
|| totalPartiallyDirtyFileSize >= config.getTargetCompactionFileSize();
@@ -165,11 +183,12 @@ private List<SettleCompactionTask> selectTasks(List<TsFileResource> resources) {
165183

166184
switch (fileDirtyInfo.status) {
167185
case FULLY_DIRTY:
168-
settleTaskResource.addFullyDirtyResource(resource);
186+
settleTaskResource.addFullyDirtyResource(resource, fileDirtyInfo.ttlTables);
169187
break;
170188
case PARTIALLY_DIRTY:
171189
shouldStop =
172-
settleTaskResource.addPartiallyDirtyResource(resource, fileDirtyInfo.dirtyDataSize);
190+
settleTaskResource.addPartiallyDirtyResource(
191+
resource, fileDirtyInfo.dirtyDataSize, fileDirtyInfo.ttlTables);
173192
break;
174193
case NOT_SATISFIED:
175194
shouldStop = !settleTaskResource.getPartiallyDirtyResources().isEmpty();
@@ -231,6 +250,7 @@ private FileDirtyInfo selectFileBaseOnDirtyData(TsFileResource resource)
231250
timeIndex = CompactionUtils.buildDeviceTimeIndex(resource);
232251
}
233252
Set<IDeviceID> deletedDevices = new HashSet<>();
253+
Set<String> ttlTables = new HashSet<>();
234254
boolean hasExpiredTooLong = false;
235255
long currentTime = CommonDateTimeUtils.currentTime();
236256

@@ -240,12 +260,17 @@ private FileDirtyInfo selectFileBaseOnDirtyData(TsFileResource resource)
240260

241261
long ttl;
242262
String tableName = device.getTableName();
263+
boolean hasSetTTL;
243264
if (tableName.startsWith("root.")) {
244265
ttl = DataNodeTTLCache.getInstance().getTTLForTree(device);
266+
hasSetTTL = ttl != Long.MAX_VALUE;
245267
} else {
246268
ttl = DataNodeTTLCache.getInstance().getTTLForTable(storageGroupName, tableName);
269+
hasSetTTL = ttl != Long.MAX_VALUE;
270+
if (hasSetTTL && ttlAuditEnabled) {
271+
ttlTables.add(tableName);
272+
}
247273
}
248-
boolean hasSetTTL = ttl != Long.MAX_VALUE;
249274

250275
long endTime = timeIndex.getEndTime(device).get();
251276
boolean isDeleted =
@@ -256,7 +281,7 @@ private FileDirtyInfo selectFileBaseOnDirtyData(TsFileResource resource)
256281
if (!isDeleted) {
257282
// For devices with TTL set, all data must expire in order to meet the conditions for
258283
// being selected.
259-
return new FileDirtyInfo(DirtyStatus.NOT_SATISFIED);
284+
return new FileDirtyInfo(DirtyStatus.NOT_SATISFIED, ttlTables);
260285
}
261286

262287
if (currentTime > endTime) {
@@ -281,13 +306,13 @@ private FileDirtyInfo selectFileBaseOnDirtyData(TsFileResource resource)
281306
((double) deletedDevices.size()) / ((ArrayDeviceTimeIndex) timeIndex).getDevices().size();
282307
if (deletedDeviceRatio == 1d) {
283308
// the whole file is completely dirty
284-
return new FileDirtyInfo(DirtyStatus.FULLY_DIRTY);
309+
return new FileDirtyInfo(DirtyStatus.FULLY_DIRTY, ttlTables);
285310
}
286311
hasExpiredTooLong = config.getMaxExpiredTime() != Long.MAX_VALUE && hasExpiredTooLong;
287312
if (hasExpiredTooLong || deletedDeviceRatio >= config.getExpiredDataRatio()) {
288313
// evaluate dirty data size in the tsfile
289314
return new FileDirtyInfo(
290-
PARTIALLY_DIRTY, (long) (deletedDeviceRatio * resource.getTsFileSize()));
315+
PARTIALLY_DIRTY, (long) (deletedDeviceRatio * resource.getTsFileSize()), ttlTables);
291316
}
292317
return new FileDirtyInfo(DirtyStatus.NOT_SATISFIED);
293318
}

0 commit comments

Comments
 (0)