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 all 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 readMode) {
LOG.debug("Set graph read mode to: '{}' of graph '{}'",
readMode, name);

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

@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.readMode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.baidu.hugegraph.type.define.Cardinality;
import com.baidu.hugegraph.type.define.DataType;
import com.baidu.hugegraph.type.define.GraphMode;
import com.baidu.hugegraph.type.define.ReadFrequency;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
Expand Down Expand Up @@ -182,6 +183,8 @@ private static class JsonPropertyKey implements Checkable {
public DataType dataType;
@JsonProperty("aggregate_type")
public AggregateType aggregateType;
@JsonProperty("read_frequency")
public ReadFrequency readFrequency;
@JsonProperty("properties")
public String[] properties;
@JsonProperty("user_data")
Expand Down Expand Up @@ -221,6 +224,9 @@ private PropertyKey.Builder convert2Builder(HugeGraph g) {
if (this.aggregateType != null) {
builder.aggregateType(this.aggregateType);
}
if (this.readFrequency != null) {
builder.readFrequency(this.readFrequency);
}
if (this.userdata != null) {
builder.userdata(this.userdata);
}
Expand All @@ -234,10 +240,10 @@ private PropertyKey.Builder convert2Builder(HugeGraph g) {
public String toString() {
return String.format("JsonPropertyKey{name=%s, cardinality=%s, " +
"dataType=%s, aggregateType=%s, " +
"properties=%s}",
"readFrequency=%s, properties=%s}",
this.name, this.cardinality,
this.dataType, this.aggregateType,
this.properties);
this.readFrequency, 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 readMode() {
this.verifyPermission(HugePermission.READ, ResourceType.STATUS);
return this.hugegraph.readMode();
}

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

@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.READ_FREQUENCY, DataType.tinyint())
.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 readMode();
public void readMode(GraphReadMode readMode);

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 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 readMode;
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.readMode = 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 readMode() {
return this.readMode;
}

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

@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 readMode() {
return StandardHugeGraph.this.readMode();
}

@Override
public SchemaTransaction schemaTransaction() {
return StandardHugeGraph.this.schemaTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.type.define.IdStrategy;
import com.baidu.hugegraph.type.define.IndexType;
import com.baidu.hugegraph.type.define.ReadFrequency;
import com.baidu.hugegraph.type.define.SchemaStatus;
import com.baidu.hugegraph.type.define.SerialEnum;
import com.baidu.hugegraph.util.Bytes;
Expand Down Expand Up @@ -997,6 +998,7 @@ public BinaryBackendEntry writePropertyKey(PropertyKey schema) {
writeEnum(HugeKeys.DATA_TYPE, schema.dataType());
writeEnum(HugeKeys.CARDINALITY, schema.cardinality());
writeEnum(HugeKeys.AGGREGATE_TYPE, schema.aggregateType());
writeEnum(HugeKeys.READ_FREQUENCY, schema.readFrequency());
writeIds(HugeKeys.PROPERTIES, schema.properties());
writeEnum(HugeKeys.STATUS, schema.status());
writeUserdata(schema);
Expand All @@ -1016,6 +1018,8 @@ public PropertyKey readPropertyKey(HugeGraph graph,
Cardinality.class));
propertyKey.aggregateType(readEnum(HugeKeys.AGGREGATE_TYPE,
AggregateType.class));
propertyKey.readFrequency(readEnum(HugeKeys.READ_FREQUENCY,
ReadFrequency.class));
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 @@ -56,6 +56,7 @@
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.type.define.IdStrategy;
import com.baidu.hugegraph.type.define.IndexType;
import com.baidu.hugegraph.type.define.ReadFrequency;
import com.baidu.hugegraph.type.define.SchemaStatus;
import com.baidu.hugegraph.type.define.SerialEnum;
import com.baidu.hugegraph.util.E;
Expand Down Expand Up @@ -464,6 +465,8 @@ public BackendEntry writePropertyKey(PropertyKey propertyKey) {
entry.column(HugeKeys.CARDINALITY, propertyKey.cardinality().code());
entry.column(HugeKeys.AGGREGATE_TYPE,
propertyKey.aggregateType().code());
entry.column(HugeKeys.READ_FREQUENCY,
propertyKey.readFrequency().code());
entry.column(HugeKeys.PROPERTIES,
this.toLongSet(propertyKey.properties()));
this.writeUserdata(propertyKey, entry);
Expand Down Expand Up @@ -560,6 +563,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);
Number readFrequency = entry.column(HugeKeys.READ_FREQUENCY);
Object properties = entry.column(HugeKeys.PROPERTIES);
Number status = entry.column(HugeKeys.STATUS);

Expand All @@ -571,6 +575,9 @@ public PropertyKey readPropertyKey(HugeGraph graph,
propertyKey.aggregateType(SerialEnum.fromCode(
AggregateType.class,
aggregateType.byteValue()));
propertyKey.readFrequency(SerialEnum.fromCode(
ReadFrequency.class,
readFrequency.byteValue()));
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.READ_FREQUENCY, propertyKey.readFrequency());
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 @@ -37,6 +37,7 @@
import com.baidu.hugegraph.type.define.AggregateType;
import com.baidu.hugegraph.type.define.Cardinality;
import com.baidu.hugegraph.type.define.DataType;
import com.baidu.hugegraph.type.define.ReadFrequency;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.LongEncoding;

Expand All @@ -45,12 +46,14 @@ public class PropertyKey extends SchemaElement implements Propfiable {
private DataType dataType;
private Cardinality cardinality;
private AggregateType aggregateType;
private ReadFrequency readFrequency;

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.readFrequency = ReadFrequency.OLTP;
}

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

public void readFrequency(ReadFrequency readFrequency) {
this.readFrequency = readFrequency;
}

public ReadFrequency readFrequency() {
return this.readFrequency;
}

@Override
public Set<Id> properties() {
return Collections.emptySet();
Expand All @@ -108,7 +119,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.readFrequency == other.readFrequency();
}

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

Builder calcOld();

Builder calcSet();

Builder calcList();

Builder readFrequency(ReadFrequency readFrequency);

Builder cardinality(Cardinality cardinality);

Builder dataType(DataType dataType);
Expand Down
Loading