DanielWang2035 commented on code in PR #17238:
URL: https://github.com/apache/iotdb/pull/17238#discussion_r3279117542


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALNode.java:
##########
@@ -898,11 +925,117 @@ public long getCurrentWALFileVersion() {
     return buffer.getCurrentWALFileVersion();
   }
 
+  public WALMetaData getCurrentWALMetaDataSnapshot() {
+    return buffer.getCurrentWALMetaDataSnapshot();
+  }
+
   @Override
   public long getTotalSize() {
     return WALManager.getInstance().getTotalDiskUsage();
   }
 
+  @Override
+  public long getRegionDiskUsage() {
+    return buffer.getDiskUsage();
+  }
+
+  @Override
+  public long getSearchIndexToFreeAtLeast(long bytesToFree) {
+    if (bytesToFree <= 0) {
+      return DEFAULT_SAFELY_DELETED_SEARCH_INDEX;
+    }
+    File[] walFiles = WALFileUtils.listAllWALFiles(logDirectory);
+    if (walFiles == null || walFiles.length <= 1) {
+      // No files or only the current-writing file — cannot free anything
+      return DEFAULT_SAFELY_DELETED_SEARCH_INDEX;
+    }
+    WALFileUtils.ascSortByVersionId(walFiles);
+    // Exclude the last file (currently being written)
+    long accumulated = 0;
+    for (int i = 0; i < walFiles.length - 1; i++) {
+      accumulated += walFiles[i].length();
+      if (accumulated >= bytesToFree) {
+        // The next file's startSearchIndex is the boundary: everything before 
it can be deleted
+        if (i + 1 < walFiles.length) {
+          return WALFileUtils.parseStartSearchIndex(walFiles[i + 1].getName());
+        }
+        break;
+      }
+    }
+    // Could not free enough even by deleting all non-current files — allow 
deleting all
+    return Long.MAX_VALUE;
+  }
+
+  @Override
+  public long getVersionIdToFreeAtLeast(long bytesToFree) {

Review Comment:
   Added combined deletion-bound APIs so size/time retention can get 
searchIndex and versionId in one WAL file scan.



-- 
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]

Reply via email to