Skip to content

Commit

Permalink
add ReadFrequency
Browse files Browse the repository at this point in the history
Change-Id: I5db5a1bc91c14b659bbba27c2ad15b40245bc62a
  • Loading branch information
zhoney committed Jan 14, 2021
1 parent 7bfc0a3 commit 64f0e04
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ public Map<String, GraphMode> mode(@Context GraphManager manager,
public Map<String, GraphReadMode> graphReadMode(
@Context GraphManager manager,
@PathParam("name") String name,
GraphReadMode graphReadMode) {
GraphReadMode readMode) {
LOG.debug("Set graph read mode to: '{}' of graph '{}'",
graphReadMode, name);
readMode, name);

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

@GET
Expand All @@ -201,6 +201,6 @@ public Map<String, GraphReadMode> graphReadMode(
LOG.debug("Get graph read mode of graph '{}'", name);

HugeGraph g = graph(manager, name);
return ImmutableMap.of("graph_read_mode", g.graphReadMode());
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,8 +183,8 @@ private static class JsonPropertyKey implements Checkable {
public DataType dataType;
@JsonProperty("aggregate_type")
public AggregateType aggregateType;
@JsonProperty("olap")
public Boolean olap;
@JsonProperty("read_frequency")
public ReadFrequency readFrequency;
@JsonProperty("properties")
public String[] properties;
@JsonProperty("user_data")
Expand Down Expand Up @@ -223,8 +224,8 @@ private PropertyKey.Builder convert2Builder(HugeGraph g) {
if (this.aggregateType != null) {
builder.aggregateType(this.aggregateType);
}
if (this.olap != null) {
builder.olap(this.olap);
if (this.readFrequency != null) {
builder.readFrequency(this.readFrequency);
}
if (this.userdata != null) {
builder.userdata(this.userdata);
Expand All @@ -239,10 +240,10 @@ private PropertyKey.Builder convert2Builder(HugeGraph g) {
public String toString() {
return String.format("JsonPropertyKey{name=%s, cardinality=%s, " +
"dataType=%s, aggregateType=%s, " +
"olap=%s, properties=%s}",
"readFrequency=%s, properties=%s}",
this.name, this.cardinality,
this.dataType, this.aggregateType,
this.olap, this.properties);
this.readFrequency, this.properties);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,15 @@ public void mode(GraphMode mode) {
}

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +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.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 @@ -137,8 +137,8 @@ public interface HugeGraph extends Graph {
public GraphMode mode();
public void mode(GraphMode mode);

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

public void waitStarted();
public void serverStarted(Id serverId, NodeRole serverRole);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface HugeGraphParams {
public HugeGraph graph();
public String name();
public GraphMode mode();
public GraphReadMode graphReadMode();
public GraphReadMode readMode();

public SchemaTransaction schemaTransaction();
public GraphTransaction systemTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +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 GraphReadMode readMode;
private volatile HugeVariables variables;

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

LockUtil.init(this.name);

Expand Down Expand Up @@ -269,13 +269,13 @@ public void mode(GraphMode mode) {
}

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

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

@Override
Expand Down Expand Up @@ -971,8 +971,8 @@ public GraphMode mode() {
}

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

@Override
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,7 +998,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());
writeEnum(HugeKeys.READ_FREQUENCY, schema.readFrequency());
writeIds(HugeKeys.PROPERTIES, schema.properties());
writeEnum(HugeKeys.STATUS, schema.status());
writeUserdata(schema);
Expand All @@ -1017,7 +1018,8 @@ public PropertyKey readPropertyKey(HugeGraph graph,
Cardinality.class));
propertyKey.aggregateType(readEnum(HugeKeys.AGGREGATE_TYPE,
AggregateType.class));
propertyKey.olap(readBool(HugeKeys.OLAP));
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,7 +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.OLAP, propertyKey.olap());
entry.column(HugeKeys.READ_FREQUENCY,
propertyKey.readFrequency().code());
entry.column(HugeKeys.PROPERTIES,
this.toLongSet(propertyKey.properties()));
this.writeUserdata(propertyKey, entry);
Expand Down Expand Up @@ -561,7 +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);
Boolean olap = entry.column(HugeKeys.OLAP);
Number readFrequency = entry.column(HugeKeys.READ_FREQUENCY);
Object properties = entry.column(HugeKeys.PROPERTIES);
Number status = entry.column(HugeKeys.STATUS);

Expand All @@ -573,7 +575,9 @@ public PropertyKey readPropertyKey(HugeGraph graph,
propertyKey.aggregateType(SerialEnum.fromCode(
AggregateType.class,
aggregateType.byteValue()));
propertyKey.olap(olap);
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 @@ -98,7 +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.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 @@ -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,14 +46,14 @@ public class PropertyKey extends SchemaElement implements Propfiable {
private DataType dataType;
private Cardinality cardinality;
private AggregateType aggregateType;
private boolean olap;
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.olap = false;
this.readFrequency = ReadFrequency.OLTP;
}

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

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

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

@Override
Expand Down Expand Up @@ -119,7 +120,7 @@ public boolean hasSameContent(PropertyKey other) {
this.dataType == other.dataType() &&
this.cardinality == other.cardinality() &&
this.aggregateType == other.aggregateType() &&
this.olap == other.olap();
this.readFrequency == other.readFrequency();
}

public String clazz() {
Expand Down Expand Up @@ -385,7 +386,7 @@ public interface Builder extends SchemaBuilder<PropertyKey> {

Builder calcList();

Builder olap(boolean olap);
Builder readFrequency(ReadFrequency readFrequency);

Builder cardinality(Cardinality cardinality);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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;

public class PropertyKeyBuilder extends AbstractBuilder
Expand All @@ -46,7 +47,7 @@ public class PropertyKeyBuilder extends AbstractBuilder
private DataType dataType;
private Cardinality cardinality;
private AggregateType aggregateType;
private boolean olap;
private ReadFrequency readFrequency;
private boolean checkExist;
private Userdata userdata;

Expand All @@ -59,7 +60,7 @@ public PropertyKeyBuilder(SchemaTransaction transaction,
this.dataType = DataType.TEXT;
this.cardinality = Cardinality.SINGLE;
this.aggregateType = AggregateType.NONE;
this.olap = false;
this.readFrequency = ReadFrequency.OLTP;
this.userdata = new Userdata();
this.checkExist = true;
}
Expand All @@ -73,7 +74,7 @@ public PropertyKeyBuilder(SchemaTransaction transaction,
this.dataType = copy.dataType();
this.cardinality = copy.cardinality();
this.aggregateType = copy.aggregateType();
this.olap = copy.olap();
this.readFrequency = copy.readFrequency();
this.userdata = new Userdata(copy.userdata());
this.checkExist = false;
}
Expand All @@ -86,7 +87,7 @@ public PropertyKey build() {
propertyKey.dataType(this.dataType);
propertyKey.cardinality(this.cardinality);
propertyKey.aggregateType(this.aggregateType);
propertyKey.olap(this.olap);
propertyKey.readFrequency(this.readFrequency);
propertyKey.userdata(this.userdata);
return propertyKey;
}
Expand Down Expand Up @@ -141,7 +142,7 @@ private boolean hasSameProperties(PropertyKey propertyKey) {
return false;
}

if (this.olap != propertyKey.olap()) {
if (this.readFrequency != propertyKey.readFrequency()) {
return false;
}

Expand Down Expand Up @@ -312,8 +313,8 @@ public PropertyKey.Builder calcList() {
}

@Override
public PropertyKey.Builder olap(boolean olap) {
this.olap = olap;
public PropertyKey.Builder readFrequency(ReadFrequency readFrequency) {
this.readFrequency = readFrequency;
return this;
}

Expand Down Expand Up @@ -409,7 +410,7 @@ private void checkAggregateType() {
}

private void checkOlap() {
if (!this.olap) {
if (this.readFrequency == ReadFrequency.OLTP) {
return;
}

Expand All @@ -421,7 +422,7 @@ private void checkOlap() {

if (!this.aggregateType.isNone()) {
throw new NotAllowException(
"Not allow to set aggregate type '%s' for olap result " +
"Not allow to set aggregate type '%s' for olap " +
"property key '%s'", this.aggregateType, this.name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum HugeKeys {
DATA_TYPE(120, "data_type"),
CARDINALITY(121, "cardinality"),
AGGREGATE_TYPE(122, "aggregate_type"),
OLAP(123, "olap"),
READ_FREQUENCY(123, "read_frequency"),

/* Column names of schema type (IndexLabel) */
BASE_TYPE(150, "base_type"),
Expand Down
Loading

0 comments on commit 64f0e04

Please sign in to comment.