use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class CachedSchemaTransaction 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 schema cache on event '{}'", this.graph(), event.name());
this.clearCache(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 schema 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, Id.class);
HugeType type = (HugeType) args[1];
Id id = (Id) args[2];
this.invalidateCache(type, id);
this.resetCachedAll(type);
return true;
} else if (Cache.ACTION_CLEAR.equals(args[0])) {
event.checkArgs(String.class, HugeType.class);
this.clearCache(false);
return true;
}
return false;
};
EventHub schemaEventHub = this.params().schemaEventHub();
if (!schemaEventHub.containsListener(Events.CACHE)) {
schemaEventHub.listen(Events.CACHE, this.cacheEventListener);
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class IndexLabelBuilder method createWithTask.
/**
* Create index label with async mode
*/
@Override
public SchemaElement.TaskWithSchema createWithTask() {
HugeType type = HugeType.INDEX_LABEL;
this.checkSchemaName(this.name);
return this.lockCheckAndCreateSchema(type, this.name, name -> {
IndexLabel indexLabel = this.indexLabelOrNull(name);
if (indexLabel != null) {
if (this.checkExist || !hasSameProperties(indexLabel)) {
throw new ExistedException(type, name);
}
return new SchemaElement.TaskWithSchema(indexLabel, IdGenerator.ZERO);
}
this.checkSchemaIdIfRestoringMode(type, this.id);
this.checkBaseType();
this.checkIndexType();
if (VertexLabel.OLAP_VL.name().equals(this.baseValue)) {
return new SchemaElement.TaskWithSchema(this.build(), IdGenerator.ZERO);
}
SchemaLabel schemaLabel = this.loadBaseLabel();
/*
* If new index label is prefix of existed index label, or has
* the same fields, fail to create new index label.
*/
this.checkFields(schemaLabel.properties());
this.checkRepeatIndex(schemaLabel);
Userdata.check(this.userdata, Action.INSERT);
// Async delete index label which is prefix of the new index label
// TODO: use event to replace direct call
Set<Id> removeTasks = this.removeSubIndex(schemaLabel);
indexLabel = this.build();
assert indexLabel.name().equals(name);
/*
* If not rebuild, just create index label and return.
* The actual indexes may be rebuilt later as needed
*/
if (!this.rebuild) {
indexLabel.status(SchemaStatus.CREATED);
this.graph().addIndexLabel(schemaLabel, indexLabel);
return new SchemaElement.TaskWithSchema(indexLabel, IdGenerator.ZERO);
}
// Create index label (just schema)
indexLabel.status(SchemaStatus.CREATING);
this.graph().addIndexLabel(schemaLabel, indexLabel);
try {
// Async rebuild index
Id rebuildTask = this.rebuildIndex(indexLabel, removeTasks);
E.checkNotNull(rebuildTask, "rebuild-index task");
return new SchemaElement.TaskWithSchema(indexLabel, rebuildTask);
} catch (Throwable e) {
this.updateSchemaStatus(indexLabel, SchemaStatus.INVALID);
throw e;
}
});
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class IndexLabelRebuildJob method schemaElement.
private SchemaElement schemaElement() {
HugeType type = this.schemaType();
Id id = this.schemaId();
switch(type) {
case VERTEX_LABEL:
return this.graph().vertexLabel(id);
case EDGE_LABEL:
return this.graph().edgeLabel(id);
case INDEX_LABEL:
return this.graph().indexLabel(id);
default:
throw new AssertionError(String.format("Invalid HugeType '%s' for rebuild", type));
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class DeleteExpiredIndexJob method deleteExpiredIndex.
/*
* Delete expired element(if exist) of the index,
* otherwise just delete expired index only
*/
private void deleteExpiredIndex(HugeGraphParams graph, HugeIndex index) {
GraphTransaction tx = graph.graphTransaction();
HugeType type = index.indexLabel().queryType().isVertex() ? HugeType.VERTEX : HugeType.EDGE;
IdQuery query = new IdQuery(type);
query.query(index.elementId());
query.showExpired(true);
Iterator<?> elements = type.isVertex() ? tx.queryVertices(query) : tx.queryEdges(query);
if (elements.hasNext()) {
HugeElement element = (HugeElement) elements.next();
if (element.expiredTime() == index.expiredTime()) {
element.remove();
} else {
tx.removeIndex(index);
}
} else {
tx.removeIndex(index);
}
}
use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.
the class RocksDBStore method tableDBMapping.
protected Map<String, RocksDBSessions> tableDBMapping() {
Map<String, RocksDBSessions> tableDBMap = InsertionOrderUtil.newMap();
for (Entry<HugeType, String> e : this.tableDiskMapping.entrySet()) {
HugeType type = e.getKey();
RocksDBSessions db = this.db(e.getValue());
String key = type != HugeType.OLAP ? this.table(type).table() : type.string();
tableDBMap.put(key, db);
}
return tableDBMap;
}
Aggregations