This is an automated email from the ASF dual-hosted git repository.
vgalaxies pushed a commit to branch intro-hstore
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
The following commit(s) were added to refs/heads/intro-hstore by this push:
new 79f6be95b adapt
79f6be95b is described below
commit 79f6be95bff4cc6433e1c2f57f65e0dbc7191eac
Author: VGalaxies <[email protected]>
AuthorDate: Fri Apr 26 14:29:41 2024 +0800
adapt
---
hugegraph-server/hugegraph-core/pom.xml | 26 ++++
.../apache/hugegraph/backend/id/IdGenerator.java | 2 +-
.../apache/hugegraph/backend/query/Condition.java | 84 +++++++++++-
.../hugegraph/backend/query/ConditionQuery.java | 66 +++++++++
.../org/apache/hugegraph/backend/query/Query.java | 47 ++++++-
.../serializer/AbstractSerializerAdapter.java | 66 +++++++++
.../backend/query/serializer/QueryAdapter.java | 148 +++++++++++++++++++++
.../backend/query/serializer/QueryIdAdapter.java | 46 +++++++
.../backend/serializer/BinaryBackendEntry.java | 12 +-
.../hugegraph/backend/serializer/BytesBuffer.java | 40 +++++-
.../backend/store/AbstractBackendStore.java | 7 +
.../hugegraph/backend/store/BackendFeatures.java | 2 +
.../hugegraph/backend/store/BackendMutation.java | 4 +
.../hugegraph/backend/store/BackendStore.java | 4 +
.../hugegraph/backend/store/BackendTable.java | 5 +
.../org/apache/hugegraph/config/CoreOptions.java | 31 +++++
.../org/apache/hugegraph/type/HugeTableType.java | 64 +++++++++
.../java/org/apache/hugegraph/type/HugeType.java | 9 +-
18 files changed, 650 insertions(+), 13 deletions(-)
diff --git a/hugegraph-server/hugegraph-core/pom.xml
b/hugegraph-server/hugegraph-core/pom.xml
index dad67853e..6b6a37e7a 100644
--- a/hugegraph-server/hugegraph-core/pom.xml
+++ b/hugegraph-server/hugegraph-core/pom.xml
@@ -253,6 +253,32 @@
<version>${jjwt.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hugegraph</groupId>
+ <artifactId>hg-pd-client</artifactId>
+ <version>${revision}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hugegraph</groupId>
+ <artifactId>hg-store-common</artifactId>
+ <version>${revision}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-core</artifactId>
+ <version>0.5.9</version>
+ <exclusions>
+ <exclusion>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<build>
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java
index 99bb1ad58..9261d31fe 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java
@@ -379,7 +379,7 @@ public abstract class IdGenerator {
/**
* This class is just used by backend store for wrapper object as Id
*/
- private static final class ObjectId implements Id {
+ public static final class ObjectId implements Id {
private final Object object;
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java
index 94f64f3d7..3ef9cd5fa 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Condition.java
@@ -47,7 +47,8 @@ public abstract class Condition {
NONE,
RELATION,
AND,
- OR
+ OR,
+ NOT
}
public enum RelationType implements BiPredicate<Object, Object> {
@@ -300,7 +301,8 @@ public abstract class Condition {
public boolean isLogic() {
return this.type() == ConditionType.AND ||
- this.type() == ConditionType.OR;
+ this.type() == ConditionType.OR ||
+ this.type() == ConditionType.NOT;
}
public boolean isFlattened() {
@@ -315,6 +317,10 @@ public abstract class Condition {
return new Or(left, right);
}
+ public static Condition not(Condition condition) {
+ return new Not(condition);
+ }
+
public static Relation eq(HugeKeys key, Object value) {
return new SyspropRelation(key, RelationType.EQ, value);
}
@@ -536,6 +542,80 @@ public abstract class Condition {
}
}
+ public static class Not extends Condition {
+
+ Condition condition;
+
+ public Not(Condition condition) {
+ super();
+ this.condition = condition;
+ }
+
+ public Condition condition() {
+ return condition;
+ }
+
+ @Override
+ public ConditionType type() {
+ return ConditionType.NOT;
+ }
+
+ @Override
+ public boolean test(Object value) {
+ return !this.condition.test(value);
+ }
+
+ @Override
+ public boolean test(HugeElement element) {
+ return !this.condition.test(element);
+ }
+
+ @Override
+ public Condition copy() {
+ return new Not(this.condition.copy());
+ }
+
+ @Override
+ public boolean isSysprop() {
+ return this.condition.isSysprop();
+ }
+
+ @Override
+ public List<? extends Relation> relations() {
+ return new ArrayList<Relation>(this.condition.relations());
+ }
+
+ @Override
+ public Condition replace(Relation from, Relation to) {
+ this.condition = this.condition.replace(from, to);
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(64);
+ sb.append(this.type().name()).append(' ');
+ sb.append(this.condition);
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof Not)) {
+ return false;
+ }
+ Not other = (Not) object;
+ return this.type().equals(other.type()) &&
+ this.condition.equals(other.condition());
+ }
+
+ @Override
+ public int hashCode() {
+ return this.type().hashCode() ^
+ this.condition.hashCode();
+ }
+ }
+
public abstract static class Relation extends Condition {
// Relational operator (like: =, >, <, in, ...)
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java
index a4386831b..8a5706a77 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQuery.java
@@ -18,6 +18,7 @@
package org.apache.hugegraph.backend.query;
import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -34,6 +35,8 @@ import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.SplicingIdGenerator;
import org.apache.hugegraph.backend.query.Condition.Relation;
import org.apache.hugegraph.backend.query.Condition.RelationType;
+import org.apache.hugegraph.backend.query.serializer.QueryAdapter;
+import org.apache.hugegraph.backend.query.serializer.QueryIdAdapter;
import org.apache.hugegraph.perf.PerfUtil.Watched;
import org.apache.hugegraph.structure.HugeElement;
import org.apache.hugegraph.structure.HugeProperty;
@@ -48,6 +51,8 @@ import org.apache.hugegraph.util.NumericUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
public class ConditionQuery extends IdQuery {
@@ -73,6 +78,12 @@ public class ConditionQuery extends IdQuery {
private static final List<Condition> EMPTY_CONDITIONS = ImmutableList.of();
+ private static final Gson gson = new GsonBuilder()
+ .registerTypeAdapter(Condition.class, new QueryAdapter())
+ .registerTypeAdapter(Id.class, new QueryIdAdapter())
+ .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
+ .create();
+
// Conditions will be contacted with `and` by default
private List<Condition> conditions = EMPTY_CONDITIONS;
@@ -220,6 +231,31 @@ public class ConditionQuery extends IdQuery {
return null;
}
+ public boolean containsLabelOrUserpropRelation() {
+ for (Condition c : this.conditions) {
+ while (c instanceof Condition.Not) {
+ c = ((Condition.Not) c).condition();
+ }
+ if (c.isLogic()) {
+ Condition.BinCondition binCondition =
+ (Condition.BinCondition) c;
+ ConditionQuery query = new ConditionQuery(HugeType.EDGE);
+ query.query(binCondition.left());
+ query.query(binCondition.right());
+ if (query.containsLabelOrUserpropRelation()) {
+ return true;
+ }
+ } else {
+ Condition.Relation r = (Condition.Relation) c;
+ if (r.key().equals(HugeKeys.LABEL) ||
+ c instanceof Condition.UserpropRelation) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
@Watched
public <T> T condition(Object key) {
List<Object> valuesEQ = InsertionOrderUtil.newList();
@@ -300,6 +336,19 @@ public class ConditionQuery extends IdQuery {
return false;
}
+ public boolean containsCondition(Condition.RelationType type) {
+ for (Relation r : this.relations()) {
+ if (r.relation().equals(type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean containsScanCondition() {
+ return this.containsCondition(Condition.RelationType.SCAN);
+ }
+
public boolean containsRelation(HugeKeys key, Condition.RelationType type)
{
for (Relation r : this.relations()) {
if (r.key().equals(key) && r.relation().equals(type)) {
@@ -702,6 +751,18 @@ public class ConditionQuery extends IdQuery {
}
}
+ public static ConditionQuery fromBytes(byte[] bytes) {
+ Gson gson = new GsonBuilder()
+ .registerTypeAdapter(Condition.class, new QueryAdapter())
+ .registerTypeAdapter(Id.class, new QueryIdAdapter())
+ .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
+ .create();
+ String cqs = new String(bytes, StandardCharsets.UTF_8);
+ ConditionQuery conditionQuery = gson.fromJson(cqs,
ConditionQuery.class);
+
+ return conditionQuery;
+ }
+
private static boolean needConvertNumber(Object value) {
// Numeric or date values should be converted to number from string
return NumericUtil.isNumber(value) || value instanceof Date;
@@ -891,4 +952,9 @@ public class ConditionQuery extends IdQuery {
boolean test(HugeElement element);
}
+
+ public byte[] bytes() {
+ String cqs = gson.toJson(this);
+ return cqs.getBytes(StandardCharsets.UTF_8);
+ }
}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java
index 56352e4c1..593887d92 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java
@@ -62,12 +62,15 @@ public class Query implements Cloneable {
private long actualOffset;
private long actualStoreOffset;
private long limit;
+ private long skipDegree;
private String page;
private long capacity;
private boolean showHidden;
private boolean showDeleting;
private boolean showExpired;
private boolean olap;
+ private boolean withProperties;
+ private OrderType orderType;
private Set<Id> olapPks;
private Aggregate aggregate;
@@ -88,6 +91,7 @@ public class Query implements Cloneable {
this.actualOffset = 0L;
this.actualStoreOffset = 0L;
this.limit = NO_LIMIT;
+ this.skipDegree = NO_LIMIT;
this.page = null;
this.capacity = defaultCapacity();
@@ -95,6 +99,9 @@ public class Query implements Cloneable {
this.showHidden = false;
this.showDeleting = false;
+ this.withProperties = true;
+ this.orderType = OrderType.ORDER_STRICT;
+
this.aggregate = null;
this.showExpired = false;
this.olap = false;
@@ -105,10 +112,13 @@ public class Query implements Cloneable {
E.checkNotNull(query, "query");
this.offset = query.offset();
this.limit = query.limit();
+ this.skipDegree = query.skipDegree();
this.page = query.page();
this.capacity = query.capacity();
this.showHidden = query.showHidden();
this.showDeleting = query.showDeleting();
+ this.withProperties = query.withProperties();
+ this.orderType = query.orderType();
this.aggregate = query.aggregate();
this.showExpired = query.showExpired();
this.olap = query.olap();
@@ -441,6 +451,30 @@ public class Query implements Cloneable {
this.showDeleting = showDeleting;
}
+ public long skipDegree() {
+ return this.skipDegree;
+ }
+
+ public void skipDegree(long skipDegree) {
+ this.skipDegree = skipDegree;
+ }
+
+ public boolean withProperties() {
+ return this.withProperties;
+ }
+
+ public void withProperties(boolean withProperties) {
+ this.withProperties = withProperties;
+ }
+
+ public OrderType orderType() {
+ return this.orderType;
+ }
+
+ public void orderType(OrderType orderType) {
+ this.orderType = orderType;
+ }
+
public boolean showExpired() {
return this.showExpired;
}
@@ -493,7 +527,8 @@ public class Query implements Cloneable {
this.limit == other.limit &&
Objects.equals(this.page, other.page) &&
this.ids().equals(other.ids()) &&
- this.conditions().equals(other.conditions());
+ this.conditions().equals(other.conditions()) &&
+ this.withProperties == other.withProperties;
}
@Override
@@ -504,7 +539,8 @@ public class Query implements Cloneable {
Long.hashCode(this.limit) ^
Objects.hashCode(this.page) ^
this.ids().hashCode() ^
- this.conditions().hashCode();
+ this.conditions().hashCode() ^
+ Boolean.hashCode(this.withProperties);
}
@Override
@@ -580,6 +616,13 @@ public class Query implements Cloneable {
}
}
+ public enum OrderType {
+ // 批量接口下,返回顺序的要求
+ ORDER_NONE, // 允许无序
+ ORDER_WITHIN_VERTEX, // 一个点内的边不会被打断,单不同点之间为无序
+ ORDER_STRICT // 保证原始的输入点顺序
+ }
+
public enum Order {
ASC,
DESC
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/AbstractSerializerAdapter.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/AbstractSerializerAdapter.java
new file mode 100644
index 000000000..1a66ddf07
--- /dev/null
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/AbstractSerializerAdapter.java
@@ -0,0 +1,66 @@
+/*
+ * 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.backend.query.serializer;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import org.apache.hugegraph.backend.BackendException;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
+// TODO: optimize by binary protocol
+public abstract class AbstractSerializerAdapter<T> implements
JsonSerializer<T>,
+
JsonDeserializer<T> {
+
+ //Note: By overriding the method to get the mapping
+ public abstract Map<String, Type> validType();
+
+ @Override
+ public T deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws
+
JsonParseException {
+ JsonObject object = json.getAsJsonObject();
+ String type = object.get("cls").getAsString();
+ JsonElement element = object.get("el");
+ try {
+ return context.deserialize(element, validType().get(type));
+ } catch (Exception e) {
+ throw new BackendException("Unknown element type: " + type, e);
+ }
+ }
+
+ /*
+ * Note: Currently, only the first character of the class name is taken as
the key
+ * to reduce serialization results
+ * */
+ @Override
+ public JsonElement serialize(T src, Type typeOfSrc,
JsonSerializationContext context) {
+ JsonObject result = new JsonObject();
+ Class clazz = src.getClass();
+ result.add("cls", new JsonPrimitive(clazz.getSimpleName().substring(0,
1).toUpperCase()));
+ result.add("el", context.serialize(src, clazz));
+ return result;
+ }
+}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/QueryAdapter.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/QueryAdapter.java
new file mode 100644
index 000000000..47b7c76a0
--- /dev/null
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/QueryAdapter.java
@@ -0,0 +1,148 @@
+/*
+ * 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.backend.query.serializer;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hugegraph.backend.query.Condition;
+import org.apache.hugegraph.type.define.Directions;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.reflect.TypeToken;
+
+public class QueryAdapter extends AbstractSerializerAdapter<Condition> {
+
+ static ImmutableMap<String, Type> cls =
+ ImmutableMap.<String, Type>builder()
+ // TODO: uncomment later
+ .put("N", Condition.Not.class)
+ .put("A", Condition.And.class)
+ .put("O", Condition.Or.class)
+ .put("S", Condition.SyspropRelation.class)
+ .put("U", Condition.UserpropRelation.class)
+ .build();
+
+ static boolean isPrimitive(Class clz) {
+ try {
+ return (clz == Date.class) || ((Class)
clz.getField("TYPE").get(null)).isPrimitive();
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ @Override
+ public Map<String, Type> validType() {
+ return cls;
+ }
+
+ @Override
+ public Condition deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context)
+ throws JsonParseException {
+ Condition condition = super.deserialize(json, typeOfT, context);
+ if (condition instanceof Condition.Relation) {
+ JsonObject object = json.getAsJsonObject();
+ if (object.has("el")) {
+ JsonElement elElement = object.get("el");
+ JsonElement valueElement =
elElement.getAsJsonObject().get("value");
+ if (valueElement.isJsonObject()) {
+ String cls =
valueElement.getAsJsonObject().get("cls").getAsString();
+ try {
+ Class actualClass = Class.forName(cls);
+ Object obj = context.deserialize(valueElement,
actualClass);
+ ((Condition.Relation) condition).value(obj);
+ } catch (ClassNotFoundException e) {
+ throw new JsonParseException(e.getMessage());
+ }
+ } else if (elElement.getAsJsonObject().has("valuecls")) {
+ if (valueElement.isJsonArray()) {
+ String cls =
elElement.getAsJsonObject().get("valuecls").getAsString();
+ try {
+ Class actualClass = Class.forName(cls);
+ Type type =
TypeToken.getParameterized(ArrayList.class, actualClass)
+ .getType();
+ Object value = context.deserialize(valueElement,
type);
+ ((Condition.Relation) condition).value(value);
+ } catch (ClassNotFoundException e) {
+ throw new JsonParseException(e.getMessage());
+ }
+ } else {
+ String cls =
elElement.getAsJsonObject().get("valuecls").getAsString();
+ try {
+ Class actualClass = Class.forName(cls);
+ Object obj = context.deserialize(valueElement,
actualClass);
+ ((Condition.Relation) condition).value(obj);
+ } catch (ClassNotFoundException e) {
+ throw new JsonParseException(e.getMessage());
+ }
+ }
+
+ } else if (valueElement.isJsonPrimitive() &&
+ valueElement.getAsJsonPrimitive().isString()) {
+ switch ((String) ((Condition.Relation) condition).value())
{
+ case "OUT":
+ ((Condition.Relation)
condition).value(Directions.OUT);
+ break;
+ case "IN":
+ ((Condition.Relation)
condition).value(Directions.IN);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ return condition;
+ }
+
+ @Override
+ public JsonElement serialize(Condition src, Type typeOfSrc,
JsonSerializationContext context) {
+ JsonElement result = super.serialize(src, typeOfSrc, context);
+ if (src instanceof Condition.Relation) {
+ JsonObject object = result.getAsJsonObject();
+ JsonElement valueElement =
object.get("el").getAsJsonObject().get("value");
+ if (valueElement.isJsonObject()) {
+ valueElement.getAsJsonObject()
+ .add("cls",
+ new JsonPrimitive(
+ ((Condition.Relation)
src).value().getClass().getName()));
+ } else if (isPrimitive(((Condition.Relation)
src).value().getClass())) {
+ object.get("el").getAsJsonObject()
+ .add("valuecls",
+ new JsonPrimitive(
+ ((Condition.Relation)
src).value().getClass().getName()));
+ } else if (valueElement.isJsonArray()) {
+ if (((Condition.Relation) src).value() instanceof List) {
+ String valueCls =
+ ((List) ((Condition.Relation)
src).value()).get(0).getClass().getName();
+ object.get("el").getAsJsonObject().add("valuecls", new
JsonPrimitive(valueCls));
+ }
+ }
+ }
+ return result;
+ }
+}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/QueryIdAdapter.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/QueryIdAdapter.java
new file mode 100644
index 000000000..e7ebaea76
--- /dev/null
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/serializer/QueryIdAdapter.java
@@ -0,0 +1,46 @@
+/*
+ * 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.backend.query.serializer;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import org.apache.hugegraph.backend.id.EdgeId;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.id.IdGenerator;
+import org.apache.hugegraph.backend.serializer.BinaryBackendEntry;
+
+import com.google.common.collect.ImmutableMap;
+
+public class QueryIdAdapter extends AbstractSerializerAdapter<Id> {
+
+ static ImmutableMap<String, Type> cls =
+ ImmutableMap.<String, Type>builder()
+ .put("E", EdgeId.class)
+ .put("S", IdGenerator.StringId.class)
+ .put("L", IdGenerator.LongId.class)
+ .put("U", IdGenerator.UuidId.class)
+ .put("O", IdGenerator.ObjectId.class)
+ .put("B", BinaryBackendEntry.BinaryId.class)
+ .build();
+
+ @Override
+ public Map<String, Type> validType() {
+ return cls;
+ }
+}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinaryBackendEntry.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinaryBackendEntry.java
index a3b3138e2..6f8fc21c9 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinaryBackendEntry.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BinaryBackendEntry.java
@@ -48,6 +48,11 @@ public class BinaryBackendEntry implements BackendEntry {
this(type, BytesBuffer.wrap(bytes).parseId(type, enablePartition));
}
+ // FIXME: `enablePartition` is unused here
+ public BinaryBackendEntry(HugeType type, byte[] bytes, boolean
enablePartition, boolean isOlap) {
+ this(type, BytesBuffer.wrap(bytes).parseOlapId(type, isOlap));
+ }
+
public BinaryBackendEntry(HugeType type, BinaryId id) {
this.type = type;
this.id = id;
@@ -169,7 +174,10 @@ public class BinaryBackendEntry implements BackendEntry {
return false;
}
if (!this.id().equals(other.id())) {
- return false;
+ // 兼容从ap查回的数据, vertex id
+ if (!this.id().origin().equals(other.originId())) {
+ return false;
+ }
}
this.columns(other.columns());
return true;
@@ -199,7 +207,7 @@ public class BinaryBackendEntry implements BackendEntry {
return this.id().hashCode() ^ this.columns.size();
}
- protected static final class BinaryId implements Id {
+ public static final class BinaryId implements Id {
private final byte[] bytes;
private final Id id;
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BytesBuffer.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BytesBuffer.java
index 7cc15188d..f293dd287 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BytesBuffer.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/serializer/BytesBuffer.java
@@ -597,6 +597,10 @@ public final class BytesBuffer extends OutputStream {
}
}
+ public static byte getType(int value) {
+ return (byte) (value & 0x3f);
+ }
+
public Object readProperty(DataType dataType) {
switch (dataType) {
case BOOLEAN:
@@ -752,11 +756,11 @@ public final class BytesBuffer extends OutputStream {
public BinaryId readIndexId(HugeType type) {
byte[] id;
if (type.isRange4Index()) {
- // IndexLabel 4 bytes + fieldValue 4 bytes
- id = this.read(8);
+ // HugeTypeCode 1 byte + IndexLabel 4 bytes + fieldValue 4 bytes
+ id = this.read(9);
} else if (type.isRange8Index()) {
- // IndexLabel 4 bytes + fieldValue 8 bytes
- id = this.read(12);
+ // HugeTypeCode 1 byte + IndexLabel 4 bytes + fieldValue 8 bytes
+ id = this.read(13);
} else {
assert type.isStringIndex();
id = this.readBytesWithEnding();
@@ -790,6 +794,34 @@ public final class BytesBuffer extends OutputStream {
return new BinaryId(bytes, id);
}
+ /**
+ * 解析 olap id
+ * @param type
+ * @param isOlap
+ * @return
+ */
+ public BinaryId parseOlapId(HugeType type, boolean isOlap) {
+ if (type.isIndex()) {
+ return this.readIndexId(type);
+ }
+ // Parse id from bytes
+ int start = this.buffer.position();
+ /**
+ * OLAP
+ * {PropertyKey}{VertexId}
+ */
+ if (isOlap) {
+ // 先 read olap property id
+ Id pkId = this.readId();
+ }
+ Id id = this.readId();
+ int end = this.buffer.position();
+ int len = end - start;
+ byte[] bytes = new byte[len];
+ System.arraycopy(this.array(), start, bytes, 0, len);
+ return new BinaryId(bytes, id);
+ }
+
private void writeNumber(long val) {
/*
* 8 kinds of number, 2 ~ 9 bytes number:
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/AbstractBackendStore.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/AbstractBackendStore.java
index 53ea9b4e4..2ef9a6db7 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/AbstractBackendStore.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/AbstractBackendStore.java
@@ -80,6 +80,13 @@ public abstract class AbstractBackendStore<Session extends
BackendSession>
protected abstract BackendTable<Session, ?> table(HugeType type);
+ protected static HugeType convertTaskOrServerToVertex(HugeType type) {
+ if (HugeType.TASK.equals(type) || HugeType.SERVER.equals(type)) {
+ return HugeType.VERTEX;
+ }
+ return type;
+ }
+
// NOTE: Need to support passing null
protected abstract Session session(HugeType type);
}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java
index 22f1cbff6..90001cc1e 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendFeatures.java
@@ -31,6 +31,8 @@ public interface BackendFeatures {
return false;
}
+ default boolean supportsTaskAndServerVertex() { return false; }
+
boolean supportsScanToken();
boolean supportsScanKeyPrefix();
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendMutation.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendMutation.java
index 64c4dfb6c..02b342900 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendMutation.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendMutation.java
@@ -350,4 +350,8 @@ public class BackendMutation {
this.mutations.clear();
}
}
+
+ public Map<HugeType, Map<Id, List<BackendAction>>> mutations() {
+ return this.updates.mutations;
+ }
}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendStore.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendStore.java
index a136aab1a..5c05e37c5 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendStore.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendStore.java
@@ -166,6 +166,10 @@ public interface BackendStore {
throw new
UnsupportedOperationException("BackendStore.removeOlapTable()");
}
+ default boolean existOlapTable(Id pkId) {
+ throw new
UnsupportedOperationException("BackendStore.existOlapTable()");
+ }
+
default Map<String, String> createSnapshot(String snapshotDir) {
throw new UnsupportedOperationException("createSnapshot");
}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendTable.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendTable.java
index 8715dc0e1..a9ee4b5c7 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendTable.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/BackendTable.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.lang3.NotImplementedException;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.serializer.BytesBuffer;
@@ -136,6 +137,10 @@ public abstract class BackendTable<Session extends
BackendSession, Entry> {
public abstract Iterator<BackendEntry> query(Session session, Query query);
+ public Iterator<BackendEntry> queryOlap(Session session, Query query) {
+ throw new NotImplementedException();
+ }
+
public abstract Number queryNumber(Session session, Query query);
public abstract boolean queryExist(Session session, Entry entry);
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/CoreOptions.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/CoreOptions.java
index 9b9bc5ca3..f17853d4a 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/CoreOptions.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/config/CoreOptions.java
@@ -297,6 +297,14 @@ public class CoreOptions extends OptionHolder {
0
);
+ public static final ConfigOption<Long> TASK_SCHEDULE_PERIOD =
+ new ConfigOption<>(
+ "task.schedule_period",
+ "Period time when scheduler to schedule task",
+ rangeInt(0L, Long.MAX_VALUE),
+ 10L
+ );
+
public static final ConfigOption<Long> TASK_WAIT_TIMEOUT =
new ConfigOption<>(
"task.wait_timeout",
@@ -331,6 +339,14 @@ public class CoreOptions extends OptionHolder {
1
);
+ public static final ConfigOption<String> SCHEDULER_TYPE =
+ new ConfigOption<>(
+ "task.scheduler_type",
+ "The type of scheduler used in distribution system.",
+ allowValues("local", "distributed"),
+ "local"
+ );
+
public static final ConfigOption<Boolean> TASK_SYNC_DELETION =
new ConfigOption<>(
"task.sync_deletion",
@@ -339,6 +355,14 @@ public class CoreOptions extends OptionHolder {
false
);
+ public static final ConfigOption<Integer> TASK_RETRY =
+ new ConfigOption<>(
+ "task.retry",
+ "Task retry times.",
+ rangeInt(0, 3),
+ 0
+ );
+
public static final ConfigOption<Long> STORE_CONN_DETECT_INTERVAL =
new ConfigOption<>(
"store.connection_detect_interval",
@@ -650,4 +674,11 @@ public class CoreOptions extends OptionHolder {
CollectionType::valueOf,
"EC"
);
+
+ public static final ConfigOption<String> PD_PEERS = new ConfigOption<>(
+ "pd.peers",
+ "The addresses of pd nodes, separated with commas.",
+ disallowEmpty(),
+ "127.0.0.1:8686"
+ );
}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/HugeTableType.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/HugeTableType.java
new file mode 100644
index 000000000..a3edf746f
--- /dev/null
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/HugeTableType.java
@@ -0,0 +1,64 @@
+/*
+ * 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.type;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hugegraph.type.define.SerialEnum;
+
+public enum HugeTableType implements SerialEnum {
+
+ UNKNOWN(0, "UNKNOWN"),
+
+ /* Schema types */
+ VERTEX(1, "V"), // 顶点表
+ OUT_EDGE(2, "OE"), // 出边表
+ IN_EDGE(3, "IE"), // 入边表
+ ALL_INDEX_TABLE(4, "INDEX"), // 索引表
+ TASK_INFO_TABLE(5, "TASK"), // 任务信息表
+ OLAP_TABLE(6, "OLAP"), // OLAP 表
+ SERVER_INFO_TABLE(7, "SERVER"); // SERVER 信息表
+
+ private static final Map<String, HugeTableType> ALL_NAME = new HashMap<>();
+
+ static {
+ SerialEnum.register(HugeTableType.class);
+ for (HugeTableType type : values()) {
+ ALL_NAME.put(type.name, type);
+ }
+ }
+
+ private byte type = 0;
+ private String name;
+
+ HugeTableType(int type, String name) {
+ assert type < 256;
+ this.type = (byte) type;
+ this.name = name;
+ }
+
+ @Override
+ public byte code() {
+ return this.type;
+ }
+
+ public String string() {
+ return this.name;
+ }
+}
diff --git
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/HugeType.java
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/HugeType.java
index aae2a07ae..c7d9fcea5 100644
---
a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/HugeType.java
+++
b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/type/HugeType.java
@@ -65,7 +65,8 @@ public enum HugeType implements SerialEnum {
SHARD_INDEX(175, "HI"),
UNIQUE_INDEX(178, "UI"),
- TASK(180, "T"),
+ TASK(180, "TASK"),
+ SERVER(181, "SERVER"),
// System schema
SYS_SCHEMA(250, "SS"),
@@ -115,7 +116,7 @@ public enum HugeType implements SerialEnum {
}
public boolean isVertex() {
- return this == HugeType.VERTEX;
+ return this == HugeType.VERTEX || this == HugeType.TASK || this ==
HugeType.SERVER;
}
public boolean isEdge() {
@@ -192,4 +193,8 @@ public enum HugeType implements SerialEnum {
public static HugeType fromCode(byte code) {
return SerialEnum.fromCode(HugeType.class, code);
}
+
+ public boolean isLabelIndex() {
+ return this == VERTEX_LABEL_INDEX || this == EDGE_LABEL_INDEX;
+ }
}