From ba306546380612f7c5ae9dce3ea7f53ae2f0f6e7 Mon Sep 17 00:00:00 2001 From: Linary Date: Wed, 23 Sep 2020 15:13:30 +0800 Subject: [PATCH] Define loading mode to speed up when loading data (#1188) Change-Id: Ia9a93a3f0433c67353d89eb877a799ed5202fac1 --- .../java/com/baidu/hugegraph/StandardHugeGraph.java | 1 + .../backend/store/raft/RaftSharedContext.java | 5 +++++ .../backend/store/raft/StoreStateMachine.java | 7 +++++-- .../baidu/hugegraph/backend/tx/GraphTransaction.java | 4 +++- .../com/baidu/hugegraph/type/define/GraphMode.java | 11 ++++++++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java index a25bcd93d8..cf0a82016c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/StandardHugeGraph.java @@ -243,6 +243,7 @@ public GraphMode mode() { @Override public void mode(GraphMode mode) { + LOG.info("Graph {} will work in {} mode", this, mode); this.mode = mode; } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftSharedContext.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftSharedContext.java index 65adc20449..c6e70b7958 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftSharedContext.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/RaftSharedContext.java @@ -49,6 +49,7 @@ import com.baidu.hugegraph.config.HugeConfig; import com.baidu.hugegraph.event.EventHub; import com.baidu.hugegraph.type.HugeType; +import com.baidu.hugegraph.type.define.GraphMode; import com.baidu.hugegraph.util.Events; import com.baidu.hugegraph.util.Log; @@ -216,6 +217,10 @@ public ExecutorService backendExecutor() { return this.backendExecutor; } + public GraphMode graphMode() { + return this.params.mode(); + } + private HugeConfig config() { return this.params.configuration(); } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/StoreStateMachine.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/StoreStateMachine.java index 8167c30fff..c7d76025e7 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/StoreStateMachine.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/raft/StoreStateMachine.java @@ -43,6 +43,7 @@ import com.baidu.hugegraph.backend.store.BackendStore; import com.baidu.hugegraph.backend.store.raft.RaftBackendStore.IncrCounter; import com.baidu.hugegraph.type.HugeType; +import com.baidu.hugegraph.type.define.GraphMode; import com.baidu.hugegraph.util.LZ4Util; import com.baidu.hugegraph.util.Log; @@ -81,8 +82,10 @@ private void registerCommands() { this.store.beginTx(); for (BackendMutation mutation : ms) { this.store.mutate(mutation); - // update cache on follower - this.updateCacheIfNeeded(mutation); + // update cache on follower when graph run in general mode + if (this.context.graphMode() == GraphMode.NONE) { + this.updateCacheIfNeeded(mutation); + } } this.store.commitTx(); return null; 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 1b4d8c3ff3..a327d73cac 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 @@ -320,7 +320,9 @@ protected void prepareAdditions(Map addedVertices, v.committed(); this.checkAggregateProperty(v); // Check whether passed all non-null properties - this.checkNonnullProperty(v); + if (!this.graphMode().loading()) { + this.checkNonnullProperty(v); + } // Add vertex entry this.doInsert(this.serializer.writeVertex(v)); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java index 846c6d40c2..97e5d143ae 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/type/define/GraphMode.java @@ -40,7 +40,12 @@ public enum GraphMode { * 1. Not allowed create schema with specified id * 2. Support create vertex with id for AUTOMATIC id strategy */ - MERGING(3, "merging"); + MERGING(3, "merging"), + + /* + * LOADING mode used to load data via hugegraph-loader. + */ + LOADING(4, "loading"); private final byte code; private final String name; @@ -62,4 +67,8 @@ public String string() { public boolean maintaining() { return this == RESTORING || this == MERGING; } + + public boolean loading() { + return this == LOADING; + } }