Skip to content

Commit aaf67cf

Browse files
authored
fix(core): close flat mapper iterator after usage (#2281)
close [Bug] FlatMapperIterator should be closed after usage #2280
1 parent 8a515f2 commit aaf67cf

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.hugegraph.iterator.FlatMapperIterator;
3333
import org.apache.hugegraph.structure.HugeEdge;
3434
import org.apache.hugegraph.util.E;
35+
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
3536

3637
public class CountTraverser extends HugeTraverser {
3738

@@ -78,19 +79,23 @@ public long count(Id source, List<EdgeStep> steps,
7879
});
7980
}
8081

81-
// The last step, just query count
82-
EdgeStep lastStep = steps.get(stepNum - 1);
83-
while (edges.hasNext()) {
84-
Id target = ((HugeEdge) edges.next()).id().otherVertexId();
85-
if (this.dedup(target)) {
86-
continue;
82+
try {
83+
// The last step, just query count
84+
EdgeStep lastStep = steps.get(stepNum - 1);
85+
while (edges.hasNext()) {
86+
Id target = ((HugeEdge) edges.next()).id().otherVertexId();
87+
if (this.dedup(target)) {
88+
continue;
89+
}
90+
// Count last layer vertices(without dedup size)
91+
long edgesCount = this.edgesCount(target, lastStep);
92+
this.count.add(edgesCount);
8793
}
88-
// Count last layer vertices(without dedup size)
89-
long edgesCount = this.edgesCount(target, lastStep);
90-
this.count.add(edgesCount);
91-
}
9294

93-
return this.count.longValue();
95+
return this.count.longValue();
96+
} finally {
97+
CloseableIterator.closeIterator(edges);
98+
}
9499
}
95100

96101
private Iterator<Edge> edgesOfVertexWithCount(Id source, EdgeStep step) {

0 commit comments

Comments
 (0)