jt2594838 commented on code in PR #16687:
URL: https://github.com/apache/iotdb/pull/16687#discussion_r2492536155
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java:
##########
@@ -2900,50 +2900,57 @@ private void deleteDataInUnsealedFiles(
private void deleteDataInSealedFiles(Collection<TsFileResource>
sealedTsFiles, ModEntry deletion)
throws IOException {
Set<ModificationFile> involvedModificationFiles = new HashSet<>();
+ List<TsFileResource> deletedByMods = new ArrayList<>();
+ List<TsFileResource> deletedByFiles = new ArrayList<>();
for (TsFileResource sealedTsFile : sealedTsFiles) {
if (canSkipDelete(sealedTsFile, deletion)) {
continue;
}
- ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
sealedTsFile.getTimeIndex();
- Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
- boolean onlyOneTable = devicesInFile.size() == 1;
- IDeviceID theOnlyDevice = onlyOneTable ? devicesInFile.iterator().next()
: null;
-
- boolean fileFullyDeleted = false;
-
- for (IDeviceID device : devicesInFile) {
- Optional<Long> optStart = deviceTimeIndex.getStartTime(device);
- Optional<Long> optEnd = deviceTimeIndex.getEndTime(device);
- if (!optStart.isPresent() || !optEnd.isPresent()) {
- continue;
- }
-
- long fileStart = optStart.get();
- long fileEnd = optEnd.get();
+ ITimeIndex timeIndex = sealedTsFile.getTimeIndex();
- if (onlyOneTable
- && device.equals(theOnlyDevice)
- && deletion.getStartTime() <= fileStart
- && deletion.getEndTime() >= fileEnd) {
+ if ((timeIndex instanceof ArrayDeviceTimeIndex)
+ && (deletion.getType() == ModEntry.ModType.TABLE_DELETION)) {
+ ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
timeIndex;
+ Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
+ boolean onlyOneTable = devicesInFile.size() == 1;
+ IDeviceID deviceID = onlyOneTable ? devicesInFile.iterator().next() :
null;
- logger.info(
- "[Deletion] TsFile {} only contains one table and will be
removed physically.",
- sealedTsFile.getTsFilePath());
+ for (IDeviceID device : devicesInFile) {
+ Optional<Long> optStart = deviceTimeIndex.getStartTime(device);
+ Optional<Long> optEnd = deviceTimeIndex.getEndTime(device);
+ if (!optStart.isPresent() || !optEnd.isPresent()) {
+ continue;
+ }
- deleteTsFileCompletely(sealedTsFile);
- removeTsFileResourceFromList(sealedTsFile);
+ long fileStartTime = optStart.get();
+ long fileEndTime = optEnd.get();
- fileFullyDeleted = true;
- // current file is deleted, other devices need do nothing
- break;
+ if (onlyOneTable
+ && device.equals(deviceID)
Review Comment:
Unnecessary
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java:
##########
@@ -2900,50 +2900,57 @@ private void deleteDataInUnsealedFiles(
private void deleteDataInSealedFiles(Collection<TsFileResource>
sealedTsFiles, ModEntry deletion)
throws IOException {
Set<ModificationFile> involvedModificationFiles = new HashSet<>();
+ List<TsFileResource> deletedByMods = new ArrayList<>();
+ List<TsFileResource> deletedByFiles = new ArrayList<>();
for (TsFileResource sealedTsFile : sealedTsFiles) {
if (canSkipDelete(sealedTsFile, deletion)) {
continue;
}
- ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
sealedTsFile.getTimeIndex();
- Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
- boolean onlyOneTable = devicesInFile.size() == 1;
- IDeviceID theOnlyDevice = onlyOneTable ? devicesInFile.iterator().next()
: null;
-
- boolean fileFullyDeleted = false;
-
- for (IDeviceID device : devicesInFile) {
- Optional<Long> optStart = deviceTimeIndex.getStartTime(device);
- Optional<Long> optEnd = deviceTimeIndex.getEndTime(device);
- if (!optStart.isPresent() || !optEnd.isPresent()) {
- continue;
- }
-
- long fileStart = optStart.get();
- long fileEnd = optEnd.get();
+ ITimeIndex timeIndex = sealedTsFile.getTimeIndex();
- if (onlyOneTable
- && device.equals(theOnlyDevice)
- && deletion.getStartTime() <= fileStart
- && deletion.getEndTime() >= fileEnd) {
+ if ((timeIndex instanceof ArrayDeviceTimeIndex)
+ && (deletion.getType() == ModEntry.ModType.TABLE_DELETION)) {
+ ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
timeIndex;
+ Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
+ boolean onlyOneTable = devicesInFile.size() == 1;
+ IDeviceID deviceID = onlyOneTable ? devicesInFile.iterator().next() :
null;
Review Comment:
onlyOneTable != onlyOneDevice.
Add some tests where there is more than one device in the table.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java:
##########
@@ -2900,50 +2900,57 @@ private void deleteDataInUnsealedFiles(
private void deleteDataInSealedFiles(Collection<TsFileResource>
sealedTsFiles, ModEntry deletion)
throws IOException {
Set<ModificationFile> involvedModificationFiles = new HashSet<>();
+ List<TsFileResource> deletedByMods = new ArrayList<>();
+ List<TsFileResource> deletedByFiles = new ArrayList<>();
for (TsFileResource sealedTsFile : sealedTsFiles) {
if (canSkipDelete(sealedTsFile, deletion)) {
continue;
}
- ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
sealedTsFile.getTimeIndex();
- Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
- boolean onlyOneTable = devicesInFile.size() == 1;
- IDeviceID theOnlyDevice = onlyOneTable ? devicesInFile.iterator().next()
: null;
-
- boolean fileFullyDeleted = false;
-
- for (IDeviceID device : devicesInFile) {
- Optional<Long> optStart = deviceTimeIndex.getStartTime(device);
- Optional<Long> optEnd = deviceTimeIndex.getEndTime(device);
- if (!optStart.isPresent() || !optEnd.isPresent()) {
- continue;
- }
-
- long fileStart = optStart.get();
- long fileEnd = optEnd.get();
+ ITimeIndex timeIndex = sealedTsFile.getTimeIndex();
- if (onlyOneTable
- && device.equals(theOnlyDevice)
- && deletion.getStartTime() <= fileStart
- && deletion.getEndTime() >= fileEnd) {
+ if ((timeIndex instanceof ArrayDeviceTimeIndex)
+ && (deletion.getType() == ModEntry.ModType.TABLE_DELETION)) {
+ ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
timeIndex;
+ Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
+ boolean onlyOneTable = devicesInFile.size() == 1;
+ IDeviceID deviceID = onlyOneTable ? devicesInFile.iterator().next() :
null;
- logger.info(
- "[Deletion] TsFile {} only contains one table and will be
removed physically.",
- sealedTsFile.getTsFilePath());
+ for (IDeviceID device : devicesInFile) {
+ Optional<Long> optStart = deviceTimeIndex.getStartTime(device);
+ Optional<Long> optEnd = deviceTimeIndex.getEndTime(device);
+ if (!optStart.isPresent() || !optEnd.isPresent()) {
+ continue;
+ }
- deleteTsFileCompletely(sealedTsFile);
- removeTsFileResourceFromList(sealedTsFile);
+ long fileStartTime = optStart.get();
+ long fileEndTime = optEnd.get();
- fileFullyDeleted = true;
- // current file is deleted, other devices need do nothing
- break;
+ if (onlyOneTable
Review Comment:
Should be outside the loop
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java:
##########
@@ -2900,50 +2900,57 @@ private void deleteDataInUnsealedFiles(
private void deleteDataInSealedFiles(Collection<TsFileResource>
sealedTsFiles, ModEntry deletion)
throws IOException {
Set<ModificationFile> involvedModificationFiles = new HashSet<>();
+ List<TsFileResource> deletedByMods = new ArrayList<>();
+ List<TsFileResource> deletedByFiles = new ArrayList<>();
for (TsFileResource sealedTsFile : sealedTsFiles) {
if (canSkipDelete(sealedTsFile, deletion)) {
continue;
}
- ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
sealedTsFile.getTimeIndex();
- Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
- boolean onlyOneTable = devicesInFile.size() == 1;
- IDeviceID theOnlyDevice = onlyOneTable ? devicesInFile.iterator().next()
: null;
-
- boolean fileFullyDeleted = false;
-
- for (IDeviceID device : devicesInFile) {
- Optional<Long> optStart = deviceTimeIndex.getStartTime(device);
- Optional<Long> optEnd = deviceTimeIndex.getEndTime(device);
- if (!optStart.isPresent() || !optEnd.isPresent()) {
- continue;
- }
-
- long fileStart = optStart.get();
- long fileEnd = optEnd.get();
+ ITimeIndex timeIndex = sealedTsFile.getTimeIndex();
- if (onlyOneTable
- && device.equals(theOnlyDevice)
- && deletion.getStartTime() <= fileStart
- && deletion.getEndTime() >= fileEnd) {
+ if ((timeIndex instanceof ArrayDeviceTimeIndex)
+ && (deletion.getType() == ModEntry.ModType.TABLE_DELETION)) {
+ ArrayDeviceTimeIndex deviceTimeIndex = (ArrayDeviceTimeIndex)
timeIndex;
+ Set<IDeviceID> devicesInFile = deviceTimeIndex.getDevices();
+ boolean onlyOneTable = devicesInFile.size() == 1;
+ IDeviceID deviceID = onlyOneTable ? devicesInFile.iterator().next() :
null;
- logger.info(
- "[Deletion] TsFile {} only contains one table and will be
removed physically.",
- sealedTsFile.getTsFilePath());
+ for (IDeviceID device : devicesInFile) {
+ Optional<Long> optStart = deviceTimeIndex.getStartTime(device);
+ Optional<Long> optEnd = deviceTimeIndex.getEndTime(device);
+ if (!optStart.isPresent() || !optEnd.isPresent()) {
+ continue;
+ }
- deleteTsFileCompletely(sealedTsFile);
- removeTsFileResourceFromList(sealedTsFile);
+ long fileStartTime = optStart.get();
+ long fileEndTime = optEnd.get();
- fileFullyDeleted = true;
- // current file is deleted, other devices need do nothing
- break;
+ if (onlyOneTable
+ && device.equals(deviceID)
+ && deletion.getStartTime() <= fileStartTime
+ && deletion.getEndTime() >= fileEndTime
+ && sealedTsFile.isClosed()
+ && sealedTsFile.setStatus(TsFileResourceStatus.DELETED)) {
Review Comment:
Unnecessary, files should all be closed in this method.
--
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]