Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
private final TsFileManager tsFileManager;
private boolean isSeq;
private final CompactionScheduleContext context;
private final boolean ttlAuditEnabled;

public SettleSelectorImpl(
boolean heavySelect,
Expand All @@ -85,19 +86,28 @@
this.timePartition = timePartition;
this.tsFileManager = tsFileManager;
this.context = context;
// this will be enabled in other branches
this.ttlAuditEnabled = false;
}

static class FileDirtyInfo {
DirtyStatus status;
long dirtyDataSize = 0;
Set<String> ttlTables = Collections.emptySet();

public FileDirtyInfo(DirtyStatus status) {
this.status = status;
}

public FileDirtyInfo(DirtyStatus status, long dirtyDataSize) {
public FileDirtyInfo(DirtyStatus status, Set<String> ttlTables) {
this.status = status;
this.ttlTables = ttlTables;
}

public FileDirtyInfo(DirtyStatus status, long dirtyDataSize, Set<String> ttlTables) {
this.status = status;
this.dirtyDataSize = dirtyDataSize;
this.ttlTables = ttlTables;
}
}

Expand All @@ -106,15 +116,19 @@
List<TsFileResource> fullyDirtyResources = new ArrayList<>();
List<TsFileResource> partiallyDirtyResources = new ArrayList<>();
long totalPartiallyDirtyFileSize = 0;
final Set<String> ttlTables = new HashSet<>();

public void addFullyDirtyResource(TsFileResource resource) {
public void addFullyDirtyResource(TsFileResource resource, Set<String> fileTTLTables) {

Check warning on line 121 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/SettleSelectorImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Abbreviation in name 'fileTTLTables' must contain no more than '2' consecutive capital letters.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ9uUvtmpMYBLw0HzPpC&open=AZ9uUvtmpMYBLw0HzPpC&pullRequest=18230
fullyDirtyResources.add(resource);
ttlTables.addAll(fileTTLTables);
}

public boolean addPartiallyDirtyResource(TsFileResource resource, long dirtyDataSize) {
public boolean addPartiallyDirtyResource(
TsFileResource resource, long dirtyDataSize, Set<String> fileTTLTables) {

Check warning on line 127 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/SettleSelectorImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Abbreviation in name 'fileTTLTables' must contain no more than '2' consecutive capital letters.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ9uUvtmpMYBLw0HzPpD&open=AZ9uUvtmpMYBLw0HzPpD&pullRequest=18230
partiallyDirtyResources.add(resource);
totalPartiallyDirtyFileSize += resource.getTsFileSize();
totalPartiallyDirtyFileSize -= dirtyDataSize;
ttlTables.addAll(fileTTLTables);
return checkHasReachedThreshold();
}

Expand All @@ -126,6 +140,10 @@
return partiallyDirtyResources;
}

public Set<String> getTTLTables() {

Check warning on line 143 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/SettleSelectorImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Abbreviation in name 'getTTLTables' must contain no more than '2' consecutive capital letters.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ9uUvtmpMYBLw0HzPpE&open=AZ9uUvtmpMYBLw0HzPpE&pullRequest=18230
return ttlTables;
}

public boolean checkHasReachedThreshold() {
return partiallyDirtyResources.size() >= config.getInnerCompactionCandidateFileNum()
|| totalPartiallyDirtyFileSize >= config.getTargetCompactionFileSize();
Expand Down Expand Up @@ -165,11 +183,12 @@

switch (fileDirtyInfo.status) {
case FULLY_DIRTY:
settleTaskResource.addFullyDirtyResource(resource);
settleTaskResource.addFullyDirtyResource(resource, fileDirtyInfo.ttlTables);
break;
case PARTIALLY_DIRTY:
shouldStop =
settleTaskResource.addPartiallyDirtyResource(resource, fileDirtyInfo.dirtyDataSize);
settleTaskResource.addPartiallyDirtyResource(
resource, fileDirtyInfo.dirtyDataSize, fileDirtyInfo.ttlTables);
break;
case NOT_SATISFIED:
shouldStop = !settleTaskResource.getPartiallyDirtyResources().isEmpty();
Expand Down Expand Up @@ -231,6 +250,7 @@
timeIndex = CompactionUtils.buildDeviceTimeIndex(resource);
}
Set<IDeviceID> deletedDevices = new HashSet<>();
Set<String> ttlTables = new HashSet<>();
boolean hasExpiredTooLong = false;
long currentTime = CommonDateTimeUtils.currentTime();

Expand All @@ -240,12 +260,17 @@

long ttl;
String tableName = device.getTableName();
boolean hasSetTTL;

Check warning on line 263 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/selector/impl/SettleSelectorImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Abbreviation in name 'hasSetTTL' must contain no more than '2' consecutive capital letters.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AZ9uUvtmpMYBLw0HzPpF&open=AZ9uUvtmpMYBLw0HzPpF&pullRequest=18230
if (tableName.startsWith("root.")) {
ttl = DataNodeTTLCache.getInstance().getTTLForTree(device);
hasSetTTL = ttl != Long.MAX_VALUE;
} else {
ttl = DataNodeTTLCache.getInstance().getTTLForTable(storageGroupName, tableName);
hasSetTTL = ttl != Long.MAX_VALUE;
if (hasSetTTL && ttlAuditEnabled) {
ttlTables.add(tableName);
}
}
boolean hasSetTTL = ttl != Long.MAX_VALUE;

long endTime = timeIndex.getEndTime(device).get();
boolean isDeleted =
Expand All @@ -256,7 +281,7 @@
if (!isDeleted) {
// For devices with TTL set, all data must expire in order to meet the conditions for
// being selected.
return new FileDirtyInfo(DirtyStatus.NOT_SATISFIED);
return new FileDirtyInfo(DirtyStatus.NOT_SATISFIED, ttlTables);
}

if (currentTime > endTime) {
Expand All @@ -281,13 +306,13 @@
((double) deletedDevices.size()) / ((ArrayDeviceTimeIndex) timeIndex).getDevices().size();
if (deletedDeviceRatio == 1d) {
// the whole file is completely dirty
return new FileDirtyInfo(DirtyStatus.FULLY_DIRTY);
return new FileDirtyInfo(DirtyStatus.FULLY_DIRTY, ttlTables);
}
hasExpiredTooLong = config.getMaxExpiredTime() != Long.MAX_VALUE && hasExpiredTooLong;
if (hasExpiredTooLong || deletedDeviceRatio >= config.getExpiredDataRatio()) {
// evaluate dirty data size in the tsfile
return new FileDirtyInfo(
PARTIALLY_DIRTY, (long) (deletedDeviceRatio * resource.getTsFileSize()));
PARTIALLY_DIRTY, (long) (deletedDeviceRatio * resource.getTsFileSize()), ttlTables);
}
return new FileDirtyInfo(DirtyStatus.NOT_SATISFIED);
}
Expand Down
Loading