@Watched(prefix = "index") private Set<Id> doIndexQuery(IndexLabel indexLabel, ConditionQuery query) { Set<Id> ids = InsertionOrderUtil.newSet(); LockUtil.Locks locks = new LockUtil.Locks(this.graph().name()); try { locks.lockReads(LockUtil.INDEX_LABEL_DELETE, indexLabel.id()); locks.lockReads(LockUtil.INDEX_LABEL_REBUILD, indexLabel.id()); Iterator<BackendEntry> entries = super.query(query); while(entries.hasNext()) { HugeIndex index = this.serializer.readIndex(graph(), query, entries.next()); ids.addAll(index.elementIds()); if (query.reachLimit(ids.size())) { break; } } } finally { locks.unlock(); } return ids; }
public void lockReads(String group, Collection<Id> locks) { for (Id lock : locks) { this.lockList.add(this.lockRead(group, lock)); } }
public void lockWrites(String group, Id... locks) { for (Id lock : locks) { this.lockList.add(this.lockWrite(group, lock)); } }
LockUtil.Locks locks = new LockUtil.Locks(this.graph().name()); try { locks.lockWrites(LockUtil.INDEX_LABEL_REBUILD, indexLabelIds); locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, indexLabelIds); locks.unlock();
LockUtil.Locks locks = new LockUtil.Locks(graph.name()); try { locks.lockWrites(LockUtil.VERTEX_LABEL_DELETE, id); schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.DELETING); for (Id indexLabelId : indexLabelIds) { locks.unlock();
protected static void removeIndexLabel(HugeGraph graph, Id id) { GraphTransaction graphTx = graph.graphTransaction(); SchemaTransaction schemaTx = graph.schemaTransaction(); IndexLabel indexLabel = schemaTx.getIndexLabel(id); // If the index label does not exist, return directly if (indexLabel == null) { return; } LockUtil.Locks locks = new LockUtil.Locks(graph.name()); try { locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, id); // TODO add update lock // Set index label to "deleting" status schemaTx.updateSchemaStatus(indexLabel, SchemaStatus.DELETING); // Remove index data // TODO: use event to replace direct call graphTx.removeIndex(indexLabel); // Remove label from indexLabels of vertex or edge label removeIndexLabelFromBaseLabel(schemaTx, indexLabel); removeSchema(schemaTx, indexLabel); // Should commit changes to backend store before release delete lock graph.tx().commit(); } finally { locks.unlock(); } } }
protected static void removeEdgeLabel(HugeGraph graph, Id id) { GraphTransaction graphTx = graph.graphTransaction(); SchemaTransaction schemaTx = graph.schemaTransaction(); EdgeLabel edgeLabel = schemaTx.getEdgeLabel(id); // If the edge label does not exist, return directly if (edgeLabel == null) { return; } // TODO: use event to replace direct call // Remove index related data(include schema) of this edge label Set<Id> indexIds = ImmutableSet.copyOf(edgeLabel.indexLabels()); LockUtil.Locks locks = new LockUtil.Locks(graph.name()); try { locks.lockWrites(LockUtil.EDGE_LABEL_DELETE, id); schemaTx.updateSchemaStatus(edgeLabel, SchemaStatus.DELETING); for (Id indexId : indexIds) { IndexLabelRemoveCallable.removeIndexLabel(graph, indexId); } // Remove all edges which has matched label graphTx.removeEdges(edgeLabel); removeSchema(schemaTx, edgeLabel); // Should commit changes to backend store before release delete lock graph.tx().commit(); } finally { locks.unlock(); } } }
@Watched(prefix = "index") private Set<Id> doIndexQuery(IndexLabel indexLabel, ConditionQuery query) { Set<Id> ids = InsertionOrderUtil.newSet(); LockUtil.Locks locks = new LockUtil.Locks(this.graph().name()); try { locks.lockReads(LockUtil.INDEX_LABEL_DELETE, indexLabel.id()); locks.lockReads(LockUtil.INDEX_LABEL_REBUILD, indexLabel.id()); Iterator<BackendEntry> entries = super.query(query); while(entries.hasNext()) { HugeIndex index = this.serializer.readIndex(graph(), query, entries.next()); ids.addAll(index.elementIds()); if (query.reachLimit(ids.size())) { break; } } } finally { locks.unlock(); } return ids; }
protected void removeSchema(SchemaElement schema) { LOG.debug("SchemaTransaction remove {} by id '{}'", schema.type(), schema.id()); LockUtil.Locks locks = new LockUtil.Locks(this.graph().name()); try { locks.lockWrites(LockUtil.hugeType2Group(schema.type()), schema.id()); this.beforeWrite(); this.indexTx.updateNameIndex(schema, true); BackendEntry e = this.serializer.writeId(schema.type(), schema.id()); this.doRemove(e); this.afterWrite(); } finally { locks.unlock(); } }
protected void addSchema(SchemaElement schema) { LOG.debug("SchemaTransaction add {} with id '{}'", schema.type(), schema.id()); LockUtil.Locks locks = new LockUtil.Locks(this.graph().name()); try { locks.lockWrites(LockUtil.hugeType2Group(schema.type()), schema.id()); this.beforeWrite(); this.doInsert(this.serialize(schema)); this.indexTx.updateNameIndex(schema, false); this.afterWrite(); } finally { locks.unlock(); } }
public LocksTable(String graph) { this.table = new HashMap<>(); this.locks = new LockUtil.Locks(graph); }
public void unlock() { this.locks.unlock(); }
private Lock lockRead(String group, Id lock) { return LockUtil.lockRead(join(this.graph, group), lock.asString()); }
public void lockReads(String group, Collection<Id> locks) { List<Id> newLocks = new ArrayList<>(locks.size()); for (Id lock : locks) { Set<Id> locked = locksOfGroup(group); if (!locked.contains(lock)) { newLocks.add(lock); } } this.locks.lockReads(group, newLocks); }
public void lockWrites(String group, Id... locks) { for (Id lock : locks) { this.lockList.add(this.lockWrite(group, lock)); } }
public void lockReads(String group, Collection<Id> locks) { for (Id lock : locks) { this.lockList.add(this.lockRead(group, lock)); } }
private Lock lockWrite(String group, Id lock) { return LockUtil.lockWrite(join(this.graph, group), lock.asString(), WRITE_WAIT_TIMEOUT); }
public void lockWrites(String group, Collection<Id> locks) { for (Id lock : locks) { this.lockList.add(this.lockWrite(group, lock)); } }
public void lockReads(String group, Id... locks) { for (Id lock : locks) { this.lockList.add(this.lockRead(group, lock)); } }
LockUtil.Locks locks = new LockUtil.Locks(this.graph().name()); try { locks.lockWrites(LockUtil.INDEX_LABEL_REBUILD, indexLabelIds); locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, indexLabelIds); locks.unlock();