You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by zh...@apache.org on 2022/11/24 06:11:48 UTC

[incubator-hugegraph] 01/01: Fix tx leak

This is an automated email from the ASF dual-hosted git repository.

zhaocong pushed a commit to branch fix_tx_leak
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit 72700500a3ca55589df04f18de8124ed64cc4088
Author: coderzc <zh...@apache.org>
AuthorDate: Thu Nov 24 14:11:32 2022 +0800

    Fix tx leak
---
 .../backend/store/BackendProviderFactory.java      |  1 +
 .../hugegraph/backend/store/ram/RamTable.java      |  3 +-
 .../com/baidu/hugegraph/core/BaseCoreTest.java     | 45 +++++++++++++++++++++-
 .../com/baidu/hugegraph/core/CoreTestSuite.java    | 40 -------------------
 4 files changed, 46 insertions(+), 43 deletions(-)

diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendProviderFactory.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendProviderFactory.java
index c8d22450a..27582b916 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendProviderFactory.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendProviderFactory.java
@@ -60,6 +60,7 @@ public class BackendProviderFactory {
 
     private static BackendStoreProvider newProvider(HugeConfig config) {
         String backend = config.get(CoreOptions.BACKEND).toLowerCase();
+        System.out.println("OPen backend" + backend);
         String graph = config.get(CoreOptions.STORE);
 
         if (InMemoryDBStoreProvider.matchType(backend)) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java
index ba2bbc4bd..f20daaa59 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamTable.java
@@ -200,7 +200,6 @@ public final class RamTable {
         Id lastId = IdGenerator.ZERO;
         while (vertices.hasNext()) {
             Id vertex = (Id) vertices.next().id();
-            LOG.info("scan from hbase {} loadfromDB", vertex);
             if (vertex.compareTo(lastId) < 0) {
                 throw new HugeException("The ramtable feature is not " +
                                         "supported by %s backend",
@@ -502,7 +501,9 @@ public final class RamTable {
 
         protected long load(Iterator<Vertex> vertices) {
             Consumers<Id> consumers = new Consumers<>(this.executor, vertex -> {
+                LOG.info("start query");
                 Iterator<Edge> adjEdges = this.graph.adjacentEdges(vertex);
+                this.graph.tx().commit();
                 this.edges.put(vertex, IteratorUtils.list(adjEdges));
             }, null);
 
diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java
index 43118961e..81608c877 100644
--- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java
+++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/BaseCoreTest.java
@@ -24,14 +24,21 @@ import java.util.Random;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.slf4j.Logger;
 
 import com.baidu.hugegraph.HugeGraph;
 import com.baidu.hugegraph.HugeGraphParams;
+import com.baidu.hugegraph.backend.id.IdGenerator;
 import com.baidu.hugegraph.backend.store.BackendFeatures;
+import com.baidu.hugegraph.dist.RegisterUtil;
 import com.baidu.hugegraph.schema.SchemaManager;
+import com.baidu.hugegraph.testutil.Utils;
 import com.baidu.hugegraph.testutil.Whitebox;
+import com.baidu.hugegraph.type.define.NodeRole;
 import com.baidu.hugegraph.util.Log;
 
 public class BaseCoreTest {
@@ -39,9 +46,43 @@ public class BaseCoreTest {
     protected static final Logger LOG = Log.logger(BaseCoreTest.class);
 
     protected static final int TX_BATCH = 100;
+    private static HugeGraph graph = null;
 
-    public HugeGraph graph() {
-        return CoreTestSuite.graph();
+    public static HugeGraph graph() {
+        Assert.assertNotNull(graph);
+        //Assert.assertFalse(graph.closed());
+        return graph;
+    }
+
+    @BeforeClass
+    public static void initEnv() {
+        RegisterUtil.registerBackends();
+    }
+
+    @BeforeClass
+    public static void init() {
+        graph = Utils.open();
+        graph.clearBackend();
+        graph.initBackend();
+        graph.serverStarted(IdGenerator.of("server1"), NodeRole.MASTER);
+    }
+
+    @AfterClass
+    public static void clear() {
+        if (graph == null) {
+            return;
+        }
+
+        try {
+            graph.clearBackend();
+        } finally {
+            try {
+                graph.close();
+            } catch (Throwable e) {
+                LOG.error("Error when close()", e);
+            }
+            graph = null;
+        }
     }
 
     @Before
diff --git a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java
index a95ff0912..f9e707011 100644
--- a/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java
+++ b/hugegraph-test/src/main/java/com/baidu/hugegraph/core/CoreTestSuite.java
@@ -54,44 +54,4 @@ import com.baidu.hugegraph.util.Log;
 })
 public class CoreTestSuite {
 
-    private static final Logger LOG = Log.logger(CoreTestSuite.class);
-
-    private static HugeGraph graph = null;
-
-    @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
-    }
-
-    @BeforeClass
-    public static void init() {
-        graph = Utils.open();
-        graph.clearBackend();
-        graph.initBackend();
-        graph.serverStarted(IdGenerator.of("server1"), NodeRole.MASTER);
-    }
-
-    @AfterClass
-    public static void clear() {
-        if (graph == null) {
-            return;
-        }
-
-        try {
-            graph.clearBackend();
-        } finally {
-            try {
-                graph.close();
-            } catch (Throwable e) {
-                LOG.error("Error when close()", e);
-            }
-            graph = null;
-        }
-    }
-
-    protected static HugeGraph graph() {
-        Assert.assertNotNull(graph);
-        //Assert.assertFalse(graph.closed());
-        return graph;
-    }
 }