Skip to content

Commit 9f89afc

Browse files
authored
feat(server): support new backend Hstore (#2560)
subtask of #2483
1 parent 37e71c4 commit 9f89afc

File tree

108 files changed

+10558
-330
lines changed

Some content is hidden

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

108 files changed

+10558
-330
lines changed

.github/workflows/pd-store-ci.yml

+70
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,73 @@ jobs:
116116
uses: codecov/codecov-action@v3.0.0
117117
with:
118118
file: ${{ env.REPORT_DIR }}/*.xml
119+
120+
hstore:
121+
# TODO: avoid duplicated env setup
122+
runs-on: ubuntu-latest
123+
env:
124+
USE_STAGE: 'true' # Whether to include the stage repository.
125+
TRAVIS_DIR: hugegraph-server/hugegraph-dist/src/assembly/travis
126+
REPORT_DIR: target/site/jacoco
127+
BACKEND: hstore
128+
RELEASE_BRANCH: ${{ startsWith(github.ref_name, 'release-') || startsWith(github.ref_name, 'test-') || startsWith(github.base_ref, 'release-') }}
129+
130+
steps:
131+
- name: Install JDK 11
132+
uses: actions/setup-java@v3
133+
with:
134+
java-version: '11'
135+
distribution: 'zulu'
136+
137+
- name: Cache Maven packages
138+
uses: actions/cache@v3
139+
with:
140+
path: ~/.m2
141+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
142+
restore-keys: ${{ runner.os }}-m2
143+
144+
- name: Checkout
145+
uses: actions/checkout@v3
146+
with:
147+
fetch-depth: 2
148+
149+
- name: use staged maven repo settings
150+
if: ${{ env.USE_STAGE == 'true' }}
151+
run: |
152+
cp $HOME/.m2/settings.xml /tmp/settings.xml
153+
mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml
154+
155+
- name: Package
156+
run: |
157+
mvn clean package -U -Dmaven.javadoc.skip=true -Dmaven.test.skip=true -ntp
158+
159+
- name: Prepare env and service
160+
run: |
161+
$TRAVIS_DIR/install-backend.sh $BACKEND
162+
163+
- name: Run unit test
164+
run: |
165+
$TRAVIS_DIR/run-unit-test.sh $BACKEND
166+
167+
- name: Run core test
168+
run: |
169+
$TRAVIS_DIR/run-core-test.sh $BACKEND
170+
171+
- name: Run api test
172+
run: |
173+
$TRAVIS_DIR/run-api-test.sh $BACKEND $REPORT_DIR
174+
175+
- name: Run raft test
176+
if: ${{ env.BACKEND == 'rocksdb' }}
177+
run: |
178+
$TRAVIS_DIR/run-api-test-for-raft.sh $BACKEND $REPORT_DIR
179+
180+
- name: Run TinkerPop test
181+
if: ${{ env.RELEASE_BRANCH == 'true' }}
182+
run: |
183+
$TRAVIS_DIR/run-tinkerpop-test.sh $BACKEND tinkerpop
184+
185+
- name: Upload coverage to Codecov
186+
uses: codecov/codecov-action@v3.0.0
187+
with:
188+
file: ${{ env.REPORT_DIR }}/*.xml

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ public Map<String, Object> get(@Context GraphManager manager,
136136
@RedirectFilter.RedirectMasterRole
137137
public void delete(@Context GraphManager manager,
138138
@PathParam("graph") String graph,
139-
@PathParam("id") long id) {
139+
@PathParam("id") long id,
140+
@DefaultValue("false") @QueryParam("force") boolean force) {
140141
LOG.debug("Graph [{}] delete task: {}", graph, id);
141142

142143
TaskScheduler scheduler = graph(manager, graph).taskScheduler();
143-
HugeTask<?> task = scheduler.delete(IdGenerator.of(id));
144+
HugeTask<?> task = scheduler.delete(IdGenerator.of(id), force);
144145
E.checkArgument(task != null, "There is no task with id '%s'", id);
145146
}
146147

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java

+34-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Objects;
2727
import java.util.Optional;
2828
import java.util.Set;
29+
import java.util.concurrent.Callable;
2930
import java.util.concurrent.Future;
3031
import java.util.concurrent.LinkedBlockingQueue;
3132
import java.util.concurrent.ThreadFactory;
@@ -71,6 +72,7 @@
7172
import org.apache.hugegraph.structure.HugeFeatures;
7273
import org.apache.hugegraph.structure.HugeVertex;
7374
import org.apache.hugegraph.task.HugeTask;
75+
import org.apache.hugegraph.task.ServerInfoManager;
7476
import org.apache.hugegraph.task.TaskManager;
7577
import org.apache.hugegraph.task.TaskScheduler;
7678
import org.apache.hugegraph.task.TaskStatus;
@@ -1085,10 +1087,10 @@ public <V> Iterator<HugeTask<V>> tasks(TaskStatus status,
10851087
}
10861088

10871089
@Override
1088-
public <V> HugeTask<V> delete(Id id) {
1090+
public <V> HugeTask<V> delete(Id id, boolean force) {
10891091
verifyTaskPermission(HugePermission.DELETE,
10901092
this.taskScheduler.task(id));
1091-
return this.taskScheduler.delete(id);
1093+
return this.taskScheduler.delete(id, force);
10921094
}
10931095

10941096
@Override
@@ -1124,6 +1126,36 @@ public void checkRequirement(String op) {
11241126
this.taskScheduler.checkRequirement(op);
11251127
}
11261128

1129+
@Override
1130+
public <V> V call(Callable<V> callable) {
1131+
verifyAnyPermission();
1132+
return this.taskScheduler.call(callable);
1133+
}
1134+
1135+
@Override
1136+
public <V> V call(Runnable runnable) {
1137+
verifyAnyPermission();
1138+
return this.taskScheduler.call(runnable);
1139+
}
1140+
1141+
@Override
1142+
public ServerInfoManager serverManager() {
1143+
verifyAnyPermission();
1144+
return this.taskScheduler.serverManager();
1145+
}
1146+
1147+
@Override
1148+
public String graphName() {
1149+
verifyAnyPermission();
1150+
return this.taskScheduler.graphName();
1151+
}
1152+
1153+
@Override
1154+
public void taskDone(HugeTask<?> task) {
1155+
verifyAnyPermission();
1156+
this.taskScheduler.taskDone(task);
1157+
}
1158+
11271159
private void verifyTaskPermission(HugePermission actionPerm) {
11281160
verifyPermission(actionPerm, ResourceType.TASK);
11291161
}

hugegraph-server/hugegraph-cassandra/src/main/java/org/apache/hugegraph/backend/store/cassandra/CassandraStore.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ protected Collection<CassandraTable> tables() {
592592

593593
@Override
594594
protected final CassandraTable table(HugeType type) {
595-
return this.table(type.string());
595+
return this.table(convertTaskOrServerToVertex(type).string());
596596
}
597597

598598
protected final CassandraTable table(String name) {

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/HugeGraphParams.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.hugegraph.backend.store.BackendStore;
2525
import org.apache.hugegraph.backend.store.ram.RamTable;
2626
import org.apache.hugegraph.backend.tx.GraphTransaction;
27+
import org.apache.hugegraph.backend.tx.ISchemaTransaction;
2728
import org.apache.hugegraph.backend.tx.SchemaTransaction;
2829
import org.apache.hugegraph.config.HugeConfig;
2930
import org.apache.hugegraph.event.EventHub;
@@ -47,7 +48,7 @@ public interface HugeGraphParams {
4748

4849
GraphReadMode readMode();
4950

50-
SchemaTransaction schemaTransaction();
51+
ISchemaTransaction schemaTransaction();
5152

5253
GraphTransaction systemTransaction();
5354

@@ -94,4 +95,6 @@ public interface HugeGraphParams {
9495
RamTable ramtable();
9596

9697
<T> void submitEphemeralJob(EphemeralJob<T> job);
98+
99+
String schedulerType();
97100
}

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java

+37-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.hugegraph.backend.cache.CacheNotifier.SchemaCacheNotifier;
3838
import org.apache.hugegraph.backend.cache.CachedGraphTransaction;
3939
import org.apache.hugegraph.backend.cache.CachedSchemaTransaction;
40+
import org.apache.hugegraph.backend.cache.CachedSchemaTransactionV2;
4041
import org.apache.hugegraph.backend.id.Id;
4142
import org.apache.hugegraph.backend.id.IdGenerator;
4243
import org.apache.hugegraph.backend.id.SnowflakeIdGenerator;
@@ -52,7 +53,7 @@
5253
import org.apache.hugegraph.backend.store.raft.RaftGroupManager;
5354
import org.apache.hugegraph.backend.store.ram.RamTable;
5455
import org.apache.hugegraph.backend.tx.GraphTransaction;
55-
import org.apache.hugegraph.backend.tx.SchemaTransaction;
56+
import org.apache.hugegraph.backend.tx.ISchemaTransaction;
5657
import org.apache.hugegraph.config.CoreOptions;
5758
import org.apache.hugegraph.config.HugeConfig;
5859
import org.apache.hugegraph.config.TypedOption;
@@ -69,6 +70,7 @@
6970
import org.apache.hugegraph.masterelection.RoleElectionStateMachine;
7071
import org.apache.hugegraph.masterelection.StandardClusterRoleStore;
7172
import org.apache.hugegraph.masterelection.StandardRoleElectionStateMachine;
73+
import org.apache.hugegraph.meta.MetaManager;
7274
import org.apache.hugegraph.perf.PerfUtil.Watched;
7375
import org.apache.hugegraph.rpc.RpcServiceConfig4Client;
7476
import org.apache.hugegraph.rpc.RpcServiceConfig4Server;
@@ -176,6 +178,8 @@ public class StandardHugeGraph implements HugeGraph {
176178

177179
private final RamTable ramtable;
178180

181+
private final String schedulerType;
182+
179183
public StandardHugeGraph(HugeConfig config) {
180184
this.params = new StandardHugeGraphParams();
181185
this.configuration = config;
@@ -209,6 +213,7 @@ public StandardHugeGraph(HugeConfig config) {
209213
this.closed = false;
210214
this.mode = GraphMode.NONE;
211215
this.readMode = GraphReadMode.OLTP_ONLY;
216+
this.schedulerType = config.get(CoreOptions.SCHEDULER_TYPE);
212217

213218
LockUtil.init(this.name);
214219

@@ -221,6 +226,13 @@ public StandardHugeGraph(HugeConfig config) {
221226
throw new HugeException(message, e);
222227
}
223228

229+
if (isHstore()) {
230+
// TODO: parameterize the remaining configurations
231+
MetaManager.instance().connect("hg", MetaManager.MetaDriverType.PD,
232+
"ca", "ca", "ca",
233+
config.get(CoreOptions.PD_PEERS));
234+
}
235+
224236
try {
225237
this.tx = new TinkerPopTransaction(this);
226238
boolean supportsPersistence = this.backendStoreFeatures().supportsPersistence();
@@ -457,9 +469,18 @@ private void clearVertexCache() {
457469
}
458470
}
459471

460-
private SchemaTransaction openSchemaTransaction() throws HugeException {
472+
private boolean isHstore() {
473+
return this.storeProvider.isHstore();
474+
}
475+
476+
private ISchemaTransaction openSchemaTransaction() throws HugeException {
461477
this.checkGraphNotClosed();
462478
try {
479+
if (isHstore()) {
480+
return new CachedSchemaTransactionV2(
481+
MetaManager.instance().metaDriver(),
482+
MetaManager.instance().cluster(), this.params);
483+
}
463484
return new CachedSchemaTransaction(this.params, loadSchemaStore());
464485
} catch (BackendException e) {
465486
String message = "Failed to open schema transaction";
@@ -504,11 +525,14 @@ private BackendStore loadGraphStore() {
504525
}
505526

506527
private BackendStore loadSystemStore() {
528+
if (isHstore()) {
529+
return this.storeProvider.loadGraphStore(this.configuration);
530+
}
507531
return this.storeProvider.loadSystemStore(this.configuration);
508532
}
509533

510534
@Watched
511-
private SchemaTransaction schemaTransaction() {
535+
private ISchemaTransaction schemaTransaction() {
512536
this.checkGraphNotClosed();
513537
/*
514538
* NOTE: each schema operation will be auto committed,
@@ -1196,7 +1220,7 @@ public GraphReadMode readMode() {
11961220
}
11971221

11981222
@Override
1199-
public SchemaTransaction schemaTransaction() {
1223+
public ISchemaTransaction schemaTransaction() {
12001224
return StandardHugeGraph.this.schemaTransaction();
12011225
}
12021226

@@ -1316,6 +1340,11 @@ public RamTable ramtable() {
13161340
public <T> void submitEphemeralJob(EphemeralJob<T> job) {
13171341
this.ephemeralJobQueue.add(job);
13181342
}
1343+
1344+
@Override
1345+
public String schedulerType() {
1346+
return StandardHugeGraph.this.schedulerType;
1347+
}
13191348
}
13201349

13211350
private class TinkerPopTransaction extends AbstractThreadLocalTransaction {
@@ -1447,7 +1476,7 @@ private void setClosed() {
14471476
}
14481477
}
14491478

1450-
private SchemaTransaction schemaTransaction() {
1479+
private ISchemaTransaction schemaTransaction() {
14511480
return this.getOrNewTransaction().schemaTx;
14521481
}
14531482

@@ -1468,7 +1497,7 @@ private Txs getOrNewTransaction() {
14681497

14691498
Txs txs = this.transactions.get();
14701499
if (txs == null) {
1471-
SchemaTransaction schemaTransaction = null;
1500+
ISchemaTransaction schemaTransaction = null;
14721501
SysTransaction sysTransaction = null;
14731502
GraphTransaction graphTransaction = null;
14741503
try {
@@ -1511,12 +1540,12 @@ private void destroyTransaction() {
15111540

15121541
private static final class Txs {
15131542

1514-
private final SchemaTransaction schemaTx;
1543+
private final ISchemaTransaction schemaTx;
15151544
private final SysTransaction systemTx;
15161545
private final GraphTransaction graphTx;
15171546
private long openedTime;
15181547

1519-
public Txs(SchemaTransaction schemaTx, SysTransaction systemTx,
1548+
public Txs(ISchemaTransaction schemaTx, SysTransaction systemTx,
15201549
GraphTransaction graphTx) {
15211550
assert schemaTx != null && systemTx != null && graphTx != null;
15221551
this.schemaTx = schemaTx;

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/HugeAccess.java

+5
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,9 @@ private String[] initProperties() {
228228
return super.initProperties(props);
229229
}
230230
}
231+
232+
public static HugeAccess fromMap(Map<String, Object> map) {
233+
HugeAccess access = new HugeAccess(null, null, null);
234+
return fromMap(map, access);
235+
}
231236
}

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/auth/HugeBelong.java

+14
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232

3333
public class HugeBelong extends Relationship {
3434

35+
public static final String UG = "ug";
36+
public static final String UR = "ur";
37+
public static final String GR = "gr";
38+
public static final String ALL = "*";
3539
private static final long serialVersionUID = -7242751631755533423L;
3640

3741
private final Id user;
3842
private final Id group;
43+
private String link;
3944
private String description;
4045

4146
public HugeBelong(Id user, Id group) {
@@ -74,6 +79,10 @@ public Id target() {
7479
return this.group;
7580
}
7681

82+
public String link() {
83+
return this.link;
84+
}
85+
7786
public String description() {
7887
return this.description;
7988
}
@@ -193,4 +202,9 @@ private String[] initProperties() {
193202
return super.initProperties(props);
194203
}
195204
}
205+
206+
public static HugeBelong fromMap(Map<String, Object> map) {
207+
HugeBelong belong = new HugeBelong(null, null);
208+
return fromMap(map, belong);
209+
}
196210
}

0 commit comments

Comments
 (0)