Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support graph read mode and set/list aggregate property #1332

Merged
merged 6 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugegraph-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>0.58.0.0</Implementation-Version>
<Implementation-Version>0.59.0.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.baidu.hugegraph.core.GraphManager;
import com.baidu.hugegraph.server.RestServer;
import com.baidu.hugegraph.type.define.GraphMode;
import com.baidu.hugegraph.type.define.GraphReadMode;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
Expand Down Expand Up @@ -167,4 +168,39 @@ public Map<String, GraphMode> mode(@Context GraphManager manager,
HugeGraph g = graph(manager, name);
return ImmutableMap.of("mode", g.mode());
}

@PUT
@Timed
@Path("{name}/graph_read_mode")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed("admin")
public Map<String, GraphReadMode> graphReadMode(
@Context GraphManager manager,
@PathParam("name") String name,
GraphReadMode graphReadMode) {
LOG.debug("Set graph read mode to: '{}' of graph '{}'",
graphReadMode, name);

E.checkArgument(graphReadMode != null,
"Graph read mode can't be null");
HugeGraph g = graph(manager, name);
g.graphReadMode(graphReadMode);
return ImmutableMap.of("graph_read_mode", graphReadMode);
}

@GET
@Timed
@Path("{name}/graph_read_mode")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin", "$owner=$name"})
public Map<String, GraphReadMode> graphReadMode(
@Context GraphManager manager,
@PathParam("name") String name) {
LOG.debug("Get graph read mode of graph '{}'", name);

HugeGraph g = graph(manager, name);
return ImmutableMap.of("graph_read_mode", g.graphReadMode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ private static class JsonPropertyKey implements Checkable {
public DataType dataType;
@JsonProperty("aggregate_type")
public AggregateType aggregateType;
@JsonProperty("olap")
public Boolean olap;
@JsonProperty("properties")
public String[] properties;
@JsonProperty("user_data")
Expand Down Expand Up @@ -221,6 +223,9 @@ private PropertyKey.Builder convert2Builder(HugeGraph g) {
if (this.aggregateType != null) {
builder.aggregateType(this.aggregateType);
}
if (this.olap != null) {
builder.olap(this.olap);
}
if (this.userdata != null) {
builder.userdata(this.userdata);
}
Expand All @@ -234,10 +239,10 @@ private PropertyKey.Builder convert2Builder(HugeGraph g) {
public String toString() {
return String.format("JsonPropertyKey{name=%s, cardinality=%s, " +
"dataType=%s, aggregateType=%s, " +
"properties=%s}",
"olap=%s, properties=%s}",
this.name, this.cardinality,
this.dataType, this.aggregateType,
this.properties);
this.olap, this.properties);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.type.Namifiable;
import com.baidu.hugegraph.type.define.GraphMode;
import com.baidu.hugegraph.type.define.GraphReadMode;
import com.baidu.hugegraph.type.define.NodeRole;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
Expand Down Expand Up @@ -596,6 +597,18 @@ public void mode(GraphMode mode) {
this.hugegraph.mode(mode);
}

@Override
public GraphReadMode graphReadMode() {
this.verifyPermission(HugePermission.READ, ResourceType.STATUS);
return this.hugegraph.graphReadMode();
}

@Override
public void graphReadMode(GraphReadMode graphReadMode) {
this.verifyPermission(HugePermission.WRITE, ResourceType.STATUS);
this.hugegraph.graphReadMode(graphReadMode);
}

@Override
public void waitStarted() {
this.verifyPermission(HugePermission.READ, ResourceType.STATUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ public final class ApiVersion {
* [0.57] Issue-1105: Allow not rebuild index when create index label
* [0.58] Issue-1173: Supports customized kout/kneighbor,
* multi-node-shortest-path, jaccard-similar and template-paths
* [0.59] Issue-1333: Support graph read mode for olap property
*/

// The second parameter of Version.of() is for IDE running without JAR
public static final Version VERSION = Version.of(ApiVersion.class, "0.58");
public static final Version VERSION = Version.of(ApiVersion.class, "0.59");

public static final void check() {
// Check version of hugegraph-core. Firstly do check from version 0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ public boolean supportsAggregateProperty() {
public boolean supportsTtl() {
return true;
}

@Override
public boolean supportsOlapProperties() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void init(CassandraSessionPool.Session session) {
.put(HugeKeys.DATA_TYPE, DataType.tinyint())
.put(HugeKeys.CARDINALITY, DataType.tinyint())
.put(HugeKeys.AGGREGATE_TYPE, DataType.tinyint())
.put(HugeKeys.OLAP, DataType.cboolean())
.put(HugeKeys.PROPERTIES, DataType.set(TYPE_PK))
.put(HugeKeys.USER_DATA, TYPE_UD)
.put(HugeKeys.STATUS, DataType.tinyint())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.baidu.hugegraph.traversal.optimize.HugeVertexStepStrategy;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.type.define.GraphMode;
import com.baidu.hugegraph.type.define.GraphReadMode;
import com.baidu.hugegraph.type.define.NodeRole;

/**
Expand Down Expand Up @@ -136,6 +137,9 @@ public interface HugeGraph extends Graph {
public GraphMode mode();
public void mode(GraphMode mode);

public GraphReadMode graphReadMode();
public void graphReadMode(GraphReadMode graphReadMode);

public void waitStarted();
public void serverStarted(Id serverId, NodeRole serverRole);
public boolean started();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.baidu.hugegraph.event.EventHub;
import com.baidu.hugegraph.task.ServerInfoManager;
import com.baidu.hugegraph.type.define.GraphMode;
import com.baidu.hugegraph.type.define.GraphReadMode;
import com.google.common.util.concurrent.RateLimiter;

/**
Expand All @@ -40,6 +41,7 @@ public interface HugeGraphParams {
public HugeGraph graph();
public String name();
public GraphMode mode();
public GraphReadMode graphReadMode();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readMode


public SchemaTransaction schemaTransaction();
public GraphTransaction systemTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import com.baidu.hugegraph.task.TaskScheduler;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.type.define.GraphMode;
import com.baidu.hugegraph.type.define.GraphReadMode;
import com.baidu.hugegraph.type.define.NodeRole;
import com.baidu.hugegraph.util.DateUtil;
import com.baidu.hugegraph.util.E;
Expand Down Expand Up @@ -123,6 +124,7 @@ public class StandardHugeGraph implements HugeGraph {
private volatile boolean started;
private volatile boolean closed;
private volatile GraphMode mode;
private volatile GraphReadMode graphReadMode;
private volatile HugeVariables variables;

private final String name;
Expand Down Expand Up @@ -179,6 +181,7 @@ public StandardHugeGraph(HugeConfig config) {
this.started = false;
this.closed = false;
this.mode = GraphMode.NONE;
this.graphReadMode = GraphReadMode.OLTP_ONLY;

LockUtil.init(this.name);

Expand Down Expand Up @@ -265,6 +268,16 @@ public void mode(GraphMode mode) {
this.mode = mode;
}

@Override
public GraphReadMode graphReadMode() {
return this.graphReadMode;
}

@Override
public void graphReadMode(GraphReadMode graphReadMode) {
this.graphReadMode = graphReadMode;
}

@Override
public void waitStarted() {
// Just for trigger Tx.getOrNewTransaction, then load 3 stores
Expand Down Expand Up @@ -957,6 +970,11 @@ public GraphMode mode() {
return StandardHugeGraph.this.mode();
}

@Override
public GraphReadMode graphReadMode() {
return StandardHugeGraph.this.graphReadMode();
}

@Override
public SchemaTransaction schemaTransaction() {
return StandardHugeGraph.this.schemaTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ public BinaryBackendEntry writePropertyKey(PropertyKey schema) {
writeEnum(HugeKeys.DATA_TYPE, schema.dataType());
writeEnum(HugeKeys.CARDINALITY, schema.cardinality());
writeEnum(HugeKeys.AGGREGATE_TYPE, schema.aggregateType());
writeBool(HugeKeys.OLAP, schema.olap());
writeIds(HugeKeys.PROPERTIES, schema.properties());
writeEnum(HugeKeys.STATUS, schema.status());
writeUserdata(schema);
Expand All @@ -1016,6 +1017,7 @@ public PropertyKey readPropertyKey(HugeGraph graph,
Cardinality.class));
propertyKey.aggregateType(readEnum(HugeKeys.AGGREGATE_TYPE,
AggregateType.class));
propertyKey.olap(readBool(HugeKeys.OLAP));
propertyKey.properties(readIds(HugeKeys.PROPERTIES));
propertyKey.status(readEnum(HugeKeys.STATUS, SchemaStatus.class));
readUserdata(propertyKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ public BackendEntry writePropertyKey(PropertyKey propertyKey) {
entry.column(HugeKeys.CARDINALITY, propertyKey.cardinality().code());
entry.column(HugeKeys.AGGREGATE_TYPE,
propertyKey.aggregateType().code());
entry.column(HugeKeys.OLAP, propertyKey.olap());
entry.column(HugeKeys.PROPERTIES,
this.toLongSet(propertyKey.properties()));
this.writeUserdata(propertyKey, entry);
Expand Down Expand Up @@ -560,6 +561,7 @@ public PropertyKey readPropertyKey(HugeGraph graph,
Number dataType = entry.column(HugeKeys.DATA_TYPE);
Number cardinality = entry.column(HugeKeys.CARDINALITY);
Number aggregateType = entry.column(HugeKeys.AGGREGATE_TYPE);
Boolean olap = entry.column(HugeKeys.OLAP);
Object properties = entry.column(HugeKeys.PROPERTIES);
Number status = entry.column(HugeKeys.STATUS);

Expand All @@ -571,6 +573,7 @@ public PropertyKey readPropertyKey(HugeGraph graph,
propertyKey.aggregateType(SerialEnum.fromCode(
AggregateType.class,
aggregateType.byteValue()));
propertyKey.olap(olap);
propertyKey.properties(this.toIdArray(properties));

this.readUserdata(propertyKey, entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ public default boolean supportsPersistence() {
public boolean supportsAggregateProperty();

public boolean supportsTtl();

public boolean supportsOlapProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,10 @@ public boolean supportsAggregateProperty() {
public boolean supportsTtl() {
return false;
}

@Override
public boolean supportsOlapProperties() {
return false;
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public Map<HugeKeys, Object> writePropertyKey(PropertyKey propertyKey) {
map.put(HugeKeys.DATA_TYPE, propertyKey.dataType());
map.put(HugeKeys.CARDINALITY, propertyKey.cardinality());
map.put(HugeKeys.AGGREGATE_TYPE, propertyKey.aggregateType());
map.put(HugeKeys.OLAP, propertyKey.olap());
map.put(HugeKeys.PROPERTIES,
graph.mapPkId2Name(propertyKey.properties()));
map.put(HugeKeys.STATUS, propertyKey.status());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ private SchemaElement schemaElement() {
"Invalid HugeType '%s' for rebuild", type));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ public class PropertyKey extends SchemaElement implements Propfiable {
private DataType dataType;
private Cardinality cardinality;
private AggregateType aggregateType;
private boolean olap;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer define enum ReadFrequency include OLTP and OLAP, maybe we'll add OLTP_COLD in the future


public PropertyKey(final HugeGraph graph, Id id, String name) {
super(graph, id, name);
this.dataType = DataType.TEXT;
this.cardinality = Cardinality.SINGLE;
this.aggregateType = AggregateType.NONE;
this.olap = false;
}

@Override
Expand Down Expand Up @@ -82,6 +84,14 @@ public void aggregateType(AggregateType aggregateType) {
this.aggregateType = aggregateType;
}

public void olap(boolean olap) {
this.olap = olap;
}

public boolean olap() {
return this.olap;
}

@Override
public Set<Id> properties() {
return Collections.emptySet();
Expand All @@ -108,7 +118,8 @@ public boolean hasSameContent(PropertyKey other) {
return super.hasSameContent(other) &&
this.dataType == other.dataType() &&
this.cardinality == other.cardinality() &&
this.aggregateType == other.aggregateType();
this.aggregateType == other.aggregateType() &&
this.olap == other.olap();
}

public String clazz() {
Expand Down Expand Up @@ -370,6 +381,12 @@ public interface Builder extends SchemaBuilder<PropertyKey> {

Builder calcOld();

Builder calcSet();

Builder calcList();

Builder olap(boolean olap);

Builder cardinality(Cardinality cardinality);

Builder dataType(DataType dataType);
Expand Down
Loading