jt2594838 commented on a change in pull request #429: [IOTDB-205]Support
storage-group-level data ttl
URL: https://github.com/apache/incubator-iotdb/pull/429#discussion_r339514483
##########
File path:
server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
##########
@@ -582,6 +612,65 @@ public void syncDeleteDataFiles() {
}
}
+ /**
+ * Iterate each TsFile and try to lock and remove those out of TTL.
+ */
+ public synchronized void checkFilesTTL() {
+ if (dataTTL == Long.MAX_VALUE) {
+ logger.debug("{}: TTL not set, ignore the check", storageGroupName);
+ return;
+ }
+ long timeBound = System.currentTimeMillis() - dataTTL;
+ if (logger.isDebugEnabled()) {
+ logger.debug("{}: TTL removing files before {}", storageGroupName, new
Date(timeBound));
+ }
+ // copy to avoid concurrent modification of deletion
+ List<TsFileResource> seqFiles = new ArrayList<>(sequenceFileList);
+ List<TsFileResource> unseqFiles = new ArrayList<>(unSequenceFileList);
+
+ for (TsFileResource tsFileResource : seqFiles) {
+ checkFileTTL(tsFileResource, timeBound, true);
+ }
+ for (TsFileResource tsFileResource : unseqFiles) {
+ checkFileTTL(tsFileResource, timeBound, false);
+ }
+ }
+
+ private void checkFileTTL(TsFileResource resource, long timeBound, boolean
isSeq) {
+ if (resource.isMerging() || !resource.isClosed()
+ || !resource.isDeleted() && resource.stillLives(timeBound)) {
+ return;
+ }
+
+ writeLock();
+ try {
+ // prevent new merges and queries from choosing this file
+ resource.setDeleted(true);
+ // the file may be chosen for merge after the last check and before
writeLock()
+ // double check to ensure the file is not used by a merge
+ if (resource.isMerging()) {
+ return;
+ }
+ // ensure that the file is not used by any queries
+ if (resource.getMergeQueryLock().writeLock().tryLock()) {
+ try {
+ // physical removal
+ resource.remove();
Review comment:
Excuse me?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services