use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class SchemaTransaction method removeVertexLabel.
@Watched(prefix = "schema")
public Id removeVertexLabel(Id id) {
LOG.debug("SchemaTransaction remove vertex label '{}'", id);
SchemaJob callable = new VertexLabelRemoveJob();
VertexLabel schema = this.getVertexLabel(id);
return asyncRun(this.graph(), schema, callable);
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class CachedGraphTransaction method commitMutation2Backend.
@Override
@Watched(prefix = "graphcache")
protected final void commitMutation2Backend(BackendMutation... mutations) {
// Collect changes before commit
Collection<HugeVertex> updates = this.verticesInTxUpdated();
Collection<HugeVertex> deletions = this.verticesInTxRemoved();
Id[] vertexIds = new Id[updates.size() + deletions.size()];
int vertexOffset = 0;
int edgesInTxSize = this.edgesInTxSize();
try {
super.commitMutation2Backend(mutations);
// Update vertex cache
if (this.enableCacheVertex()) {
for (HugeVertex vertex : updates) {
vertexIds[vertexOffset++] = vertex.id();
if (needCacheVertex(vertex)) {
// Update cache
this.verticesCache.updateIfPresent(vertex.id(), vertex);
} else {
// Skip large vertex
this.verticesCache.invalidate(vertex.id());
}
}
}
} finally {
// Update removed vertex in cache whatever success or fail
if (this.enableCacheVertex()) {
for (HugeVertex vertex : deletions) {
vertexIds[vertexOffset++] = vertex.id();
this.verticesCache.invalidate(vertex.id());
}
if (vertexOffset > 0) {
this.notifyChanges(Cache.ACTION_INVALIDED, HugeType.VERTEX, vertexIds);
}
}
/*
* Update edge cache if any vertex or edge changed
* For vertex change, the edges linked with should also be updated
* Before we find a more precise strategy, just clear all the edge cache now
*/
boolean invalidEdgesCache = (edgesInTxSize + updates.size() + deletions.size()) > 0;
if (invalidEdgesCache && this.enableCacheEdge()) {
// TODO: Use a more precise strategy to update the edge cache
this.edgesCache.clear();
this.notifyChanges(Cache.ACTION_CLEARED, HugeType.EDGE, null);
}
}
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class GraphTransaction method removeEdgeProperty.
@Watched(prefix = "graph")
public <V> void removeEdgeProperty(HugeEdgeProperty<V> prop) {
HugeEdge edge = prop.element();
PropertyKey propKey = prop.propertyKey();
E.checkState(edge != null, "No owner for removing property '%s'", prop.key());
// Maybe have ever been removed
if (!edge.hasProperty(propKey.id())) {
return;
}
// Check is removing sort key
List<Id> sortKeyIds = edge.schemaLabel().sortKeys();
E.checkArgument(!sortKeyIds.contains(prop.propertyKey().id()), "Can't remove sort key '%s'", prop.key());
// Remove property in memory for new created edge
if (edge.fresh()) {
// The owner will do property update
edge.removeProperty(propKey.id());
return;
}
// Check is updating property of added/removed edge
E.checkArgument(!this.addedEdges.containsKey(edge.id()) || this.updatedEdges.containsKey(edge.id()), "Can't remove property '%s' for adding-state edge", prop.key());
E.checkArgument(!this.removedEdges.containsKey(edge.id()), "Can't remove property '%s' for removing-state edge", prop.key());
// Do property update
this.lockForUpdateProperty(edge.schemaLabel(), prop, () -> {
// Update old edge to remove index (with the property)
this.indexTx.updateEdgeIndex(edge, true);
// Update(remove) edge property
this.propertyUpdated(edge, null, edge.removeProperty(propKey.id()));
});
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class GraphTransaction method addVertexProperty.
@Watched(prefix = "graph")
public <V> void addVertexProperty(HugeVertexProperty<V> prop) {
// NOTE: this method can also be used to update property
HugeVertex vertex = prop.element();
E.checkState(vertex != null, "No owner for updating property '%s'", prop.key());
// Add property in memory for new created vertex
if (vertex.fresh()) {
// The owner will do property update
vertex.setProperty(prop);
return;
}
// Check is updating property of added/removed vertex
E.checkArgument(!this.addedVertices.containsKey(vertex.id()) || this.updatedVertices.containsKey(vertex.id()), "Can't update property '%s' for adding-state vertex", prop.key());
E.checkArgument(!vertex.removed() && !this.removedVertices.containsKey(vertex.id()), "Can't update property '%s' for removing-state vertex", prop.key());
// Check is updating primary key
List<Id> primaryKeyIds = vertex.schemaLabel().primaryKeys();
E.checkArgument(!primaryKeyIds.contains(prop.propertyKey().id()), "Can't update primary key: '%s'", prop.key());
// Do property update
this.lockForUpdateProperty(vertex.schemaLabel(), prop, () -> {
// Update old vertex to remove index (without new property)
this.indexTx.updateVertexIndex(vertex, true);
// Update(add) vertex property
this.propertyUpdated(vertex, prop, vertex.setProperty(prop));
});
}
use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.
the class GraphTransaction method constructVertex.
@Watched(prefix = "graph")
public HugeVertex constructVertex(boolean verifyVL, Object... keyValues) {
HugeElement.ElementKeys elemKeys = HugeElement.classifyKeys(keyValues);
if (possibleOlapVertex(elemKeys)) {
Id id = HugeVertex.getIdValue(elemKeys.id());
HugeVertex vertex = HugeVertex.create(this, id, VertexLabel.OLAP_VL);
ElementHelper.attachProperties(vertex, keyValues);
Iterator<HugeProperty<?>> iterator = vertex.getProperties().iterator();
assert iterator.hasNext();
if (iterator.next().propertyKey().olap()) {
return vertex;
}
}
VertexLabel vertexLabel = this.checkVertexLabel(elemKeys.label(), verifyVL);
Id id = HugeVertex.getIdValue(elemKeys.id());
List<Id> keys = this.graph().mapPkName2Id(elemKeys.keys());
// Check whether id match with id strategy
this.checkId(id, keys, vertexLabel);
// Create HugeVertex
HugeVertex vertex = HugeVertex.create(this, null, vertexLabel);
// Set properties
ElementHelper.attachProperties(vertex, keyValues);
// Assign vertex id
if (this.params().mode().maintaining() && vertexLabel.idStrategy() == IdStrategy.AUTOMATIC) {
// Resume id for AUTOMATIC id strategy in restoring mode
vertex.assignId(id, true);
} else {
vertex.assignId(id);
}
return vertex;
}
Aggregations