Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tx leak #2031

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,72 @@

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 boolean registered = false;
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() {
if (registered) {
return;
}
RegisterUtil.registerBackends();
registered = true;
}

@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