Skip to content

Commit

Permalink
Fix tx leak
Browse files Browse the repository at this point in the history
  • Loading branch information
coderzc committed Nov 24, 2022
1 parent d340420 commit 8e5d110
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
import java.util.concurrent.ExecutorService;

import org.apache.commons.io.FileUtils;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.slf4j.Logger;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
Expand All @@ -62,6 +56,11 @@
import org.apache.hugegraph.type.define.HugeKeys;
import org.apache.hugegraph.util.Consumers;
import org.apache.hugegraph.util.Log;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.slf4j.Logger;

public final class RamTable {

Expand Down Expand Up @@ -200,7 +199,6 @@ private void loadFromDB() throws Exception {
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",
Expand Down Expand Up @@ -496,6 +494,11 @@ public LoadTraverser() {
@Override
public void close() throws Exception {
if (this.executor != null) {
for (int i = 0; i < Consumers.THREADS; i++) {
this.executor.execute(() -> {
this.graph.tx().commit();
});
}
this.executor.shutdown();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,67 @@

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.Before;
import org.slf4j.Logger;

import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.store.BackendFeatures;
import org.apache.hugegraph.dist.RegisterUtil;
import org.apache.hugegraph.schema.SchemaManager;
import org.apache.hugegraph.testutil.Utils;
import org.apache.hugegraph.testutil.Whitebox;
import org.apache.hugegraph.type.define.NodeRole;
import org.apache.hugegraph.util.Log;
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;

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,10 @@

package org.apache.hugegraph.core;

import org.apache.hugegraph.testutil.Utils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.slf4j.Logger;

import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.core.PropertyCoreTest.EdgePropertyCoreTest;
import org.apache.hugegraph.core.PropertyCoreTest.VertexPropertyCoreTest;
import org.apache.hugegraph.dist.RegisterUtil;
import org.apache.hugegraph.type.define.NodeRole;
import org.apache.hugegraph.util.Log;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({
Expand All @@ -54,44 +43,4 @@
})
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
import org.apache.commons.configuration2.BaseConfiguration;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
import org.apache.hugegraph.testutil.Utils;
import org.junit.Test;
import org.rocksdb.RocksDBException;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.IdGenerator;
Expand All @@ -48,10 +41,17 @@
import org.apache.hugegraph.schema.SchemaManager;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.testutil.Assert;
import org.apache.hugegraph.testutil.Utils;
import org.apache.hugegraph.type.define.NodeRole;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
import org.junit.Test;
import org.rocksdb.RocksDBException;

import com.google.common.collect.ImmutableList;

public class MultiGraphsTest {
public class MultiGraphsTest extends BaseCoreTest {

private static final String NAME48 =
"g12345678901234567890123456789012345678901234567";
Expand Down

0 comments on commit 8e5d110

Please sign in to comment.