use of com.baidu.hugegraph.backend.tx.SchemaTransaction in project incubator-hugegraph by apache.
the class BackendStoreSystemInfoTest method testBackendStoreSystemInfoIllegalStateException.
@Test
public void testBackendStoreSystemInfoIllegalStateException() {
HugeGraph graph = Mockito.mock(HugeGraph.class);
SchemaTransaction stx = Mockito.mock(SchemaTransaction.class);
Mockito.when(stx.getPropertyKey(PK_BACKEND_INFO)).thenThrow(new IllegalStateException("Should not exist schema " + "with same name '~backend_info'"));
Mockito.when(stx.graph()).thenReturn(graph);
Mockito.when(stx.storeInitialized()).thenReturn(true);
BackendStoreSystemInfo info = new BackendStoreSystemInfo(stx);
Assert.assertThrows(HugeException.class, () -> {
Whitebox.invoke(BackendStoreSystemInfo.class, "info", info);
}, e -> {
Assert.assertContains("There exists multiple backend info", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.tx.SchemaTransaction in project incubator-hugegraph by apache.
the class IndexLabelRebuildJob method removeIndex.
private void removeIndex(Collection<Id> indexLabelIds) {
SchemaTransaction schemaTx = this.params().schemaTransaction();
GraphTransaction graphTx = this.params().graphTransaction();
for (Id id : indexLabelIds) {
IndexLabel il = schemaTx.getIndexLabel(id);
if (il == null || il.status() == SchemaStatus.CREATING) {
/*
* TODO: How to deal with non-existent index name:
* continue or throw exception?
*/
continue;
}
LockUtil.Locks locks = new LockUtil.Locks(schemaTx.graphName());
try {
locks.lockWrites(LockUtil.INDEX_LABEL_DELETE, indexLabelIds);
graphTx.removeIndex(il);
} catch (Throwable e) {
schemaTx.updateSchemaStatus(il, SchemaStatus.INVALID);
throw e;
} finally {
locks.unlock();
}
}
}
use of com.baidu.hugegraph.backend.tx.SchemaTransaction in project incubator-hugegraph by apache.
the class IndexLabelRebuildJob method rebuildIndex.
private void rebuildIndex(SchemaLabel label, Collection<Id> indexLabelIds) {
SchemaTransaction schemaTx = this.params().schemaTransaction();
GraphTransaction graphTx = this.params().graphTransaction();
Consumer<?> indexUpdater = (elem) -> {
for (Id id : indexLabelIds) {
graphTx.updateIndex(id, (HugeElement) elem, false);
}
};
LockUtil.Locks locks = new LockUtil.Locks(schemaTx.graphName());
try {
locks.lockWrites(LockUtil.INDEX_LABEL_REBUILD, indexLabelIds);
Set<IndexLabel> ils = indexLabelIds.stream().map(this.graph()::indexLabel).collect(Collectors.toSet());
for (IndexLabel il : ils) {
if (il.status() == SchemaStatus.CREATING) {
continue;
}
schemaTx.updateSchemaStatus(il, SchemaStatus.REBUILDING);
}
this.removeIndex(indexLabelIds);
/*
* Note: Here must commit index transaction firstly.
* Because remove index convert to (id like <?>:personByCity):
* `delete from index table where label = ?`,
* But append index will convert to (id like Beijing:personByCity):
* `update index element_ids += xxx where field_value = ?
* and index_label_name = ?`,
* They have different id lead to it can't compare and optimize
*/
graphTx.commit();
try {
if (label.type() == HugeType.VERTEX_LABEL) {
@SuppressWarnings("unchecked") Consumer<Vertex> consumer = (Consumer<Vertex>) indexUpdater;
graphTx.traverseVerticesByLabel((VertexLabel) label, consumer, false);
} else {
assert label.type() == HugeType.EDGE_LABEL;
@SuppressWarnings("unchecked") Consumer<Edge> consumer = (Consumer<Edge>) indexUpdater;
graphTx.traverseEdgesByLabel((EdgeLabel) label, consumer, false);
}
graphTx.commit();
} catch (Throwable e) {
for (IndexLabel il : ils) {
schemaTx.updateSchemaStatus(il, SchemaStatus.INVALID);
}
throw e;
}
for (IndexLabel il : ils) {
schemaTx.updateSchemaStatus(il, SchemaStatus.CREATED);
}
} finally {
locks.unlock();
}
}
use of com.baidu.hugegraph.backend.tx.SchemaTransaction in project incubator-hugegraph by apache.
the class OlapPropertyKeyRemoveJob method execute.
@Override
public Object execute() {
Id olap = this.schemaId();
// Remove olap data table
this.params().graphTransaction().removeOlapPk(olap);
// Remove corresponding index label and index data
Id indexLabel = findOlapIndexLabel(this.params(), olap);
if (indexLabel != null) {
removeIndexLabel(this.params(), indexLabel);
}
// Remove olap property key
SchemaTransaction schemaTx = this.params().schemaTransaction();
PropertyKey propertyKey = schemaTx.getPropertyKey(olap);
removeSchema(schemaTx, propertyKey);
return null;
}
Aggregations