diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml
index 452a3d8d0..e8891ccf7 100644
--- a/hugegraph-api/pom.xml
+++ b/hugegraph-api/pom.xml
@@ -5,7 +5,7 @@
hugegraph
com.baidu.hugegraph
- 0.7.0-SNAPSHOT
+ 0.7.1-SNAPSHOT
4.0.0
diff --git a/hugegraph-cassandra/pom.xml b/hugegraph-cassandra/pom.xml
index 0a574fc6d..64da229df 100644
--- a/hugegraph-cassandra/pom.xml
+++ b/hugegraph-cassandra/pom.xml
@@ -5,7 +5,7 @@
hugegraph
com.baidu.hugegraph
- 0.7.0-SNAPSHOT
+ 0.7.1-SNAPSHOT
4.0.0
diff --git a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraSessionPool.java b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraSessionPool.java
index 92e70e4a0..b80c1481a 100644
--- a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraSessionPool.java
+++ b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraSessionPool.java
@@ -46,7 +46,8 @@ public class CassandraSessionPool extends BackendSessionPool {
private Cluster cluster;
private String keyspace;
- public CassandraSessionPool(String keyspace) {
+ public CassandraSessionPool(String keyspace, String store) {
+ super(keyspace + "/" + store);
this.cluster = null;
this.keyspace = keyspace;
}
@@ -149,9 +150,6 @@ public class CassandraSessionPool extends BackendSessionPool {
public Session() {
this.session = null;
this.batch = new BatchStatement(); // LOGGED
- try {
- this.open();
- } catch (InvalidQueryException ignored) {}
}
public BatchStatement add(Statement statement) {
@@ -212,16 +210,24 @@ public class CassandraSessionPool extends BackendSessionPool {
return this.session.execute(statement, args);
}
+ private void tryOpen() {
+ assert this.session == null;
+ try {
+ this.open();
+ } catch (InvalidQueryException ignored) {}
+ }
+
public void open() {
+ assert this.session == null;
this.session = cluster().connect(keyspace());
}
@Override
public boolean closed() {
if (this.session == null) {
- return true;
+ this.tryOpen();
}
- return this.session.isClosed();
+ return this.session == null ? true : this.session.isClosed();
}
@Override
diff --git a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraStore.java b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraStore.java
index 9ee363102..8c2d05a57 100644
--- a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraStore.java
+++ b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraStore.java
@@ -37,7 +37,6 @@ import com.baidu.hugegraph.backend.store.BackendStore;
import com.baidu.hugegraph.backend.store.BackendStoreProvider;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.type.HugeType;
-import com.baidu.hugegraph.type.define.Directions;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.datastax.driver.core.Cluster;
@@ -73,7 +72,7 @@ public abstract class CassandraStore implements BackendStore {
this.keyspace = keyspace;
this.store = store;
- this.sessions = new CassandraSessionPool(this.keyspace);
+ this.sessions = new CassandraSessionPool(keyspace, store);
this.tables = new ConcurrentHashMap<>();
this.conf = null;
@@ -495,17 +494,17 @@ public abstract class CassandraStore implements BackendStore {
super(provider, keyspace, store);
registerTableManager(HugeType.VERTEX,
- new CassandraTables.Vertex());
+ new CassandraTables.Vertex(store));
registerTableManager(HugeType.EDGE_OUT,
- new CassandraTables.Edge(Directions.OUT));
+ CassandraTables.Edge.out(store));
registerTableManager(HugeType.EDGE_IN,
- new CassandraTables.Edge(Directions.IN));
+ CassandraTables.Edge.in(store));
registerTableManager(HugeType.SECONDARY_INDEX,
- new CassandraTables.SecondaryIndex());
+ new CassandraTables.SecondaryIndex(store));
registerTableManager(HugeType.RANGE_INDEX,
- new CassandraTables.RangeIndex());
+ new CassandraTables.RangeIndex(store));
}
@Override
diff --git a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTable.java b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTable.java
index f26bff78c..fe9f01084 100644
--- a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTable.java
+++ b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTable.java
@@ -557,7 +557,7 @@ public abstract class CassandraTable
protected void createIndex(CassandraSessionPool.Session session,
String indexLabel, HugeKeys column) {
- String indexName = this.table() + "_" + indexLabel;
+ String indexName = joinTableName(this.table(), indexLabel);
SchemaStatement index = SchemaBuilder.createIndex(indexName)
.ifNotExists()
.onTable(this.table())
diff --git a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTables.java b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTables.java
index a970d1bc6..a68344821 100644
--- a/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTables.java
+++ b/hugegraph-cassandra/src/main/java/com/baidu/hugegraph/backend/store/cassandra/CassandraTables.java
@@ -48,6 +48,9 @@ import com.google.common.collect.ImmutableMap;
public class CassandraTables {
+ public static final String LABEL_INDEX = "label_index";
+ public static final String NAME_INDEX = "name_index";
+
private static final DataType DATATYPE_PK = DataType.cint();
private static final DataType DATATYPE_SL = DataType.cint(); // VL/EL
private static final DataType DATATYPE_IL = DataType.cint();
@@ -142,7 +145,7 @@ public class CassandraTables {
.build();
this.createTable(session, pkeys, ckeys, columns);
- this.createIndex(session, "vertex_label_name_index", HugeKeys.NAME);
+ this.createIndex(session, NAME_INDEX, HugeKeys.NAME);
}
}
@@ -175,7 +178,7 @@ public class CassandraTables {
.build();
this.createTable(session, pkeys, ckeys, columns);
- this.createIndex(session, "edge_label_name_index", HugeKeys.NAME);
+ this.createIndex(session, NAME_INDEX, HugeKeys.NAME);
}
}
@@ -202,7 +205,7 @@ public class CassandraTables {
);
this.createTable(session, pkeys, ckeys, columns);
- this.createIndex(session, "property_key_name_index", HugeKeys.NAME);
+ this.createIndex(session, NAME_INDEX, HugeKeys.NAME);
}
}
@@ -230,7 +233,7 @@ public class CassandraTables {
);
this.createTable(session, pkeys, ckeys, columns);
- this.createIndex(session, "index_label_name_index", HugeKeys.NAME);
+ this.createIndex(session, NAME_INDEX, HugeKeys.NAME);
}
}
@@ -238,8 +241,8 @@ public class CassandraTables {
public static final String TABLE = "vertices";
- public Vertex() {
- super(TABLE);
+ public Vertex(String store) {
+ super(joinTableName(store, TABLE));
}
@Override
@@ -255,7 +258,7 @@ public class CassandraTables {
);
this.createTable(session, pkeys, ckeys, columns);
- this.createIndex(session, "vertex_label_index", HugeKeys.LABEL);
+ this.createIndex(session, LABEL_INDEX, HugeKeys.LABEL);
}
}
@@ -263,13 +266,23 @@ public class CassandraTables {
public static final String TABLE_PREFIX = "edges";
+ private final String store;
private final Directions direction;
- public Edge(Directions direction) {
- super(table(direction));
+ protected Edge(String store, Directions direction) {
+ super(joinTableName(store, table(direction)));
+ this.store = store;
this.direction = direction;
}
+ protected String edgesTable(Directions direction) {
+ return joinTableName(this.store, table(direction));
+ }
+
+ protected Directions direction() {
+ return this.direction;
+ }
+
@Override
public void init(CassandraSessionPool.Session session) {
ImmutableMap pkeys = ImmutableMap.of(
@@ -293,7 +306,7 @@ public class CassandraTables {
* by label from out-edges table
*/
if (this.direction == Directions.OUT) {
- this.createIndex(session, "edge_label_index", HugeKeys.LABEL);
+ this.createIndex(session, LABEL_INDEX, HugeKeys.LABEL);
}
}
@@ -395,9 +408,9 @@ public class CassandraTables {
}
}
- private static Delete buildDelete(Id label, String ownerVertex,
- Directions direction) {
- Delete delete = QueryBuilder.delete().from(table(direction));
+ private Delete buildDelete(Id label, String ownerVertex,
+ Directions direction) {
+ Delete delete = QueryBuilder.delete().from(edgesTable(direction));
delete.where(formatEQ(HugeKeys.OWNER_VERTEX, ownerVertex));
delete.where(formatEQ(HugeKeys.DIRECTION, direction.code()));
delete.where(formatEQ(HugeKeys.LABEL, label.asLong()));
@@ -444,18 +457,26 @@ public class CassandraTables {
return vertex;
}
- public static String table(Directions direction) {
+ private static String table(Directions direction) {
assert direction == Directions.OUT || direction == Directions.IN;
return TABLE_PREFIX + "_" + direction.string();
}
+
+ public static CassandraTable out(String store) {
+ return new Edge(store, Directions.OUT);
+ }
+
+ public static CassandraTable in(String store) {
+ return new Edge(store, Directions.IN);
+ }
}
public static class SecondaryIndex extends CassandraTable {
public static final String TABLE = "secondary_indexes";
- public SecondaryIndex() {
- super(TABLE);
+ public SecondaryIndex(String store) {
+ super(joinTableName(store, TABLE));
}
@Override
@@ -548,8 +569,8 @@ public class CassandraTables {
public static final String TABLE = "range_indexes";
- public RangeIndex() {
- super(TABLE);
+ public RangeIndex(String store) {
+ super(joinTableName(store, TABLE));
}
@Override
diff --git a/hugegraph-core/pom.xml b/hugegraph-core/pom.xml
index 8baba85af..b6fa1f28b 100644
--- a/hugegraph-core/pom.xml
+++ b/hugegraph-core/pom.xml
@@ -5,7 +5,7 @@
com.baidu.hugegraph
hugegraph
- 0.7.0-SNAPSHOT
+ 0.7.1-SNAPSHOT
../pom.xml
hugegraph-core
@@ -106,7 +106,7 @@
- 0.7.0.0
+ 0.7.1.0
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
index 5eaffa8f6..b5d564f70 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/HugeGraph.java
@@ -59,6 +59,7 @@ import com.baidu.hugegraph.schema.SchemaElement;
import com.baidu.hugegraph.schema.SchemaManager;
import com.baidu.hugegraph.schema.VertexLabel;
import com.baidu.hugegraph.structure.HugeFeatures;
+import com.baidu.hugegraph.task.HugeTaskManager;
import com.baidu.hugegraph.traversal.optimize.HugeGraphStepStrategy;
import com.baidu.hugegraph.traversal.optimize.HugeVertexStepStrategy;
import com.baidu.hugegraph.util.E;
@@ -99,6 +100,7 @@ public class HugeGraph implements Graph {
private final EventHub schemaEventHub;
private final EventHub indexEventHub;
private final RateLimiter rateLimiter;
+ private final HugeTaskManager taskManager;
private final HugeFeatures features;
@@ -116,6 +118,8 @@ public class HugeGraph implements Graph {
final int limit = configuration.get(CoreOptions.RATE_LIMIT);
this.rateLimiter = limit > 0 ? RateLimiter.create(limit) : null;
+ this.taskManager = HugeTaskManager.instance();
+
this.features = new HugeFeatures(this, true);
this.name = configuration.get(CoreOptions.STORE);
@@ -132,14 +136,9 @@ public class HugeGraph implements Graph {
this.tx = new TinkerpopTransaction(this);
- this.variables = null;
- }
+ this.taskManager.addScheduler(this);
- private BackendStoreProvider loadStoreProvider() {
- String backend = this.configuration.get(CoreOptions.BACKEND);
- LOG.info("Opening backend store '{}' for graph '{}'",
- backend, this.name);
- return BackendProviderFactory.open(backend, this.name);
+ this.variables = null;
}
public String name() {
@@ -175,28 +174,34 @@ public class HugeGraph implements Graph {
}
public void initBackend() {
- this.tx.readWrite();
+ this.loadSchemaStore().open(this.configuration);
+ this.loadSystemStore().open(this.configuration);
+ this.loadGraphStore().open(this.configuration);
try {
this.storeProvider.init();
} finally {
- this.tx.close();
+ this.loadGraphStore().close();
+ this.loadSystemStore().close();
+ this.loadSchemaStore().close();
}
}
public void clearBackend() {
- this.tx.readWrite();
+ this.loadSchemaStore().open(this.configuration);
+ this.loadSystemStore().open(this.configuration);
+ this.loadGraphStore().open(this.configuration);
try {
this.storeProvider.clear();
} finally {
- this.tx.close();
+ this.loadGraphStore().close();
+ this.loadSystemStore().close();
+ this.loadSchemaStore().close();
}
}
private SchemaTransaction openSchemaTransaction() throws HugeException {
try {
- String name = this.configuration.get(CoreOptions.STORE_SCHEMA);
- BackendStore store = this.storeProvider.loadSchemaStore(name);
- return new CachedSchemaTransaction(this, store);
+ return new CachedSchemaTransaction(this, this.loadSchemaStore());
} catch (BackendException e) {
String message = "Failed to open schema transaction";
LOG.error("{}", message, e);
@@ -206,9 +211,7 @@ public class HugeGraph implements Graph {
private GraphTransaction openGraphTransaction() throws HugeException {
try {
- String graph = this.configuration.get(CoreOptions.STORE_GRAPH);
- BackendStore store = this.storeProvider.loadGraphStore(graph);
- return new CachedGraphTransaction(this, store);
+ return new CachedGraphTransaction(this, this.loadGraphStore());
} catch (BackendException e) {
String message = "Failed to open graph transaction";
LOG.error("{}", message, e);
@@ -216,6 +219,28 @@ public class HugeGraph implements Graph {
}
}
+ private BackendStoreProvider loadStoreProvider() {
+ String backend = this.configuration.get(CoreOptions.BACKEND);
+ LOG.info("Opening backend store '{}' for graph '{}'",
+ backend, this.name);
+ return BackendProviderFactory.open(backend, this.name);
+ }
+
+ private BackendStore loadSchemaStore() {
+ String name = this.configuration.get(CoreOptions.STORE_SCHEMA);
+ return this.storeProvider.loadSchemaStore(name);
+ }
+
+ private BackendStore loadGraphStore() {
+ String graph = this.configuration.get(CoreOptions.STORE_GRAPH);
+ return this.storeProvider.loadGraphStore(graph);
+ }
+
+ public BackendStore loadSystemStore() {
+ String name = this.configuration.get(CoreOptions.STORE_SYSTEM);
+ return this.storeProvider.loadSystemStore(name);
+ }
+
public SchemaTransaction schemaTransaction() {
/*
* NOTE: each schema operation will be auto committed,
@@ -238,6 +263,7 @@ public class HugeGraph implements Graph {
}
public GraphTransaction openTransaction() {
+ // Open a new one
return this.openGraphTransaction();
}
@@ -362,6 +388,7 @@ public class HugeGraph implements Graph {
this.closeTx();
} finally {
this.storeProvider.close();
+ this.taskManager.closeScheduler(this);
}
}
@@ -470,6 +497,7 @@ public class HugeGraph implements Graph {
*/
public static void shutdown(long timout) throws InterruptedException {
EventHub.destroy(timout);
+ HugeTaskManager.instance().shutdown(timout);
}
private class TinkerpopTransaction extends AbstractThreadLocalTransaction {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
index 4fb319fd5..a611ff260 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/cache/CachedGraphTransaction.java
@@ -111,7 +111,7 @@ public class CachedGraphTransaction extends GraphTransaction {
}
@Override
- public Vertex addVertex(HugeVertex vertex) {
+ public HugeVertex addVertex(HugeVertex vertex) {
// Update vertex cache
this.verticesCache.invalidate(vertex.id());
@@ -146,7 +146,7 @@ public class CachedGraphTransaction extends GraphTransaction {
}
@Override
- public Edge addEdge(HugeEdge edge) {
+ public HugeEdge addEdge(HugeEdge edge) {
// TODO: Use a more precise strategy to update the edge cache
this.edgesCache.clear();
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java
index 10eb7d809..e717daadd 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/AbstractBackendStoreProvider.java
@@ -128,4 +128,9 @@ public abstract class AbstractBackendStoreProvider
E.checkNotNull(store, "store");
return store;
}
+
+ @Override
+ public BackendStore loadSystemStore(String name) {
+ return this.loadGraphStore(name);
+ }
}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSessionPool.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSessionPool.java
index 2da4a13c2..f875bb34d 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSessionPool.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendSessionPool.java
@@ -30,10 +30,12 @@ public abstract class BackendSessionPool {
private static final Logger LOG = Log.logger(BackendSessionPool.class);
- private ThreadLocal threadLocalSession;
- private AtomicInteger sessionCount;
+ private final String name;
+ private final ThreadLocal threadLocalSession;
+ private final AtomicInteger sessionCount;
- public BackendSessionPool() {
+ public BackendSessionPool(String name) {
+ this.name = name;
this.threadLocalSession = new ThreadLocal<>();
this.sessionCount = new AtomicInteger(0);
}
@@ -102,9 +104,8 @@ public abstract class BackendSessionPool {
@Override
public String toString() {
- return String.format("%s@%08X",
- this.getClass().getSimpleName(),
- this.hashCode());
+ return String.format("%s-%s@%08X", this.name,
+ this.getClass().getSimpleName(), this.hashCode());
}
public abstract void open(HugeConfig config) throws Exception;
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java
index b0fb02683..336c7104b 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendStoreProvider.java
@@ -29,6 +29,8 @@ public interface BackendStoreProvider {
// Graph name (that's database name)
public String graph();
+ public BackendStore loadSystemStore(String name);
+
public BackendStore loadSchemaStore(String name);
public BackendStore loadGraphStore(String name);
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java
index b7fc9d56c..00bbae730 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/BackendTable.java
@@ -106,6 +106,10 @@ public abstract class BackendTable {
return type;
}
+ public static final String joinTableName(String prefix, String table) {
+ return prefix + "_" + table;
+ }
+
/*************************** abstract methods ***************************/
public abstract void init(Session session);
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java
index de0c01ce9..32ae05694 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/tx/GraphTransaction.java
@@ -308,8 +308,13 @@ public class GraphTransaction extends IndexableTransaction {
return rs;
}
- @Watched("graph.addVertex-with-instance")
- public Vertex addVertex(HugeVertex vertex) {
+ @Watched(prefix = "graph")
+ public HugeVertex addVertex(Object... keyValues) {
+ return this.addVertex(this.constructVertex(true, keyValues));
+ }
+
+ @Watched("graph.addVertex-instance")
+ public HugeVertex addVertex(HugeVertex vertex) {
this.checkOwnerThread();
// Override vertexes in local `removedVertexes`
@@ -335,10 +340,11 @@ public class GraphTransaction extends IndexableTransaction {
}
@Watched(prefix = "graph")
- public Vertex addVertex(Object... keyValues) {
+ public HugeVertex constructVertex(boolean verifyVL, Object... keyValues) {
HugeElement.ElementKeys elemKeys = HugeElement.classifyKeys(keyValues);
- VertexLabel vertexLabel = this.checkVertexLabel(elemKeys.label());
+ VertexLabel vertexLabel = this.checkVertexLabel(elemKeys.label(),
+ verifyVL);
Id id = HugeVertex.getIdValue(elemKeys.id());
List keys = this.graph().mapPkName2Id(elemKeys.keys());
@@ -363,7 +369,7 @@ public class GraphTransaction extends IndexableTransaction {
vertex.assignId(id);
}
- return this.addVertex(vertex);
+ return vertex;
}
@Watched(prefix = "graph")
@@ -469,7 +475,7 @@ public class GraphTransaction extends IndexableTransaction {
}
@Watched(prefix = "graph")
- public Edge addEdge(HugeEdge edge) {
+ public HugeEdge addEdge(HugeEdge edge) {
this.checkOwnerThread();
// Override edges in local `removedEdges`
@@ -957,7 +963,7 @@ public class GraphTransaction extends IndexableTransaction {
}
}
- private VertexLabel checkVertexLabel(Object label) {
+ private VertexLabel checkVertexLabel(Object label, boolean verifyLabel) {
HugeVertexFeatures features = graph().features().vertex();
// Check Vertex label
@@ -974,7 +980,9 @@ public class GraphTransaction extends IndexableTransaction {
"as the vertex label argument, but got: '%s'", label);
// The label must be an instance of String or VertexLabel
if (label instanceof String) {
- ElementHelper.validateLabel((String) label);
+ if (verifyLabel) {
+ ElementHelper.validateLabel((String) label);
+ }
label = graph().vertexLabel((String) label);
}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/config/CoreOptions.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/config/CoreOptions.java
index 77dcd42da..db1341678 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/config/CoreOptions.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/config/CoreOptions.java
@@ -63,6 +63,14 @@ public class CoreOptions extends OptionHolder {
"hugegraph"
);
+ public static final ConfigOption STORE_SYSTEM =
+ new ConfigOption<>(
+ "store.system",
+ "The system table name, which store system data.",
+ disallowEmpty(),
+ "system"
+ );
+
public static final ConfigOption STORE_SCHEMA =
new ConfigOption<>(
"store.schema",
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java
index bf8de29c4..8c6acdde5 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java
@@ -230,7 +230,7 @@ public class HugeVertex extends HugeElement implements Vertex, Cloneable {
*/
@Watched(prefix = "vertex")
@Override
- public Edge addEdge(String label, Vertex vertex, Object... keyValues) {
+ public HugeEdge addEdge(String label, Vertex vertex, Object... keyValues) {
ElementKeys elemKeys = HugeElement.classifyKeys(keyValues);
// Check id (must be null)
if (elemKeys.id() != null) {
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTask.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTask.java
new file mode 100644
index 000000000..cea8ff957
--- /dev/null
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/HugeTask.java
@@ -0,0 +1,361 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.task;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.FutureTask;
+
+import org.apache.tinkerpop.gremlin.structure.Graph.Hidden;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+
+import com.baidu.hugegraph.backend.id.Id;
+import com.baidu.hugegraph.type.define.SerialEnum;
+import com.baidu.hugegraph.util.E;
+
+public class HugeTask extends FutureTask {
+
+ private final HugeTaskCallable callable;
+
+ private String type;
+ private String name;
+ private final Id id;
+ private final Id parent;
+ private List children;
+ private String description;
+ private HugeTaskStatus status;
+ private int progress;
+ private Date create;
+ private Date update;
+ private int retries;
+ private String result;
+
+ public HugeTask(Id id, Id parent, HugeTaskCallable callable) {
+ super(callable);
+
+ E.checkArgumentNotNull(id, "Task id can't be null");
+ E.checkArgument(id.number(), "Invalid task id type, it must be number");
+
+ this.callable = callable;
+ this.type = null;
+ this.name = null;
+ this.id = id;
+ this.parent = parent;
+ this.children = null;
+ this.description = null;
+ this.status = HugeTaskStatus.NEW;
+ this.progress = 0;
+ this.create = new Date();
+ this.update = null;
+ this.retries = 0;
+ this.result = null;
+ }
+
+ public Id id() {
+ return this.id;
+ }
+
+ public Id parent() {
+ return this.parent;
+ }
+
+ public List children() {
+ return Collections.unmodifiableList(this.children);
+ }
+
+ public void child(Id id) {
+ if (this.children == null) {
+ this.children = new ArrayList<>();
+ }
+ this.children.add(id);
+ }
+
+ public void type(String type) {
+ this.type = type;
+ }
+
+ public String type() {
+ return this.type;
+ }
+
+ public void name(String name) {
+ this.name = name;
+ }
+
+ public String name() {
+ return this.name;
+ }
+
+ public void description(String description) {
+ this.description = description;
+ }
+
+ public String description() {
+ return this.description;
+ }
+
+ public void progress(int progress) {
+ this.progress = progress;
+ }
+
+ public int progress() {
+ return this.progress;
+ }
+
+ public void createTime(Date create) {
+ this.create = create;
+ }
+
+ public Date createTime() {
+ return this.create;
+ }
+
+ public void updateTime(Date update) {
+ this.update = update;
+ }
+
+ public Date updateTime() {
+ return this.update;
+ }
+
+ public void retry() {
+ ++this.retries;
+ }
+
+ public int retries() {
+ return this.retries;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("HugeTask(%s)%s", this.id, this.asMap());
+ }
+
+ @Override
+ public void run() {
+ this.status(HugeTaskStatus.RUNNING);
+ super.run();
+ }
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ this.status(HugeTaskStatus.CANCELLED);
+ return super.cancel(mayInterruptIfRunning);
+ }
+
+ @Override
+ protected void set(V v) {
+ this.status(HugeTaskStatus.SUCCESS);
+ this.result = v.toString();
+ super.set(v);
+ }
+
+ @Override
+ protected void setException(Throwable t) {
+ this.status(HugeTaskStatus.FAILED);
+ this.result = t.toString();
+ super.setException(t);
+ }
+
+ protected synchronized void status(HugeTaskStatus status) {
+ this.status = status;
+ }
+
+ protected HugeTaskCallable callable() {
+ return this.callable;
+ }
+
+ protected void property(String key, Object value) {
+ E.checkNotNull(key, "property key");
+ switch (key) {
+ case P.TYPE:
+ this.type = (String) value;
+ break;
+ case P.NAME:
+ this.name = (String) value;
+ break;
+ case P.DESCRIPTION:
+ this.description = (String) value;
+ break;
+ case P.STATUS:
+ this.status = SerialEnum.fromCode(HugeTaskStatus.class,
+ (byte) value);
+ break;
+ case P.PROGRESS:
+ this.progress = (int) value;
+ break;
+ case P.CREATE:
+ this.create = (Date) value;
+ break;
+ case P.UPDATE:
+ this.update = (Date) value;
+ break;
+ case P.RETRIES:
+ this.retries = (int) value;
+ break;
+ case P.RESULT:
+ this.result = (String) value;
+ break;
+ case P.CALLABLE:
+ // pass
+ break;
+ default:
+ throw new AssertionError("Unsupported key: " + key);
+ }
+ }
+
+ protected Object[] asArray() {
+ E.checkState(this.type != null, "Task type can't be null");
+ E.checkState(this.name != null, "Task name can't be null");
+
+ List