javeme commented on code in PR #2476: URL: https://github.com/apache/incubator-hugegraph/pull/2476#discussion_r1536640179
########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTkvEntry.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; + +public interface HgTkvEntry { Review Comment: this name is a bit hard to understand, to be improved ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeNotifier.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; + +/** + * 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); + Review Comment: useless blank line ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java: ########## @@ -0,0 +1,434 @@ +/* + * 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.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; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import javax.annotation.concurrent.NotThreadSafe; + +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; + +/** + * 2021/11/18 + */ +@Slf4j +@NotThreadSafe +final class NodeTxExecutor { + + 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)); + } + + private final String graphName; + NodeTxSessionProxy proxy; + Collector<NodeTkv, ?, Map<Long, List<HgOwnerKey>>> collector = Collectors.groupingBy( + nkv -> nkv.getNodeId(), Collectors.mapping(NodeTkv::getKey, Collectors.toList())); + private Map<Long, HgStoreSession> sessions = new HashMap<>(TX_SESSIONS_MAP_CAPACITY, 1); + private boolean isTx; + private List<HgPair<HgTriple<String, HgOwnerKey, Object>, + Function<NodeTkv, Boolean>>> entries = new LinkedList<>(); + + private NodeTxExecutor(String graphName, NodeTxSessionProxy proxy) { + this.graphName = graphName; + this.proxy = proxy; + } + + static NodeTxExecutor graphOf(String graphName, NodeTxSessionProxy proxy) { + return new NodeTxExecutor(graphName, proxy); + } + + public boolean isTx() { + return isTx; + } + + void setTx(boolean tx) { + isTx = tx; + } + + void commitTx() { + if (!this.isTx) { + throw new IllegalStateException("It's not in tx state"); + } + + this.doCommit(); + } + + void rollbackTx() { + if (!this.isTx) { + return; + } + try { + this.sessions.values().stream().filter(HgStoreSession::isTx) + .forEach(HgStoreSession::rollback); + } catch (Throwable t) { + throw t; + } finally { + this.isTx = false; + this.sessions.clear(); + } + } + + void doCommit() { + try { + this.retryingInvoke(() -> { + if (this.entries.isEmpty()) { + return true; + } + AtomicBoolean allSuccess = new AtomicBoolean(true); + for (HgPair<HgTriple<String, HgOwnerKey, Object>, Function<NodeTkv, Boolean>> e : + this.entries) { + doAction(e.getKey(), e.getValue()); + } + if (!allSuccess.get()) { + throw HgStoreClientException.of(msg); + } + AtomicReference<Throwable> throwable = new AtomicReference<>(); + Collection<HgStoreSession> sessions = this.sessions.values(); + sessions.parallelStream().forEach(e -> { + if (e.isTx()) { Review Comment: can we rename e to session ########## hugegraph-store/hg-store-grpc/src/main/proto/store_stream_meta.proto: ########## @@ -0,0 +1,109 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamMetaProto"; + + +message ScanStreamBatchReq { Review Comment: prefer BatchScanRequest ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/KvOneShotScanner.java: ########## @@ -0,0 +1,213 @@ +/* + * 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.Iterator; +import java.util.List; + +import javax.annotation.concurrent.NotThreadSafe; + +import org.apache.hugegraph.store.HgKvStore; +import org.apache.hugegraph.store.HgOwnerKey; +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.HgStoreClientConfig; +import org.apache.hugegraph.store.client.util.HgStoreClientConst; +import org.apache.hugegraph.store.client.util.HgStoreClientUtil; +import org.apache.hugegraph.store.grpc.common.Header; +import org.apache.hugegraph.store.grpc.common.Kv; +import org.apache.hugegraph.store.grpc.common.ScanMethod; +import org.apache.hugegraph.store.grpc.stream.HgStoreStreamGrpc.HgStoreStreamBlockingStub; +import org.apache.hugegraph.store.grpc.stream.ScanStreamReq; + +import com.google.protobuf.ByteString; + +import lombok.extern.slf4j.Slf4j; + +/** + * created on 2021/12/1 + */ +@Slf4j +@NotThreadSafe +class KvOneShotScanner implements KvCloseableIterator<Kv>, HgPageSize, HgSeekAble { Review Comment: what does the OneShot mean? can we just delete it ########## hugegraph-store/hg-store-grpc/src/main/proto/store_stream_meta.proto: ########## @@ -0,0 +1,109 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamMetaProto"; + + +message ScanStreamBatchReq { + Header header = 1; + oneof query { + ScanQueryRequest query_request = 10; + ScanPagingRequest paging_request = 11; + ScanPauseRequest pause_request = 12; + ScanCancelRequest cancel_request = 13; + ScanReceiptRequest receipt_request = 14; + } + int64 logId = 15; +} + +message ScanQueryRequest { + ScanMethod method = 2; + string table = 3; + int64 limit = 4; + int64 pageSize = 5; + int32 scanType = 6; + bytes query = 7; + bytes position = 8; + repeated ScanCondition condition = 9; + int64 perKeyLimit = 10; + int64 skipDegree = 11; + ScanOrderType orderType = 12; + int64 perKeyMax = 13; +} + +message ScanPagingRequest { + int64 pageSize = 1; +} +message ScanPauseRequest {} +message ScanCancelRequest {} +message ScanReceiptRequest { + uint32 times = 1; +} + +message ScanCondition { + int32 code = 1; // owner key hashcode + bytes prefix = 2; // key prefix + bytes start = 3; // start key + bytes end = 4; // end key + int32 serialNo = 5; // serial no +} + +message ScanStreamReq { Review Comment: prefer ScanRequest ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgTokvEntry.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; + +public interface HgTokvEntry { Review Comment: this name is a bit hard to understand, to be improved ########## hugegraph-store/hg-store-grpc/src/main/dev/org/apache/hugegraph/store/grpc/stream/store_stream.proto: ########## @@ -0,0 +1,49 @@ +/* Review Comment: also move this filr to proto dir? ########## hugegraph-store/hg-store-grpc/src/main/proto/healthy.proto: ########## @@ -0,0 +1,30 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_package = "org.apache.hugegraph.store.grpc"; + +import "google/protobuf/empty.proto"; + +service Healthy { + rpc IsOk(google.protobuf.Empty) returns (StringReply) {} +} + +message StringReply { + string message = 1; Review Comment: add `int status` field and just let message hold error message ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { + rpc Get2(GetReq) returns (FeedbackRes) {} + rpc BatchGet2(BatchGetReq) returns (FeedbackRes) {} + rpc Batch(BatchReq) returns (FeedbackRes){} + rpc Table(TableReq) returns (FeedbackRes){}; + rpc Graph(GraphReq) returns (FeedbackRes){}; + rpc Clean(CleanReq) returns (FeedbackRes) {} + rpc Count(ScanStreamReq) returns (Agg) {} Review Comment: prefer CountScan ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { + rpc Get2(GetReq) returns (FeedbackRes) {} + rpc BatchGet2(BatchGetReq) returns (FeedbackRes) {} + rpc Batch(BatchReq) returns (FeedbackRes){} + rpc Table(TableReq) returns (FeedbackRes){}; + rpc Graph(GraphReq) returns (FeedbackRes){}; + rpc Clean(CleanReq) returns (FeedbackRes) {} + rpc Count(ScanStreamReq) returns (Agg) {} +} + +message TableReq{ + Header header = 1; + TableMethod method = 2; + string table_name = 3; +} + +message GraphReq{ + Header header = 1; + GraphMethod method = 2; + string graph_name = 3; +} + +message BatchReq{ + Header header = 1; + string batch_id = 2; + oneof requests{ + BatchWriteReq write_req = 10; + BatchCommitReq commit_req = 11; + BatchRollbackReq rollback_req = 12; + } +} + +message BatchWriteReq{ + repeated BatchEntry entry = 1; +} + +message BatchCommitReq{} + +message BatchRollbackReq{} + +message BatchEntry{ + OpType op_type = 1; + int32 table = 2; + Key start_key = 3; + Key end_key = 4; + bytes value = 5; +} + +message BatchGetReq { + Header header = 1; + string table = 2; + repeated Key key = 3; + int32 partition = 9; +} + +message GetReq { + Header header = 1; + Tk tk = 2; +} + +message CleanReq{ + Header header = 1; + int32 partition = 2; +} + + +message FeedbackRes { + ResStatus status = 1; + + oneof responses{ Review Comment: can we delete FeedbackRes and split it into 3 XxResponse ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { + rpc Get2(GetReq) returns (FeedbackRes) {} + rpc BatchGet2(BatchGetReq) returns (FeedbackRes) {} Review Comment: keep BatchGet? ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartition.java: ########## @@ -0,0 +1,103 @@ +/* + * 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; + +/** + * Immutable Object Pattern + * <p> + * created on 2021/10/26 + */ +public final class HgNodePartition { Review Comment: NodePartition is not a conventional concept, can we just keep Partition name? and also remove the unused Hg? ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgNodePartition.java: ########## @@ -0,0 +1,103 @@ +/* + * 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; + +/** + * Immutable Object Pattern + * <p> + * created on 2021/10/26 + */ +public final class HgNodePartition { + + private final Long nodeId; Review Comment: prefer storeNodeId ########## hugegraph-store/hg-store-grpc/src/main/proto/store_stream_meta.proto: ########## @@ -0,0 +1,109 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamMetaProto"; + + +message ScanStreamBatchReq { + Header header = 1; + oneof query { + ScanQueryRequest query_request = 10; + ScanPagingRequest paging_request = 11; + ScanPauseRequest pause_request = 12; + ScanCancelRequest cancel_request = 13; + ScanReceiptRequest receipt_request = 14; + } + int64 logId = 15; +} + +message ScanQueryRequest { + ScanMethod method = 2; + string table = 3; + int64 limit = 4; + int64 pageSize = 5; + int32 scanType = 6; + bytes query = 7; + bytes position = 8; + repeated ScanCondition condition = 9; + int64 perKeyLimit = 10; + int64 skipDegree = 11; + ScanOrderType orderType = 12; + int64 perKeyMax = 13; +} + +message ScanPagingRequest { + int64 pageSize = 1; +} +message ScanPauseRequest {} +message ScanCancelRequest {} +message ScanReceiptRequest { + uint32 times = 1; +} + +message ScanCondition { + int32 code = 1; // owner key hashcode + bytes prefix = 2; // key prefix + bytes start = 3; // start key + bytes end = 4; // end key + int32 serialNo = 5; // serial no +} + +message ScanStreamReq { + Header header = 1; + ScanMethod method = 2; + string table = 3; + int32 code = 4; // partitionId + bytes prefix = 5; // key prefix + bytes start = 6; //start key + bytes end = 7; //end key + int64 limit = 8; + int32 scanType = 9; + bytes query = 10; + int32 pageSize = 11; + bytes position = 12; + uint32 closeFlag = 13; + SelectParam selects = 14; +} + +message SelectParam { + bytes filter = 1; + bool withNoProperties = 2; + repeated int32 properties = 3; +} + +message KvPageRes { + int32 times = 1; //query times. + bool over = 2; //true=no more data + repeated Kv data = 3; + uint32 version = 4; + bytes stream = 5; +} + +enum KvStreamType { + STREAM_TYPE_NONE = 0; + STREAM_TYPE_KV = 1; + STREAM_TYPE_K = 2; + STREAM_TYPE_SKV = 3; + STREAM_TYPE_SK = 4; Review Comment: prefer SCAN_XX_KEY ########## hugegraph-store/hg-store-grpc/src/main/proto/store_state.proto: ########## @@ -0,0 +1,73 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "google/protobuf/empty.proto"; +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.state"; +option java_outer_classname = "HgStoreStateProto"; + +service HgStoreState { Review Comment: prefer StoreNodeService name ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/NodeTxExecutor.java: ########## @@ -0,0 +1,434 @@ +/* + * 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.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; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import javax.annotation.concurrent.NotThreadSafe; + +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; + +/** + * 2021/11/18 + */ +@Slf4j +@NotThreadSafe +final class NodeTxExecutor { + + 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)); + } + + private final String graphName; + NodeTxSessionProxy proxy; + Collector<NodeTkv, ?, Map<Long, List<HgOwnerKey>>> collector = Collectors.groupingBy( + nkv -> nkv.getNodeId(), Collectors.mapping(NodeTkv::getKey, Collectors.toList())); + private Map<Long, HgStoreSession> sessions = new HashMap<>(TX_SESSIONS_MAP_CAPACITY, 1); + private boolean isTx; + private List<HgPair<HgTriple<String, HgOwnerKey, Object>, + Function<NodeTkv, Boolean>>> entries = new LinkedList<>(); + + private NodeTxExecutor(String graphName, NodeTxSessionProxy proxy) { + this.graphName = graphName; + this.proxy = proxy; + } + + static NodeTxExecutor graphOf(String graphName, NodeTxSessionProxy proxy) { + return new NodeTxExecutor(graphName, proxy); + } + + public boolean isTx() { + return isTx; + } + + void setTx(boolean tx) { + isTx = tx; + } + + void commitTx() { + if (!this.isTx) { + throw new IllegalStateException("It's not in tx state"); + } + + this.doCommit(); + } + + void rollbackTx() { + if (!this.isTx) { + return; + } + try { + this.sessions.values().stream().filter(HgStoreSession::isTx) + .forEach(HgStoreSession::rollback); + } catch (Throwable t) { + throw t; + } finally { + this.isTx = false; + this.sessions.clear(); + } + } + + void doCommit() { + try { + this.retryingInvoke(() -> { + if (this.entries.isEmpty()) { + return true; + } + AtomicBoolean allSuccess = new AtomicBoolean(true); + for (HgPair<HgTriple<String, HgOwnerKey, Object>, Function<NodeTkv, Boolean>> e : + this.entries) { + doAction(e.getKey(), e.getValue()); + } + if (!allSuccess.get()) { + throw HgStoreClientException.of(msg); + } + AtomicReference<Throwable> throwable = new AtomicReference<>(); + Collection<HgStoreSession> sessions = this.sessions.values(); + sessions.parallelStream().forEach(e -> { + if (e.isTx()) { + try { + e.commit(); + } catch (Throwable t) { Review Comment: Throwable e ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgPrivate.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; + +/** + * created on 2021/10/26 + */ +public class HgPrivate { Review Comment: this name is a bit hard to understand, to be improved ########## hugegraph-store/hg-store-grpc/src/main/proto/store_stream_meta.proto: ########## @@ -0,0 +1,109 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamMetaProto"; + + +message ScanStreamBatchReq { + Header header = 1; + oneof query { + ScanQueryRequest query_request = 10; + ScanPagingRequest paging_request = 11; + ScanPauseRequest pause_request = 12; + ScanCancelRequest cancel_request = 13; + ScanReceiptRequest receipt_request = 14; + } + int64 logId = 15; +} + +message ScanQueryRequest { + ScanMethod method = 2; + string table = 3; + int64 limit = 4; + int64 pageSize = 5; + int32 scanType = 6; + bytes query = 7; + bytes position = 8; + repeated ScanCondition condition = 9; + int64 perKeyLimit = 10; + int64 skipDegree = 11; + ScanOrderType orderType = 12; + int64 perKeyMax = 13; +} + +message ScanPagingRequest { + int64 pageSize = 1; +} +message ScanPauseRequest {} +message ScanCancelRequest {} +message ScanReceiptRequest { + uint32 times = 1; +} + +message ScanCondition { + int32 code = 1; // owner key hashcode + bytes prefix = 2; // key prefix + bytes start = 3; // start key + bytes end = 4; // end key + int32 serialNo = 5; // serial no +} + +message ScanStreamReq { + Header header = 1; + ScanMethod method = 2; + string table = 3; + int32 code = 4; // partitionId Review Comment: why not just rename code to partition ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreNodeManager.java: ########## @@ -0,0 +1,264 @@ +/* + * 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.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 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. + * <p> + * created on 2021/10/11 + * + * @version 0.2.0 + */ +@ThreadSafe +@Slf4j +public final class HgStoreNodeManager { + + private final static Set<String> CLUSTER_ID_SET = new HashSet<>(); + private final static HgStoreNodeManager instance = new HgStoreNodeManager(); + + private final String clusterId; + private final Map<String, HgStoreNode> addressMap = new ConcurrentHashMap<>(); + private final Map<Long, HgStoreNode> nodeIdMap = new ConcurrentHashMap<>(); + private final Map<String, List<HgStoreNode>> graphNodesMap = new ConcurrentHashMap<>(); + + private HgStoreNodeProvider nodeProvider; + private HgStoreNodePartitioner nodePartitioner; + private HgStoreNodeNotifier nodeNotifier; + + private HgStoreNodeManager() { + this.clusterId = HgStoreClientConst.DEFAULT_NODE_CLUSTER_ID; + } + + private HgStoreNodeManager(String clusterId) { + synchronized (CLUSTER_ID_SET) { + if (CLUSTER_ID_SET.contains(clusterId)) { + throw new RuntimeException("The cluster [" + clusterId + "] has been existing."); + } + CLUSTER_ID_SET.add(clusterId); + this.clusterId = clusterId; + } + } + + public static HgStoreNodeManager getInstance() { + return instance; + } + + /** + * Return the HgStoreNodeBuilder + * + * @return + */ + public HgStoreNodeBuilder getNodeBuilder() { + // TODO: Constructed by a provider that retrieved by SPI + return new GrpcStoreNodeBuilder(this, HgPrivate.getInstance()); + } + + /** + * Return an instance of HgStoreNode whose ID is matched to the argument. + * + * @param nodeId + * @return null when none of instance is matched to the argument,or argument is invalid. + */ + public HgStoreNode getStoreNode(Long nodeId) { + if (nodeId == null) { + return null; + } + return this.nodeIdMap.get(nodeId); + } + + /** + * Apply a HgStoreNode instance with graph-name and node-id. + * <b>CAUTION:</b> + * <b>It won't work when user haven't set a HgStoreNodeProvider via setNodeProvider method.</b> + * + * @param graphName + * @param nodeId + * @return + */ + HgStoreNode applyNode(String graphName, Long nodeId) { + HgStoreNode node = this.nodeIdMap.get(nodeId); + + if (node != null) { + return node; + } + + if (this.nodeProvider == null) { + return null; + } + + node = this.nodeProvider.apply(graphName, nodeId); + + if (node == null) { + + log.warn("Failed to apply a HgStoreNode instance form the nodeProvider [ " + + this.nodeProvider.getClass().getName() + " ]."); + notifying(graphName, nodeId, HgNodeStatus.NOT_EXIST); + return null; + } + + this.addNode(graphName, node); + + return node; + } + + private void notifying(String graphName, Long nodeId, HgNodeStatus status) { + if (this.nodeNotifier != null) { + 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); + } + } + } + + /** + * @param graphName + * @param notice + * @return null: when there is no HgStoreNodeNotifier in the nodeManager; + * @throws HgStoreClientException + */ + public Integer notifying(String graphName, HgStoreNotice notice) { + + if (this.nodeNotifier != null) { + + synchronized (Thread.currentThread()) { + try { + return this.nodeNotifier.notice(graphName, notice); + } catch (Throwable t) { + String msg = + "Failed to invoke " + this.nodeNotifier.getClass().getSimpleName() + + ", notice: [ " + notice + " ]"; + log.error(msg, t); + throw new HgStoreClientException(msg); + } + } + + } + + return null; + } + + /** + * Return a collection of HgStoreNode who is in charge of the graph passed in the argument. + * + * @param graphName + * @return null when none matched to argument or any argument is invalid. + */ + public List<HgStoreNode> getStoreNodes(String graphName) { + if (HgAssert.isInvalid(graphName)) { + return null; + } + + return this.graphNodesMap.get(graphName); + } + + /** + * Adding a new Store-Node, return the argument's value if the host+port was not existing, + * otherwise return the HgStoreNode-instance added early. + * + * @param storeNode + * @return + * @throws IllegalArgumentException when any argument is invalid. + */ + public HgStoreNode addNode(HgStoreNode storeNode) { Review Comment: prefer addOrGetStoreNode ########## hugegraph-store/hg-store-grpc/src/main/proto/store_stream_meta.proto: ########## @@ -0,0 +1,109 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamMetaProto"; + + +message ScanStreamBatchReq { + Header header = 1; + oneof query { + ScanQueryRequest query_request = 10; + ScanPagingRequest paging_request = 11; + ScanPauseRequest pause_request = 12; + ScanCancelRequest cancel_request = 13; + ScanReceiptRequest receipt_request = 14; + } + int64 logId = 15; +} + +message ScanQueryRequest { + ScanMethod method = 2; + string table = 3; + int64 limit = 4; + int64 pageSize = 5; + int32 scanType = 6; + bytes query = 7; + bytes position = 8; + repeated ScanCondition condition = 9; + int64 perKeyLimit = 10; + int64 skipDegree = 11; + ScanOrderType orderType = 12; + int64 perKeyMax = 13; +} + +message ScanPagingRequest { + int64 pageSize = 1; +} +message ScanPauseRequest {} +message ScanCancelRequest {} +message ScanReceiptRequest { + uint32 times = 1; +} + +message ScanCondition { + int32 code = 1; // owner key hashcode + bytes prefix = 2; // key prefix + bytes start = 3; // start key + bytes end = 4; // end key + int32 serialNo = 5; // serial no +} + +message ScanStreamReq { + Header header = 1; + ScanMethod method = 2; + string table = 3; + int32 code = 4; // partitionId + bytes prefix = 5; // key prefix + bytes start = 6; //start key + bytes end = 7; //end key + int64 limit = 8; + int32 scanType = 9; + bytes query = 10; + int32 pageSize = 11; + bytes position = 12; + uint32 closeFlag = 13; + SelectParam selects = 14; +} + +message SelectParam { + bytes filter = 1; + bool withNoProperties = 2; + repeated int32 properties = 3; +} + +message KvPageRes { + int32 times = 1; //query times. + bool over = 2; //true=no more data + repeated Kv data = 3; + uint32 version = 4; + bytes stream = 5; +} + +enum KvStreamType { Review Comment: prefer ScanType ########## hugegraph-store/hg-store-grpc/src/main/dev/org/apache/hugegraph/store/grpc/stream/store_stream.proto: ########## @@ -0,0 +1,49 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; +import "store_stream_meta.proto"; +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamProto"; + +/** + In order to improve performance, reuse memory, and reduce gc recycling, the KvStream.writeTo method needs to be overwrite. + */ +service HgStoreStream { + + rpc Scan(stream ScanStreamReq) returns (stream KvPageRes) {} + rpc ScanOneShot(ScanStreamReq) returns (KvPageRes) {} Review Comment: the OneShot name is to be improved ########## hugegraph-store/hg-store-grpc/src/main/proto/store_stream_meta.proto: ########## @@ -0,0 +1,109 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamMetaProto"; + + +message ScanStreamBatchReq { + Header header = 1; + oneof query { + ScanQueryRequest query_request = 10; + ScanPagingRequest paging_request = 11; + ScanPauseRequest pause_request = 12; + ScanCancelRequest cancel_request = 13; + ScanReceiptRequest receipt_request = 14; + } + int64 logId = 15; +} + +message ScanQueryRequest { + ScanMethod method = 2; + string table = 3; + int64 limit = 4; + int64 pageSize = 5; + int32 scanType = 6; + bytes query = 7; + bytes position = 8; + repeated ScanCondition condition = 9; + int64 perKeyLimit = 10; + int64 skipDegree = 11; + ScanOrderType orderType = 12; + int64 perKeyMax = 13; +} + +message ScanPagingRequest { + int64 pageSize = 1; +} +message ScanPauseRequest {} +message ScanCancelRequest {} +message ScanReceiptRequest { + uint32 times = 1; +} + +message ScanCondition { + int32 code = 1; // owner key hashcode + bytes prefix = 2; // key prefix + bytes start = 3; // start key + bytes end = 4; // end key + int32 serialNo = 5; // serial no +} + +message ScanStreamReq { + Header header = 1; + ScanMethod method = 2; + string table = 3; + int32 code = 4; // partitionId + bytes prefix = 5; // key prefix + bytes start = 6; //start key + bytes end = 7; //end key + int64 limit = 8; + int32 scanType = 9; + bytes query = 10; + int32 pageSize = 11; + bytes position = 12; + uint32 closeFlag = 13; + SelectParam selects = 14; +} + +message SelectParam { + bytes filter = 1; + bool withNoProperties = 2; + repeated int32 properties = 3; +} + +message KvPageRes { + int32 times = 1; //query times. + bool over = 2; //true=no more data + repeated Kv data = 3; + uint32 version = 4; + bytes stream = 5; +} + +enum KvStreamType { + STREAM_TYPE_NONE = 0; + STREAM_TYPE_KV = 1; Review Comment: prefer SCAN_KEY_VALUE ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/HgStoreService.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.client; + +public class HgStoreService { Review Comment: seems it's an empty class, not sure what is the usage scenarios ########## hugegraph-store/hg-store-grpc/src/main/proto/store_stream_meta.proto: ########## @@ -0,0 +1,109 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamMetaProto"; + + +message ScanStreamBatchReq { + Header header = 1; + oneof query { + ScanQueryRequest query_request = 10; + ScanPagingRequest paging_request = 11; + ScanPauseRequest pause_request = 12; + ScanCancelRequest cancel_request = 13; + ScanReceiptRequest receipt_request = 14; + } + int64 logId = 15; +} + +message ScanQueryRequest { + ScanMethod method = 2; + string table = 3; + int64 limit = 4; + int64 pageSize = 5; + int32 scanType = 6; + bytes query = 7; + bytes position = 8; + repeated ScanCondition condition = 9; + int64 perKeyLimit = 10; + int64 skipDegree = 11; + ScanOrderType orderType = 12; + int64 perKeyMax = 13; +} + +message ScanPagingRequest { + int64 pageSize = 1; +} +message ScanPauseRequest {} +message ScanCancelRequest {} +message ScanReceiptRequest { + uint32 times = 1; +} + +message ScanCondition { + int32 code = 1; // owner key hashcode + bytes prefix = 2; // key prefix + bytes start = 3; // start key + bytes end = 4; // end key + int32 serialNo = 5; // serial no +} + +message ScanStreamReq { + Header header = 1; + ScanMethod method = 2; + string table = 3; + int32 code = 4; // partitionId + bytes prefix = 5; // key prefix + bytes start = 6; //start key + bytes end = 7; //end key + int64 limit = 8; + int32 scanType = 9; + bytes query = 10; + int32 pageSize = 11; + bytes position = 12; + uint32 closeFlag = 13; + SelectParam selects = 14; +} + +message SelectParam { + bytes filter = 1; + bool withNoProperties = 2; + repeated int32 properties = 3; +} + +message KvPageRes { Review Comment: prefer ScanPageResponse? ########## hugegraph-store/hg-store-grpc/src/main/dev/org/apache/hugegraph/store/grpc/stream/store_stream.proto: ########## @@ -0,0 +1,49 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; +import "store_stream_meta.proto"; +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamProto"; + +/** + In order to improve performance, reuse memory, and reduce gc recycling, the KvStream.writeTo method needs to be overwrite. + */ +service HgStoreStream { + + rpc Scan(stream ScanStreamReq) returns (stream KvPageRes) {} + rpc ScanOneShot(ScanStreamReq) returns (KvPageRes) {} + rpc ScanBatch(stream ScanStreamBatchReq) returns (stream KvPageRes) {} + rpc ScanBatch2(stream ScanStreamBatchReq) returns (stream KvStream) {} Review Comment: just keep one of ScanBatch and ScanBatch2? ########## hugegraph-store/hg-store-grpc/src/main/dev/org/apache/hugegraph/store/grpc/stream/store_stream.proto: ########## @@ -0,0 +1,49 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; +import "store_stream_meta.proto"; +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamProto"; + +/** + In order to improve performance, reuse memory, and reduce gc recycling, the KvStream.writeTo method needs to be overwrite. + */ +service HgStoreStream { + + rpc Scan(stream ScanStreamReq) returns (stream KvPageRes) {} + rpc ScanOneShot(ScanStreamReq) returns (KvPageRes) {} + rpc ScanBatch(stream ScanStreamBatchReq) returns (stream KvPageRes) {} + rpc ScanBatch2(stream ScanStreamBatchReq) returns (stream KvStream) {} + rpc ScanBatchOneShot(ScanStreamBatchReq) returns (KvPageRes) {} +} + + +message KvStream { + int32 seq_no = 1; //query times. + bool over = 2; //true=no more data Review Comment: rename to exhausted or finished? ########## hugegraph-store/hg-store-grpc/src/main/dev/org/apache/hugegraph/store/grpc/stream/store_stream.proto: ########## @@ -0,0 +1,49 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; +import "store_stream_meta.proto"; +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamProto"; + +/** + In order to improve performance, reuse memory, and reduce gc recycling, the KvStream.writeTo method needs to be overwrite. + */ +service HgStoreStream { Review Comment: can we rename to ScanService ########## hugegraph-store/hg-store-grpc/src/main/proto/graphpb.proto: ########## @@ -0,0 +1,138 @@ +/* + * 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. + */ + +syntax = "proto3"; +package graph_pb; + +option java_package = "org.apache.hugegraph.store.grpc"; + +service GraphStore { + rpc ScanPartition(stream ScanPartitionRequest) returns (stream ScanResponse){} +} + +message ScanPartitionRequest{ + enum ScanType{ + SCAN_UNKNOWN = 0; + SCAN_VERTEX = 1; + SCAN_EDGE = 2; + } + // 请求参数 + message Request{ + ScanType scan_type = 1; + string graph_name = 2; + uint32 partition_id = 3; + uint32 start_code = 4; + uint32 end_code = 5; + // 过滤条件 + string condition = 6; + string table = 7; + int64 limit = 8; + int32 boundary = 9; + bytes position = 10; + // 返回条件 + repeated int64 properties = 11; + } + + + message Reply{ + int32 seq_no = 1; + } + RequestHeader header = 1; + oneof request { + Request scan_request = 2; + // 每消费一个数据包,通知服务端一次,返回消息序号 + Reply reply_request = 4; + } +} + +message ScanResponse{ Review Comment: prefer ScanPartitionResponse ########## hugegraph-store/hg-store-grpc/src/main/dev/org/apache/hugegraph/store/grpc/stream/store_stream.proto: ########## @@ -0,0 +1,49 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "store_common.proto"; +import "store_stream_meta.proto"; +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.stream"; +option java_outer_classname = "HgStoreStreamProto"; + +/** + In order to improve performance, reuse memory, and reduce gc recycling, the KvStream.writeTo method needs to be overwrite. + */ +service HgStoreStream { + + rpc Scan(stream ScanStreamReq) returns (stream KvPageRes) {} + rpc ScanOneShot(ScanStreamReq) returns (KvPageRes) {} + rpc ScanBatch(stream ScanStreamBatchReq) returns (stream KvPageRes) {} + rpc ScanBatch2(stream ScanStreamBatchReq) returns (stream KvStream) {} + rpc ScanBatchOneShot(ScanStreamBatchReq) returns (KvPageRes) {} +} + + +message KvStream { + int32 seq_no = 1; //query times. + bool over = 2; //true=no more data + uint32 version = 4; + bytes stream = 5; + KvStreamType type = 6; +} + + + + Review Comment: useless blank lines ########## hugegraph-store/hg-store-grpc/src/main/proto/graphpb.proto: ########## @@ -0,0 +1,138 @@ +/* + * 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. + */ + +syntax = "proto3"; +package graph_pb; + +option java_package = "org.apache.hugegraph.store.grpc"; + +service GraphStore { + rpc ScanPartition(stream ScanPartitionRequest) returns (stream ScanResponse){} +} + +message ScanPartitionRequest{ Review Comment: expect a space before "{", can we format the style of other files? ########## hugegraph-store/hg-store-grpc/src/main/proto/graphpb.proto: ########## @@ -0,0 +1,138 @@ +/* + * 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. + */ + +syntax = "proto3"; +package graph_pb; + +option java_package = "org.apache.hugegraph.store.grpc"; + +service GraphStore { Review Comment: can we rename to PartitionService or merge it into StoreNodeService, and move the define to store_partition.proto? ########## hugegraph-store/hg-store-grpc/src/main/proto/graphpb.proto: ########## @@ -0,0 +1,138 @@ +/* + * 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. + */ + +syntax = "proto3"; +package graph_pb; + +option java_package = "org.apache.hugegraph.store.grpc"; + +service GraphStore { + rpc ScanPartition(stream ScanPartitionRequest) returns (stream ScanResponse){} +} + +message ScanPartitionRequest{ + enum ScanType{ + SCAN_UNKNOWN = 0; + SCAN_VERTEX = 1; + SCAN_EDGE = 2; + } + // 请求参数 + message Request{ + ScanType scan_type = 1; + string graph_name = 2; + uint32 partition_id = 3; + uint32 start_code = 4; + uint32 end_code = 5; + // 过滤条件 + string condition = 6; + string table = 7; + int64 limit = 8; + int32 boundary = 9; + bytes position = 10; + // 返回条件 + repeated int64 properties = 11; + } + + Review Comment: useless blank line ########## hugegraph-store/hg-store-grpc/src/main/proto/store_state.proto: ########## @@ -0,0 +1,73 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "google/protobuf/empty.proto"; +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.state"; +option java_outer_classname = "HgStoreStateProto"; + +service HgStoreState { + + // Subscribe Store Node state publishing. + rpc SubState(SubStateReq) returns (stream NodeStateRes) {} Review Comment: prefer SubscribeStoreNodeState ########## hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/grpc/GrpcNodeHealthyClient.java: ########## @@ -0,0 +1,92 @@ +/* + * 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 org.apache.hugegraph.store.grpc.HealthyGrpc; +import org.apache.hugegraph.store.grpc.HealthyOuterClass; + +import com.google.protobuf.Empty; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; + +/** + * + */ +@ThreadSafe +public final class GrpcNodeHealthyClient { + + private final static Map<String, ManagedChannel> CHANNEL_MAP = new ConcurrentHashMap<>(); + private final static Map<String, HealthyGrpc.HealthyBlockingStub> STUB_MAP = + new ConcurrentHashMap<>(); + + // TODO: Forbid constructing out of the package. + public GrpcNodeHealthyClient() { + + } + + private ManagedChannel getChannel(String target) { + ManagedChannel channel = CHANNEL_MAP.get(target); + if (channel == null) { + channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build(); + CHANNEL_MAP.put(target, channel); + } + return channel; + } + + private HealthyGrpc.HealthyBlockingStub getStub(String target) { + HealthyGrpc.HealthyBlockingStub stub = STUB_MAP.get(target); + if (stub == null) { + stub = HealthyGrpc.newBlockingStub(getChannel(target)); + STUB_MAP.put(target, stub); + } + return stub; + } + + +/* boolean isHealthy(GrpcStoreNodeImpl node) { + String target = node.getAddress(); + + HealthyOuterClass.StringReply response = getStub(target).isOk(Empty.newBuilder().build()); + String res = response.getMessage(); + + if ("ok".equals(res)) { + return true; + } else { + System.out.printf("gRPC-res-msg: %s%n", res); + return false; + } + }*/ + + public boolean isHealthy() { + String target = "localhost:9080"; + ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext().build(); + HealthyGrpc.HealthyBlockingStub stub = HealthyGrpc.newBlockingStub(channel); + HealthyOuterClass.StringReply response = stub.isOk(Empty.newBuilder().build()); + + String res = response.getMessage(); + System.out.printf("gRPC response message:%s%n", res); Review Comment: please remove all the System.out.print and use log instead ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { Review Comment: can we just keep 2 services: 1. StoreNodeService(store_node.proto): include store node state, healthy, partition-scan service. 3. PartitionDataService(partition_data.proto): include write, get, scan Service. ########## hugegraph-store/hg-store-grpc/src/main/proto/graphpb.proto: ########## @@ -0,0 +1,138 @@ +/* + * 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. + */ + +syntax = "proto3"; +package graph_pb; + +option java_package = "org.apache.hugegraph.store.grpc"; + +service GraphStore { + rpc ScanPartition(stream ScanPartitionRequest) returns (stream ScanResponse){} +} + +message ScanPartitionRequest{ + enum ScanType{ + SCAN_UNKNOWN = 0; + SCAN_VERTEX = 1; + SCAN_EDGE = 2; + } + // 请求参数 + message Request{ + ScanType scan_type = 1; + string graph_name = 2; + uint32 partition_id = 3; + uint32 start_code = 4; + uint32 end_code = 5; + // 过滤条件 + string condition = 6; + string table = 7; + int64 limit = 8; + int32 boundary = 9; + bytes position = 10; + // 返回条件 + repeated int64 properties = 11; + } + + + message Reply{ + int32 seq_no = 1; + } + RequestHeader header = 1; + oneof request { + Request scan_request = 2; + // 每消费一个数据包,通知服务端一次,返回消息序号 + Reply reply_request = 4; + } +} + +message ScanResponse{ + ResponseHeader header = 1; + // 消息序号 + int32 seq_no = 2; + repeated Vertex vertex = 3; + repeated Edge edge = 4; +} + + +message Property{ + uint64 label = 1; + Variant value = 2; +} + +message Vertex{ + int64 label = 1; // 点类型 + Variant id = 2; // 点ID + repeated Property properties = 3; //点属性 +} + +message Edge{ + int64 label = 1; // 边类型 + int64 sourceLabel = 2; + int64 targetLabel = 3; + Variant source_id = 4; // 源点ID + Variant target_id = 5; // 目标点ID + + repeated Property properties = 6; //边属性 +} + +message Variant { + optional VariantType type = 1; + optional int32 value_int32 = 2; + optional int64 value_int64 = 3; + optional float value_float = 4; + optional double value_double = 5; + optional string value_string = 6; + optional bytes value_bytes = 7; + optional string value_datetime = 8; + optional bool value_boolean = 9; +} + +enum VariantType { + VT_UNKNOWN = 0; + VT_BOOLEAN = 1; + VT_INT = 2; + VT_LONG = 3; + VT_FLOAT = 4; + VT_DOUBLE = 7; + VT_STRING = 8; + VT_BYTES = 9; + VT_DATETIME = 10; +} + + + +message RequestHeader { + // 发送者 ID. + uint64 sender_id = 2; +} + +message ResponseHeader { + uint64 sender_id = 1; + Error error = 2; +} + + +enum ErrorType { + OK = 0; + UNKNOWN = 1; Review Comment: prefer FAIL ########## hugegraph-store/hg-store-grpc/src/main/proto/healthy.proto: ########## @@ -0,0 +1,30 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_package = "org.apache.hugegraph.store.grpc"; + +import "google/protobuf/empty.proto"; + +service Healthy { Review Comment: can we rename to StoreNodeHealthyService ########## hugegraph-store/hg-store-grpc/src/main/proto/store_state.proto: ########## @@ -0,0 +1,73 @@ +/* + * 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. + */ + +syntax = "proto3"; + +import "google/protobuf/empty.proto"; +import "store_common.proto"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.state"; +option java_outer_classname = "HgStoreStateProto"; + +service HgStoreState { + + // Subscribe Store Node state publishing. + rpc SubState(SubStateReq) returns (stream NodeStateRes) {} + + // Unsubscribe Store Node state publishing. + rpc UnsubState(SubStateReq) returns (google.protobuf.Empty){} + rpc getScanState(SubStateReq) returns (ScanState){} Review Comment: prefer GetStoreNodeState ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { + rpc Get2(GetReq) returns (FeedbackRes) {} + rpc BatchGet2(BatchGetReq) returns (FeedbackRes) {} + rpc Batch(BatchReq) returns (FeedbackRes){} + rpc Table(TableReq) returns (FeedbackRes){}; + rpc Graph(GraphReq) returns (FeedbackRes){}; + rpc Clean(CleanReq) returns (FeedbackRes) {} Review Comment: prefer to rename to CleanPartition and move it to PartitionService ########## hugegraph-store/hg-store-grpc/src/main/proto/healthy.proto: ########## @@ -0,0 +1,30 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_package = "org.apache.hugegraph.store.grpc"; + +import "google/protobuf/empty.proto"; + +service Healthy { + rpc IsOk(google.protobuf.Empty) returns (StringReply) {} +} + +message StringReply { Review Comment: prefer HealthyResponse ########## hugegraph-store/hg-store-grpc/src/main/proto/store_common.proto: ########## @@ -0,0 +1,113 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.common"; +option java_outer_classname = "HgStoreCommonProto"; + +message Header { + string graph = 1; +} +message Tkv { + string table = 1; + bytes key = 2; + bytes value = 3; + int32 code = 9; + +} + +message Tk { + string table = 1; + bytes key = 2; + int32 code = 9; +} + +message Tp { + string table = 1; + bytes prefix = 2; + int32 code = 9; +} + +message Tse { + string table = 1; + Key start = 2; + Key end = 3; +} + +message Key { + bytes key = 1; + int32 code = 9; +} + +message Kv { + bytes key = 1; + bytes value = 2; + int32 code = 9; +} + +message ResStatus { Review Comment: prefer Status ########## hugegraph-store/hg-store-grpc/src/main/proto/store_common.proto: ########## @@ -0,0 +1,113 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.common"; +option java_outer_classname = "HgStoreCommonProto"; + +message Header { + string graph = 1; +} +message Tkv { + string table = 1; + bytes key = 2; + bytes value = 3; + int32 code = 9; + +} + +message Tk { + string table = 1; + bytes key = 2; + int32 code = 9; +} + +message Tp { + string table = 1; + bytes prefix = 2; + int32 code = 9; +} + +message Tse { + string table = 1; + Key start = 2; + Key end = 3; +} + +message Key { + bytes key = 1; + int32 code = 9; +} + +message Kv { + bytes key = 1; + bytes value = 2; + int32 code = 9; +} + +message ResStatus { + ResCode code = 1; + string msg = 2; +} + +/*--- enum ---*/ +enum ResCode { Review Comment: prefer ErrorCode ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { + rpc Get2(GetReq) returns (FeedbackRes) {} + rpc BatchGet2(BatchGetReq) returns (FeedbackRes) {} + rpc Batch(BatchReq) returns (FeedbackRes){} Review Comment: prefer BatchWrite ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { + rpc Get2(GetReq) returns (FeedbackRes) {} Review Comment: keep Get? ########## hugegraph-store/hg-store-grpc/src/main/proto/store_session.proto: ########## @@ -0,0 +1,137 @@ +/* + * 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. + */ + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "org.apache.hugegraph.store.grpc.session"; +option java_outer_classname = "HgStoreSessionProto"; + +import "store_common.proto"; +import "store_stream_meta.proto"; + +service HgStoreSession { + rpc Get2(GetReq) returns (FeedbackRes) {} + rpc BatchGet2(BatchGetReq) returns (FeedbackRes) {} + rpc Batch(BatchReq) returns (FeedbackRes){} + rpc Table(TableReq) returns (FeedbackRes){}; + rpc Graph(GraphReq) returns (FeedbackRes){}; Review Comment: Table/Graph looks a little strange, where are these two interfaces used , and what content do they return? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
