From 2ae0f6c9d6ac5f5eceedb06368be44ad7f7afae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E5=85=85?= Date: Mon, 14 Aug 2023 17:52:01 +0800 Subject: [PATCH 1/2] fix: close flat mapper iterator after usage --- .../traversal/algorithm/CountTraverser.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java index 7025aedde0..1f23f0a1e4 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java @@ -78,19 +78,28 @@ public long count(Id source, List steps, }); } - // The last step, just query count - EdgeStep lastStep = steps.get(stepNum - 1); - while (edges.hasNext()) { - Id target = ((HugeEdge) edges.next()).id().otherVertexId(); - if (this.dedup(target)) { - continue; + try { + // The last step, just query count + EdgeStep lastStep = steps.get(stepNum - 1); + while (edges.hasNext()) { + Id target = ((HugeEdge) edges.next()).id().otherVertexId(); + if (this.dedup(target)) { + continue; + } + // Count last layer vertices(without dedup size) + long edgesCount = this.edgesCount(target, lastStep); + this.count.add(edgesCount); } - // Count last layer vertices(without dedup size) - long edgesCount = this.edgesCount(target, lastStep); - this.count.add(edgesCount); - } - return this.count.longValue(); + return this.count.longValue(); + } finally { + if (edges instanceof FlatMapperIterator) { + try { + ((FlatMapperIterator)edges).close(); + } catch (Exception ignored) { + } + } + } } private Iterator edgesOfVertexWithCount(Id source, EdgeStep step) { From 4862a7055868ad80101d56902eeeeef4233ee0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E5=85=85?= Date: Fri, 18 Aug 2023 14:52:08 +0800 Subject: [PATCH 2/2] fix: use closable iterator util to close autoclosable edges rather than mannually close it --- .../hugegraph/traversal/algorithm/CountTraverser.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java index 1f23f0a1e4..83b3747e0a 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CountTraverser.java @@ -32,6 +32,7 @@ import org.apache.hugegraph.iterator.FlatMapperIterator; import org.apache.hugegraph.structure.HugeEdge; import org.apache.hugegraph.util.E; +import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; public class CountTraverser extends HugeTraverser { @@ -93,12 +94,7 @@ public long count(Id source, List steps, return this.count.longValue(); } finally { - if (edges instanceof FlatMapperIterator) { - try { - ((FlatMapperIterator)edges).close(); - } catch (Exception ignored) { - } - } + CloseableIterator.closeIterator(edges); } }