leekeiabstraction opened a new issue, #2041: URL: https://github.com/apache/fluss/issues/2041
### Search before asking - [x] I searched in the [issues](https://github.com/apache/fluss/issues) and found nothing similar. ### Motivation Optimise/decrease memory footprint when LogScannerImpl.poll(Duration) is used by addressing TODO here: https://github.com/apache/fluss/blob/main/fluss-client/src/main/java/org/apache/fluss/client/table/scanner/log/CompletedFetch.java#L96-L97 ### Solution Proposed changes as follow: Change the signatures and implementation that currently returns `List<ScanRecord>` to return `CloseableIterator<ScanRecord>`. This includes (not exhaustive): 1. CompletedFetch's [`List<ScanRecord> fetchRecords(int)`](https://github.com/apache/fluss/blob/main/fluss-client/src/main/java/org/apache/fluss/client/table/scanner/log/CompletedFetch.java#L151) to `CloseableIterator<ScanRecord> fetchRecords()`. Current int argument is to indicate max number of records to fetch and deserialise, I propose removing it and let the eventual user of the iterator decide how many to fetch. An alternative here is to make CompletedFetch implements `Iterable<ScanRecord>`. 2. LogFetchCollector's [`Map<TableBucket, List<ScanRecord>> collectFetch(LogFetchBuffer)`](https://github.com/apache/fluss/blob/main/fluss-client/src/main/java/org/apache/fluss/client/table/scanner/log/LogFetchCollector.java#L86) to `Map<TableBucket, CloseableIterator<ScanRecord>> collectFetch(LogFetchBuffer)` 3. LogFetcher's [`Map<TableBucket, List<ScanRecord>> collectFetch(LogFetchBuffer)`](https://github.com/apache/fluss/blob/main/fluss-client/src/main/java/org/apache/fluss/client/table/scanner/log/LogFetcher.java#L158) to `Map<TableBucket, CloseableIterator <ScanRecord>> collectFetch(LogFetchBuffer)` The closing of resources is done in two places: 1. Within [ScanRecords.ConcatenatedIterable](https://github.com/apache/fluss/blob/main/fluss-client/src/main/java/org/apache/fluss/client/table/scanner/log/ScanRecords.java#L89) where CloseableIterators are closed when they have no next element. 2. Within [LogScannerImpl.close()](https://github.com/apache/fluss/blob/main/fluss-client/src/main/java/org/apache/fluss/client/table/scanner/log/LogScannerImpl.java#L289) where LogScannerImpl will track unclosed CloseableIterators and close them. ### Anything else? Feedback and suggestion on alternative approaches welcome! ### Willingness to contribute - [x] I'm willing to submit a PR! -- 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]
