sejal-gupta-ksolves commented on code in PR #16768:
URL: https://github.com/apache/iceberg/pull/16768#discussion_r3401589293


##########
core/src/main/java/org/apache/iceberg/rest/ScanTaskIterable.java:
##########
@@ -107,7 +107,18 @@ public CloseableIterator<FileScanTask> iterator() {
   }
 
   @Override
-  public void close() throws IOException {}
+  public void close() throws IOException {
+    if (shutdown.compareAndSet(false, true)) {
+      LOG.info(
+          "ScanTaskIterable is closing. Clearing {} queued tasks, {} plan 
tasks, and {} initial file scan tasks.",
+          taskQueue.size(),
+          planTasks.size(),
+          initialFileScanTasks.size());
+      taskQueue.clear();
+      planTasks.clear();
+      initialFileScanTasks.clear();
+    }
+  }

Review Comment:
   The reason we can't call `ScanTasksIterator.close()` from the outer 
`ScanTaskIterable.close()` method is that `ScanTaskIterable` does not maintain 
a reference to the instantiated iterator (a new instance is returned on every 
call to `iterator()`). 
   
   To ensure that resources are safely freed regardless of whether the query 
engine closes the outer container or the inner stream, the core resource 
cleanup logic needs to live here in the parent class.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to