imbajin commented on code in PR #3445:
URL: https://github.com/apache/hugegraph/pull/3445#discussion_r4435957693
##########
hugegraph-store/hg-store-core/src/main/java/org/apache/hugegraph/store/business/itrv2/MultiListIterator.java:
##########
@@ -115,21 +127,53 @@ public boolean isValid() {
*/
@Override
public void close() {
- if (this.innerIterator != null) {
- this.innerIterator.close();
+ if (this.closed) {
+ return;
}
+ this.closed = true;
+ ScanIterator current = this.innerIterator;
+ this.innerIterator = null;
if (this.innerListIterator == null) {
// never iterated, so every sub-iterator is still open
this.innerListIterator = this.iterators.iterator();
}
+
+ // keep closing the rest if one fails, then rethrow the first failure
+ Throwable failure = null;
+ if (current != null) {
+ failure = closeSource(current, failure);
+ }
while (this.innerListIterator.hasNext()) {
- this.innerListIterator.next().close();
+ failure = closeSource(this.innerListIterator.next(), failure);
}
this.iterators.clear();
+ if (failure instanceof RuntimeException runtimeFailure) {
+ throw runtimeFailure;
+ }
+ if (failure != null) {
+ throw (Error) failure;
+ }
+ }
+
+ private static Throwable closeSource(ScanIterator iterator, Throwable
failure) {
+ try {
+ iterator.close();
+ } catch (RuntimeException | Error e) {
+ if (failure == null) {
+ return e;
+ }
+ if (failure != e) {
+ failure.addSuppressed(e);
+ }
+ }
+ return failure;
}
@Override
public <T> T next() {
+ if (!hasNext()) {
Review Comment:
‼️ `next()` probes the current child again after the caller has already
called `hasNext()`. In multi-branch `scanIndex` with `DEDUP`,
`indexIntersection` supplies `InAccurateUnionFilterIterator` or
`InAccurateIntersectionIterator` children, whose `hasNext()` consumes and
replaces the current match. The second probe skips the first row; a single-row
child can instead be exhausted and cause `NoSuchElementException`. Please cache
the prepared state between `hasNext()` and `next()`, and add a regression test
using a child whose `hasNext()` advances.
--
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]