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

upgrade store version due to read frequency of property key #1341

Merged
merged 4 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,9 @@ public PropertyKey readPropertyKey(HugeGraph graph,
Cardinality.class));
propertyKey.aggregateType(readEnum(HugeKeys.AGGREGATE_TYPE,
AggregateType.class));
propertyKey.readFrequency(readEnum(HugeKeys.READ_FREQUENCY,
ReadFrequency.class));
propertyKey.readFrequency(readEnumOrDefault(HugeKeys.READ_FREQUENCY,
ReadFrequency.class,
ReadFrequency.OLTP));
propertyKey.properties(readIds(HugeKeys.PROPERTIES));
propertyKey.status(readEnum(HugeKeys.STATUS, SchemaStatus.class));
readUserdata(propertyKey);
Expand Down Expand Up @@ -1095,6 +1096,17 @@ private <T extends SerialEnum> T readEnum(HugeKeys key,
return SerialEnum.fromCode(clazz, value[0]);
}

private <T extends SerialEnum> T readEnumOrDefault(HugeKeys key,
Class<T> clazz,
T defaultValue) {
BackendColumn column = this.entry.column(formatColumnName(key));
if (column == null) {
return defaultValue;
}
E.checkNotNull(column.value, "column.value");
return SerialEnum.fromCode(clazz, column.value[0]);
}

private void writeLong(HugeKeys key, long value) {
@SuppressWarnings("resource")
BytesBuffer buffer = new BytesBuffer(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,28 +485,28 @@ public VertexLabel readVertexLabel(HugeGraph graph,

Number id = schemaColumn(entry, HugeKeys.ID);
String name = schemaColumn(entry, HugeKeys.NAME);
Number idStrategy = schemaColumn(entry, HugeKeys.ID_STRATEGY);
IdStrategy idStrategy = schemaEnum(entry, HugeKeys.ID_STRATEGY,
IdStrategy.class);
Object properties = schemaColumn(entry, HugeKeys.PROPERTIES);
Object primaryKeys = schemaColumn(entry, HugeKeys.PRIMARY_KEYS);
Object nullableKeys = schemaColumn(entry, HugeKeys.NULLABLE_KEYS);
Object indexLabels = schemaColumn(entry, HugeKeys.INDEX_LABELS);
Number status = schemaColumn(entry, HugeKeys.STATUS);
SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS,
SchemaStatus.class);
Number ttl = schemaColumn(entry, HugeKeys.TTL);
Number ttlStartTime = schemaColumn(entry, HugeKeys.TTL_START_TIME);

VertexLabel vertexLabel = new VertexLabel(graph, this.toId(id), name);
vertexLabel.idStrategy(SerialEnum.fromCode(IdStrategy.class,
idStrategy.byteValue()));
vertexLabel.idStrategy(idStrategy);
vertexLabel.properties(this.toIdArray(properties));
vertexLabel.primaryKeys(this.toIdArray(primaryKeys));
vertexLabel.nullableKeys(this.toIdArray(nullableKeys));
vertexLabel.indexLabels(this.toIdArray(indexLabels));
this.readEnableLabelIndex(vertexLabel, entry);
this.readUserdata(vertexLabel, entry);
vertexLabel.status(SerialEnum.fromCode(SchemaStatus.class,
status.byteValue()));
vertexLabel.status(status);
vertexLabel.ttl(ttl.longValue());
vertexLabel.ttlStartTime(this.toId(ttlStartTime));
this.readEnableLabelIndex(vertexLabel, entry);
this.readUserdata(vertexLabel, entry);
return vertexLabel;
}

Expand All @@ -520,32 +520,32 @@ public EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry backendEntry) {

Number id = schemaColumn(entry, HugeKeys.ID);
String name = schemaColumn(entry, HugeKeys.NAME);
Number frequency = schemaColumn(entry, HugeKeys.FREQUENCY);
Frequency frequency = schemaEnum(entry, HugeKeys.FREQUENCY,
Frequency.class);
Number sourceLabel = schemaColumn(entry, HugeKeys.SOURCE_LABEL);
Number targetLabel = schemaColumn(entry, HugeKeys.TARGET_LABEL);
Object sortKeys = schemaColumn(entry, HugeKeys.SORT_KEYS);
Object nullableKeys = schemaColumn(entry, HugeKeys.NULLABLE_KEYS);
Object properties = schemaColumn(entry, HugeKeys.PROPERTIES);
Object indexLabels = schemaColumn(entry, HugeKeys.INDEX_LABELS);
Number status = schemaColumn(entry, HugeKeys.STATUS);
SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS,
SchemaStatus.class);
Number ttl = schemaColumn(entry, HugeKeys.TTL);
Number ttlStartTime = schemaColumn(entry, HugeKeys.TTL_START_TIME);

EdgeLabel edgeLabel = new EdgeLabel(graph, this.toId(id), name);
edgeLabel.frequency(SerialEnum.fromCode(Frequency.class,
frequency.byteValue()));
edgeLabel.frequency(frequency);
edgeLabel.sourceLabel(this.toId(sourceLabel));
edgeLabel.targetLabel(this.toId(targetLabel));
edgeLabel.properties(this.toIdArray(properties));
edgeLabel.sortKeys(this.toIdArray(sortKeys));
edgeLabel.nullableKeys(this.toIdArray(nullableKeys));
edgeLabel.indexLabels(this.toIdArray(indexLabels));
this.readEnableLabelIndex(edgeLabel, entry);
this.readUserdata(edgeLabel, entry);
edgeLabel.status(SerialEnum.fromCode(SchemaStatus.class,
status.byteValue()));
edgeLabel.status(status);
edgeLabel.ttl(ttl.longValue());
edgeLabel.ttlStartTime(this.toId(ttlStartTime));
this.readEnableLabelIndex(edgeLabel, entry);
this.readUserdata(edgeLabel, entry);
return edgeLabel;
}

Expand All @@ -560,29 +560,27 @@ public PropertyKey readPropertyKey(HugeGraph graph,

Number id = schemaColumn(entry, HugeKeys.ID);
String name = schemaColumn(entry, HugeKeys.NAME);
Number dataType = schemaColumn(entry, HugeKeys.DATA_TYPE);
Number cardinality = schemaColumn(entry, HugeKeys.CARDINALITY);
Number aggregateType = schemaColumn(entry, HugeKeys.AGGREGATE_TYPE);
Number readFrequency = schemaColumn(entry, HugeKeys.READ_FREQUENCY);
DataType dataType = schemaEnum(entry, HugeKeys.DATA_TYPE,
DataType.class);
Cardinality cardinality = schemaEnum(entry, HugeKeys.CARDINALITY,
Cardinality.class);
AggregateType aggregateType = schemaEnum(entry, HugeKeys.AGGREGATE_TYPE,
AggregateType.class);
ReadFrequency readFrequency = schemaEnumOrDefault(
entry, HugeKeys.READ_FREQUENCY,
ReadFrequency.class, ReadFrequency.OLTP);
Object properties = schemaColumn(entry, HugeKeys.PROPERTIES);
Number status = schemaColumn(entry, HugeKeys.STATUS);
SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS,
SchemaStatus.class);

PropertyKey propertyKey = new PropertyKey(graph, this.toId(id), name);
propertyKey.dataType(SerialEnum.fromCode(DataType.class,
dataType.byteValue()));
propertyKey.cardinality(SerialEnum.fromCode(Cardinality.class,
cardinality.byteValue()));
propertyKey.aggregateType(SerialEnum.fromCode(
AggregateType.class,
aggregateType.byteValue()));
propertyKey.readFrequency(SerialEnum.fromCode(
ReadFrequency.class,
readFrequency.byteValue()));
propertyKey.dataType(dataType);
propertyKey.cardinality(cardinality);
propertyKey.aggregateType(aggregateType);
propertyKey.readFrequency(readFrequency);
propertyKey.properties(this.toIdArray(properties));

propertyKey.status(status);
this.readUserdata(propertyKey, entry);
propertyKey.status(SerialEnum.fromCode(SchemaStatus.class,
status.byteValue()));
return propertyKey;
}

Expand Down Expand Up @@ -612,22 +610,22 @@ public IndexLabel readIndexLabel(HugeGraph graph,

Number id = schemaColumn(entry, HugeKeys.ID);
String name = schemaColumn(entry, HugeKeys.NAME);
Number baseType = schemaColumn(entry, HugeKeys.BASE_TYPE);
HugeType baseType = schemaEnum(entry, HugeKeys.BASE_TYPE,
HugeType.class);
Number baseValueId = schemaColumn(entry, HugeKeys.BASE_VALUE);
Number indexType = schemaColumn(entry, HugeKeys.INDEX_TYPE);
IndexType indexType = schemaEnum(entry, HugeKeys.INDEX_TYPE,
IndexType.class);
Object indexFields = schemaColumn(entry, HugeKeys.FIELDS);
Number status = schemaColumn(entry, HugeKeys.STATUS);
SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS,
SchemaStatus.class);

IndexLabel indexLabel = new IndexLabel(graph, this.toId(id), name);
indexLabel.baseType(SerialEnum.fromCode(HugeType.class,
baseType.byteValue()));
indexLabel.baseType(baseType);
indexLabel.baseValue(this.toId(baseValueId));
indexLabel.indexType(SerialEnum.fromCode(IndexType.class,
indexType.byteValue()));
indexLabel.indexType(indexType);
indexLabel.indexFields(this.toIdArray(indexFields));
indexLabel.status(status);
this.readUserdata(indexLabel, entry);
indexLabel.status(SerialEnum.fromCode(SchemaStatus.class,
status.byteValue()));
return indexLabel;
}

Expand Down Expand Up @@ -683,9 +681,27 @@ protected abstract void readUserdata(SchemaElement schema,
private static <T> T schemaColumn(TableBackendEntry entry, HugeKeys key) {
assert entry.type().isSchema();

T column = entry.column(key);
E.checkState(column != null, "Not found key '%s' from entry %s",
key, entry);
return column;
T value = entry.column(key);
E.checkState(value != null,
"Not found key '%s' from entry %s", key, entry);
return value;
}

private <T extends SerialEnum> T schemaEnum(TableBackendEntry entry,
Copy link
Contributor

Choose a reason for hiding this comment

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

set static

HugeKeys key, Class<T> clazz) {
Number value = schemaColumn(entry, key);
return SerialEnum.fromCode(clazz, value.byteValue());
}

private <T extends SerialEnum> T schemaEnumOrDefault(
TableBackendEntry entry, HugeKeys key,
Class<T> clazz, T defaultValue) {
assert entry.type().isSchema();

Number value = entry.column(key);
if (value == null) {
return defaultValue;
}
return SerialEnum.fromCode(clazz, value.byteValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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.util.E;
import com.baidu.hugegraph.util.JsonUtil;
Expand Down Expand Up @@ -658,6 +659,8 @@ public BackendEntry writePropertyKey(PropertyKey propertyKey) {
JsonUtil.toJson(propertyKey.cardinality()));
entry.column(HugeKeys.AGGREGATE_TYPE,
JsonUtil.toJson(propertyKey.aggregateType()));
entry.column(HugeKeys.READ_FREQUENCY,
JsonUtil.toJson(propertyKey.readFrequency()));
entry.column(HugeKeys.PROPERTIES, writeIds(propertyKey.properties()));
writeUserdata(propertyKey, entry);
entry.column(HugeKeys.STATUS,
Expand All @@ -679,6 +682,7 @@ public PropertyKey readPropertyKey(HugeGraph graph,
String dataType = entry.column(HugeKeys.DATA_TYPE);
String cardinality = entry.column(HugeKeys.CARDINALITY);
String aggregateType = entry.column(HugeKeys.AGGREGATE_TYPE);
String readFrequency = entry.column(HugeKeys.READ_FREQUENCY);
String properties = entry.column(HugeKeys.PROPERTIES);
String status = entry.column(HugeKeys.STATUS);

Expand All @@ -688,6 +692,8 @@ public PropertyKey readPropertyKey(HugeGraph graph,
Cardinality.class));
propertyKey.aggregateType(JsonUtil.fromJson(aggregateType,
AggregateType.class));
propertyKey.readFrequency(JsonUtil.fromJson(readFrequency,
ReadFrequency.class));
propertyKey.properties(readIds(properties));
readUserdata(propertyKey, entry);
propertyKey.status(JsonUtil.fromJson(status, SchemaStatus.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public static <T extends SerialEnum> T fromCode(Class<T> clazz, byte code) {

public static void registerInternalEnums() {
SerialEnum.register(Action.class);
SerialEnum.register(AggregateType.class);
SerialEnum.register(Cardinality.class);
SerialEnum.register(DataType.class);
SerialEnum.register(Directions.class);
SerialEnum.register(HugeType.class);
SerialEnum.register(IdStrategy.class);
SerialEnum.register(IndexType.class);
SerialEnum.register(SchemaStatus.class);
}
}