use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class StoreDumper method main.
public static void main(String[] args) throws Exception {
E.checkArgument(args.length >= 1, "StoreDumper need a config file.");
String conf = args[0];
RegisterUtil.registerBackends();
HugeType table = HugeType.valueOf(arg(args, 1, "VERTEX").toUpperCase());
long offset = Long.parseLong(arg(args, 2, "0"));
long limit = Long.parseLong(arg(args, 3, "20"));
StoreDumper dumper = new StoreDumper(conf);
dumper.dump(table, offset, limit);
dumper.close();
// Stop daemon thread
HugeFactory.shutdown(30L);
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class SchemaTransaction method removeIndexLabelFromBaseLabel.
@Watched(prefix = "schema")
public void removeIndexLabelFromBaseLabel(IndexLabel indexLabel) {
HugeType baseType = indexLabel.baseType();
Id baseValue = indexLabel.baseValue();
SchemaLabel schemaLabel;
if (baseType == HugeType.VERTEX_LABEL) {
schemaLabel = this.getVertexLabel(baseValue);
} else {
assert baseType == HugeType.EDGE_LABEL;
schemaLabel = this.getEdgeLabel(baseValue);
}
if (schemaLabel == null) {
LOG.info("The base label '{}' of index label '{}' " + "may be deleted before", baseValue, indexLabel);
return;
}
if (schemaLabel.equals(VertexLabel.OLAP_VL)) {
return;
}
// FIXME: move schemaLabel update into updateSchema() lock block instead
synchronized (schemaLabel) {
schemaLabel.removeIndexLabel(indexLabel.id());
this.updateSchema(schemaLabel);
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class EdgeId method parse.
public static EdgeId parse(String id, boolean returnNullIfError) throws NotFoundException {
String[] idParts = SplicingIdGenerator.split(id);
if (!(idParts.length == 4 || idParts.length == 5)) {
if (returnNullIfError) {
return null;
}
throw new NotFoundException("Edge id must be formatted as 4~5 " + "parts, but got %s parts: '%s'", idParts.length, id);
}
try {
if (idParts.length == 4) {
Id ownerVertexId = IdUtil.readString(idParts[0]);
Id edgeLabelId = IdUtil.readLong(idParts[1]);
String sortValues = idParts[2];
Id otherVertexId = IdUtil.readString(idParts[3]);
return new EdgeId(ownerVertexId, Directions.OUT, edgeLabelId, sortValues, otherVertexId);
} else {
assert idParts.length == 5;
Id ownerVertexId = IdUtil.readString(idParts[0]);
HugeType direction = HugeType.fromString(idParts[1]);
Id edgeLabelId = IdUtil.readLong(idParts[2]);
String sortValues = idParts[3];
Id otherVertexId = IdUtil.readString(idParts[4]);
return new EdgeId(ownerVertexId, Directions.convert(direction), edgeLabelId, sortValues, otherVertexId);
}
} catch (Throwable e) {
if (returnNullIfError) {
return null;
}
throw new NotFoundException("Invalid format of edge id '%s'", e, id);
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class CachedGraphTransaction method listenChanges.
private void listenChanges() {
// Listen store event: "store.init", "store.clear", ...
Set<String> storeEvents = ImmutableSet.of(Events.STORE_INIT, Events.STORE_CLEAR, Events.STORE_TRUNCATE);
this.storeEventListener = event -> {
if (storeEvents.contains(event.name())) {
LOG.debug("Graph {} clear graph cache on event '{}'", this.graph(), event.name());
this.clearCache(null, true);
return true;
}
return false;
};
this.store().provider().listen(this.storeEventListener);
// Listen cache event: "cache"(invalid cache item)
this.cacheEventListener = event -> {
LOG.debug("Graph {} received graph cache event: {}", this.graph(), event);
Object[] args = event.args();
E.checkArgument(args.length > 0 && args[0] instanceof String, "Expect event action argument");
if (Cache.ACTION_INVALID.equals(args[0])) {
event.checkArgs(String.class, HugeType.class, Object.class);
HugeType type = (HugeType) args[1];
if (type.isVertex()) {
// Invalidate vertex cache
Object arg2 = args[2];
if (arg2 instanceof Id) {
Id id = (Id) arg2;
this.verticesCache.invalidate(id);
} else if (arg2 != null && arg2.getClass().isArray()) {
int size = Array.getLength(arg2);
for (int i = 0; i < size; i++) {
Object id = Array.get(arg2, i);
E.checkArgument(id instanceof Id, "Expect instance of Id in array, " + "but got '%s'", id.getClass());
this.verticesCache.invalidate((Id) id);
}
} else {
E.checkArgument(false, "Expect Id or Id[], but got: %s", arg2);
}
} else if (type.isEdge()) {
/*
* Invalidate edge cache via clear instead of invalidate
* because of the cacheKey is QueryId not EdgeId
*/
// this.edgesCache.invalidate(id);
this.edgesCache.clear();
}
return true;
} else if (Cache.ACTION_CLEAR.equals(args[0])) {
event.checkArgs(String.class, HugeType.class);
HugeType type = (HugeType) args[1];
this.clearCache(type, false);
return true;
}
return false;
};
EventHub graphEventHub = this.params().graphEventHub();
if (!graphEventHub.containsListener(Events.CACHE)) {
graphEventHub.listen(Events.CACHE, this.cacheEventListener);
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class TableSerializer method readIndexLabel.
@Override
public IndexLabel readIndexLabel(HugeGraph graph, BackendEntry backendEntry) {
if (backendEntry == null) {
return null;
}
TableBackendEntry entry = this.convertEntry(backendEntry);
Number id = schemaColumn(entry, HugeKeys.ID);
String name = schemaColumn(entry, HugeKeys.NAME);
HugeType baseType = schemaEnum(entry, HugeKeys.BASE_TYPE, HugeType.class);
Number baseValueId = schemaColumn(entry, HugeKeys.BASE_VALUE);
IndexType indexType = schemaEnum(entry, HugeKeys.INDEX_TYPE, IndexType.class);
Object indexFields = schemaColumn(entry, HugeKeys.FIELDS);
SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS, SchemaStatus.class);
IndexLabel indexLabel = new IndexLabel(graph, this.toId(id), name);
indexLabel.baseType(baseType);
indexLabel.baseValue(this.toId(baseValueId));
indexLabel.indexType(indexType);
indexLabel.indexFields(this.toIdArray(indexFields));
indexLabel.status(status);
this.readUserdata(indexLabel, entry);
return indexLabel;
}
Aggregations