diff --git a/hg-store-cli/pom.xml b/hg-store-cli/pom.xml
index ed2d472b3..0749c0516 100644
--- a/hg-store-cli/pom.xml
+++ b/hg-store-cli/pom.xml
@@ -20,9 +20,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ org.apache.hugegraph
hugegraph-store-root
- com.baidu.hugegraph
- 3.6.3-SNAPSHOT
+ ${revision}
4.0.0
@@ -40,19 +40,19 @@
- com.baidu.hugegraph
+ org.apache.hugegraph
hg-store-client
- ${project.version}
+ ${revision}
- com.baidu.hugegraph
+ org.apache.hugegraph
hg-store-grpc
- ${project.version}
+ ${revision}
- com.baidu.hugegraph
+ org.apache.hugegraph
hg-pd-client
- ${project.version}
+ ${revision}
diff --git a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/StoreConsoleApplication.java b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/StoreConsoleApplication.java
index 362f9ff6b..858bf9ddb 100644
--- a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/StoreConsoleApplication.java
+++ b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/StoreConsoleApplication.java
@@ -19,6 +19,7 @@ package org.apache.hugegraph.store.cli;
import java.io.IOException;
+import org.apache.hugegraph.store.HgStoreClient;
import org.apache.hugegraph.store.cli.loader.HgThread2DB;
import org.apache.hugegraph.store.cli.scan.GrpcShardScanner;
import org.apache.hugegraph.store.cli.scan.HgStoreCommitter;
@@ -30,7 +31,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.baidu.hugegraph.pd.client.PDConfig;
import com.baidu.hugegraph.pd.common.PDException;
-import com.baidu.hugegraph.store.HgStoreClient;
import lombok.extern.slf4j.Slf4j;
diff --git a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/loader/HgThread2DB.java b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/loader/HgThread2DB.java
index 0b75c308b..807a6b3d1 100644
--- a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/loader/HgThread2DB.java
+++ b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/loader/HgThread2DB.java
@@ -36,18 +36,18 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.HgStoreClient;
+import org.apache.hugegraph.store.HgStoreSession;
import org.apache.hugegraph.store.cli.util.HgCliUtil;
+import org.apache.hugegraph.store.client.grpc.KvCloseableIterator;
+import org.apache.hugegraph.store.client.util.MetricX;
import com.baidu.hugegraph.pd.client.PDClient;
import com.baidu.hugegraph.pd.client.PDConfig;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.HgStoreClient;
-import com.baidu.hugegraph.store.HgStoreSession;
-import com.baidu.hugegraph.store.client.grpc.KvCloseableIterator;
-import com.baidu.hugegraph.store.client.util.MetricX;
import lombok.extern.slf4j.Slf4j;
diff --git a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreCommitter.java b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreCommitter.java
index 0189aa752..48ace5444 100644
--- a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreCommitter.java
+++ b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreCommitter.java
@@ -17,12 +17,11 @@
package org.apache.hugegraph.store.cli.scan;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgSessionManager;
+import org.apache.hugegraph.store.HgStoreSession;
import org.apache.hugegraph.store.cli.util.HgCliUtil;
-
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgSessionManager;
-import com.baidu.hugegraph.store.HgStoreSession;
-import com.baidu.hugegraph.store.client.HgStoreNodeManager;
+import org.apache.hugegraph.store.client.HgStoreNodeManager;
/**
* @author lynn.bond@hotmail.com on 2022/2/28
diff --git a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreScanner.java b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreScanner.java
index d80de3696..a61730906 100644
--- a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreScanner.java
+++ b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/scan/HgStoreScanner.java
@@ -20,22 +20,22 @@ package org.apache.hugegraph.store.cli.scan;
import java.util.Arrays;
import java.util.List;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvStore;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.HgSessionManager;
+import org.apache.hugegraph.store.HgStoreClient;
+import org.apache.hugegraph.store.HgStoreSession;
import org.apache.hugegraph.store.cli.util.HgCliUtil;
import org.apache.hugegraph.store.cli.util.HgMetricX;
+import org.apache.hugegraph.store.client.grpc.KvCloseableIterator;
+import org.apache.hugegraph.store.client.util.HgStoreClientConfig;
+import org.apache.hugegraph.store.client.util.MetricX;
import com.baidu.hugegraph.pd.client.PDClient;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.grpc.Metapb;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvStore;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.HgSessionManager;
-import com.baidu.hugegraph.store.HgStoreClient;
-import com.baidu.hugegraph.store.HgStoreSession;
-import com.baidu.hugegraph.store.client.grpc.KvCloseableIterator;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConfig;
-import com.baidu.hugegraph.store.client.util.MetricX;
import lombok.extern.slf4j.Slf4j;
diff --git a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/util/HgCliUtil.java b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/util/HgCliUtil.java
index 38e2256ec..188c524bc 100644
--- a/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/util/HgCliUtil.java
+++ b/hg-store-cli/src/main/java/org/apache/hugegraph/store/cli/util/HgCliUtil.java
@@ -26,10 +26,10 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgStoreSession;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgStoreSession;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
/**
diff --git a/hg-store-client/deploy-snapshot.sh b/hg-store-client/deploy-snapshot.sh
index f35659e36..d4f643995 100644
--- a/hg-store-client/deploy-snapshot.sh
+++ b/hg-store-client/deploy-snapshot.sh
@@ -1,5 +1,22 @@
#!/bin/bash
+#
+# 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.
+#
+
readonly REPO_URL=http://10.14.139.8:8081/artifactory/star-snapshot
mvn --settings ../settings.xml -Dmaven.test.skip=true -DaltDeploymentRepository=star-snapshot::default::${REPO_URL} clean deploy
diff --git a/hg-store-client/pom.xml b/hg-store-client/pom.xml
index 930a1ef30..5f9e3666e 100644
--- a/hg-store-client/pom.xml
+++ b/hg-store-client/pom.xml
@@ -1,12 +1,29 @@
+
+
4.0.0
- com.baidu.hugegraph
+ org.apache.hugegraph
hg-store-client
- 3.6.3-SNAPSHOT
+ ${revision}
11
@@ -18,15 +35,26 @@
- com.baidu.hugegraph
+ org.apache.hugegraph
hg-store-grpc
- ${project.version}
+ ${revision}
- com.baidu.hugegraph
+ org.apache.hugegraph
hg-store-common
- ${project.version}
+ ${revision}
+
+ org.apache.hugegraph
+ hg-pd-client
+ ${revision}
+
+
+ org.apache.hugegraph
+ hg-pd-grpc
+ ${revision}
+
+
org.projectlombok
lombok
@@ -37,18 +65,6 @@
log4j-slf4j-impl
${log4j2.version}
-
- com.baidu.hugegraph
- hg-pd-client
- ${project.version}
-
-
-
-
- com.baidu.hugegraph
- hg-pd-grpc
- ${project.version}
-
junit
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvEntry.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvEntry.java
deleted file mode 100644
index 68afae352..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvEntry.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-public interface HgKvEntry {
- byte[] key();
-
- byte[] value();
-
- default int code(){
- return -1;
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvIterator.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvIterator.java
deleted file mode 100644
index af2323aea..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvIterator.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.baidu.hugegraph.store;
-
-import java.io.Closeable;
-import java.util.Iterator;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/21
- */
-public interface HgKvIterator extends Iterator, HgSeekAble, Closeable {
-
- byte[] key();
-
- byte[] value();
-
- void close();
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvOrderedIterator.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvOrderedIterator.java
deleted file mode 100644
index 52cc5bc6c..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvOrderedIterator.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * @author lynn.bond@hotmail.com created on 2022/03/10
- */
-public interface HgKvOrderedIterator extends HgKvIterator, Comparable {
- long getSequence();
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvPagingIterator.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvPagingIterator.java
deleted file mode 100644
index 7b647ce22..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvPagingIterator.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/24
- */
-public interface HgKvPagingIterator extends HgKvIterator, HgPageSize {
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgPageSize.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgPageSize.java
deleted file mode 100644
index 150d9924b..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgPageSize.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * Return the amount of records returned by one query in pageable-query.
- *
- * @author lynn.bond@hotmail.com created on 2021/10/24
- */
-public interface HgPageSize {
- long getPageSize();
- default boolean isPageEmpty(){
- return false;
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgPrivate.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgPrivate.java
deleted file mode 100644
index 898571696..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgPrivate.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-public final class HgPrivate {
-
- private static HgPrivate instance = new HgPrivate();
-
- private HgPrivate() {
- }
-
- static HgPrivate of() {
- return instance;
- }
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSeekAble.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSeekAble.java
deleted file mode 100644
index f26bc3e51..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSeekAble.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * @author lynn.bond@hotmail.com created on 2022/03/11
- */
-public interface HgSeekAble {
- byte[] position();
-
- void seek(byte[] position);
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSessionManager.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSessionManager.java
deleted file mode 100644
index a4aaf4bf7..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSessionManager.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.baidu.hugegraph.store;
-
-import com.baidu.hugegraph.store.client.HgStoreSessionProvider;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-/**
- * Maintain HgStoreSession instances.
- * // TODO: Holding more than one HgSessionManager is available,if you want to connect multi HgStore-clusters.
- *
- * @author lynn.bond@hotmail.com
- */
-
-@ThreadSafe
-public final class HgSessionManager {
- private HgSessionProvider sessionProvider;
- private final static HgSessionManager instance =new HgSessionManager();
-
- private HgSessionManager(){
- // TODO: constructed by SPI
- this.sessionProvider=new HgStoreSessionProvider();
- }
-
-
- public static HgSessionManager getInstance(){
- return instance;
- }
-
- /**
- * Retrieve or create a HgStoreSession.
- * @param graphName
- * @return
- */
- public HgStoreSession openSession(String graphName){
- return this.sessionProvider.createSession(graphName);
- }
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSessionProvider.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSessionProvider.java
deleted file mode 100644
index 779c845be..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgSessionProvider.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.baidu.hugegraph.store;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/12
- */
-@ThreadSafe
-public interface HgSessionProvider {
- HgStoreSession createSession(String graphName);
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgStoreSession.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgStoreSession.java
deleted file mode 100644
index 90bcc47d5..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgStoreSession.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.baidu.hugegraph.store;
-
-import com.baidu.hugegraph.store.client.type.HgStoreClientException;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-public interface HgStoreSession extends HgKvStore {
-
- void beginTx();
-
- /**
- * @throws IllegalStateException when the tx hasn't been beginning.
- * @throws HgStoreClientException when failed to commit .
- */
- void commit();
-
- /**
- * @throws IllegalStateException when the tx hasn't been beginning.
- * @throws HgStoreClientException when failed to rollback.
- */
- void rollback();
-
- boolean isTx();
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgTkvEntry.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgTkvEntry.java
deleted file mode 100644
index fd6699107..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgTkvEntry.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-public interface HgTkvEntry {
- String table();
- byte[] key();
- byte[] value();
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgTokvEntry.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgTokvEntry.java
deleted file mode 100644
index f2d1e264d..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgTokvEntry.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baidu.hugegraph.store;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-public interface HgTokvEntry {
- String table();
- HgOwnerKey ownerKey();
- byte[] value();
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgPrivate.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgPrivate.java
deleted file mode 100644
index 184686c25..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgPrivate.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import java.util.Arrays;
-import java.util.Objects;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/26
- */
-public class HgPrivate {
- private final static HgPrivate instance = new HgPrivate();
-
- static HgPrivate getInstance() {
- return instance;
- }
-
- private HgPrivate() {
-
- }
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNode.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNode.java
deleted file mode 100644
index c9ab58577..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNode.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import com.baidu.hugegraph.store.HgStoreSession;
-
-import java.util.Set;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/11
- * @version 0.2.0
- */
-public interface HgStoreNode {
-
- /**
- * Return boolean value of being online or not
- * @return
- */
- default boolean isHealthy(){
- return true;
- }
-
- /**
- * Return the unique ID of store-node.
- * @return
- */
- Long getNodeId();
-
- /**
- * A string value concatenated by host and port: "host:port"
- * @return
- */
- String getAddress();
-
- /**
- * Return a new HgStoreSession instance, that is not Thread safe.
- * Return null when the node is not in charge of the graph that was passed from argument.
- * @return
- */
- HgStoreSession openSession(String graphName);
-
-}
\ No newline at end of file
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeBuilder.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeBuilder.java
deleted file mode 100644
index 0734ddb1f..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeBuilder.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/11
- */
-public interface HgStoreNodeBuilder {
-
- HgStoreNodeBuilder setNodeId(Long nodeId);
-
- HgStoreNodeBuilder setAddress(String address);
-
- /**
- * To build a HgStoreNode instance.
- *
- * @return
- */
- HgStoreNode build();
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeCandidates.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeCandidates.java
deleted file mode 100644
index 3be9048ed..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeCandidates.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import java.util.List;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/12
- */
-public final class HgStoreNodeCandidates {
-
- List nodeList;
-
- HgStoreNodeCandidates(List nodeList){
- this.nodeList=nodeList;
- }
-
- public int size(){
- return this.nodeList.size();
- }
-
- public HgStoreNode getNode(int index){
- return this.nodeList.get(index);
- }
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeNotifier.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeNotifier.java
deleted file mode 100644
index 3110b42d9..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeNotifier.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import com.baidu.hugegraph.store.client.type.HgNodeStatus;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/12
- * @version 1.0.0
- */
-public interface HgStoreNodeNotifier {
-
- /**
- * It will be invoked by NodeManager, when some exception or issue was happened.
- * @param graphName
- * @param storeNotice
- * @return return 0 please, for no matter what.
- */
- int notice(String graphName, HgStoreNotice storeNotice);
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeProvider.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeProvider.java
deleted file mode 100644
index 9775ce6f8..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeProvider.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/27
- */
-public interface HgStoreNodeProvider {
-
- /**
- * Applying a new HgStoreNode instance
- * @param graphName
- * @param nodeId
- * @return
- */
- HgStoreNode apply(String graphName, Long nodeId);
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeSession.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeSession.java
deleted file mode 100644
index c1565da4b..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeSession.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import com.baidu.hugegraph.store.HgStoreSession;
-
-/**
- * @version 0.1.0
- * @author lynn.bond@hotmail.com created on 2021/10/11
- */
-public interface HgStoreNodeSession extends HgStoreSession {
-
- /**
- * Return the name of graph.
- * @return
- */
- String getGraphName();
-
- /**
- * Return an instance of HgStoreNode, which provided the connection of Store-Node machine.
- * @return
- */
- HgStoreNode getStoreNode();
-
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreService.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreService.java
deleted file mode 100644
index 0ce220655..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreService.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-
-public class HgStoreService {
- private static HgStoreService instance=new HgStoreService();
- private HgStoreService(){}
-
- static HgStoreService of(){
- return instance;
- }
-
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreSessionProvider.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreSessionProvider.java
deleted file mode 100644
index 0e8d2c637..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreSessionProvider.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import com.baidu.hugegraph.store.HgSessionProvider;
-import com.baidu.hugegraph.store.HgStoreSession;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/12
- */
-@ThreadSafe
-public class HgStoreSessionProvider implements HgSessionProvider {
- private MultiNodeSessionFactory sessionFactory=MultiNodeSessionFactory.getInstance();
-
- @Override
- public HgStoreSession createSession(String graphName) {
- return this.sessionFactory.createStoreSession(graphName);
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgTkvEntryImpl.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgTkvEntryImpl.java
deleted file mode 100644
index f51d37f86..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgTkvEntryImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgTkvEntry;
-import com.baidu.hugegraph.store.HgTokvEntry;
-
-import java.util.Arrays;
-import java.util.Objects;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/14
- */
-class HgTkvEntryImpl implements HgTkvEntry {
- private String table;
- private byte[] key;
- private byte[] value;
-
- HgTkvEntryImpl(String table, byte[] key, byte[] value) {
- this.table = table;
- this.key = key;
- this.value = value;
- }
-
- @Override
- public String table() {
- return this.table;
- }
-
- @Override
- public byte[] key() {
- return this.key;
- }
-
- @Override
- public byte[] value() {
- return this.value;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- HgTkvEntryImpl that = (HgTkvEntryImpl) o;
- return Objects.equals(table, that.table) && Arrays.equals(key, that.key) && Arrays.equals(value, that.value);
- }
-
- @Override
- public int hashCode() {
- int result = Objects.hash(table);
- result = 31 * result + Arrays.hashCode(key);
- result = 31 * result + Arrays.hashCode(value);
- return result;
- }
-
- @Override
- public String toString() {
- return "HgTkvEntryImpl{" +
- "table='" + table + '\'' +
- ", key=" + Arrays.toString(key) +
- ", value=" + Arrays.toString(value) +
- '}';
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgTokvEntryImpl.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgTokvEntryImpl.java
deleted file mode 100644
index 2fc9255b0..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgTokvEntryImpl.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.baidu.hugegraph.store.client;
-
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgTokvEntry;
-
-import java.util.Arrays;
-import java.util.Objects;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/14
- */
-class HgTokvEntryImpl implements HgTokvEntry {
-
- private String table;
- private HgOwnerKey ownerKey;
- private byte[] value;
-
- HgTokvEntryImpl(String table, HgOwnerKey ownerKey, byte[] value) {
- this.table = table;
- this.ownerKey = ownerKey;
- this.value = value;
- }
-
- @Override
- public String table() {
- return this.table;
- }
-
- @Override
- public HgOwnerKey ownerKey() {
- return this.ownerKey;
- }
-
- @Override
- public byte[] value() {
- return this.value;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- HgTokvEntryImpl that = (HgTokvEntryImpl) o;
- return Objects.equals(table, that.table) && Objects.equals(ownerKey, that.ownerKey) && Arrays.equals(value, that.value);
- }
-
- @Override
- public int hashCode() {
- int result = Objects.hash(table, ownerKey);
- result = 31 * result + Arrays.hashCode(value);
- return result;
- }
-
- @Override
- public String toString() {
- return "HgTokvEntryImpl{" +
- "table='" + table + '\'' +
- ", okv=" + ownerKey +
- ", value=" + Arrays.toString(value) +
- '}';
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcKvEntryImpl.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcKvEntryImpl.java
deleted file mode 100644
index 0bcebc135..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcKvEntryImpl.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.baidu.hugegraph.store.client.grpc;
-
-import com.baidu.hugegraph.store.HgKvEntry;
-
-import java.util.Arrays;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-class GrpcKvEntryImpl implements HgKvEntry {
- private byte[] key;
- private byte[] value;
- private int code;
-
- GrpcKvEntryImpl(byte[] k, byte[] v,int code) {
- this.key = k;
- this.value = v;
- this.code=code;
- }
-
- @Override
- public int code() {
- return code;
- }
-
- @Override
- public byte[] key() {
- return key;
- }
-
- @Override
- public byte[] value() {
- return value;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- GrpcKvEntryImpl hgKvEntry = (GrpcKvEntryImpl) o;
- return Arrays.equals(key, hgKvEntry.key) && Arrays.equals(value, hgKvEntry.value);
- }
-
- @Override
- public int hashCode() {
- int result = Arrays.hashCode(key);
- result = 31 * result + Arrays.hashCode(value);
- return result;
- }
-
- @Override
- public String toString() {
- return "HgKvEntryImpl{" +
- "key=" + Arrays.toString(key) +
- ", value=" + Arrays.toString(value) +
- ", code=" + code +
- '}';
- }
-}
\ No newline at end of file
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeBuilder.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeBuilder.java
deleted file mode 100644
index d534dabba..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeBuilder.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.baidu.hugegraph.store.client.grpc;
-
-import com.baidu.hugegraph.store.client.HgPrivate;
-import com.baidu.hugegraph.store.client.HgStoreNode;
-import com.baidu.hugegraph.store.client.HgStoreNodeBuilder;
-import com.baidu.hugegraph.store.client.HgStoreNodeManager;
-import com.baidu.hugegraph.store.client.util.HgAssert;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/12
- */
-public class GrpcStoreNodeBuilder implements HgStoreNodeBuilder {
-
- private static GrpcStoreSessionClient sessionClient = new GrpcStoreSessionClient();
- private static GrpcStoreStreamClient streamClient = new GrpcStoreStreamClient();
- private static final AtomicLong ids = new AtomicLong(0);
-
- private Long nodeId;
- private String address;
- private HgStoreNodeManager nodeManager;
-
- public GrpcStoreNodeBuilder(HgStoreNodeManager nodeManager, HgPrivate hgPrivate) {
- HgAssert.isArgumentNotNull(hgPrivate, "hgPrivate");
- HgAssert.isArgumentNotNull(nodeManager, "nodeManager");
- this.nodeManager = nodeManager;
- }
-
- @Override
- public GrpcStoreNodeBuilder setAddress(String address) {
- HgAssert.isFalse(HgAssert.isInvalid(address), "The argument is invalid: address.");
- this.address = address;
- return this;
- }
-
- @Override
- public GrpcStoreNodeBuilder setNodeId(Long nodeId) {
- HgAssert.isFalse(nodeId == null, "The argument is invalid: nodeId.");
- this.nodeId = nodeId;
- return this;
- }
-
- @Override
- public HgStoreNode build() {
- // TODO: delete
- if (this.nodeId == null) {
- this.nodeId = ids.addAndGet(-1l);
- }
-
- HgAssert.isFalse(this.nodeId == null, "nodeId can't to be null");
- HgAssert.isFalse(this.address == null, "address can't to be null");
-
- GrpcStoreNodeImpl node = new GrpcStoreNodeImpl(this.nodeManager, sessionClient, streamClient);
- node.setNodeId(this.nodeId);
- node.setAddress(this.address);
-
- return node;
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvCloseableIterator.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvCloseableIterator.java
deleted file mode 100644
index 370603650..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvCloseableIterator.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.baidu.hugegraph.store.client.grpc;
-
-import java.io.Closeable;
-import java.util.Iterator;
-
-/**
- * @author lynn.bond@hotmail.com on 2022/3/16
- */
-public interface KvCloseableIterator extends Iterator, Closeable {
- public void close();
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvListIterator.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvListIterator.java
deleted file mode 100644
index 669ff1803..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvListIterator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.baidu.hugegraph.store.client.grpc;
-
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author lynn.bond@hotmail.com on 2022/4/6
- */
-class KvListIterator implements KvCloseableIterator{
-
- private final Iterator iterator;
-
- KvListIterator(List list){
- this.iterator=list.iterator();
- }
-
- @Override
- public void close() {
- /*Nothing to do.*/
- }
-
- @Override
- public boolean hasNext() {
- return this.iterator.hasNext();
- }
-
- @Override
- public T next() {
- return this.iterator.next();
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/ScanUtil.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/ScanUtil.java
deleted file mode 100644
index 747440159..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/ScanUtil.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.baidu.hugegraph.store.client.grpc;
-
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_BYTES;
-
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
-import com.baidu.hugegraph.store.grpc.common.Header;
-import com.google.protobuf.ByteString;
-
-/**
- * @author zhangyingjie
- * @date 2022/10/8
- **/
-public class ScanUtil {
-
-
- public static Header getHeader(HgStoreNodeSession nodeSession) {
- return Header.newBuilder().setGraph(nodeSession.getGraphName()).build();
- }
-
- public static HgOwnerKey toOk(HgOwnerKey key) {
- return key == null ? HgStoreClientConst.EMPTY_OWNER_KEY : key;
- }
-
- public static ByteString toBs(byte[] bytes) {
- return ByteString.copyFrom((bytes != null) ? bytes : EMPTY_BYTES);
- }
-
- public static ByteString getHgOwnerKey(HgOwnerKey ownerKey) {
- return toBs(toOk(ownerKey).getKey());
- }
-
- public static byte[] getQuery(byte[] query) {
- return query != null ? query : HgStoreClientConst.EMPTY_BYTES;
- }
- public static long getLimit(long limit) {
- return limit <= HgStoreClientConst.NO_LIMIT ? Integer.MAX_VALUE : limit;
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/SeekAbleIterator.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/SeekAbleIterator.java
deleted file mode 100644
index 7bb985f60..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/SeekAbleIterator.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.baidu.hugegraph.store.client.grpc;
-
-import com.baidu.hugegraph.store.HgSeekAble;
-import com.baidu.hugegraph.store.client.util.HgAssert;
-
-import java.util.Iterator;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-
-/**
- * @author lynn.bond@hotmail.com on 2022/3/11
- */
-class SeekAbleIterator implements Iterator, HgSeekAble {
- private Iterator iterator;
- private Consumer seeker;
- private Supplier positioner;
-
- public static SeekAbleIterator of(Iterator iterator,Supplier positioner, Consumer seeker) {
- HgAssert.isArgumentNotNull(iterator, "iterator");
- HgAssert.isArgumentNotNull(positioner, "positioner");
- HgAssert.isArgumentNotNull(seeker, "seeker");
- return new SeekAbleIterator(iterator,positioner, seeker);
- }
-
- private SeekAbleIterator(Iterator iterator, Supplier positioner,Consumer seeker) {
- this.iterator = iterator;
- this.positioner=positioner;
- this.seeker = seeker;
- }
-
- @Override
- public byte[] position() {
- return this.positioner.get();
- }
-
- @Override
- public void seek(byte[] position) {
- this.seeker.accept(position);
- }
-
- @Override
- public boolean hasNext() {
- return this.iterator.hasNext();
- }
-
- @Override
- public E next() {
- return this.iterator.next();
- }
-}
\ No newline at end of file
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/SwitchingExecutor.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/SwitchingExecutor.java
deleted file mode 100644
index b42585634..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/SwitchingExecutor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.baidu.hugegraph.store.client.grpc;
-
-import javax.annotation.concurrent.ThreadSafe;
-import java.util.Optional;
-import java.util.function.Supplier;
-
-/**
- * @author lynn.bond@hotmail.com on 2021/12/1
- */
-@ThreadSafe
-final class SwitchingExecutor {
-
- static SwitchingExecutor of(){
- return new SwitchingExecutor();
- }
-
- private SwitchingExecutor(){}
-
- Optional invoke(Supplier switcher,Supplier trueSupplier,Supplier falseSupplier){
- Optional option = null;
-
- if(switcher.get()){
- option= Optional.of(trueSupplier.get());
- }else{
- option=Optional.of(falseSupplier.get());
- }
- if (option == null) {
- option = Optional.empty();
- }
-
- return option;
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/type/HgNodeStatus.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/type/HgNodeStatus.java
deleted file mode 100644
index 1f68aac83..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/type/HgNodeStatus.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.baidu.hugegraph.store.client.type;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/26
- */
-public enum HgNodeStatus {
-
- UNKNOWN(0, "UNKNOWN"),
- NOT_EXIST(100,"NOT_EXIST"), // Failed to apply for an instance via node-id from NodeManager.
- NOT_ONLINE(105,"NOT_ONLINE"), // Failed to connect to Store-Node at the first time.
- NOT_WORK(110,"NOT_WORK"), // When a Store-Node to be not work anymore.
-
- PARTITION_COMMON_FAULT(200,"PARTITION_COMMON_FAULT"), //
- NOT_PARTITION_LEADER(205,"NOT_PARTITION_LEADER") // When a Store-Node is not a specific partition leader.
-
- ;
-
- private int status;
- private String name;
-
- private HgNodeStatus(int status,String name){
- this.status=status;
- this.name=name;
- }
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/type/HgStoreClientException.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/type/HgStoreClientException.java
deleted file mode 100644
index 5d6545fef..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/type/HgStoreClientException.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baidu.hugegraph.store.client.type;
-
-/**
- * @author lynn.bond@hotmail.com created on 2021/10/27
- */
-public class HgStoreClientException extends RuntimeException {
-
- public static HgStoreClientException of(String msg) {
- return new HgStoreClientException(msg);
- }
- public static HgStoreClientException of(String msg,Throwable cause) {
- return new HgStoreClientException(msg,cause);
- }
-
- public static HgStoreClientException of(Throwable cause) {
- return new HgStoreClientException(cause);
- }
-
- public HgStoreClientException(String msg) {
- super(msg);
- }
-
- public HgStoreClientException(Throwable cause) {
- super(cause);
- }
-
- public HgStoreClientException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/HgStoreClientConst.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/HgStoreClientConst.java
deleted file mode 100644
index fa9ffbc9e..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/HgStoreClientConst.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.baidu.hugegraph.store.client.util;
-
-import com.baidu.hugegraph.store.HgKvStore;
-import com.baidu.hugegraph.store.HgOwnerKey;
-
-import java.util.Collections;
-import java.util.List;
-
-import static com.baidu.hugegraph.store.HgKvStore.*;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-public final class HgStoreClientConst {
- public final static String DEFAULT_NODE_CLUSTER_ID = "default-node-cluster";
-
- public final static String EMPTY_STRING = "";
- public final static String EMPTY_TABLE = "";
- public final static byte[] EMPTY_BYTES = new byte[0];
- public final static byte[] MAX_BYTES=new byte[]{(byte)0b11111111};
- public final static List EMPTY_LIST = Collections.EMPTY_LIST;
-
- public final static byte[] ALL_PARTITION_OWNER = new byte[0]; // means to dispatch to all partitions.
- public final static HgOwnerKey EMPTY_OWNER_KEY = HgOwnerKey.of(EMPTY_BYTES, EMPTY_BYTES);
- public final static HgOwnerKey ALL_PARTITION_OWNER_KEY = HgOwnerKey.of(ALL_PARTITION_OWNER, ALL_PARTITION_OWNER);
-
- //public final static int SCAN_GTE_BEGIN_LT_END = SCAN_GTE_BEGIN | SCAN_LT_END;
- public final static int SCAN_TYPE_RANGE= SCAN_GTE_BEGIN | SCAN_LTE_END;
- public final static int SCAN_TYPE_ANY = SCAN_ANY;
- public final static int NO_LIMIT=0;
-
- public final static int TX_SESSIONS_MAP_CAPACITY=32;
- public static final int NODE_MAX_RETRYING_TIMES=10;
-
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/HgUuid.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/HgUuid.java
deleted file mode 100644
index 93577a94e..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/HgUuid.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.baidu.hugegraph.store.client.util;
-
-import java.nio.ByteBuffer;
-import java.util.UUID;
-
-/**
- * @author lynn.bond@hotmail.com
- */
-public final class HgUuid {
-
- private static String encode(UUID uuid) {
- ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
- bb.putLong(uuid.getMostSignificantBits());
- bb.putLong(uuid.getLeastSignificantBits());
- return Base58.encode(bb.array());
- }
-
- /**
- * Get a UUID in Base58 FORM
- * @return
- */
- public static String newUUID() {
- return encode(UUID.randomUUID());
- }
-
-}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/MetricX.java b/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/MetricX.java
deleted file mode 100644
index 2e897dd41..000000000
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/util/MetricX.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.baidu.hugegraph.store.client.util;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @author lynn.bond@hotmail.com on 2022/1/29
- */
-public class MetricX {
- public static AtomicLong iteratorSum=new AtomicLong();
- public static AtomicLong iteratorCount=new AtomicLong();
- public static AtomicLong iteratorMax=new AtomicLong();
-
- public AtomicLong failureCount=new AtomicLong();
-
- private long start;
- private long end;
-
- public static MetricX ofStart(){
- return new MetricX(System.currentTimeMillis());
- }
-
- private MetricX(long start){
- this.start=start;
- };
-
- public long start(){
- return this.start=System.currentTimeMillis();
- }
-
- public long end(){
- return this.end=System.currentTimeMillis();
- }
-
- public long past(){
- return this.end-this.start;
- }
-
- public static void plusIteratorWait(long nanoSeconds){
- iteratorSum.addAndGet(nanoSeconds);
- iteratorCount.getAndIncrement();
- if(iteratorMax.get() extends Iterator, HgSeekAble, Closeable {
+
+ byte[] key();
+
+ byte[] value();
+
+ void close();
+
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvOrderedIterator.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvOrderedIterator.java
new file mode 100644
index 000000000..1e315d581
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvOrderedIterator.java
@@ -0,0 +1,25 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2022/03/10
+ */
+public interface HgKvOrderedIterator extends HgKvIterator, Comparable {
+ long getSequence();
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvPagingIterator.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvPagingIterator.java
new file mode 100644
index 000000000..abf50b0d9
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvPagingIterator.java
@@ -0,0 +1,24 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/24
+ */
+public interface HgKvPagingIterator extends HgKvIterator, HgPageSize {
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvStore.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvStore.java
similarity index 64%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvStore.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvStore.java
index b5b5954aa..e2c9dc91b 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgKvStore.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvStore.java
@@ -1,12 +1,28 @@
-package com.baidu.hugegraph.store;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.client.grpc.KvCloseableIterator;
-import com.baidu.hugegraph.store.grpc.common.Kv;
-import com.baidu.hugegraph.store.grpc.stream.ScanStreamReq;
+package org.apache.hugegraph.store;
-import java.util.Iterator;
import java.util.List;
+import org.apache.hugegraph.store.client.grpc.KvCloseableIterator;
+
+import com.baidu.hugegraph.store.grpc.stream.ScanStreamReq;
+
/**
* @author lynn.bond@hotmail.com
* @version 0.2.0
@@ -31,7 +47,8 @@ public interface HgKvStore {
* 该版本被store内部使用。向分区写入数据,
* partitionId与key.keyCode必须与pd存储的分区信息保持一致。
*/
- boolean directPut(String table, int partitionId, HgOwnerKey key, byte[] value);
+ boolean directPut(String table, int partitionId, HgOwnerKey key, byte[] value);
+
byte[] get(String table, HgOwnerKey ownerKey);
boolean clean(int partId);
@@ -45,6 +62,7 @@ public interface HgKvStore {
boolean deleteRange(String table, HgOwnerKey start, HgOwnerKey end);
boolean merge(String table, HgOwnerKey key, byte[] value);
+
@Deprecated
List batchGetOwner(String table, List keyList);
@@ -60,17 +78,22 @@ public interface HgKvStore {
HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix, long limit);
- HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix, long limit, byte[] query);
+ HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix, long limit,
+ byte[] query);
HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey);
- HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey, long limit);
+ HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey,
+ long limit);
- HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey, long limit, byte[] query);
+ HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey,
+ long limit, byte[] query);
- HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey, long limit, int scanType, byte[] query);
+ HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey,
+ long limit, int scanType, byte[] query);
- HgKvIterator scanIterator(String table, int codeFrom, int codeTo, int scanType, byte[] query);
+ HgKvIterator scanIterator(String table, int codeFrom, int codeTo, int scanType,
+ byte[] query);
// HgKvIterator scanIterator(ScanStreamReq scanReq);
@@ -89,10 +112,13 @@ public interface HgKvStore {
boolean dropTable(String table);
boolean deleteGraph(String graph);
+
List> scanBatch(HgScanQuery scanQuery);
KvCloseableIterator> scanBatch2(HgScanQuery scanQuery);
- KvCloseableIterator> scanBatch3(HgScanQuery scanQuery, KvCloseableIterator iterator);
+
+ KvCloseableIterator> scanBatch3(HgScanQuery scanQuery,
+ KvCloseableIterator iterator);
HgKvIterator batchPrefix(String table, List prefixList);
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgOwnerKey.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgOwnerKey.java
similarity index 56%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/HgOwnerKey.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/HgOwnerKey.java
index db60b6c28..54495b981 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgOwnerKey.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgOwnerKey.java
@@ -1,18 +1,32 @@
-package com.baidu.hugegraph.store;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.client.util.HgStoreClientUtil;
+package org.apache.hugegraph.store;
+
+import static org.apache.hugegraph.store.client.util.HgStoreClientConst.EMPTY_BYTES;
+import static org.apache.hugegraph.store.client.util.HgStoreClientConst.EMPTY_OWNER_KEY;
import java.io.Serializable;
import java.util.Arrays;
-import static com.baidu.hugegraph.store.client.util.HgAssert.isArgumentNotNull;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_BYTES;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_OWNER_KEY;
+import org.apache.hugegraph.store.client.util.HgStoreClientUtil;
/**
* @author lynn.bond@hotmail.com created on 2021/10/14
- * @version 1.1.0 add argument assertion.
- * @version 1.2.0 add newEmpty
* @version 1.3.0 add canceled assert
*/
public class HgOwnerKey implements Serializable {
@@ -21,32 +35,34 @@ public class HgOwnerKey implements Serializable {
private byte[] key;
private int serialNo; //顺序号,用于批量查询保证返回结果的顺序性
- public static HgOwnerKey emptyOf(){
+ public static HgOwnerKey emptyOf() {
return EMPTY_OWNER_KEY;
}
- public static HgOwnerKey newEmpty(){
- return HgOwnerKey.of(EMPTY_BYTES,EMPTY_BYTES);
+ public static HgOwnerKey newEmpty() {
+ return HgOwnerKey.of(EMPTY_BYTES, EMPTY_BYTES);
}
- public static HgOwnerKey ownerOf(byte[] owner){
- return new HgOwnerKey(owner,EMPTY_BYTES);
+ public static HgOwnerKey ownerOf(byte[] owner) {
+ return new HgOwnerKey(owner, EMPTY_BYTES);
}
- public static HgOwnerKey codeOf(int code){
+
+ public static HgOwnerKey codeOf(int code) {
return HgOwnerKey.of(EMPTY_BYTES, EMPTY_BYTES).setKeyCode(code);
}
- public static HgOwnerKey of(byte[] owner, byte[] key){
- return new HgOwnerKey(owner,key);
+ public static HgOwnerKey of(byte[] owner, byte[] key) {
+ return new HgOwnerKey(owner, key);
}
- public static HgOwnerKey of(int keyCode, byte[] key){
+
+ public static HgOwnerKey of(int keyCode, byte[] key) {
return new HgOwnerKey(keyCode, key);
}
/**
- * @see HgOwnerKey:of(byte[] owner, byte[] key)
* @param owner
* @param key
+ * @see HgOwnerKey:of(byte[] owner, byte[] key)
*/
@Deprecated
public HgOwnerKey(byte[] owner, byte[] key) {
@@ -92,14 +108,15 @@ public class HgOwnerKey implements Serializable {
return this;
}
- public HgOwnerKey setSerialNo(int serialNo){
+ public HgOwnerKey setSerialNo(int serialNo) {
this.serialNo = serialNo;
return this;
}
- public int getSerialNo(){
+ public int getSerialNo() {
return this.serialNo;
}
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -118,10 +135,10 @@ public class HgOwnerKey implements Serializable {
@Override
public String toString() {
return "HgOwnerKey{" +
- "owner=" + Arrays.toString(owner) +
- ", key=" + Arrays.toString(key) +
- ", code=" + keyCode +
- '}';
+ "owner=" + Arrays.toString(owner) +
+ ", key=" + Arrays.toString(key) +
+ ", code=" + keyCode +
+ '}';
}
}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgPageSize.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgPageSize.java
new file mode 100644
index 000000000..aa01b7710
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgPageSize.java
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+/**
+ * Return the amount of records returned by one query in pageable-query.
+ *
+ * @author lynn.bond@hotmail.com created on 2021/10/24
+ */
+public interface HgPageSize {
+ long getPageSize();
+
+ default boolean isPageEmpty() {
+ return false;
+ }
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgPrivate.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgPrivate.java
new file mode 100644
index 000000000..8da436912
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgPrivate.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+/**
+ * @author lynn.bond@hotmail.com
+ */
+public final class HgPrivate {
+
+ private static final HgPrivate instance = new HgPrivate();
+
+ private HgPrivate() {
+ }
+
+ static HgPrivate of() {
+ return instance;
+ }
+
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgScanQuery.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgScanQuery.java
similarity index 81%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/HgScanQuery.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/HgScanQuery.java
index da1aed0c6..f497739b7 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgScanQuery.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgScanQuery.java
@@ -1,13 +1,29 @@
-package com.baidu.hugegraph.store;
-
-import com.baidu.hugegraph.store.client.util.HgAssert;
-import com.baidu.hugegraph.store.grpc.common.ScanOrderType;
+/*
+ * 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 org.apache.hugegraph.store;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import org.apache.hugegraph.store.client.util.HgAssert;
+import org.apache.hugegraph.store.grpc.common.ScanOrderType;
+
/**
* @author lynn.bond@hotmail.com on 2022/3/4
* @version 0.5.0
@@ -34,6 +50,7 @@ public interface HgScanQuery {
long getSkipDegree();
int getScanType();
+
ScanOrderType getOrderType();
boolean isOnlyKey();
@@ -41,11 +58,15 @@ public interface HgScanQuery {
byte[] getQuery();
enum ScanMethod {
- ALL, PREFIX, RANGE
+ ALL,
+ PREFIX,
+ RANGE
}
enum SortType {
- UNSORTED, SORT_BY_EDGE, SORT_BY_VERTEX
+ UNSORTED,
+ SORT_BY_EDGE,
+ SORT_BY_VERTEX
}
@@ -63,7 +84,8 @@ public interface HgScanQuery {
return ScanBuilder.prefixOf(table, prefixList).build();
}
- static HgScanQuery prefixOf(String table, List prefixList, ScanOrderType orderType) {
+ static HgScanQuery prefixOf(String table, List prefixList,
+ ScanOrderType orderType) {
return ScanBuilder.prefixOf(table, prefixList).setOrderType(orderType).build();
}
@@ -71,7 +93,8 @@ public interface HgScanQuery {
return ScanBuilder.prefixIteratorOf(table, prefixItr).build();
}
- static HgScanQuery prefixIteratorOf(String table, Iterator prefixItr, ScanOrderType orderType) {
+ static HgScanQuery prefixIteratorOf(String table, Iterator prefixItr,
+ ScanOrderType orderType) {
return ScanBuilder.prefixIteratorOf(table, prefixItr).setOrderType(orderType).build();
}
@@ -93,7 +116,8 @@ public interface HgScanQuery {
private List endList;
private Iterator prefixItr;
- public static ScanBuilder rangeOf(String table, List startList, List endList) {
+ public static ScanBuilder rangeOf(String table, List startList,
+ List endList) {
HgAssert.isArgumentValid(table, "table");
HgAssert.isArgumentValid(startList, "startList");
HgAssert.isArgumentValid(endList, "endList");
@@ -158,7 +182,7 @@ public interface HgScanQuery {
return this;
}
- public ScanBuilder setOrderType(ScanOrderType orderType){
+ public ScanBuilder setOrderType(ScanOrderType orderType) {
this.orderType = orderType;
return this;
}
@@ -167,12 +191,13 @@ public interface HgScanQuery {
this.query = query;
return this;
}
- public ScanBuilder setSkipDegree(long skipDegree){
+
+ public ScanBuilder setSkipDegree(long skipDegree) {
this.skipDegree = skipDegree;
return this;
}
- public ScanBuilder setOnlyKey(boolean onlyKey){
+ public ScanBuilder setOnlyKey(boolean onlyKey) {
this.onlyKey = onlyKey;
return this;
}
@@ -287,11 +312,13 @@ public interface HgScanQuery {
sb.append(", orderType=").append(getOrderType());
sb.append(", onlyKey=").append(isOnlyKey());
sb.append(", query=");
- if (query == null) sb.append("null");
- else {
+ if (query == null) {
+ sb.append("null");
+ } else {
sb.append('[');
- for (int i = 0; i < query.length; ++i)
+ for (int i = 0; i < query.length; ++i) {
sb.append(i == 0 ? "" : ", ").append(query[i]);
+ }
sb.append(']');
}
sb.append('}');
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSeekAble.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSeekAble.java
new file mode 100644
index 000000000..32114fd9e
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSeekAble.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2022/03/11
+ */
+public interface HgSeekAble {
+ byte[] position();
+
+ void seek(byte[] position);
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSessionManager.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSessionManager.java
new file mode 100644
index 000000000..ba1fccdce
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSessionManager.java
@@ -0,0 +1,57 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.apache.hugegraph.store.client.HgStoreSessionProvider;
+
+/**
+ * Maintain HgStoreSession instances.
+ * // TODO: Holding more than one HgSessionManager is available,if you want to connect multi
+ * HgStore-clusters.
+ *
+ * @author lynn.bond@hotmail.com
+ */
+
+@ThreadSafe
+public final class HgSessionManager {
+ private final HgSessionProvider sessionProvider;
+ private final static HgSessionManager INSTANCE = new HgSessionManager();
+
+ private HgSessionManager() {
+ // TODO: constructed by SPI
+ this.sessionProvider = new HgStoreSessionProvider();
+ }
+
+
+ public static HgSessionManager getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Retrieve or create a HgStoreSession.
+ *
+ * @param graphName
+ * @return
+ */
+ public HgStoreSession openSession(String graphName) {
+ return this.sessionProvider.createSession(graphName);
+ }
+
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSessionProvider.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSessionProvider.java
new file mode 100644
index 000000000..ccdb20066
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSessionProvider.java
@@ -0,0 +1,28 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/12
+ */
+@ThreadSafe
+public interface HgSessionProvider {
+ HgStoreSession createSession(String graphName);
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgStoreClient.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgStoreClient.java
similarity index 57%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/HgStoreClient.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/HgStoreClient.java
index 131a6bac1..f34909cb3 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/HgStoreClient.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgStoreClient.java
@@ -1,23 +1,41 @@
-package com.baidu.hugegraph.store;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.pd.client.PDClient;
-import com.baidu.hugegraph.pd.client.PDConfig;
-import com.baidu.hugegraph.store.client.HgStoreNodeManager;
-import com.baidu.hugegraph.store.client.HgStoreNodePartitionerImpl;
-import com.baidu.hugegraph.store.client.HgStoreSessionProvider;
+package org.apache.hugegraph.store;
import javax.annotation.concurrent.ThreadSafe;
+import org.apache.hugegraph.pd.client.PDClient;
+import org.apache.hugegraph.pd.client.PDConfig;
+import org.apache.hugegraph.store.client.HgStoreNodeManager;
+import org.apache.hugegraph.store.client.HgStoreNodePartitionerImpl;
+import org.apache.hugegraph.store.client.HgStoreSessionProvider;
+
/**
* Maintain HgStoreSession instances.
- * // TODO: Holding more than one HgSessionManager is available,if you want to connect multi HgStore-clusters.
+ * // TODO: Holding more than one HgSessionManager is available,if you want to connect multi
+ * HgStore-clusters.
*
* @author lynn.bond@hotmail.com
*/
@ThreadSafe
public final class HgStoreClient {
- private HgSessionProvider sessionProvider;
+ private final HgSessionProvider sessionProvider;
private PDClient pdClient;
public HgStoreClient() {
@@ -29,10 +47,12 @@ public final class HgStoreClient {
pdClient = PDClient.create(config);
setPdClient(pdClient);
}
+
public HgStoreClient(PDClient pdClient) {
this.sessionProvider = new HgStoreSessionProvider();
setPdClient(pdClient);
}
+
public static HgStoreClient create(PDConfig config) {
return new HgStoreClient(config);
}
@@ -41,7 +61,7 @@ public final class HgStoreClient {
return new HgStoreClient(pdClient);
}
- public static HgStoreClient create(){
+ public static HgStoreClient create() {
return new HgStoreClient();
}
@@ -71,7 +91,7 @@ public final class HgStoreClient {
return this.sessionProvider.createSession(graphName);
}
- public PDClient getPdClient(){
+ public PDClient getPdClient() {
return pdClient;
}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgStoreSession.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgStoreSession.java
new file mode 100644
index 000000000..860d58f8c
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgStoreSession.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+import org.apache.hugegraph.store.client.type.HgStoreClientException;
+
+/**
+ * @author lynn.bond@hotmail.com
+ */
+public interface HgStoreSession extends HgKvStore {
+
+ void beginTx();
+
+ /**
+ * @throws IllegalStateException when the tx hasn't been beginning.
+ * @throws HgStoreClientException when failed to commit .
+ */
+ void commit();
+
+ /**
+ * @throws IllegalStateException when the tx hasn't been beginning.
+ * @throws HgStoreClientException when failed to rollback.
+ */
+ void rollback();
+
+ boolean isTx();
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTkvEntry.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTkvEntry.java
new file mode 100644
index 000000000..c13d529ab
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTkvEntry.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+/**
+ * @author lynn.bond@hotmail.com
+ */
+public interface HgTkvEntry {
+ String table();
+
+ byte[] key();
+
+ byte[] value();
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTokvEntry.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTokvEntry.java
new file mode 100644
index 000000000..6b51bfdbf
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTokvEntry.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.apache.hugegraph.store;
+
+/**
+ * @author lynn.bond@hotmail.com
+ */
+public interface HgTokvEntry {
+ String table();
+
+ HgOwnerKey ownerKey();
+
+ byte[] value();
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgNodePartition.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartition.java
similarity index 52%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgNodePartition.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartition.java
index 8eff82d83..0259d5654 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgNodePartition.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartition.java
@@ -1,4 +1,21 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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 org.apache.hugegraph.store.client;
import java.util.Objects;
@@ -8,23 +25,25 @@ import java.util.Objects;
* @author lynn.bond@hotmail.com created on 2021/10/26
*/
public final class HgNodePartition {
- private Long nodeId;
+ private final Long nodeId;
//当前key的hashcode
- private Integer keyCode;
+ private final Integer keyCode;
//分区的开始结束范围
- private Integer startKey;
- private Integer endKey;
+ private final Integer startKey;
+ private final Integer endKey;
private int hash = -1;
public static HgNodePartition of(Long nodeId, Integer keyCode) {
return new HgNodePartition(nodeId, keyCode);
}
- public static HgNodePartition of(Long nodeId, Integer keyCode, Integer startKey, Integer endKey) {
+
+ public static HgNodePartition of(Long nodeId, Integer keyCode, Integer startKey,
+ Integer endKey) {
return new HgNodePartition(nodeId, keyCode, startKey, endKey);
}
- HgNodePartition(Long nodeId, Integer keyCode) {
+ HgNodePartition(Long nodeId, Integer keyCode) {
this.nodeId = nodeId;
this.keyCode = keyCode;
this.startKey = this.endKey = keyCode;
@@ -36,6 +55,7 @@ public final class HgNodePartition {
this.startKey = startKey;
this.endKey = endKey;
}
+
public Long getNodeId() {
return nodeId;
}
@@ -44,13 +64,14 @@ public final class HgNodePartition {
return keyCode;
}
- public Integer getStartKey(){
+ public Integer getStartKey() {
return startKey;
}
- public Integer getEndKey(){
+ public Integer getEndKey() {
return endKey;
}
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -61,15 +82,15 @@ public final class HgNodePartition {
@Override
public int hashCode() {
- if(this.hash==-1)this.hash=Objects.hash(nodeId, keyCode);
+ if (this.hash == -1) this.hash = Objects.hash(nodeId, keyCode);
return this.hash;
}
@Override
public String toString() {
return "HgNodePartition{" +
- "nodeId=" + nodeId +
- ", partitionId=" + keyCode +
- '}';
+ "nodeId=" + nodeId +
+ ", partitionId=" + keyCode +
+ '}';
}
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgNodePartitionerBuilder.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartitionerBuilder.java
similarity index 50%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgNodePartitionerBuilder.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartitionerBuilder.java
index e706ad1ce..bb4497ab7 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgNodePartitionerBuilder.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartitionerBuilder.java
@@ -1,10 +1,29 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import static org.apache.hugegraph.store.client.util.HgAssert.isFalse;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import javax.annotation.concurrent.NotThreadSafe;
-import java.net.CookieHandler;
-import java.util.*;
-
-import static com.baidu.hugegraph.store.client.util.HgAssert.isFalse;
/**
* @author lynn.bond@hotmail.com created on 2021/10/26
@@ -14,8 +33,8 @@ import static com.baidu.hugegraph.store.client.util.HgAssert.isFalse;
public final class HgNodePartitionerBuilder {
private Set partitions = null;
+
/**
- *
* @param nodeId
* @param keyCode
* @return
@@ -26,8 +45,8 @@ public final class HgNodePartitionerBuilder {
isFalse(nodeId == null, "The argument is invalid: nodeId");
isFalse(keyCode == null, "The argument is invalid: keyCode");
- if(this.partitions==null){
- this.partitions=new HashSet<>(16,1);
+ if (this.partitions == null) {
+ this.partitions = new HashSet<>(16, 1);
}
this.partitions.add(HgNodePartition.of(nodeId, keyCode));
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgPrivate.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgPrivate.java
new file mode 100644
index 000000000..15b4a26f8
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgPrivate.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/26
+ */
+public class HgPrivate {
+ private final static HgPrivate instance = new HgPrivate();
+
+ static HgPrivate getInstance() {
+ return instance;
+ }
+
+ private HgPrivate() {
+
+ }
+
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNode.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNode.java
new file mode 100644
index 000000000..e75a99371
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNode.java
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import org.apache.hugegraph.store.HgStoreSession;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/11
+ * @version 0.2.0
+ */
+public interface HgStoreNode {
+
+ /**
+ * Return boolean value of being online or not
+ *
+ * @return
+ */
+ default boolean isHealthy() {
+ return true;
+ }
+
+ /**
+ * Return the unique ID of store-node.
+ *
+ * @return
+ */
+ Long getNodeId();
+
+ /**
+ * A string value concatenated by host and port: "host:port"
+ *
+ * @return
+ */
+ String getAddress();
+
+ /**
+ * Return a new HgStoreSession instance, that is not Thread safe.
+ * Return null when the node is not in charge of the graph that was passed from argument.
+ *
+ * @return
+ */
+ HgStoreSession openSession(String graphName);
+
+}
\ No newline at end of file
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeBuilder.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeBuilder.java
new file mode 100644
index 000000000..377ecf469
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeBuilder.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/11
+ */
+public interface HgStoreNodeBuilder {
+
+ HgStoreNodeBuilder setNodeId(Long nodeId);
+
+ HgStoreNodeBuilder setAddress(String address);
+
+ /**
+ * To build a HgStoreNode instance.
+ *
+ * @return
+ */
+ HgStoreNode build();
+
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeCandidates.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeCandidates.java
new file mode 100644
index 000000000..b69f53035
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeCandidates.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import java.util.List;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/12
+ */
+public final class HgStoreNodeCandidates {
+
+ List nodeList;
+
+ HgStoreNodeCandidates(List nodeList) {
+ this.nodeList = nodeList;
+ }
+
+ public int size() {
+ return this.nodeList.size();
+ }
+
+ public HgStoreNode getNode(int index) {
+ return this.nodeList.get(index);
+ }
+
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeManager.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeManager.java
similarity index 80%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeManager.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeManager.java
index 6600f271b..6f3d283a0 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodeManager.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeManager.java
@@ -1,15 +1,38 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.client.grpc.GrpcStoreNodeBuilder;
-import com.baidu.hugegraph.store.client.type.HgNodeStatus;
-import com.baidu.hugegraph.store.client.type.HgStoreClientException;
-import com.baidu.hugegraph.store.client.util.HgAssert;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
-import lombok.extern.slf4j.Slf4j;
+package org.apache.hugegraph.store.client;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.concurrent.ThreadSafe;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.hugegraph.store.client.grpc.GrpcStoreNodeBuilder;
+import org.apache.hugegraph.store.client.type.HgNodeStatus;
+import org.apache.hugegraph.store.client.type.HgStoreClientException;
+import org.apache.hugegraph.store.client.util.HgAssert;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
+
+import lombok.extern.slf4j.Slf4j;
/**
* // TODO: Mapping to Store-Node-Cluster, one to one.
@@ -98,7 +121,7 @@ public final class HgStoreNodeManager {
if (node == null) {
log.warn("Failed to apply a HgStoreNode instance form the nodeProvider [ "
- + this.nodeProvider.getClass().getName() + " ].");
+ + this.nodeProvider.getClass().getName() + " ].");
notifying(graphName, nodeId, HgNodeStatus.NOT_EXIST);
return null;
}
@@ -113,7 +136,8 @@ public final class HgStoreNodeManager {
try {
this.nodeNotifier.notice(graphName, HgStoreNotice.of(nodeId, status));
} catch (Throwable t) {
- log.error("Failed to invoke " + this.nodeNotifier.getClass().getSimpleName() + ":notice(" + nodeId + "," + status + ")", t);
+ log.error("Failed to invoke " + this.nodeNotifier.getClass().getSimpleName() +
+ ":notice(" + nodeId + "," + status + ")", t);
}
}
}
@@ -132,7 +156,9 @@ public final class HgStoreNodeManager {
try {
return this.nodeNotifier.notice(graphName, notice);
} catch (Throwable t) {
- String msg = "Failed to invoke " + this.nodeNotifier.getClass().getSimpleName() + ", notice: [ " + notice + " ]";
+ String msg =
+ "Failed to invoke " + this.nodeNotifier.getClass().getSimpleName() +
+ ", notice: [ " + notice + " ]";
log.error(msg, t);
throw new HgStoreClientException(msg);
}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeNotifier.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeNotifier.java
new file mode 100644
index 000000000..cae2b49e1
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeNotifier.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/12
+ * @version 1.0.0
+ */
+public interface HgStoreNodeNotifier {
+
+ /**
+ * It will be invoked by NodeManager, when some exception or issue was happened.
+ *
+ * @param graphName
+ * @param storeNotice
+ * @return return 0 please, for no matter what.
+ */
+ int notice(String graphName, HgStoreNotice storeNotice);
+
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodePartitioner.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodePartitioner.java
similarity index 53%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodePartitioner.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodePartitioner.java
index 9979a4fd0..a6c7393b6 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodePartitioner.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodePartitioner.java
@@ -1,7 +1,23 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
+package org.apache.hugegraph.store.client;
+
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
/**
* @author lynn.bond@hotmail.com created on 2021/10/12
@@ -12,7 +28,8 @@ public interface HgStoreNodePartitioner {
/**
* The partition algorithm implementation, that specialized by user.
*
- * @param builder The builder of HgNodePartitionerBuilder. It's supposed to be invoked directly by user.
+ * @param builder The builder of HgNodePartitionerBuilder. It's supposed to be invoked
+ * directly by user.
* e.g. builder.add(nodeId,address,partitionId);
* @param graphName
* @param startKey
@@ -23,7 +40,8 @@ public interface HgStoreNodePartitioner {
* 10: The partitioner is not work.
*
*/
- int partition(HgNodePartitionerBuilder builder, String graphName, byte[] startKey, byte[] endKey);
+ int partition(HgNodePartitionerBuilder builder, String graphName, byte[] startKey,
+ byte[] endKey);
/**
* @param builder
@@ -32,7 +50,8 @@ public interface HgStoreNodePartitioner {
* @param endCode hash code
* @return
*/
- default int partition(HgNodePartitionerBuilder builder, String graphName, int startCode, int endCode) {
+ default int partition(HgNodePartitionerBuilder builder, String graphName, int startCode,
+ int endCode) {
return this.partition(builder, graphName
, HgStoreClientConst.ALL_PARTITION_OWNER
, HgStoreClientConst.ALL_PARTITION_OWNER);
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodePartitionerImpl.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodePartitionerImpl.java
similarity index 75%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodePartitionerImpl.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodePartitionerImpl.java
index 1aecdabf4..b57b1b12d 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNodePartitionerImpl.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodePartitionerImpl.java
@@ -1,22 +1,41 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.hugegraph.store.client.type.HgNodeStatus;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
import com.baidu.hugegraph.pd.client.PDClient;
import com.baidu.hugegraph.pd.common.KVPair;
import com.baidu.hugegraph.pd.common.PDException;
import com.baidu.hugegraph.pd.common.PartitionUtils;
import com.baidu.hugegraph.pd.grpc.Metapb;
-import com.baidu.hugegraph.store.client.type.HgNodeStatus;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
-import lombok.extern.slf4j.Slf4j;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
+import lombok.extern.slf4j.Slf4j;
@Slf4j
public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
- HgStoreNodeProvider,
- HgStoreNodeNotifier {
+ HgStoreNodeProvider,
+ HgStoreNodeNotifier {
private PDClient pdClient;
private HgStoreNodeManager nodeManager;
@@ -44,15 +63,17 @@ public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
}
} else if (endKey == HgStoreClientConst.EMPTY_BYTES
- || startKey == endKey || Arrays.equals(startKey, endKey)) {
+ || startKey == endKey || Arrays.equals(startKey, endKey)) {
KVPair partShard =
pdClient.getPartition(graphName, startKey);
Metapb.Shard leader = partShard.getValue();
partitions = new HashSet<>();
partitions.add(HgNodePartition.of(leader.getStoreId(),
- pdClient.keyToCode(graphName, startKey)));
+ pdClient.keyToCode(graphName, startKey)));
} else {
- log.warn("StartOwnerkey is not equal to endOwnerkey, which is meaningless!!, It is a error!!");
+ log.warn(
+ "StartOwnerkey is not equal to endOwnerkey, which is meaningless!!, It is" +
+ " a error!!");
List stores = pdClient.getActiveStores(graphName);
partitions = new HashSet<>(stores.size());
for (Metapb.Store store : stores) {
@@ -74,14 +95,15 @@ public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
HashSet partitions = new HashSet<>();
Metapb.Partition partition = null;
while ((partition == null || partition.getEndKey() < endKey)
- && startKey < PartitionUtils.MAX_VALUE) {
+ && startKey < PartitionUtils.MAX_VALUE) {
KVPair partShard =
pdClient.getPartitionByCode(graphName, startKey);
if (partShard != null) {
partition = partShard.getKey();
Metapb.Shard leader = partShard.getValue();
partitions.add(HgNodePartition.of(leader.getStoreId(), startKey,
- (int) partition.getStartKey(), (int) partition.getEndKey()));
+ (int) partition.getStartKey(),
+ (int) partition.getEndKey()));
startKey = (int) partition.getEndKey();
} else {
break;
@@ -108,7 +130,8 @@ public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
if (partShard != null) {
partition = partShard.getKey();
Metapb.Shard leader = partShard.getValue();
- partitions.add(HgNodePartition.of(leader.getStoreId(), (int) partition.getStartKey()));
+ partitions.add(
+ HgNodePartition.of(leader.getStoreId(), (int) partition.getStartKey()));
}
builder.setPartitions(partitions);
} catch (PDException e) {
@@ -117,6 +140,7 @@ public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
}
return 0;
}
+
/**
* 查询hgstore信息
*
@@ -127,7 +151,7 @@ public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
try {
Metapb.Store store = pdClient.getStore(nodeId);
return nodeManager.getNodeBuilder().setNodeId(store.getId())
- .setAddress(store.getAddress()).build();
+ .setAddress(store.getAddress()).build();
} catch (PDException e) {
throw new RuntimeException(e.getMessage(), e);
}
@@ -143,7 +167,7 @@ public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
storeNotice.getPartitionLeaders().forEach((partId, leader) -> {
pdClient.updatePartitionLeader(graphName, partId, leader);
log.warn("updatePartitionLeader:{}-{}-{}",
- graphName, partId, leader);
+ graphName, partId, leader);
});
}
if (storeNotice.getPartitionIds() != null) {
@@ -153,7 +177,7 @@ public class HgStoreNodePartitionerImpl implements HgStoreNodePartitioner,
}
if (!storeNotice.getNodeStatus().equals(
HgNodeStatus.PARTITION_COMMON_FAULT)
- && !storeNotice.getNodeStatus().equals(
+ && !storeNotice.getNodeStatus().equals(
HgNodeStatus.NOT_PARTITION_LEADER)) {
pdClient.invalidPartitionCache();
log.warn("invalidPartitionCache:{} ", storeNotice.getNodeStatus());
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeProvider.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeProvider.java
new file mode 100644
index 000000000..7fc1ef86a
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeProvider.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/27
+ */
+public interface HgStoreNodeProvider {
+
+ /**
+ * Applying a new HgStoreNode instance
+ *
+ * @param graphName
+ * @param nodeId
+ * @return
+ */
+ HgStoreNode apply(String graphName, Long nodeId);
+
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeSession.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeSession.java
new file mode 100644
index 000000000..fcc086db6
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeSession.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import org.apache.hugegraph.store.HgStoreSession;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/11
+ * @version 0.1.0
+ */
+public interface HgStoreNodeSession extends HgStoreSession {
+
+ /**
+ * Return the name of graph.
+ *
+ * @return
+ */
+ String getGraphName();
+
+ /**
+ * Return an instance of HgStoreNode, which provided the connection of Store-Node machine.
+ *
+ * @return
+ */
+ HgStoreNode getStoreNode();
+
+
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNotice.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNotice.java
similarity index 57%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNotice.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNotice.java
index 627b8a872..20326180e 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/HgStoreNotice.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNotice.java
@@ -1,21 +1,38 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.client.type.HgNodeStatus;
-import com.baidu.hugegraph.store.client.util.HgAssert;
+package org.apache.hugegraph.store.client;
-import javax.annotation.concurrent.NotThreadSafe;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
+
+import javax.annotation.concurrent.NotThreadSafe;
+
+import org.apache.hugegraph.store.client.type.HgNodeStatus;
+import org.apache.hugegraph.store.client.util.HgAssert;
/**
* @author lynn.bond@hotmail.com on 2021/11/16
*/
@NotThreadSafe
public class HgStoreNotice {
- private Long nodeId;
- private HgNodeStatus nodeStatus;
- private String message;
+ private final Long nodeId;
+ private final HgNodeStatus nodeStatus;
+ private final String message;
private Map partitionLeaders;
private List partitionIds;
@@ -72,11 +89,11 @@ public class HgStoreNotice {
@Override
public String toString() {
return "HgStoreNotice{" +
- "nodeId=" + nodeId +
- ", nodeStatus=" + nodeStatus +
- ", message='" + message + '\'' +
- ", partitionLeaders=" + partitionLeaders +
- ", partitionIds=" + partitionIds +
- '}';
+ "nodeId=" + nodeId +
+ ", nodeStatus=" + nodeStatus +
+ ", message='" + message + '\'' +
+ ", partitionLeaders=" + partitionLeaders +
+ ", partitionIds=" + partitionIds +
+ '}';
}
}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreService.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreService.java
new file mode 100644
index 000000000..02b2d2931
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreService.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+
+public class HgStoreService {
+ private static final HgStoreService instance = new HgStoreService();
+
+ private HgStoreService() {
+ }
+
+ static HgStoreService of() {
+ return instance;
+ }
+
+
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreSessionProvider.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreSessionProvider.java
new file mode 100644
index 000000000..2b85848db
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreSessionProvider.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.apache.hugegraph.store.HgSessionProvider;
+import org.apache.hugegraph.store.HgStoreSession;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/12
+ */
+@ThreadSafe
+public class HgStoreSessionProvider implements HgSessionProvider {
+ private final MultiNodeSessionFactory sessionFactory = MultiNodeSessionFactory.getInstance();
+
+ @Override
+ public HgStoreSession createSession(String graphName) {
+ return this.sessionFactory.createStoreSession(graphName);
+ }
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgTkvEntryImpl.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgTkvEntryImpl.java
new file mode 100644
index 000000000..b7c11c58e
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgTkvEntryImpl.java
@@ -0,0 +1,79 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.apache.hugegraph.store.HgTkvEntry;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/14
+ */
+class HgTkvEntryImpl implements HgTkvEntry {
+ private final String table;
+ private final byte[] key;
+ private final byte[] value;
+
+ HgTkvEntryImpl(String table, byte[] key, byte[] value) {
+ this.table = table;
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public String table() {
+ return this.table;
+ }
+
+ @Override
+ public byte[] key() {
+ return this.key;
+ }
+
+ @Override
+ public byte[] value() {
+ return this.value;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ HgTkvEntryImpl that = (HgTkvEntryImpl) o;
+ return Objects.equals(table, that.table) && Arrays.equals(key, that.key) &&
+ Arrays.equals(value, that.value);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = Objects.hash(table);
+ result = 31 * result + Arrays.hashCode(key);
+ result = 31 * result + Arrays.hashCode(value);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "HgTkvEntryImpl{" +
+ "table='" + table + '\'' +
+ ", key=" + Arrays.toString(key) +
+ ", value=" + Arrays.toString(value) +
+ '}';
+ }
+}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgTokvEntryImpl.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgTokvEntryImpl.java
new file mode 100644
index 000000000..d58c8c275
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgTokvEntryImpl.java
@@ -0,0 +1,80 @@
+/*
+ * 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 org.apache.hugegraph.store.client;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgTokvEntry;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/14
+ */
+class HgTokvEntryImpl implements HgTokvEntry {
+
+ private final String table;
+ private final HgOwnerKey ownerKey;
+ private final byte[] value;
+
+ HgTokvEntryImpl(String table, HgOwnerKey ownerKey, byte[] value) {
+ this.table = table;
+ this.ownerKey = ownerKey;
+ this.value = value;
+ }
+
+ @Override
+ public String table() {
+ return this.table;
+ }
+
+ @Override
+ public HgOwnerKey ownerKey() {
+ return this.ownerKey;
+ }
+
+ @Override
+ public byte[] value() {
+ return this.value;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ HgTokvEntryImpl that = (HgTokvEntryImpl) o;
+ return Objects.equals(table, that.table) && Objects.equals(ownerKey, that.ownerKey) &&
+ Arrays.equals(value, that.value);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = Objects.hash(table, ownerKey);
+ result = 31 * result + Arrays.hashCode(value);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "HgTokvEntryImpl{" +
+ "table='" + table + '\'' +
+ ", okv=" + ownerKey +
+ ", value=" + Arrays.toString(value) +
+ '}';
+ }
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/MultiNodeSessionFactory.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/MultiNodeSessionFactory.java
similarity index 52%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/MultiNodeSessionFactory.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/MultiNodeSessionFactory.java
index 6fa80d8c2..e3d2507fc 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/MultiNodeSessionFactory.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/MultiNodeSessionFactory.java
@@ -1,9 +1,25 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.HgStoreSession;
+package org.apache.hugegraph.store.client;
import javax.annotation.concurrent.ThreadSafe;
-import java.util.List;
+
+import org.apache.hugegraph.store.HgStoreSession;
/**
* @author lynn.bond@hotmail.com created on 2021/10/12
@@ -13,7 +29,7 @@ public final class MultiNodeSessionFactory {
// TODO multi-instance ?
private final static MultiNodeSessionFactory instance = new MultiNodeSessionFactory();
// TODO multi-instance ?
- private HgStoreNodeManager nodeManager = HgStoreNodeManager.getInstance();
+ private final HgStoreNodeManager nodeManager = HgStoreNodeManager.getInstance();
// TODO: to be a chain assigned to each graph
//private HgStoreNodeDispatcher storeNodeDispatcher;
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTkv.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTkv.java
similarity index 62%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTkv.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTkv.java
index a081478fb..7db52cc06 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTkv.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTkv.java
@@ -1,11 +1,28 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgStoreSession;
+package org.apache.hugegraph.store.client;
+
+import java.util.Objects;
import javax.annotation.concurrent.ThreadSafe;
-import java.util.Arrays;
-import java.util.Objects;
+
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgStoreSession;
/**
* @author lynn.bond@hotmail.com created on 2021/10/26
@@ -17,6 +34,7 @@ class NodeTkv {
private final HgOwnerKey key;
private final HgOwnerKey endKey;
private HgStoreSession session;
+
NodeTkv(HgNodePartition nodePartition, String table, HgOwnerKey key) {
this.nodePartition = nodePartition;
this.table = table;
@@ -24,6 +42,7 @@ class NodeTkv {
this.endKey = key;
this.key.setKeyCode(this.nodePartition.getKeyCode());
}
+
NodeTkv(HgNodePartition nodePartition, String table, HgOwnerKey key, int keyCode) {
this.nodePartition = nodePartition;
this.table = table;
@@ -32,6 +51,7 @@ class NodeTkv {
this.key.setKeyCode(keyCode);
}
+
NodeTkv(HgNodePartition nodePartition, String table, HgOwnerKey startKey,
HgOwnerKey endKey) {
this.nodePartition = nodePartition;
@@ -58,7 +78,7 @@ class NodeTkv {
return endKey;
}
- public NodeTkv setKeyCode(int code){
+ public NodeTkv setKeyCode(int code) {
this.key.setKeyCode(code);
return this;
}
@@ -68,9 +88,10 @@ class NodeTkv {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeTkv nptKv = (NodeTkv) o;
- return Objects.equals(nodePartition, nptKv.nodePartition) && Objects.equals(table, nptKv.table)
- && Objects.equals(key, nptKv.key)
- && Objects.equals(endKey, nptKv.endKey);
+ return Objects.equals(nodePartition, nptKv.nodePartition) &&
+ Objects.equals(table, nptKv.table)
+ && Objects.equals(key, nptKv.key)
+ && Objects.equals(endKey, nptKv.endKey);
}
@Override
@@ -82,11 +103,11 @@ class NodeTkv {
@Override
public String toString() {
return "NptKv{" +
- "nodePartition=" + nodePartition +
- ", table='" + table + '\'' +
- ", key=" + key +
- ", endKey=" + endKey +
- '}';
+ "nodePartition=" + nodePartition +
+ ", table='" + table + '\'' +
+ ", key=" + key +
+ ", endKey=" + endKey +
+ '}';
}
public HgStoreSession getSession() {
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTxExecutor.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java
similarity index 83%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTxExecutor.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java
index 888d558a0..ca1d616ba 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTxExecutor.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java
@@ -1,8 +1,25 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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.
+ */
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_LIST;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.NODE_MAX_RETRYING_TIMES;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.TX_SESSIONS_MAP_CAPACITY;
+package org.apache.hugegraph.store.client;
+
+import static org.apache.hugegraph.store.client.util.HgStoreClientConst.EMPTY_LIST;
+import static org.apache.hugegraph.store.client.util.HgStoreClientConst.NODE_MAX_RETRYING_TIMES;
+import static org.apache.hugegraph.store.client.util.HgStoreClientConst.TX_SESSIONS_MAP_CAPACITY;
import java.util.Collection;
import java.util.HashMap;
@@ -21,13 +38,13 @@ import java.util.stream.Stream;
import javax.annotation.concurrent.NotThreadSafe;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgStoreSession;
-import com.baidu.hugegraph.store.client.type.HgStoreClientException;
-import com.baidu.hugegraph.store.client.util.HgAssert;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
-import com.baidu.hugegraph.store.term.HgPair;
-import com.baidu.hugegraph.store.term.HgTriple;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgStoreSession;
+import org.apache.hugegraph.store.client.type.HgStoreClientException;
+import org.apache.hugegraph.store.client.util.HgAssert;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
+import org.apache.hugegraph.store.term.HgPair;
+import org.apache.hugegraph.store.term.HgTriple;
import lombok.extern.slf4j.Slf4j;
@@ -38,7 +55,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@NotThreadSafe
final class NodeTxExecutor {
- private String graphName;
+ private final String graphName;
private Map sessions = new HashMap<>(TX_SESSIONS_MAP_CAPACITY, 1);
private boolean isTx;
NodeTxSessionProxy proxy;
@@ -46,16 +63,17 @@ final class NodeTxExecutor {
Function>> entries = new LinkedList<>();
Collector>> collector = Collectors.groupingBy(
nkv -> nkv.getNodeId(), Collectors.mapping(NodeTkv::getKey, Collectors.toList()));
- private static String maxTryMsg = "the number of retries reached the upper limit : " + NODE_MAX_RETRYING_TIMES +
- ",caused by:";
- private static String msg = "Not all tx-data delivered to real-node-session successfully.";
+ private static final String maxTryMsg =
+ "the number of retries reached the upper limit : " + NODE_MAX_RETRYING_TIMES +
+ ",caused by:";
+ private static final String msg = "Not all tx-data delivered to real-node-session successfully.";
+
static {
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism",
String.valueOf(Runtime.getRuntime().availableProcessors() * 2));
}
-
static NodeTxExecutor graphOf(String graphName, NodeTxSessionProxy proxy) {
return new NodeTxExecutor(graphName, proxy);
}
@@ -103,7 +121,8 @@ final class NodeTxExecutor {
return true;
}
AtomicBoolean allSuccess = new AtomicBoolean(true);
- for (HgPair, Function> e : this.entries) {
+ for (HgPair, Function> e :
+ this.entries) {
doAction(e.getKey(), e.getValue());
}
if (!allSuccess.get()) {
@@ -163,10 +182,12 @@ final class NodeTxExecutor {
// } if ( nodeParams.getZ() instanceof Integer ){
// return this.proxy.doPartition(nodeParams.getX(), (Integer) nodeParams.getZ())
// .stream()
- // .map(e -> new NodeTkv(e, nodeParams.getX(), nodeParams.getY(), nodeParams.getY()
+ // .map(e -> new NodeTkv(e, nodeParams.getX(), nodeParams.getY(),
+ // nodeParams.getY()
// .getKeyCode()))
// .map(
- // e -> new HgPair<>(this.proxy.getStoreNode(e.getNodeId()), e)
+ // e -> new HgPair<>(this.proxy.getStoreNode(e.getNodeId
+ // ()), e)
// );
// }else {
// HgAssert.isTrue(nodeParams.getZ() instanceof byte[],
@@ -186,18 +207,25 @@ final class NodeTxExecutor {
// (HgOwnerKey) nodeParams.getZ());
// }
// if (nodeParams.getZ() instanceof Integer) {
- // Collection nodePartitions = this.proxy.doPartition(nodeParams.getX(),
- // (Integer) nodeParams.getZ());
- // ArrayList> hgPairs = new ArrayList<>(nodePartitions.size());
+ // Collection nodePartitions = this.proxy.doPartition(nodeParams
+ // .getX(),
+ // (Integer)
+ // nodeParams
+ // .getZ());
+ // ArrayList> hgPairs = new ArrayList<>
+ // (nodePartitions.size());
// for (HgNodePartition nodePartition : nodePartitions) {
- // NodeTkv nodeTkv = new NodeTkv(nodePartition, nodeParams.getX(), nodeParams.getY(),
+ // NodeTkv nodeTkv = new NodeTkv(nodePartition, nodeParams.getX(), nodeParams
+ // .getY(),
// nodeParams.getY().getKeyCode());
- // hgPairs.add(new HgPair<>(this.proxy.getStoreNode(nodeTkv.getNodeId()), nodeTkv));
+ // hgPairs.add(new HgPair<>(this.proxy.getStoreNode(nodeTkv.getNodeId()),
+ // nodeTkv));
//
// }
// return hgPairs;
// } else {
- // HgAssert.isTrue(nodeParams.getZ() instanceof byte[], "Illegal parameter to get node id");
+ // HgAssert.isTrue(nodeParams.getZ() instanceof byte[], "Illegal parameter to get
+ // node id");
// throw new RuntimeException("not implemented");
// }
// }
@@ -206,7 +234,8 @@ final class NodeTxExecutor {
private boolean doAction(HgTriple nodeParams,
Function action) {
if (nodeParams.getZ() == null) {
- return this.proxy.doAction(nodeParams.getX(), nodeParams.getY(), nodeParams.getY(), action);
+ return this.proxy.doAction(nodeParams.getX(), nodeParams.getY(), nodeParams.getY(),
+ action);
} else {
if (nodeParams.getZ() instanceof HgOwnerKey) {
boolean result = this.proxy.doAction(nodeParams.getX(), nodeParams.getY(),
@@ -214,9 +243,11 @@ final class NodeTxExecutor {
return result;
}
if (nodeParams.getZ() instanceof Integer) {
- return this.proxy.doAction(nodeParams.getX(), nodeParams.getY(), (Integer) nodeParams.getZ(), action);
+ return this.proxy.doAction(nodeParams.getX(), nodeParams.getY(),
+ (Integer) nodeParams.getZ(), action);
} else {
- HgAssert.isTrue(nodeParams.getZ() instanceof byte[], "Illegal parameter to get node id");
+ HgAssert.isTrue(nodeParams.getZ() instanceof byte[],
+ "Illegal parameter to get node id");
throw new RuntimeException("not implemented");
}
}
@@ -277,7 +308,9 @@ final class NodeTxExecutor {
.map(
e -> new SessionData>
(
- openNodeSession(nodeFunction.apply(e.getKey())), e.getValue()
+ openNodeSession(
+ nodeFunction.apply(e.getKey())),
+ e.getValue()
)
)
.parallel()
@@ -378,11 +411,7 @@ final class NodeTxExecutor {
return false;
}
- if (EMPTY_LIST.equals(obj)) {
- return false;
- }
-
- return true;
+ return !EMPTY_LIST.equals(obj);
}
class SessionData {
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTxSessionProxy.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxSessionProxy.java
similarity index 88%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTxSessionProxy.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxSessionProxy.java
index 78b3e0c1b..f1edca106 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/NodeTxSessionProxy.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxSessionProxy.java
@@ -1,12 +1,29 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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 org.apache.hugegraph.store.client;
-import static com.baidu.hugegraph.store.client.util.HgAssert.isArgumentNotNull;
-import static com.baidu.hugegraph.store.client.util.HgAssert.isArgumentValid;
-import static com.baidu.hugegraph.store.client.util.HgAssert.isFalse;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_STRING;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientUtil.err;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientUtil.toStr;
import static java.util.stream.Collectors.groupingBy;
+import static org.apache.hugegraph.store.client.util.HgAssert.isArgumentNotNull;
+import static org.apache.hugegraph.store.client.util.HgAssert.isArgumentValid;
+import static org.apache.hugegraph.store.client.util.HgAssert.isFalse;
+import static org.apache.hugegraph.store.client.util.HgStoreClientConst.EMPTY_STRING;
+import static org.apache.hugegraph.store.client.util.HgStoreClientUtil.err;
+import static org.apache.hugegraph.store.client.util.HgStoreClientUtil.toStr;
import java.util.ArrayList;
import java.util.Collection;
@@ -22,20 +39,21 @@ import java.util.stream.Stream;
import javax.annotation.concurrent.NotThreadSafe;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvOrderedIterator;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.HgStoreSession;
-import com.baidu.hugegraph.store.client.grpc.KvBatchScanner;
-import com.baidu.hugegraph.store.client.grpc.KvCloseableIterator;
-import com.baidu.hugegraph.store.client.util.HgAssert;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
-import com.baidu.hugegraph.store.client.util.HgStoreClientUtil;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvOrderedIterator;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.HgStoreSession;
+import org.apache.hugegraph.store.client.grpc.KvBatchScanner;
+import org.apache.hugegraph.store.client.grpc.KvCloseableIterator;
+import org.apache.hugegraph.store.client.util.HgAssert;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
+import org.apache.hugegraph.store.client.util.HgStoreClientUtil;
+import org.apache.hugegraph.store.term.HgPair;
+import org.apache.hugegraph.store.term.HgTriple;
+
import com.baidu.hugegraph.store.grpc.stream.ScanStreamReq.Builder;
-import com.baidu.hugegraph.store.term.HgPair;
-import com.baidu.hugegraph.store.term.HgTriple;
import lombok.extern.slf4j.Slf4j;
@@ -103,7 +121,7 @@ class NodeTxSessionProxy implements HgStoreSession {
isArgumentNotNull(ownerKey, "ownerKey");
return this.txExecutor.prepareTx(
- new HgTriple(table, ownerKey, (Integer) partitionId),
+ new HgTriple(table, ownerKey, partitionId),
e -> e.getSession().put(table, e.getKey(), value)
);
}
@@ -369,7 +387,8 @@ class NodeTxSessionProxy implements HgStoreSession {
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix, long limit, byte[] query) {
+ public HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix, long limit,
+ byte[] query) {
HgAssert.isFalse(HgAssert.isInvalid(table), "The argument is invalid: table");
HgAssert.isFalse(keyPrefix == null, "The argument is invalid: keyPrefix");
@@ -385,12 +404,14 @@ class NodeTxSessionProxy implements HgStoreSession {
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey) {
+ public HgKvIterator scanIterator(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey) {
return this.scanIterator(table, startKey, endKey, 0, null);
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey, long limit) {
+ public HgKvIterator scanIterator(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey, long limit) {
HgAssert.isFalse(HgAssert.isInvalid(table), "The argument is invalid: table");
HgAssert.isFalse(startKey == null, "The argument is invalid: startKey");
HgAssert.isFalse(endKey == null, "The argument is invalid: endKey");
@@ -418,7 +439,8 @@ class NodeTxSessionProxy implements HgStoreSession {
.parallelStream()
.map(
e -> this.getStoreNode(e.getNodeId()).openSession(this.graphName)
- .scanIterator(e.getTable(), e.getKey(), e.getEndKey(), limit, query)
+ .scanIterator(e.getTable(), e.getKey(), e.getEndKey(), limit,
+ query)
)
.collect(Collectors.toList())
, limit);
@@ -437,7 +459,8 @@ class NodeTxSessionProxy implements HgStoreSession {
.parallelStream()
.map(
e -> this.getStoreNode(e.getNodeId()).openSession(this.graphName)
- .scanIterator(e.getTable(), e.getKey(), e.getEndKey(), limit, scanType, query)
+ .scanIterator(e.getTable(), e.getKey(), e.getEndKey(), limit,
+ scanType, query)
)
.collect(Collectors.toList())
, limit);
@@ -445,7 +468,8 @@ class NodeTxSessionProxy implements HgStoreSession {
}
@Override
- public HgKvIterator scanIterator(String table, int codeFrom, int codeTo, int scanType, byte[] query) {
+ public HgKvIterator scanIterator(String table, int codeFrom, int codeTo,
+ int scanType, byte[] query) {
if (log.isDebugEnabled()) {
log.debug("graph: {}, table: {}, codeFrom: {}, codeTo: {}, scanType: {}, query: {}"
, graphName, table, codeFrom, codeTo, scanType, HgStoreClientUtil.toStr(query));
@@ -540,7 +564,8 @@ class NodeTxSessionProxy implements HgStoreSession {
return notifierWrap;
}
- private Function>> toTkvMapFunc(HgScanQuery.ScanMethod scanMethod) {
+ private Function>> toTkvMapFunc(
+ HgScanQuery.ScanMethod scanMethod) {
switch (scanMethod) {
case RANGE:
return scanQuery -> {
@@ -549,7 +574,8 @@ class NodeTxSessionProxy implements HgStoreSession {
int size = starts.size();
return IntStream.range(0, size)
.boxed()
- .map(i -> this.toNodeTkvList(scanQuery.getTable(), starts.get(i), ends.get(i)))
+ .map(i -> this.toNodeTkvList(scanQuery.getTable(),
+ starts.get(i), ends.get(i)))
.flatMap(List::stream)
.collect(groupingBy(NodeTkv::getNodeId));
};
@@ -557,7 +583,8 @@ class NodeTxSessionProxy implements HgStoreSession {
return scanQuery ->
scanQuery.getPrefixList()
.stream()
- .map(keyPrefix -> this.toNodeTkvList(scanQuery.getTable(), keyPrefix))
+ .map(keyPrefix -> this.toNodeTkvList(scanQuery.getTable(),
+ keyPrefix))
.flatMap(List::stream)
.collect(groupingBy(NodeTkv::getNodeId));
@@ -599,7 +626,8 @@ class NodeTxSessionProxy implements HgStoreSession {
/*-- common --*/
private HgKvIterator toHgKvIteratorProxy(List iteratorList, long limit) {
boolean isAllOrderedLimiter = iteratorList.stream()
- .allMatch(e -> HgKvOrderedIterator.class.isInstance(e));
+ .allMatch(
+ e -> e instanceof HgKvOrderedIterator);
HgKvIterator iterator;
if (isAllOrderedLimiter) {
@@ -623,8 +651,10 @@ class NodeTxSessionProxy implements HgStoreSession {
return res;
}
- public boolean doAction(String table, HgOwnerKey startKey, HgOwnerKey endKey, Function action) {
- Collection partitions = doPartition(table, startKey.getOwner(), endKey.getOwner());
+ public boolean doAction(String table, HgOwnerKey startKey, HgOwnerKey endKey,
+ Function action) {
+ Collection partitions =
+ doPartition(table, startKey.getOwner(), endKey.getOwner());
for (HgNodePartition partition : partitions) {
HgStoreNode storeNode = this.getStoreNode(partition.getNodeId());
HgStoreSession session = this.txExecutor.openNodeSession(storeNode);
@@ -637,7 +667,8 @@ class NodeTxSessionProxy implements HgStoreSession {
return true;
}
- public boolean doAction(String table, HgOwnerKey startKey, Integer code, Function action) {
+ public boolean doAction(String table, HgOwnerKey startKey, Integer code,
+ Function action) {
Collection partitions = this.doPartition(table, code);
for (HgNodePartition partition : partitions) {
HgStoreNode storeNode = this.getStoreNode(partition.getNodeId());
@@ -679,7 +710,8 @@ class NodeTxSessionProxy implements HgStoreSession {
}
private List toNodeTkvList(String table, HgOwnerKey ownerKey) {
- Collection partitions = doPartition(table, ownerKey.getOwner(), ownerKey.getOwner());
+ Collection partitions =
+ doPartition(table, ownerKey.getOwner(), ownerKey.getOwner());
ArrayList nodeTkvs = new ArrayList<>(partitions.size());
for (HgNodePartition partition : partitions) {
nodeTkvs.add(new NodeTkv(partition, table, ownerKey, ownerKey));
@@ -689,7 +721,8 @@ class NodeTxSessionProxy implements HgStoreSession {
}
private List toNodeTkvList(String table, HgOwnerKey startKey, HgOwnerKey endKey) {
- Collection partitions = doPartition(table, startKey.getOwner(), endKey.getOwner());
+ Collection partitions =
+ doPartition(table, startKey.getOwner(), endKey.getOwner());
ArrayList nodeTkvs = new ArrayList<>(partitions.size());
for (HgNodePartition partition : partitions) {
nodeTkvs.add(new NodeTkv(partition, table, startKey, endKey));
@@ -703,17 +736,20 @@ class NodeTxSessionProxy implements HgStoreSession {
ArrayList nodeTkvs = new ArrayList<>(partitions.size());
for (HgNodePartition partition : partitions) {
nodeTkvs.add(
- new NodeTkv(partition, table, HgOwnerKey.codeOf(startCode), HgOwnerKey.codeOf(endCode)));
+ new NodeTkv(partition, table, HgOwnerKey.codeOf(startCode),
+ HgOwnerKey.codeOf(endCode)));
}
return nodeTkvs;
}
+
/**
* @return not null
*/
private Collection doPartition(String table, byte[] startKey, byte[] endKey) {
HgNodePartitionerBuilder partitionerBuilder = HgNodePartitionerBuilder.resetAndGet();
- int status = this.nodePartitioner.partition(partitionerBuilder, this.graphName, startKey, endKey);
+ int status = this.nodePartitioner.partition(partitionerBuilder, this.graphName, startKey,
+ endKey);
if (status != 0) {
throw err("The node-partitioner is not work.");
@@ -733,7 +769,8 @@ class NodeTxSessionProxy implements HgStoreSession {
*/
private Collection doPartition(String table, int startCode, int endCode) {
HgNodePartitionerBuilder partitionerBuilder = HgNodePartitionerBuilder.resetAndGet();
- int status = this.nodePartitioner.partition(partitionerBuilder, this.graphName, startCode, endCode);
+ int status = this.nodePartitioner.partition(partitionerBuilder, this.graphName, startCode,
+ endCode);
if (status != 0) {
throw err("The node-partitioner is not work.");
@@ -750,7 +787,8 @@ class NodeTxSessionProxy implements HgStoreSession {
Collection doPartition(String table, int partitionId) {
HgNodePartitionerBuilder partitionerBuilder = HgNodePartitionerBuilder.resetAndGet();
- int status = this.nodePartitioner.partition(partitionerBuilder, this.graphName, partitionId);
+ int status =
+ this.nodePartitioner.partition(partitionerBuilder, this.graphName, partitionId);
if (status != 0) {
throw err("The node-partitioner is not work.");
@@ -764,12 +802,13 @@ class NodeTxSessionProxy implements HgStoreSession {
return partitions;
}
+
private Stream> getNodeStream(String table) {
return this.toNodeTkvList(table)
.stream()
.map(
e -> new HgPair<>(this.getStoreNode(e.getNodeId()), e)
- );
+ );
}
Stream> getNodeStream(String table,
@@ -781,7 +820,8 @@ class NodeTxSessionProxy implements HgStoreSession {
);
}
- Stream> getNodeStream(String table, HgOwnerKey startKey, HgOwnerKey endKey) {
+ Stream> getNodeStream(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey) {
return this.toNodeTkvList(table, startKey, endKey)
.stream()
.map(
@@ -800,7 +840,8 @@ class NodeTxSessionProxy implements HgStoreSession {
return nodeTkv2Node(nodeTkvList);
}
- List> getNode(String table, HgOwnerKey startKey, HgOwnerKey endKey) {
+ List> getNode(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey) {
List nodeTkvList = this.toNodeTkvList(table, startKey, endKey);
return nodeTkv2Node(nodeTkvList);
@@ -814,7 +855,8 @@ class NodeTxSessionProxy implements HgStoreSession {
// List> getNode(String table, Integer endKey) {
// .stream()
- // .map(e -> new NodeTkv(e, nodeParams.getX(), nodeParams.getY(), nodeParams.getY().getKeyCode()))
+ // .map(e -> new NodeTkv(e, nodeParams.getX(), nodeParams.getY(), nodeParams.getY
+ // ().getKeyCode()))
// .map(
// e -> new HgPair<>(this.proxy.getStoreNode(e.getNodeId()), e)
// );
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/SequencedIterator.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/SequencedIterator.java
similarity index 72%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/SequencedIterator.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/SequencedIterator.java
index 9c3e0a4cc..4e8365e06 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/SequencedIterator.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/SequencedIterator.java
@@ -1,4 +1,21 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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 org.apache.hugegraph.store.client;
import java.util.Collections;
import java.util.LinkedList;
@@ -6,9 +23,9 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.Queue;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvOrderedIterator;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvOrderedIterator;
import lombok.extern.slf4j.Slf4j;
@@ -22,9 +39,9 @@ import lombok.extern.slf4j.Slf4j;
public class SequencedIterator implements HgKvIterator {
private static final byte[] EMPTY_BYTES = new byte[0];
private HgKvOrderedIterator iterator;
- private Queue queue;
+ private final Queue queue;
private HgKvEntry entry;
- private long limit;
+ private final long limit;
private int count;
private byte[] position = EMPTY_BYTES;
private byte[] position4Seeking = EMPTY_BYTES;
@@ -44,9 +61,6 @@ public class SequencedIterator implements HgKvIterator {
break;
}
}
- if (buf == null) {
- return null;
- }
return buf;
}
@@ -98,11 +112,7 @@ public class SequencedIterator implements HgKvIterator {
this.iterator.close();
this.iterator = this.getIterator();
}
- if (this.iterator == null) {
- return false;
- } else {
- return true;
- }
+ return this.iterator != null;
}
@Override
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/ShiftWorkIteratorProxy.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/ShiftWorkIteratorProxy.java
similarity index 71%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/ShiftWorkIteratorProxy.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/ShiftWorkIteratorProxy.java
index 795f13e0b..47c8abbea 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/ShiftWorkIteratorProxy.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/ShiftWorkIteratorProxy.java
@@ -1,13 +1,30 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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 org.apache.hugegraph.store.client;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Queue;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvPagingIterator;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvPagingIterator;
import lombok.extern.slf4j.Slf4j;
@@ -21,7 +38,7 @@ public class ShiftWorkIteratorProxy implements HgKvIterator {
private HgKvPagingIterator iterator;
private Queue queue = new LinkedList<>();
private HgKvEntry entry;
- private int limit;
+ private final int limit;
private int count;
private int shiftCount;
@@ -112,11 +129,7 @@ public class ShiftWorkIteratorProxy implements HgKvIterator {
|| !this.iterator.hasNext()) {
this.iterator = this.getIterator();
}
- if (this.iterator == null) {
- return false;
- } else {
- return true;
- }
+ return this.iterator != null;
}
@Override
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/TopWorkIteratorProxy.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/TopWorkIteratorProxy.java
similarity index 60%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/TopWorkIteratorProxy.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/TopWorkIteratorProxy.java
index 80b0d8a28..a101f5b6e 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/TopWorkIteratorProxy.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/TopWorkIteratorProxy.java
@@ -1,10 +1,29 @@
-package com.baidu.hugegraph.store.client;
+/*
+ * 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.
+ */
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
+package org.apache.hugegraph.store.client;
-import java.io.IOException;
-import java.util.*;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Queue;
+
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
/**
* @author lynn.bond@hotmail.com created on 2021/10/21
@@ -13,9 +32,9 @@ import java.util.*;
class TopWorkIteratorProxy implements HgKvIterator {
private static final byte[] EMPTY_BYTES = new byte[0];
private HgKvIterator iterator;
- private Queue queue;
+ private final Queue queue;
private HgKvEntry entry;
- private long limit;
+ private final long limit;
private int count;
TopWorkIteratorProxy(List iterators, long limit) {
@@ -42,6 +61,7 @@ class TopWorkIteratorProxy implements HgKvIterator {
return buf;
}
+
private void closeIterators() {
if (this.queue.isEmpty()) return;
@@ -52,6 +72,7 @@ class TopWorkIteratorProxy implements HgKvIterator {
}
}
+
private void setIterator() {
this.iterator = null;
}
@@ -79,7 +100,7 @@ class TopWorkIteratorProxy implements HgKvIterator {
@Override
public void seek(byte[] position) {
- if(this.iterator!=null)this.iterator.seek(position);
+ if (this.iterator != null) this.iterator.seek(position);
}
@Override
@@ -90,11 +111,7 @@ class TopWorkIteratorProxy implements HgKvIterator {
if (this.iterator == null) {
this.iterator = this.getIterator();
}
- if (this.iterator == null) {
- return false;
- } else {
- return true;
- }
+ return this.iterator != null;
}
@@ -113,8 +130,8 @@ class TopWorkIteratorProxy implements HgKvIterator {
}
@Override
- public void close() {
- if(this.iterator!=null)this.iterator.close();
+ public void close() {
+ if (this.iterator != null) this.iterator.close();
this.closeIterators();
}
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/AbstractGrpcClient.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/AbstractGrpcClient.java
similarity index 66%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/AbstractGrpcClient.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/AbstractGrpcClient.java
index fd8090e9d..22c67162a 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/AbstractGrpcClient.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/AbstractGrpcClient.java
@@ -1,4 +1,21 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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 org.apache.hugegraph.store.client.grpc;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -6,8 +23,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.IntStream;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConfig;
-import com.baidu.hugegraph.store.term.HgPair;
+import org.apache.hugegraph.store.client.util.HgStoreClientConfig;
+import org.apache.hugegraph.store.term.HgPair;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
@@ -20,14 +37,16 @@ import io.grpc.stub.AbstractBlockingStub;
**/
public abstract class AbstractGrpcClient {
- private static Map channels = new ConcurrentHashMap<>();
- private static int n = 5;
- private static int concurrency = 1 << n;
- private static AtomicLong counter = new AtomicLong(0);
- private static long limit = Long.MAX_VALUE >> 1;
- private Map[]> blockingStubs = new ConcurrentHashMap<>();
- private Map[]> asyncStubs = new ConcurrentHashMap<>();
- private static HgStoreClientConfig config = HgStoreClientConfig.of();
+ private static final Map channels = new ConcurrentHashMap<>();
+ private static final int n = 5;
+ private static final int concurrency = 1 << n;
+ private static final AtomicLong counter = new AtomicLong(0);
+ private static final long limit = Long.MAX_VALUE >> 1;
+ private final Map[]> blockingStubs =
+ new ConcurrentHashMap<>();
+ private final Map[]> asyncStubs =
+ new ConcurrentHashMap<>();
+ private static final HgStoreClientConfig config = HgStoreClientConfig.of();
public AbstractGrpcClient() {
@@ -39,7 +58,8 @@ public abstract class AbstractGrpcClient {
synchronized (channels) {
if ((tc = channels.get(target)) == null) {
ManagedChannel[] value = new ManagedChannel[concurrency];
- IntStream.range(0, concurrency).parallel().forEach(i -> value[i] = getManagedChannel(target));
+ IntStream.range(0, concurrency).parallel()
+ .forEach(i -> value[i] = getManagedChannel(target));
channels.put(target, tc = value);
}
}
@@ -72,16 +92,18 @@ public abstract class AbstractGrpcClient {
});
blockingStubs.put(target, value);
AbstractBlockingStub stub = value[index].getValue();
- return (AbstractBlockingStub) stub.withDeadlineAfter(config.getGrpcTimeoutSeconds(),
- TimeUnit.SECONDS);
+ return (AbstractBlockingStub) stub.withDeadlineAfter(
+ config.getGrpcTimeoutSeconds(),
+ TimeUnit.SECONDS);
}
}
}
- return (AbstractBlockingStub) pairs[index].getValue().withDeadlineAfter(config.getGrpcTimeoutSeconds(),
- TimeUnit.SECONDS);
+ return (AbstractBlockingStub) pairs[index].getValue()
+ .withDeadlineAfter(config.getGrpcTimeoutSeconds(),
+ TimeUnit.SECONDS);
}
- public AbstractAsyncStub getAsyncStub(ManagedChannel channel){
+ public AbstractAsyncStub getAsyncStub(ManagedChannel channel) {
return null;
}
@@ -117,7 +139,6 @@ public abstract class AbstractGrpcClient {
}
-
private ManagedChannel getManagedChannel(String target) {
return ManagedChannelBuilder.forTarget(target).usePlaintext().build();
}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcKvEntryImpl.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcKvEntryImpl.java
new file mode 100644
index 000000000..614336eab
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcKvEntryImpl.java
@@ -0,0 +1,76 @@
+/*
+ * 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 org.apache.hugegraph.store.client.grpc;
+
+import java.util.Arrays;
+
+import org.apache.hugegraph.store.HgKvEntry;
+
+/**
+ * @author lynn.bond@hotmail.com
+ */
+class GrpcKvEntryImpl implements HgKvEntry {
+ private final byte[] key;
+ private final byte[] value;
+ private final int code;
+
+ GrpcKvEntryImpl(byte[] k, byte[] v, int code) {
+ this.key = k;
+ this.value = v;
+ this.code = code;
+ }
+
+ @Override
+ public int code() {
+ return code;
+ }
+
+ @Override
+ public byte[] key() {
+ return key;
+ }
+
+ @Override
+ public byte[] value() {
+ return value;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ GrpcKvEntryImpl hgKvEntry = (GrpcKvEntryImpl) o;
+ return Arrays.equals(key, hgKvEntry.key) && Arrays.equals(value, hgKvEntry.value);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = Arrays.hashCode(key);
+ result = 31 * result + Arrays.hashCode(value);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "HgKvEntryImpl{" +
+ "key=" + Arrays.toString(key) +
+ ", value=" + Arrays.toString(value) +
+ ", code=" + code +
+ '}';
+ }
+}
\ No newline at end of file
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcKvIteratorImpl.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcKvIteratorImpl.java
similarity index 59%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcKvIteratorImpl.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcKvIteratorImpl.java
index 5ec219868..e188dc28b 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcKvIteratorImpl.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcKvIteratorImpl.java
@@ -1,17 +1,34 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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.
+ */
-import static com.baidu.hugegraph.store.client.util.HgStoreClientUtil.toIntBytes;
+package org.apache.hugegraph.store.client.grpc;
import java.util.List;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvOrderedIterator;
-import com.baidu.hugegraph.store.HgKvPagingIterator;
-import com.baidu.hugegraph.store.HgPageSize;
-import com.baidu.hugegraph.store.HgSeekAble;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvOrderedIterator;
+import org.apache.hugegraph.store.HgKvPagingIterator;
+import org.apache.hugegraph.store.HgPageSize;
+import org.apache.hugegraph.store.HgSeekAble;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
+import org.apache.hugegraph.store.client.util.HgStoreClientUtil;
+
import com.baidu.hugegraph.store.grpc.common.Kv;
import lombok.extern.slf4j.Slf4j;
@@ -23,20 +40,22 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
class GrpcKvIteratorImpl implements HgKvPagingIterator, HgKvOrderedIterator {
- private byte[] emptyBytes = HgStoreClientConst.EMPTY_BYTES;
- private KvCloseableIterator iterator;
+ private final byte[] emptyBytes = HgStoreClientConst.EMPTY_BYTES;
+ private final KvCloseableIterator iterator;
private HgKvEntry element;
- private HgPageSize pageLimiter;
- private HgStoreNodeSession session;
+ private final HgPageSize pageLimiter;
+ private final HgStoreNodeSession session;
- public static HgKvIterator of(HgStoreNodeSession nodeSession, KvCloseableIterator iterator) {
- if (HgPageSize.class.isInstance(iterator)) {
+ public static HgKvIterator of(HgStoreNodeSession nodeSession,
+ KvCloseableIterator iterator) {
+ if (iterator instanceof HgPageSize) {
return of(nodeSession, iterator, (HgPageSize) iterator);
}
return new GrpcKvIteratorImpl(nodeSession, iterator, () -> 1);
}
- public static HgKvIterator of(HgStoreNodeSession nodeSession, KvCloseableIterator iterator,
+ public static HgKvIterator of(HgStoreNodeSession nodeSession,
+ KvCloseableIterator iterator,
HgPageSize pageLimiter) {
return new GrpcKvIteratorImpl(nodeSession, iterator, pageLimiter);
}
@@ -46,7 +65,8 @@ class GrpcKvIteratorImpl implements HgKvPagingIterator, HgKvOrderedIt
return new GrpcKvIteratorImpl(nodeSession, new KvListIterator(kvList), () -> pageSize);
}
- private GrpcKvIteratorImpl(HgStoreNodeSession session, KvCloseableIterator iterator, HgPageSize pageLimiter) {
+ private GrpcKvIteratorImpl(HgStoreNodeSession session, KvCloseableIterator iterator,
+ HgPageSize pageLimiter) {
this.iterator = iterator;
this.pageLimiter = pageLimiter;
this.session = session;
@@ -65,7 +85,8 @@ class GrpcKvIteratorImpl implements HgKvPagingIterator, HgKvOrderedIt
@Override
public HgKvEntry next() {
Kv kv = this.iterator.next();
- this.element = new GrpcKvEntryImpl(kv.getKey().toByteArray(), kv.getValue().toByteArray(), kv.getCode());
+ this.element = new GrpcKvEntryImpl(kv.getKey().toByteArray(), kv.getValue().toByteArray(),
+ kv.getCode());
return this.element;
}
@@ -94,11 +115,11 @@ class GrpcKvIteratorImpl implements HgKvPagingIterator, HgKvOrderedIt
if (key == null) {
return emptyBytes;
}
- if (!HgSeekAble.class.isInstance(this.iterator)) {
+ if (!(this.iterator instanceof HgSeekAble)) {
return emptyBytes;
}
byte[] upstream = ((HgSeekAble) this.iterator).position();
- byte[] code = toIntBytes(this.element.code());
+ byte[] code = HgStoreClientUtil.toIntBytes(this.element.code());
byte[] result = new byte[upstream.length + Integer.BYTES + key.length];
System.arraycopy(upstream, 0, result, 0, upstream.length);
System.arraycopy(code, 0, result, upstream.length, Integer.BYTES);
@@ -108,7 +129,7 @@ class GrpcKvIteratorImpl implements HgKvPagingIterator, HgKvOrderedIt
@Override
public void seek(byte[] position) {
- if (HgSeekAble.class.isInstance(this.iterator)) {
+ if (this.iterator instanceof HgSeekAble) {
((HgSeekAble) this.iterator).seek(position);
}
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcNodeHealthyClient.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcNodeHealthyClient.java
similarity index 69%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcNodeHealthyClient.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcNodeHealthyClient.java
index a2e43f054..708d32085 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcNodeHealthyClient.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcNodeHealthyClient.java
@@ -1,15 +1,34 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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 org.apache.hugegraph.store.client.grpc;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.concurrent.ThreadSafe;
import com.baidu.hugegraph.store.grpc.HealthyGrpc;
import com.baidu.hugegraph.store.grpc.HealthyOuterClass;
import com.google.protobuf.Empty;
+
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
-import javax.annotation.concurrent.ThreadSafe;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
/**
*
*/
@@ -17,7 +36,8 @@ import java.util.concurrent.ConcurrentHashMap;
public final class GrpcNodeHealthyClient {
private final static Map CHANNEL_MAP = new ConcurrentHashMap<>();
- private final static Map STUB_MAP = new ConcurrentHashMap<>();
+ private final static Map STUB_MAP =
+ new ConcurrentHashMap<>();
// TODO: Forbid constructing out of the package.
public GrpcNodeHealthyClient() {
@@ -66,11 +86,6 @@ public final class GrpcNodeHealthyClient {
String res = response.getMessage();
System.out.printf("gRPC response message:%s%n", res);
- if ("ok".equals(res)) {
- return true;
- } else {
-
- return false;
- }
+ return "ok".equals(res);
}
}
diff --git a/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeBuilder.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeBuilder.java
new file mode 100644
index 000000000..9f2707952
--- /dev/null
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeBuilder.java
@@ -0,0 +1,78 @@
+/*
+ * 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 org.apache.hugegraph.store.client.grpc;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.hugegraph.store.client.HgPrivate;
+import org.apache.hugegraph.store.client.HgStoreNode;
+import org.apache.hugegraph.store.client.HgStoreNodeBuilder;
+import org.apache.hugegraph.store.client.HgStoreNodeManager;
+import org.apache.hugegraph.store.client.util.HgAssert;
+
+/**
+ * @author lynn.bond@hotmail.com created on 2021/10/12
+ */
+public class GrpcStoreNodeBuilder implements HgStoreNodeBuilder {
+
+ private static final GrpcStoreSessionClient sessionClient = new GrpcStoreSessionClient();
+ private static final GrpcStoreStreamClient streamClient = new GrpcStoreStreamClient();
+ private static final AtomicLong ids = new AtomicLong(0);
+
+ private Long nodeId;
+ private String address;
+ private final HgStoreNodeManager nodeManager;
+
+ public GrpcStoreNodeBuilder(HgStoreNodeManager nodeManager, HgPrivate hgPrivate) {
+ HgAssert.isArgumentNotNull(hgPrivate, "hgPrivate");
+ HgAssert.isArgumentNotNull(nodeManager, "nodeManager");
+ this.nodeManager = nodeManager;
+ }
+
+ @Override
+ public GrpcStoreNodeBuilder setAddress(String address) {
+ HgAssert.isFalse(HgAssert.isInvalid(address), "The argument is invalid: address.");
+ this.address = address;
+ return this;
+ }
+
+ @Override
+ public GrpcStoreNodeBuilder setNodeId(Long nodeId) {
+ HgAssert.isFalse(nodeId == null, "The argument is invalid: nodeId.");
+ this.nodeId = nodeId;
+ return this;
+ }
+
+ @Override
+ public HgStoreNode build() {
+ // TODO: delete
+ if (this.nodeId == null) {
+ this.nodeId = ids.addAndGet(-1L);
+ }
+
+ HgAssert.isFalse(this.nodeId == null, "nodeId can't to be null");
+ HgAssert.isFalse(this.address == null, "address can't to be null");
+
+ GrpcStoreNodeImpl node =
+ new GrpcStoreNodeImpl(this.nodeManager, sessionClient, streamClient);
+ node.setNodeId(this.nodeId);
+ node.setAddress(this.address);
+
+ return node;
+ }
+}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeImpl.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeImpl.java
similarity index 57%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeImpl.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeImpl.java
index e1d7854aa..4e6858ec2 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeImpl.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeImpl.java
@@ -1,18 +1,35 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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 org.apache.hugegraph.store.client.grpc;
import java.util.Objects;
-import com.baidu.hugegraph.store.HgStoreSession;
-import com.baidu.hugegraph.store.client.HgStoreNode;
-import com.baidu.hugegraph.store.client.HgStoreNodeManager;
+import org.apache.hugegraph.store.HgStoreSession;
+import org.apache.hugegraph.store.client.HgStoreNode;
+import org.apache.hugegraph.store.client.HgStoreNodeManager;
/**
* @author lynn.bond@hotmail.com created on 2021/10/11
*/
class GrpcStoreNodeImpl implements HgStoreNode {
- private GrpcStoreSessionClient sessionClient;
- private GrpcStoreStreamClient streamClient;
- private HgStoreNodeManager nodeManager;
+ private final GrpcStoreSessionClient sessionClient;
+ private final GrpcStoreStreamClient streamClient;
+ private final HgStoreNodeManager nodeManager;
private String address;
private Long nodeId;
@@ -46,9 +63,11 @@ class GrpcStoreNodeImpl implements HgStoreNode {
@Override
public HgStoreSession openSession(String graphName) {
// HgAssert.isFalse(HgAssert.isInvalid(graphName), "the argument: graphName is invalid.");
- // return new GrpcStoreNodeSessionImpl2(this, graphName,this.nodeManager, this.sessionClient, this
+ // return new GrpcStoreNodeSessionImpl2(this, graphName,this.nodeManager, this
+ // .sessionClient, this
// .streamClient);
- return new GrpcStoreNodeSessionImpl(this, graphName, this.nodeManager, this.sessionClient, this.streamClient);
+ return new GrpcStoreNodeSessionImpl(this, graphName, this.nodeManager, this.sessionClient,
+ this.streamClient);
}
@Override
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeSessionImpl.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeSessionImpl.java
similarity index 75%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeSessionImpl.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeSessionImpl.java
index 4a6c3203a..b63f03434 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreNodeSessionImpl.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreNodeSessionImpl.java
@@ -15,14 +15,7 @@
* under the License.
*/
-package com.baidu.hugegraph.store.client.grpc;
-
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_BYTES;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_LIST;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_TABLE;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.SCAN_TYPE_ANY;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.SCAN_TYPE_RANGE;
-import static com.baidu.hugegraph.store.client.util.HgStoreClientUtil.isValid;
+package org.apache.hugegraph.store.client.grpc;
import java.util.Collections;
import java.util.LinkedList;
@@ -33,20 +26,21 @@ import java.util.stream.Collectors;
import javax.annotation.concurrent.NotThreadSafe;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvStore;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.client.HgStoreNode;
+import org.apache.hugegraph.store.client.HgStoreNodeManager;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
+import org.apache.hugegraph.store.client.util.HgAssert;
+import org.apache.hugegraph.store.client.util.HgStoreClientConfig;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
+import org.apache.hugegraph.store.client.util.HgStoreClientUtil;
+import org.apache.hugegraph.store.client.util.HgUuid;
import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc.HgStoreStreamStub;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvStore;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.client.HgStoreNode;
-import com.baidu.hugegraph.store.client.HgStoreNodeManager;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
-import com.baidu.hugegraph.store.client.util.HgAssert;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConfig;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
-import com.baidu.hugegraph.store.client.util.HgUuid;
import com.baidu.hugegraph.store.grpc.common.GraphMethod;
import com.baidu.hugegraph.store.grpc.common.Key;
import com.baidu.hugegraph.store.grpc.common.OpType;
@@ -65,20 +59,20 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@NotThreadSafe
class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
- private static HgStoreClientConfig hgStoreClientConfig = HgStoreClientConfig.of();
- private HgStoreNode storeNode;
- private String graphName;
- private GrpcStoreSessionClient storeSessionClient;
- private GrpcStoreStreamClient storeStreamClient;
- private HgStoreNodeManager nodeManager;
- private NotifyingExecutor notifier;
- private SwitchingExecutor switcher;
- private BatchEntry.Builder batchEntryBuilder = BatchEntry.newBuilder();
- private Key.Builder builder = Key.newBuilder();
+ private static final HgStoreClientConfig hgStoreClientConfig = HgStoreClientConfig.of();
+ private final HgStoreNode storeNode;
+ private final String graphName;
+ private final GrpcStoreSessionClient storeSessionClient;
+ private final GrpcStoreStreamClient storeStreamClient;
+ private final HgStoreNodeManager nodeManager;
+ private final NotifyingExecutor notifier;
+ private final SwitchingExecutor switcher;
+ private final BatchEntry.Builder batchEntryBuilder = BatchEntry.newBuilder();
+ private final Key.Builder builder = Key.newBuilder();
private boolean isAutoCommit = true;
private String batchId;
private LinkedList batchEntries = new LinkedList<>();
- private static ConcurrentHashMap tables = new ConcurrentHashMap() {{
+ private static final ConcurrentHashMap tables = new ConcurrentHashMap() {{
put("unknown", 0);
put("vertex", 1);
put("out_edge", 2);
@@ -88,8 +82,10 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
put("olap", 6);
}};
- GrpcStoreNodeSessionImpl(HgStoreNode storeNode, String graphName, HgStoreNodeManager nodeManager,
- GrpcStoreSessionClient sessionClient , GrpcStoreStreamClient streamClient) {
+ GrpcStoreNodeSessionImpl(HgStoreNode storeNode, String graphName,
+ HgStoreNodeManager nodeManager,
+ GrpcStoreSessionClient sessionClient,
+ GrpcStoreStreamClient streamClient) {
HgAssert.isFalse(HgAssert.isInvalid(graphName), "the argument: graphName is invalid.");
HgAssert.isFalse(nodeManager == null, "the argument: nodeManager is null.");
@@ -187,7 +183,7 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
}
@Override
- public boolean directPut(String table, int partitionId, HgOwnerKey key, byte[] value) {
+ public boolean directPut(String table, int partitionId, HgOwnerKey key, byte[] value) {
return false;
}
@@ -241,7 +237,7 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
return this.notifier.invoke(
() -> this.storeSessionClient.doBatch(this, this.getBatchId(), entries),
e -> true
- ).orElse(false);
+ ).orElse(false);
}
@Override
@@ -250,7 +246,7 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
() -> this.storeSessionClient.doGet(this, table, ownerKey)
,
e -> e.getValueResponse().getValue().toByteArray()
- ).orElse(EMPTY_BYTES);
+ ).orElse(HgStoreClientConst.EMPTY_BYTES);
}
@Override
@@ -260,7 +256,7 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
,
e -> true
- ).orElse(false);
+ ).orElse(false);
}
@Override
@@ -271,24 +267,26 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
.stream()
.map(kv -> (HgKvEntry) new GrpcKvEntryImpl(kv.getKey().toByteArray()
, kv.getValue().toByteArray(), kv.getCode())
- )
+ )
.collect(Collectors.toList()))
- .orElse((List) EMPTY_LIST);
+ .orElse((List) HgStoreClientConst.EMPTY_LIST);
}
@Override
public HgKvIterator batchPrefix(String table, List keyList) {
return GrpcKvIteratorImpl.of(this,
this.storeStreamClient.doBatchScanOneShot(this,
- HgScanQuery.prefixOf(table,
- keyList))
- );
+ HgScanQuery.prefixOf(
+ table,
+ keyList))
+ );
}
@Override
public boolean existsTable(String table) {
return this.notifier.invoke(
- () -> this.storeSessionClient.doTable(this, table, TableMethod.TABLE_METHOD_EXISTS),
+ () -> this.storeSessionClient.doTable(this, table,
+ TableMethod.TABLE_METHOD_EXISTS),
e -> true)
.orElse(false);
}
@@ -296,7 +294,8 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
@Override
public boolean createTable(String table) {
return this.notifier.invoke(
- () -> this.storeSessionClient.doTable(this, table, TableMethod.TABLE_METHOD_CREATE),
+ () -> this.storeSessionClient.doTable(this, table,
+ TableMethod.TABLE_METHOD_CREATE),
e -> true)
.orElse(false);
}
@@ -304,7 +303,8 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
@Override
public boolean deleteTable(String table) {
return this.notifier.invoke(
- () -> this.storeSessionClient.doTable(this, table, TableMethod.TABLE_METHOD_DELETE),
+ () -> this.storeSessionClient.doTable(this, table,
+ TableMethod.TABLE_METHOD_DELETE),
e -> true)
.orElse(false);
}
@@ -312,7 +312,8 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
@Override
public boolean dropTable(String table) {
return this.notifier.invoke(
- () -> this.storeSessionClient.doTable(this, table, TableMethod.TABLE_METHOD_DROP),
+ () -> this.storeSessionClient.doTable(this, table,
+ TableMethod.TABLE_METHOD_DROP),
e -> true)
.orElse(false);
}
@@ -320,7 +321,8 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
@Override
public boolean deleteGraph(String graph) {
return this.notifier.invoke(
- () -> this.storeSessionClient.doGraph(this, graph, GraphMethod.GRAPH_METHOD_DELETE),
+ () -> this.storeSessionClient.doGraph(this, graph,
+ GraphMethod.GRAPH_METHOD_DELETE),
e -> true)
.orElse(false);
}
@@ -328,7 +330,8 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
@Override
public boolean truncate() {
return this.notifier.invoke(
- () -> this.storeSessionClient.doTable(this, EMPTY_TABLE
+ () -> this.storeSessionClient.doTable(this,
+ HgStoreClientConst.EMPTY_TABLE
, TableMethod.TABLE_METHOD_TRUNCATE),
e -> true)
.orElse(false);
@@ -343,11 +346,14 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
public HgKvIterator scanIterator(String table, long limit) {
return this.switcher.invoke(getSwitcherSupplier(limit)
, () -> GrpcKvIteratorImpl.of(this, this.storeStreamClient.doScan
- (this, table, limit))
+ (this, table,
+ limit))
, () -> GrpcKvIteratorImpl.of(this, this.storeStreamClient.doScanOneShot
- (this, table, limit))
- ).get();
+ (this, table,
+ limit))
+ ).get();
}
+
@Override
public HgKvIterator scanIterator(ScanStreamReq.Builder builder) {
HgStoreStreamStub stub = getStub();
@@ -379,15 +385,18 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
public HgKvIterator scanIterator(String table, long limit, byte[] query) {
return this.switcher.invoke(getSwitcherSupplier(limit)
, () -> GrpcKvIteratorImpl.of(this, this.storeStreamClient.doScan
- (this, table, limit, query))
+ (this, table,
+ limit, query))
, () -> GrpcKvIteratorImpl.of(this, this.storeStreamClient.doScanOneShot
- (this, table, limit, query))
- ).get();
+ (this, table,
+ limit, query))
+ ).get();
}
@Override
public HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix) {
- return GrpcKvIteratorImpl.of(this, this.storeStreamClient.doScan(this, table, keyPrefix, 0));
+ return GrpcKvIteratorImpl.of(this,
+ this.storeStreamClient.doScan(this, table, keyPrefix, 0));
}
@Override
@@ -399,103 +408,119 @@ class GrpcStoreNodeSessionImpl implements HgStoreNodeSession {
keyPrefix,
limit)),
() -> GrpcKvIteratorImpl.of(this,
- this.storeStreamClient.doScanOneShot(this,
- table,
- keyPrefix,
- limit)))
+ this.storeStreamClient.doScanOneShot(
+ this,
+ table,
+ keyPrefix,
+ limit)))
.get();
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix, long limit, byte[] query) {
+ public HgKvIterator scanIterator(String table, HgOwnerKey keyPrefix, long limit,
+ byte[] query) {
return this.switcher.invoke(getSwitcherSupplier(limit),
() -> GrpcKvIteratorImpl.of(this,
this.storeStreamClient.doScan(
- this,
- table,
- keyPrefix,
- limit,
- query)),
+ this,
+ table,
+ keyPrefix,
+ limit,
+ query)),
() -> GrpcKvIteratorImpl.of(this,
- this.storeStreamClient.doScanOneShot(this,
- table,
- keyPrefix,
- limit,
- query)))
+ this.storeStreamClient.doScanOneShot(
+ this,
+ table,
+ keyPrefix,
+ limit,
+ query)))
.get();
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey) {
+ public HgKvIterator scanIterator(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey) {
return scanIterator(table, startKey, endKey, 0, HgKvStore.SCAN_ANY, null);
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey, long limit) {
- return scanIterator(table, startKey, endKey, limit, isValid(endKey) ? SCAN_TYPE_RANGE : SCAN_TYPE_ANY, null);
+ public HgKvIterator scanIterator(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey, long limit) {
+ return scanIterator(table, startKey, endKey, limit,
+ HgStoreClientUtil.isValid(endKey) ? HgStoreClientConst.SCAN_TYPE_RANGE :
+ HgStoreClientConst.SCAN_TYPE_ANY, null);
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey, long limit, byte[] query) {
- return scanIterator(table, startKey, endKey, limit, isValid(endKey) ? SCAN_TYPE_RANGE : SCAN_TYPE_ANY, query);
+ public HgKvIterator scanIterator(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey, long limit, byte[] query) {
+ return scanIterator(table, startKey, endKey, limit,
+ HgStoreClientUtil.isValid(endKey) ? HgStoreClientConst.SCAN_TYPE_RANGE :
+ HgStoreClientConst.SCAN_TYPE_ANY, query);
}
@Override
- public HgKvIterator scanIterator(String table, HgOwnerKey startKey, HgOwnerKey endKey,
+ public HgKvIterator scanIterator(String table, HgOwnerKey startKey,
+ HgOwnerKey endKey,
long limit, int scanType, byte[] query) {
return this.switcher.invoke(getSwitcherSupplier(limit),
() -> GrpcKvIteratorImpl.of(this,
this.storeStreamClient.doScan(
- this,
- table,
- startKey,
- endKey,
- limit,
- scanType,
- query)),
+ this,
+ table,
+ startKey,
+ endKey,
+ limit,
+ scanType,
+ query)),
() -> GrpcKvIteratorImpl.of(this,
- this.storeStreamClient.doScanOneShot(this,
- table,
- startKey,
- endKey,
- limit,
- scanType,
- query)))
+ this.storeStreamClient.doScanOneShot(
+ this,
+ table,
+ startKey,
+ endKey,
+ limit,
+ scanType,
+ query)))
.get();
}
@Override
- public HgKvIterator scanIterator(String table, int codeFrom, int codeTo, int scanType, byte[] query) {
+ public HgKvIterator scanIterator(String table, int codeFrom, int codeTo,
+ int scanType, byte[] query) {
//TODO: Should be changed when start using hashcode as partitionId.
- if(log.isDebugEnabled())log.debug("scanIterator-scanType: {}", scanType);
+ if (log.isDebugEnabled()) log.debug("scanIterator-scanType: {}", scanType);
return GrpcKvIteratorImpl.of(this,
this.storeStreamClient.doScan(this, table
, HgOwnerKey.newEmpty().codeToKey(codeFrom)
, HgOwnerKey.newEmpty().codeToKey(codeTo)
, HgStoreClientConst.NO_LIMIT
- , SCAN_PREFIX_BEGIN | SCAN_HASHCODE | scanType
+ , HgKvStore.SCAN_PREFIX_BEGIN |
+ HgKvStore.SCAN_HASHCODE | scanType
, query
- )
- );
+ )
+ );
}
@Override
public List> scanBatch(HgScanQuery scanQuery) {
return Collections.singletonList(GrpcKvIteratorImpl.of(this,
- this.storeStreamClient.doBatchScan(this, scanQuery)
- ));
+ this.storeStreamClient.doBatchScan(
+ this, scanQuery)
+ ));
}
@Override
public KvCloseableIterator> scanBatch2(HgScanQuery scanQuery) {
- throw new RuntimeException("not implemented");
+ throw new RuntimeException("not implemented");
}
@Override
- public KvCloseableIterator> scanBatch3(HgScanQuery scanQuery, KvCloseableIterator iterator) {
+ public KvCloseableIterator> scanBatch3(HgScanQuery scanQuery,
+ KvCloseableIterator iterator) {
return this.storeStreamClient.doBatchScan3(this, scanQuery, iterator);
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreSessionClient.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreSessionClient.java
similarity index 65%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreSessionClient.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreSessionClient.java
index 205a8a4a8..5f67bee78 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreSessionClient.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreSessionClient.java
@@ -1,15 +1,29 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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.
+ */
-import static com.baidu.hugegraph.store.client.grpc.GrpcUtil.getHeader;
-import static com.baidu.hugegraph.store.client.grpc.GrpcUtil.toKey;
-import static com.baidu.hugegraph.store.client.grpc.GrpcUtil.toTk;
+package org.apache.hugegraph.store.client.grpc;
import java.util.List;
import javax.annotation.concurrent.ThreadSafe;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
+
import com.baidu.hugegraph.store.grpc.common.GraphMethod;
import com.baidu.hugegraph.store.grpc.common.TableMethod;
import com.baidu.hugegraph.store.grpc.session.BatchEntry;
@@ -44,21 +58,26 @@ class GrpcStoreSessionClient extends AbstractGrpcClient {
private HgStoreSessionBlockingStub getBlockingStub(HgStoreNodeSession nodeSession) {
HgStoreSessionBlockingStub stub =
- (HgStoreSessionBlockingStub) getBlockingStub(nodeSession.getStoreNode().getAddress());
+ (HgStoreSessionBlockingStub) getBlockingStub(
+ nodeSession.getStoreNode().getAddress());
return stub;
}
FeedbackRes doGet(HgStoreNodeSession nodeSession, String table, HgOwnerKey ownerKey) {
if (log.isDebugEnabled()) {
log.debug("doGet: {}-{}-{}-{}", nodeSession, table, ownerKey, GetReq.newBuilder()
- .setHeader(getHeader(nodeSession))
- .setTk(toTk(table, ownerKey))
+ .setHeader(
+ GrpcUtil.getHeader(
+ nodeSession))
+ .setTk(GrpcUtil.toTk(
+ table,
+ ownerKey))
.build());
}
return this.getBlockingStub(nodeSession)
.get2(GetReq.newBuilder()
- .setHeader(getHeader(nodeSession))
- .setTk(toTk(table, ownerKey))
+ .setHeader(GrpcUtil.getHeader(nodeSession))
+ .setTk(GrpcUtil.toTk(table, ownerKey))
.build()
);
}
@@ -66,7 +85,7 @@ class GrpcStoreSessionClient extends AbstractGrpcClient {
FeedbackRes doClean(HgStoreNodeSession nodeSession, int partId) {
return this.getBlockingStub(nodeSession)
.clean(CleanReq.newBuilder()
- .setHeader(getHeader(nodeSession))
+ .setHeader(GrpcUtil.getHeader(nodeSession))
.setPartition(partId)
.build()
);
@@ -74,10 +93,10 @@ class GrpcStoreSessionClient extends AbstractGrpcClient {
FeedbackRes doBatchGet(HgStoreNodeSession nodeSession, String table, List keyList) {
BatchGetReq.Builder builder = BatchGetReq.newBuilder();
- builder.setHeader(getHeader(nodeSession)).setTable(table);
+ builder.setHeader(GrpcUtil.getHeader(nodeSession)).setTable(table);
for (HgOwnerKey key : keyList) {
- builder.addKey(toKey(key));
+ builder.addKey(GrpcUtil.toKey(key));
}
if (log.isDebugEnabled()) {
@@ -92,7 +111,7 @@ class GrpcStoreSessionClient extends AbstractGrpcClient {
writeReq.addAllEntry(entries);
return this.getBlockingStub(nodeSession)
.batch(BatchReq.newBuilder()
- .setHeader(getHeader(nodeSession))
+ .setHeader(GrpcUtil.getHeader(nodeSession))
.setWriteReq(writeReq)
.setBatchId(batchId)
.build()
@@ -102,7 +121,7 @@ class GrpcStoreSessionClient extends AbstractGrpcClient {
FeedbackRes doTable(HgStoreNodeSession nodeSession, String table, TableMethod method) {
return this.getBlockingStub(nodeSession)
.table(TableReq.newBuilder()
- .setHeader(getHeader(nodeSession))
+ .setHeader(GrpcUtil.getHeader(nodeSession))
.setTableName(table)
.setMethod(method)
.build()
@@ -112,7 +131,7 @@ class GrpcStoreSessionClient extends AbstractGrpcClient {
FeedbackRes doGraph(HgStoreNodeSession nodeSession, String graph, GraphMethod method) {
return this.getBlockingStub(nodeSession)
.graph(GraphReq.newBuilder()
- .setHeader(getHeader(nodeSession))
+ .setHeader(GrpcUtil.getHeader(nodeSession))
.setGraphName(graph)
.setMethod(method)
.build()
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreStateClient.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreStateClient.java
similarity index 68%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreStateClient.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreStateClient.java
index 408ea169e..79368eb8d 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreStateClient.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreStateClient.java
@@ -1,4 +1,21 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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 org.apache.hugegraph.store.client.grpc;
import java.util.List;
import java.util.Set;
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreStreamClient.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreStreamClient.java
similarity index 81%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreStreamClient.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreStreamClient.java
index e4a0b7ed4..0a3028114 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcStoreStreamClient.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcStoreStreamClient.java
@@ -15,19 +15,19 @@
* under the License.
*/
-package com.baidu.hugegraph.store.client.grpc;
+package org.apache.hugegraph.store.client.grpc;
import javax.annotation.concurrent.ThreadSafe;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc;
import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc.HgStoreStreamBlockingStub;
import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc.HgStoreStreamStub;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
import com.baidu.hugegraph.store.grpc.common.Kv;
import io.grpc.ManagedChannel;
@@ -48,7 +48,7 @@ public class GrpcStoreStreamClient extends AbstractGrpcClient {
}
@Override
- public AbstractAsyncStub getAsyncStub(ManagedChannel channel){
+ public AbstractAsyncStub getAsyncStub(ManagedChannel channel) {
return HgStoreStreamGrpc.newStub(channel);
}
@@ -58,10 +58,11 @@ public class GrpcStoreStreamClient extends AbstractGrpcClient {
@Override
public AbstractBlockingStub getBlockingStub(ManagedChannel channel) {
- return HgStoreStreamGrpc.newBlockingStub(channel);
+ return HgStoreStreamGrpc.newBlockingStub(channel);
}
- KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table, long limit, byte[] query) {
+ KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table, long limit,
+ byte[] query) {
return KvOneShotScanner.scanAll(nodeSession
, this.getBlockingStub(nodeSession)
, table
@@ -70,7 +71,8 @@ public class GrpcStoreStreamClient extends AbstractGrpcClient {
);
}
- KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table, long limit) {
+ KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table,
+ long limit) {
return KvOneShotScanner.scanAll(nodeSession
, this.getBlockingStub(nodeSession)
, table
@@ -79,7 +81,8 @@ public class GrpcStoreStreamClient extends AbstractGrpcClient {
);
}
- KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table, HgOwnerKey prefix, long limit) {
+ KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table,
+ HgOwnerKey prefix, long limit) {
return KvOneShotScanner.scanPrefix(nodeSession
, this.getBlockingStub(nodeSession)
, table
@@ -89,7 +92,8 @@ public class GrpcStoreStreamClient extends AbstractGrpcClient {
);
}
- KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table, HgOwnerKey prefix, long limit,
+ KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table,
+ HgOwnerKey prefix, long limit,
byte[] query) {
return KvOneShotScanner.scanPrefix(nodeSession
, this.getBlockingStub(nodeSession)
@@ -100,7 +104,8 @@ public class GrpcStoreStreamClient extends AbstractGrpcClient {
);
}
- KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table, HgOwnerKey startKey,
+ KvCloseableIterator doScanOneShot(HgStoreNodeSession nodeSession, String table,
+ HgOwnerKey startKey,
HgOwnerKey endKey
, long limit
, int scanType
@@ -198,13 +203,17 @@ public class GrpcStoreStreamClient extends AbstractGrpcClient {
// 返回多个小的迭代器,允许上层并行处理
KvCloseableIterator> doBatchScan3(HgStoreNodeSession nodeSession,
- HgScanQuery scanQuery, KvCloseableIterator iterator) {
- KvBatchScanner.scan(this.getStub(nodeSession), nodeSession.getGraphName(), scanQuery, iterator);
+ HgScanQuery scanQuery,
+ KvCloseableIterator iterator) {
+ KvBatchScanner.scan(this.getStub(nodeSession), nodeSession.getGraphName(), scanQuery,
+ iterator);
return iterator;
}
- KvCloseableIterator doBatchScanOneShot(HgStoreNodeSession nodeSession, HgScanQuery scanQuery) {
- return KvBatchOneShotScanner.scan(nodeSession, this.getBlockingStub(nodeSession), scanQuery);
+ KvCloseableIterator doBatchScanOneShot(HgStoreNodeSession nodeSession,
+ HgScanQuery scanQuery) {
+ return KvBatchOneShotScanner.scan(nodeSession, this.getBlockingStub(nodeSession),
+ scanQuery);
}
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcUtil.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcUtil.java
similarity index 53%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcUtil.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcUtil.java
index d2fa13338..d93b937ac 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/GrpcUtil.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcUtil.java
@@ -1,15 +1,31 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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.
+ */
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_BYTES;
+package org.apache.hugegraph.store.client.grpc;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
+
import com.baidu.hugegraph.store.grpc.common.Header;
import com.baidu.hugegraph.store.grpc.common.Key;
import com.baidu.hugegraph.store.grpc.common.Kv;
@@ -27,20 +43,20 @@ import io.grpc.StatusRuntimeException;
*/
final class GrpcUtil {
- private static ThreadLocal keyBuilder = new ThreadLocal();
+ private static final ThreadLocal keyBuilder = new ThreadLocal();
static Header getHeader(HgStoreNodeSession nodeSession) {
return Header.newBuilder()
- .setGraph(nodeSession.getGraphName())
- .build();
+ .setGraph(nodeSession.getGraphName())
+ .build();
}
static Tk toTk(String table, HgOwnerKey ownerKey) {
return Tk.newBuilder()
- .setTable(table)
- .setKey(ByteString.copyFrom(ownerKey.getKey()))
- .setCode(ownerKey.getKeyCode())
- .build();
+ .setTable(table)
+ .setKey(ByteString.copyFrom(ownerKey.getKey()))
+ .setCode(ownerKey.getKeyCode())
+ .build();
}
static Key.Builder getOwnerKeyBuilder() {
@@ -82,27 +98,27 @@ final class GrpcUtil {
static Tkv toTkv(String table, HgOwnerKey ownerKey, byte[] value) {
return Tkv.newBuilder()
- .setTable(table)
- .setKey(ByteString.copyFrom(ownerKey.getKey()))
- .setValue(ByteString.copyFrom(value))
- .setCode(ownerKey.getKeyCode())
- .build();
+ .setTable(table)
+ .setKey(ByteString.copyFrom(ownerKey.getKey()))
+ .setValue(ByteString.copyFrom(value))
+ .setCode(ownerKey.getKeyCode())
+ .build();
}
static Tp toTp(String table, HgOwnerKey ownerKey) {
return Tp.newBuilder()
- .setTable(table)
- .setPrefix(ByteString.copyFrom(ownerKey.getKey()))
- .setCode(ownerKey.getKeyCode())
- .build();
+ .setTable(table)
+ .setPrefix(ByteString.copyFrom(ownerKey.getKey()))
+ .setCode(ownerKey.getKeyCode())
+ .build();
}
static Tse toTse(String table, HgOwnerKey startKey, HgOwnerKey endKey) {
return Tse.newBuilder()
- .setTable(table)
- .setStart(toKey(startKey))
- .setEnd(toKey(endKey))
- .build();
+ .setTable(table)
+ .setStart(toKey(startKey))
+ .setEnd(toKey(endKey))
+ .build();
}
@@ -116,17 +132,18 @@ final class GrpcUtil {
while (iter.hasNext()) {
Kv entry = iter.next();
- resList.add(new GrpcKvEntryImpl(entry.getKey().toByteArray(), entry.getValue().toByteArray(),entry.getCode()));
+ resList.add(new GrpcKvEntryImpl(entry.getKey().toByteArray(),
+ entry.getValue().toByteArray(), entry.getCode()));
}
return resList;
}
- static StatusRuntimeException toErr(String msg){
+ static StatusRuntimeException toErr(String msg) {
return new StatusRuntimeException(Status.UNKNOWN.withDescription(msg));
}
- static ByteString toBs(byte[] bytes){
- return ByteString.copyFrom((bytes != null) ? bytes : EMPTY_BYTES);
+ static ByteString toBs(byte[] bytes) {
+ return ByteString.copyFrom((bytes != null) ? bytes : HgStoreClientConst.EMPTY_BYTES);
}
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchOneShotScanner.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchOneShotScanner.java
similarity index 77%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchOneShotScanner.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchOneShotScanner.java
index a4c02b5ef..aae557cfb 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchOneShotScanner.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchOneShotScanner.java
@@ -15,23 +15,23 @@
* under the License.
*/
-package com.baidu.hugegraph.store.client.grpc;
+package org.apache.hugegraph.store.client.grpc;
-import static com.baidu.hugegraph.store.client.grpc.KvBatchUtil.EMPTY_POSITION;
-import static com.baidu.hugegraph.store.client.grpc.KvBatchUtil.createQueryReq;
-import static com.baidu.hugegraph.store.client.grpc.KvBatchUtil.getHeader;
+import static org.apache.hugegraph.store.client.grpc.KvBatchUtil.EMPTY_POSITION;
+import static org.apache.hugegraph.store.client.grpc.KvBatchUtil.createQueryReq;
+import static org.apache.hugegraph.store.client.grpc.KvBatchUtil.getHeader;
import java.util.Iterator;
import java.util.List;
import javax.annotation.concurrent.NotThreadSafe;
+import org.apache.hugegraph.store.HgPageSize;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.HgSeekAble;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc;
-import com.baidu.hugegraph.store.HgPageSize;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.HgSeekAble;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
import com.baidu.hugegraph.store.grpc.common.Kv;
import com.baidu.hugegraph.store.grpc.stream.ScanStreamBatchReq;
@@ -68,9 +68,9 @@ class KvBatchOneShotScanner implements KvCloseableIterator, HgPageSize, HgSe
private ScanStreamBatchReq createReq() {
return ScanStreamBatchReq.newBuilder()
- .setHeader(getHeader(this.nodeSession))
- .setQueryRequest(createQueryReq(this.scanQuery, Integer.MAX_VALUE))
- .build();
+ .setHeader(getHeader(this.nodeSession))
+ .setQueryRequest(createQueryReq(this.scanQuery, Integer.MAX_VALUE))
+ .build();
}
private Iterator createIterator() {
@@ -82,7 +82,7 @@ class KvBatchOneShotScanner implements KvCloseableIterator, HgPageSize, HgSe
@Override
public boolean hasNext() {
if (this.iterator == null) {
- this.iterator =this.createIterator();
+ this.iterator = this.createIterator();
}
return this.iterator.hasNext();
}
@@ -90,7 +90,7 @@ class KvBatchOneShotScanner implements KvCloseableIterator, HgPageSize, HgSe
@Override
public Kv next() {
if (this.iterator == null) {
- this.iterator =this.createIterator();
+ this.iterator = this.createIterator();
}
return this.iterator.next();
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScanner.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScanner.java
similarity index 79%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScanner.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScanner.java
index ad898a381..a6c31cba0 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScanner.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScanner.java
@@ -15,9 +15,9 @@
* under the License.
*/
-package com.baidu.hugegraph.store.client.grpc;
+package org.apache.hugegraph.store.client.grpc;
-import static com.baidu.hugegraph.store.client.grpc.KvBatchUtil.createQueryReq;
+import static org.apache.hugegraph.store.client.grpc.KvBatchUtil.createQueryReq;
import java.io.Closeable;
import java.nio.ByteBuffer;
@@ -29,16 +29,16 @@ import java.util.function.Supplier;
import javax.annotation.concurrent.NotThreadSafe;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvOrderedIterator;
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.buffer.KVByteBuffer;
+import org.apache.hugegraph.store.client.util.PropertyUtil;
import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc;
import org.apache.hugegraph.store.grpc.stream.KvStream;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvOrderedIterator;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.buffer.KVByteBuffer;
-import com.baidu.hugegraph.store.client.util.PropertyUtil;
import com.baidu.hugegraph.store.grpc.common.Header;
import com.baidu.hugegraph.store.grpc.common.ScanOrderType;
import com.baidu.hugegraph.store.grpc.stream.ScanReceiptRequest;
@@ -66,20 +66,21 @@ public class KvBatchScanner implements Closeable {
private final HgScanQuery scanQuery;
static final Supplier> NO_DATA = () -> null;
private final ScanReceiptRequest.Builder responseBuilder = ScanReceiptRequest.newBuilder();
- private KvBatchReceiver receiver;
+ private final KvBatchReceiver receiver;
public KvBatchScanner(
- HgStoreStreamGrpc.HgStoreStreamStub stub,
- String graphName,
- HgScanQuery scanQuery,
- KvCloseableIterator iterator) {
+ HgStoreStreamGrpc.HgStoreStreamStub stub,
+ String graphName,
+ HgScanQuery scanQuery,
+ KvCloseableIterator iterator) {
this.graphName = graphName;
this.notifier = (KvBatchScannerMerger) iterator;
this.notifier.registerScanner(this);
this.running = true;
this.scanQuery = scanQuery;
- receiver = new KvBatchReceiver(this, scanQuery.getOrderType() == ScanOrderType.ORDER_STRICT);
+ receiver =
+ new KvBatchReceiver(this, scanQuery.getOrderType() == ScanOrderType.ORDER_STRICT);
sender = stub.scanBatch2(receiver);
sendQuery(this.scanQuery); // 发送查询请求
}
@@ -93,10 +94,11 @@ public class KvBatchScanner implements Closeable {
* @return data merger iterator
*/
public static KvCloseableIterator ofMerger(
- HgScanQuery scanQuery, BiFunction handler) {
+ HgScanQuery scanQuery, BiFunction handler) {
KvBatchScannerMerger merger;
if (scanQuery.getOrderType() == ScanOrderType.ORDER_STRICT) {
- merger = new KvBatchScannerMerger.SortedScannerMerger(new TaskSplitter(scanQuery, handler));
+ merger = new KvBatchScannerMerger.SortedScannerMerger(
+ new TaskSplitter(scanQuery, handler));
} else {
merger = new KvBatchScannerMerger(new TaskSplitter(scanQuery, handler));
}
@@ -105,10 +107,10 @@ public class KvBatchScanner implements Closeable {
}
public static void scan(
- HgStoreStreamGrpc.HgStoreStreamStub stub,
- String graphName,
- HgScanQuery scanQuery,
- KvCloseableIterator iterator) {
+ HgStoreStreamGrpc.HgStoreStreamStub stub,
+ String graphName,
+ HgScanQuery scanQuery,
+ KvCloseableIterator iterator) {
new KvBatchScanner(stub, graphName, scanQuery, iterator);
}
@@ -121,10 +123,11 @@ public class KvBatchScanner implements Closeable {
synchronized (this.sender) {
if (running) {
this.sender.onNext(
- ScanStreamBatchReq.newBuilder()
- .setHeader(Header.newBuilder().setGraph(graphName).build())
- .setQueryRequest(createQueryReq(query, 0))
- .build());
+ ScanStreamBatchReq.newBuilder()
+ .setHeader(
+ Header.newBuilder().setGraph(graphName).build())
+ .setQueryRequest(createQueryReq(query, 0))
+ .build());
}
}
}
@@ -145,15 +148,18 @@ public class KvBatchScanner implements Closeable {
synchronized (this.sender) {
if (running) {
this.sender.onNext(
- ScanStreamBatchReq.newBuilder()
- .setHeader(Header.newBuilder().setGraph(graphName).build())
- .setReceiptRequest(responseBuilder.setTimes(seqNo).build())
- .build());
+ ScanStreamBatchReq.newBuilder()
+ .setHeader(
+ Header.newBuilder().setGraph(graphName).build())
+ .setReceiptRequest(
+ responseBuilder.setTimes(seqNo).build())
+ .build());
}
}
}
- public void dataArrived(Supplier> supplier) throws InterruptedException {
+ public void dataArrived(Supplier> supplier) throws
+ InterruptedException {
notifier.dataArrived(this, supplier);
}
@@ -194,12 +200,14 @@ public class KvBatchScanner implements Closeable {
private KvBatchScannerMerger notifier;
private Iterator prefixItr;
private int maxTaskSize = 0; // 最大并行任务数
- private int maxBatchSize = PropertyUtil.getInt("net.kv.scanner.batch.size", 1000); // 每批次最大点数量
+ private int maxBatchSize = PropertyUtil.getInt("net.kv.scanner.batch.size", 1000);
+ // 每批次最大点数量
private volatile boolean finished = false;
private volatile boolean splitting = false;
private volatile int nextKeySerialNo = 1;
- public TaskSplitter(HgScanQuery scanQuery, BiFunction handler) {
+ public TaskSplitter(HgScanQuery scanQuery,
+ BiFunction handler) {
this.scanQuery = scanQuery;
this.taskHandler = handler;
if (scanQuery.getScanMethod() == HgScanQuery.ScanMethod.PREFIX) {
@@ -253,13 +261,15 @@ public class KvBatchScanner implements Closeable {
}
this.splitting = true;
if (scanQuery.getScanMethod() == HgScanQuery.ScanMethod.PREFIX) {
- if (prefixItr.hasNext() && (maxTaskSize == 0 || notifier.getScannerCount() < maxTaskSize)) {
+ if (prefixItr.hasNext() &&
+ (maxTaskSize == 0 || notifier.getScannerCount() < maxTaskSize)) {
List keys = new ArrayList<>(maxBatchSize);
for (int i = 0; i < maxBatchSize && prefixItr.hasNext(); i++) {
keys.add(prefixItr.next().setSerialNo(nextKeySerialNo++));
}
taskHandler.apply(
- HgScanQuery.prefixOf(scanQuery.getTable(), keys, scanQuery.getOrderType()), this.notifier);
+ HgScanQuery.prefixOf(scanQuery.getTable(), keys,
+ scanQuery.getOrderType()), this.notifier);
// 评估最大任务数
evaluateMaxTaskSize();
if (this.notifier.getScannerCount() < this.maxTaskSize) {
@@ -299,13 +309,13 @@ public class KvBatchScanner implements Closeable {
int seqNo = value.getSeqNo();
boolean isOver = value.getOver();
scanner.dataArrived(
- () -> {
- scanner.sendResponse(seqNo);
- if (isOver) {
- scanner.dataComplete();
- }
- return new KVBytesIterator(buffer, sortByVertex, scanner);
- });
+ () -> {
+ scanner.sendResponse(seqNo);
+ if (isOver) {
+ scanner.dataComplete();
+ }
+ return new KVBytesIterator(buffer, sortByVertex, scanner);
+ });
} catch (InterruptedException e) {
close();
log.error("exception ", e);
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScanner5.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScanner5.java
similarity index 82%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScanner5.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScanner5.java
index 7491601a4..57ef6a76e 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScanner5.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScanner5.java
@@ -15,10 +15,7 @@
* under the License.
*/
-package com.baidu.hugegraph.store.client.grpc;
-
-import static com.baidu.hugegraph.store.client.grpc.KvBatchUtil.createQueryReq;
-import static com.baidu.hugegraph.store.client.grpc.KvBatchUtil.getRequestBuilder;
+package org.apache.hugegraph.store.client.grpc;
import java.util.Iterator;
import java.util.List;
@@ -34,14 +31,14 @@ import java.util.function.Supplier;
import javax.annotation.concurrent.NotThreadSafe;
+import org.apache.hugegraph.store.HgPageSize;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
+import org.apache.hugegraph.store.client.type.HgStoreClientException;
+import org.apache.hugegraph.store.client.util.Base58;
+import org.apache.hugegraph.store.client.util.HgStoreClientConfig;
import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc;
-import com.baidu.hugegraph.store.HgPageSize;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
-import com.baidu.hugegraph.store.client.type.HgStoreClientException;
-import com.baidu.hugegraph.store.client.util.Base58;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConfig;
import com.baidu.hugegraph.store.grpc.common.Kv;
import com.baidu.hugegraph.store.grpc.stream.*;
@@ -56,7 +53,8 @@ import lombok.extern.slf4j.Slf4j;
@NotThreadSafe
class KvBatchScanner5 {
private final static HgStoreClientConfig storeClientConfig = HgStoreClientConfig.of();
- //private final static int HAVE_NEXT_TIMEOUT_SECONDS = storeClientConfig.getNetKvScannerHaveNextTimeout();
+ //private final static int HAVE_NEXT_TIMEOUT_SECONDS = storeClientConfig
+ // .getNetKvScannerHaveNextTimeout();
private final static int HAVE_NEXT_TIMEOUT_SECONDS = 60;
private final static long PAGE_SIZE = storeClientConfig.getNetKvScannerPageSize();
@@ -87,7 +85,8 @@ class KvBatchScanner5 {
private final AtomicBoolean serverFinished = new AtomicBoolean();
private final AtomicBoolean clientFinished = new AtomicBoolean();
- private final ScanReceiptRequest.Builder receiptReqBuilder = ScanReceiptRequest.newBuilder();
+ private final ScanReceiptRequest.Builder receiptReqBuilder =
+ ScanReceiptRequest.newBuilder();
private final ScanCancelRequest cancelReq = ScanCancelRequest.newBuilder().build();
private final HgStoreNodeSession nodeSession;
private final OrderAgent agent;
@@ -105,20 +104,22 @@ class KvBatchScanner5 {
HgScanQuery scanQuery,
HgStoreNodeSession nodeSession) {
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
if (scanQuery.getPrefixList() != null && scanQuery.getPrefixList().size() > 0) {
brokerId = Base58.encode(scanQuery.getPrefixList().get(0).getKey());
- log.debug("[ANALYSIS START] [{}] firstKey: {}, keyLength: {}, table: {}, node: {}"
+ log.debug(
+ "[ANALYSIS START] [{}] firstKey: {}, keyLength: {}, table: {}, node: {}"
, brokerId
, scanQuery.getPrefixList().get(0)
, scanQuery.getPrefixList().size()
, scanQuery.getTable()
, nodeSession.getStoreNode().getAddress());
}
+ }
this.scanQuery = scanQuery;
- this.reqBuilder = getRequestBuilder(nodeSession);
+ this.reqBuilder = KvBatchUtil.getRequestBuilder(nodeSession);
this.nodeSession = nodeSession;
this.agent = new OrderAgent(brokerId);
this.requestObserver = stub.scanBatch(agent);
@@ -157,33 +158,39 @@ class KvBatchScanner5 {
if (!this.clientFinished.get()) {
this.send(() ->
- getReqBuilder().setReceiptRequest(this.receiptReqBuilder.setTimes(timesBuf.get()).build()).build()
+ getReqBuilder().setReceiptRequest(
+ this.receiptReqBuilder.setTimes(timesBuf.get()).build())
+ .build()
);
}
}
private void makeADeal() {
this.send(() -> getReqBuilder()
- .setQueryRequest(createQueryReq(scanQuery, PAGE_SIZE)).build()
+ .setQueryRequest(KvBatchUtil.createQueryReq(scanQuery, PAGE_SIZE)).build()
);
}
private void finish(long tookAmt) {
this.clientFinished.set(true);
- if (log.isDebugEnabled()) log.debug("[ANALYSIS END] [{}] times: {}, received: {}, took: {}"
- , this.brokerId
- , this.receivedLastTimes.get()
- , this.receivedCount.get()
- , tookAmt
- );
- if (this.receivedCount.get() != tookAmt) {
- if (log.isDebugEnabled()) log.debug("[ANALYSIS END] [{}] times: {}, received: {}, took: {}"
+ if (log.isDebugEnabled()) {
+ log.debug("[ANALYSIS END] [{}] times: {}, received: {}, took: {}"
, this.brokerId
, this.receivedLastTimes.get()
, this.receivedCount.get()
, tookAmt
);
}
+ if (this.receivedCount.get() != tookAmt) {
+ if (log.isDebugEnabled()) {
+ log.debug("[ANALYSIS END] [{}] times: {}, received: {}, took: {}"
+ , this.brokerId
+ , this.receivedLastTimes.get()
+ , this.receivedCount.get()
+ , tookAmt
+ );
+ }
+ }
synchronized (this.state) {
if (this.state.value < OrderState.COMPLETED.value) {
this.send(() -> getReqBuilder().setCancelRequest(this.cancelReq).build());
@@ -199,7 +206,7 @@ class KvBatchScanner5 {
private void send(Supplier supplier) {
this.senderLock.lock();
try {
- if (this.serverFinished.get() == false) {
+ if (!this.serverFinished.get()) {
this.requestObserver.onNext(supplier.get());
}
Thread.yield();
@@ -210,7 +217,7 @@ class KvBatchScanner5 {
private class OrderAgent implements StreamObserver {
private final AtomicInteger count = new AtomicInteger(0);
- private AtomicBoolean over = new AtomicBoolean(false);
+ private final AtomicBoolean over = new AtomicBoolean(false);
private final String agentId;
OrderAgent(String agentId) {
@@ -221,7 +228,8 @@ class KvBatchScanner5 {
public void onNext(KvPageRes value) {
if (log.isDebugEnabled()) {
log.debug("Scan [ {} ] [ {} ] times, received: [ {} ]"
- , nodeSession.getStoreNode().getAddress(), value.getTimes(), value.getDataList().size());
+ , nodeSession.getStoreNode().getAddress(), value.getTimes(),
+ value.getDataList().size());
}
serverFinished.set(value.getOver());
@@ -298,7 +306,9 @@ class KvBatchScanner5 {
if (this.done.get()) {
res = () -> null;
} else {
- throw HgStoreClientException.of("Timeout, max time: " + HAVE_NEXT_TIMEOUT_SECONDS + " seconds" +
+ throw HgStoreClientException.of(
+ "Timeout, max time: " + HAVE_NEXT_TIMEOUT_SECONDS +
+ " seconds" +
", isOver: " + this.done.get() +
", isStop: " + this.stop.get() +
", last-times: " + this.lastTimes +
@@ -308,12 +318,15 @@ class KvBatchScanner5 {
}
} catch (InterruptedException e) {
- log.error("Failed to receive List from queue because of interruption of current thread ["
+ log.error(
+ "Failed to receive List from queue because of interruption of " +
+ "current thread ["
+ Thread.currentThread().getName() + "]");
Thread.currentThread().interrupt();
- throw HgStoreClientException.of("Failed to receive List from queue, cause by:", e);
+ throw HgStoreClientException.of(
+ "Failed to receive List from queue, cause by:", e);
} finally {
pickUpLock.unlock();
}
@@ -347,7 +360,7 @@ class KvBatchScanner5 {
/* iterator */
private static class OrderConsumer implements KvCloseableIterator, HgPageSize {
- private OrderBroker broker;
+ private final OrderBroker broker;
private Iterator dataIterator;
private long tookCount = 0;
private final String consumerId;
@@ -398,13 +411,15 @@ class KvBatchScanner5 {
if (this.dataIterator == null) {
if (log.isDebugEnabled()) {
- log.debug("[ANALYSIS NULL -> FALSE] [{}] , tookCount: {}", consumerId, tookCount);
+ log.debug("[ANALYSIS NULL -> FALSE] [{}] , tookCount: {}", consumerId,
+ tookCount);
}
return false;
} else {
if (log.isDebugEnabled()) {
if (!this.dataIterator.hasNext()) {
- log.debug("[ANALYSIS hasNext -> FALSE] [{}] , tookCount: {}", consumerId, tookCount);
+ log.debug("[ANALYSIS hasNext -> FALSE] [{}] , tookCount: {}", consumerId,
+ tookCount);
}
}
return this.dataIterator.hasNext();
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScannerMerger.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScannerMerger.java
similarity index 82%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScannerMerger.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScannerMerger.java
index 812ebecfd..e7e62b2a6 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchScannerMerger.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchScannerMerger.java
@@ -1,6 +1,21 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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.
+ */
-import static com.baidu.hugegraph.store.client.grpc.KvBatchScanner.NO_DATA;
+package org.apache.hugegraph.store.client.grpc;
import java.util.Iterator;
import java.util.List;
@@ -12,11 +27,11 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
-import com.baidu.hugegraph.store.HgKvEntry;
-import com.baidu.hugegraph.store.HgKvIterator;
-import com.baidu.hugegraph.store.HgKvOrderedIterator;
-import com.baidu.hugegraph.store.HgPageSize;
-import com.baidu.hugegraph.store.client.util.PropertyUtil;
+import org.apache.hugegraph.store.HgKvEntry;
+import org.apache.hugegraph.store.HgKvIterator;
+import org.apache.hugegraph.store.HgKvOrderedIterator;
+import org.apache.hugegraph.store.HgPageSize;
+import org.apache.hugegraph.store.client.util.PropertyUtil;
import lombok.extern.slf4j.Slf4j;
@@ -25,13 +40,15 @@ import lombok.extern.slf4j.Slf4j;
* 对请求任务的拆分,创建多个请求队列
*/
@Slf4j
-public class KvBatchScannerMerger implements KvCloseableIterator>, HgPageSize {
+public class KvBatchScannerMerger implements KvCloseableIterator>,
+ HgPageSize {
static int maxWaitCount = PropertyUtil.getInt("net.kv.scanner.wait.timeout", 60);
- protected final BlockingQueue>> queue = new LinkedBlockingQueue<>();
+ protected final BlockingQueue>> queue =
+ new LinkedBlockingQueue<>();
private Supplier> current = null;
private final KvBatchScanner.TaskSplitter taskSplitter;
- private List scanners = new CopyOnWriteArrayList<>();
+ private final List scanners = new CopyOnWriteArrayList<>();
public KvBatchScannerMerger(KvBatchScanner.TaskSplitter splitter) {
this.taskSplitter = splitter;
@@ -62,8 +79,9 @@ public class KvBatchScannerMerger implements KvCloseableIterator maxWaitCount) {
- log.error("KvBatchScanner wait data timeout {}, closeables is {}, task is {}",
- waitTime, scanners.size(), taskSplitter.isFinished());
+ log.error(
+ "KvBatchScanner wait data timeout {}, closeables is {}, task is {}",
+ waitTime, scanners.size(), taskSplitter.isFinished());
break;
}
}
@@ -72,7 +90,7 @@ public class KvBatchScannerMerger implements KvCloseableIterator maxWaitCount) {
break;
}
- } else if (current == NO_DATA) {
+ } else if (current == KvBatchScanner.NO_DATA) {
queue = null;
break;
} else {
@@ -207,7 +225,7 @@ public class KvBatchScannerMerger implements KvCloseableIterator scannerQueues = new ConcurrentHashMap<>();
+ private final Map scannerQueues = new ConcurrentHashMap<>();
public SortedScannerMerger(KvBatchScanner.TaskSplitter splitter) {
super(splitter);
@@ -298,11 +316,12 @@ public class KvBatchScannerMerger implements KvCloseableIterator> supplier) {
+ public void dataArrived(KvBatchScanner scanner,
+ Supplier> supplier) {
scannerQueues.putIfAbsent(scanner, new ScannerDataQueue());
scannerQueues.get(scanner).add(supplier);
}
diff --git a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchUtil.java b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchUtil.java
similarity index 58%
rename from hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchUtil.java
rename to hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchUtil.java
index d8bbeca76..55b62856a 100644
--- a/hg-store-client/src/main/java/com/baidu/hugegraph/store/client/grpc/KvBatchUtil.java
+++ b/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvBatchUtil.java
@@ -1,20 +1,38 @@
-package com.baidu.hugegraph.store.client.grpc;
+/*
+ * 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 org.apache.hugegraph.store.client.grpc;
+
+import java.util.List;
+
+import javax.annotation.concurrent.NotThreadSafe;
+
+import org.apache.hugegraph.store.HgOwnerKey;
+import org.apache.hugegraph.store.HgScanQuery;
+import org.apache.hugegraph.store.client.HgStoreNodeSession;
+import org.apache.hugegraph.store.client.util.HgStoreClientConst;
-import com.baidu.hugegraph.store.HgOwnerKey;
-import com.baidu.hugegraph.store.HgScanQuery;
-import com.baidu.hugegraph.store.client.HgStoreNodeSession;
-import com.baidu.hugegraph.store.client.util.HgStoreClientConst;
import com.baidu.hugegraph.store.grpc.common.Header;
import com.baidu.hugegraph.store.grpc.common.ScanMethod;
import com.baidu.hugegraph.store.grpc.stream.*;
import com.google.protobuf.ByteString;
+
import lombok.extern.slf4j.Slf4j;
-import javax.annotation.concurrent.NotThreadSafe;
-import java.util.List;
-
-import static com.baidu.hugegraph.store.client.util.HgStoreClientConst.EMPTY_BYTES;
-
/**
* @author lynn.bond@hotmail.com created on 2022/04/23
*/
@@ -70,34 +88,41 @@ class KvBatchUtil {
return Header.newBuilder().setGraph(nodeSession.getGraphName()).build();
}
- static void addPrefixCondition(HgScanQuery scanQuery, ScanQueryRequest.Builder qb, ScanCondition.Builder cb) {
+ static void addPrefixCondition(HgScanQuery scanQuery, ScanQueryRequest.Builder qb,
+ ScanCondition.Builder cb) {
List prefixList = scanQuery.getPrefixList();
if (prefixList == null || prefixList.isEmpty()) {
- throw new RuntimeException("The start-list of ScanQuery shouldn't to be invalid in ScanMethod.PREFIX mode.");
+ throw new RuntimeException(
+ "The start-list of ScanQuery shouldn't to be invalid in ScanMethod.PREFIX " +
+ "mode.");
}
prefixList.forEach((e) -> {
qb.addCondition(cb.clear()
- .setPrefix(toBs(e.getKey()))
- .setCode(e.getKeyCode())
- .setSerialNo(e.getSerialNo())
- .build()
+ .setPrefix(toBs(e.getKey()))
+ .setCode(e.getKeyCode())
+ .setSerialNo(e.getSerialNo())
+ .build()
);
});
}
- static void addRangeCondition(HgScanQuery scanQuery, ScanQueryRequest.Builder qb, ScanCondition.Builder cb) {
+ static void addRangeCondition(HgScanQuery scanQuery, ScanQueryRequest.Builder qb,
+ ScanCondition.Builder cb) {
List startList = scanQuery.getStartList();
List