Skip to content

Commit 381202e

Browse files
JisoLyaCopilot
authored andcommitted
refactor(store): integrate store client module (#47)
* refactor(store): Added query pushdown support for Server & PD - Add StreamObserver implementation for server side - Modified the visibility of member variables to support query pushdown - Add HgSessionConfig.java * refactor(store): Support get partition from pd based on graph name & code & start key * chore(store): reformat code & code cleanup * fix(store): fix problems in code review fix(store): fix unused sessionConfig in HgStoreClient.java fix(store): fix potential NPE exception fix(store): Fix incorrect spelling fix(store): Fix the unit inconsistency in the time comparison Update hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/query/QueryExecutor.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/query/StreamSortedIterator.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/query/MultiStreamIterator.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/client/query/StreamFinalAggregationIterator.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore(store): remove unused code & modify import path * fix(store): fix bug in ut * fix(store): add missing table statement * fix(store): fix ci problem * Trigger ci --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 10ab5b6 commit 381202e

46 files changed

Lines changed: 2199 additions & 198 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/PDConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public final class PDConfig {
3737
private boolean enablePDNotify = false;
3838

3939
private boolean enableCache = false;
40-
private String authority;
41-
private String userName = "";
40+
// FIXME: need to add AuthCheck
41+
private String authority = "DEFAULT";
42+
private String userName = "store";
4243
private static final int GRPC_DEFAULT_MAX_INBOUND_MESSAGE_SIZE = 1024 * 1024 * 1024;
4344
private static final int GRPC_DEFAULT_MAX_OUTBOUND_MESSAGE_SIZE = 1024 * 1024 * 1024;
4445
private static int inboundMessageSize = GRPC_DEFAULT_MAX_INBOUND_MESSAGE_SIZE;

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/BaseCoreTest.java

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,71 +24,24 @@
2424
import org.apache.hugegraph.HugeGraphParams;
2525
import org.apache.hugegraph.backend.cache.CacheManager;
2626
import org.apache.hugegraph.backend.store.BackendFeatures;
27-
import org.apache.hugegraph.dist.RegisterUtil;
28-
import org.apache.hugegraph.masterelection.GlobalMasterInfo;
2927
import org.apache.hugegraph.schema.EdgeLabel;
3028
import org.apache.hugegraph.schema.SchemaManager;
31-
import org.apache.hugegraph.testutil.Utils;
3229
import org.apache.hugegraph.testutil.Whitebox;
3330
import org.apache.hugegraph.util.Log;
3431
import org.apache.tinkerpop.gremlin.structure.Edge;
3532
import org.apache.tinkerpop.gremlin.structure.Vertex;
3633
import org.junit.After;
37-
import org.junit.AfterClass;
38-
import org.junit.Assert;
3934
import org.junit.Before;
40-
import org.junit.BeforeClass;
4135
import org.slf4j.Logger;
4236

4337
public class BaseCoreTest {
4438

4539
protected static final Logger LOG = Log.logger(BaseCoreTest.class);
4640

4741
protected static final int TX_BATCH = 100;
48-
private static boolean registered = false;
49-
private static HugeGraph graph = null;
5042

51-
public static final String DEFAULT_GRAPH_SPACE = "DEFAULT";
52-
53-
public static HugeGraph graph() {
54-
Assert.assertNotNull(graph);
55-
//Assert.assertFalse(graph.closed());
56-
return graph;
57-
}
58-
59-
@BeforeClass
60-
public static void initEnv() {
61-
if (registered) {
62-
return;
63-
}
64-
RegisterUtil.registerBackends();
65-
registered = true;
66-
}
67-
68-
@BeforeClass
69-
public static void init() {
70-
graph = Utils.open();
71-
graph.clearBackend();
72-
graph.initBackend();
73-
graph.serverStarted(GlobalMasterInfo.master("server-test"));
74-
}
75-
76-
@AfterClass
77-
public static void clear() {
78-
if (graph == null) {
79-
return;
80-
}
81-
82-
try {
83-
graph.clearBackend();
84-
} finally {
85-
try {
86-
graph.close();
87-
} catch (Throwable e) {
88-
LOG.error("Error when close()", e);
89-
}
90-
graph = null;
91-
}
43+
public HugeGraph graph() {
44+
return CoreTestSuite.graph();
9245
}
9346

9447
@Before

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@
1717

1818
package org.apache.hugegraph.core;
1919

20-
import org.apache.hugegraph.core.PropertyCoreTest.EdgePropertyCoreTest;
21-
import org.apache.hugegraph.core.PropertyCoreTest.VertexPropertyCoreTest;
20+
import org.apache.hugegraph.HugeGraph;
21+
import org.apache.hugegraph.dist.RegisterUtil;
22+
import org.apache.hugegraph.masterelection.GlobalMasterInfo;
23+
import org.apache.hugegraph.testutil.Utils;
24+
import org.apache.hugegraph.util.Log;
25+
import org.junit.AfterClass;
26+
import org.junit.Assert;
27+
import org.junit.BeforeClass;
2228
import org.junit.runner.RunWith;
2329
import org.junit.runners.Suite;
30+
import org.slf4j.Logger;
2431

2532
@RunWith(Suite.class)
2633
@Suite.SuiteClasses({
@@ -31,8 +38,8 @@
3138
VertexCoreTest.class,
3239
EdgeCoreTest.class,
3340
ParentAndSubEdgeCoreTest.class,
34-
VertexPropertyCoreTest.class,
35-
EdgePropertyCoreTest.class,
41+
PropertyCoreTest.VertexPropertyCoreTest.class,
42+
PropertyCoreTest.EdgePropertyCoreTest.class,
3643
RestoreCoreTest.class,
3744
TaskCoreTest.class,
3845
AuthTest.class,
@@ -41,4 +48,49 @@
4148
})
4249
public class CoreTestSuite {
4350

51+
private static boolean registered = false;
52+
private static HugeGraph graph = null;
53+
54+
public static HugeGraph graph() {
55+
Assert.assertNotNull(graph);
56+
//Assert.assertFalse(graph.closed());
57+
return graph;
58+
}
59+
60+
protected static final Logger LOG = Log.logger(CoreTestSuite.class);
61+
62+
@BeforeClass
63+
public static void initEnv() {
64+
if (registered) {
65+
return;
66+
}
67+
RegisterUtil.registerBackends();
68+
registered = true;
69+
}
70+
71+
@BeforeClass
72+
public static void init() {
73+
graph = Utils.open();
74+
graph.clearBackend();
75+
graph.initBackend();
76+
graph.serverStarted(GlobalMasterInfo.master("server-test"));
77+
}
78+
79+
@AfterClass
80+
public static void clear() {
81+
if (graph == null) {
82+
return;
83+
}
84+
85+
try {
86+
graph.clearBackend();
87+
} finally {
88+
try {
89+
graph.close();
90+
} catch (Throwable e) {
91+
LOG.error("Error when close()", e);
92+
}
93+
graph = null;
94+
}
95+
}
4496
}

hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvIterator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@
2525
*/
2626
public interface HgKvIterator<E> extends Iterator<E>, HgSeekAble, Closeable {
2727

28-
byte[] key();
28+
default byte[] key() {
29+
return new byte[0];
30+
}
2931

30-
byte[] value();
32+
default byte[] value() {
33+
return new byte[0];
34+
}
3135

3236
@Override
33-
void close();
37+
default void close() {
38+
}
3439

3540
}

hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgKvStore.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919

2020
import java.util.List;
2121

22+
import org.apache.hugegraph.HugeGraphSupplier;
23+
import org.apache.hugegraph.pd.common.PDException;
2224
import org.apache.hugegraph.store.client.grpc.KvCloseableIterator;
2325
import org.apache.hugegraph.store.grpc.stream.ScanStreamReq;
26+
import org.apache.hugegraph.store.query.StoreQueryParam;
27+
import org.apache.hugegraph.structure.BaseElement;
2428

2529
/**
2630
* @version 0.2.0
@@ -98,7 +102,8 @@ HgKvIterator<HgKvEntry> scanIterator(String table, int codeFrom, int codeTo, int
98102

99103
HgKvIterator<HgKvEntry> scanIterator(ScanStreamReq.Builder scanReqBuilder);
100104

101-
long count(String table);
105+
List<HgKvIterator<BaseElement>> query(StoreQueryParam query, HugeGraphSupplier supplier) throws
106+
PDException;
102107

103108
boolean truncate();
104109

hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgPageSize.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
/**
2121
* Return the amount of records returned by one query in pageable-query.
22-
* <p>
2322
* created on 2021/10/24
2423
*/
2524
public interface HgPageSize {

hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSeekAble.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
*/
2323
public interface HgSeekAble {
2424

25-
byte[] position();
25+
default byte[] position() {
26+
throw new UnsupportedOperationException("HgSeekAble.position() is unsupported by default");
27+
}
28+
29+
default void seek(byte[] position) {
30+
throw new UnsupportedOperationException("HgSeekAble.seek() is unsupported by default");
31+
}
2632

27-
void seek(byte[] position);
2833
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hugegraph.store;
19+
20+
import lombok.Data;
21+
22+
@Data
23+
public class HgSessionConfig {
24+
25+
private long queryPushDownTimeout = 1800_000;
26+
}

hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgSessionProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@
2626
public interface HgSessionProvider {
2727

2828
HgStoreSession createSession(String graphName);
29+
30+
HgStoreSession createSession(String graphName, HgSessionConfig sessionConfig);
2931
}

hugegraph-store/hg-store-client/src/main/java/org/apache/hugegraph/store/HgStoreClient.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public final class HgStoreClient {
3737
private final HgSessionProvider sessionProvider;
3838
private PDClient pdClient;
3939

40+
private HgSessionConfig sessionConfig;
41+
4042
public HgStoreClient() {
4143
this.sessionProvider = new HgStoreSessionProvider();
4244
}
@@ -69,14 +71,18 @@ public void setPDConfig(PDConfig config) {
6971
setPdClient(pdClient);
7072
}
7173

74+
public void setSessionConfig(HgSessionConfig sessionConfig) {
75+
this.sessionConfig = sessionConfig;
76+
}
77+
7278
/**
7379
* Retrieve or create a HgStoreSession.
7480
*
7581
* @param graphName
7682
* @return
7783
*/
7884
public HgStoreSession openSession(String graphName) {
79-
return this.sessionProvider.createSession(graphName);
85+
return this.sessionProvider.createSession(graphName, this.sessionConfig);
8086
}
8187

8288
public PDClient getPdClient() {

0 commit comments

Comments
 (0)