use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class BinarySerializerTest method testVertexForPartition.
@Test
public void testVertexForPartition() {
BinarySerializer ser = new BinarySerializer(true, true, true);
HugeEdge edge = new FakeObjects().newEdge("123", "456");
BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
Assert.assertEquals(edge.sourceVertex(), vertex1);
assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
Assert.assertEquals(edge.targetVertex(), vertex2);
assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
Whitebox.setInternalState(vertex2, "removed", true);
Assert.assertTrue(vertex2.removed());
BackendEntry entry3 = ser.writeVertex(vertex2);
Assert.assertEquals(0, entry3.columnsSize());
Assert.assertNull(ser.readVertex(edge.graph(), null));
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class StoreSerializerTest method testSerializeBackendMutation.
@Test
public void testSerializeBackendMutation() {
BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX, new byte[] { 1, 2 });
entry.column(new byte[] { 1 }, new byte[] { 1 });
entry.column(new byte[] { 2 }, new byte[] { 2 });
entry.column(new byte[] { 127 }, new byte[] { 127 });
BackendMutation origin = new BackendMutation();
origin.add(entry, Action.INSERT);
byte[] bytes = StoreSerializer.writeMutation(origin);
BytesBuffer buffer = BytesBuffer.wrap(bytes);
BackendMutation actual = StoreSerializer.readMutation(buffer);
Assert.assertEquals(1, actual.size());
Iterator<BackendAction> iter = actual.mutation();
while (iter.hasNext()) {
BackendAction item = iter.next();
Assert.assertEquals(Action.INSERT, item.action());
BackendEntry e = item.entry();
Assert.assertEquals(entry.type(), e.type());
Assert.assertEquals(entry.id(), e.id());
Assert.assertEquals(entry.subId(), e.subId());
Assert.assertEquals(entry.ttl(), e.ttl());
Assert.assertEquals(entry.columnsSize(), e.columnsSize());
Assert.assertEquals(entry.columns(), e.columns());
}
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class GraphIndexTransaction method existUniqueValueInStore.
private boolean existUniqueValueInStore(IndexLabel indexLabel, Object value) {
ConditionQuery query = new ConditionQuery(HugeType.UNIQUE_INDEX);
query.eq(HugeKeys.INDEX_LABEL_ID, indexLabel.id());
query.eq(HugeKeys.FIELD_VALUES, value);
boolean exist;
Iterator<BackendEntry> iterator = this.query(query).iterator();
try {
exist = iterator.hasNext();
if (exist) {
HugeIndex index = this.serializer.readIndex(graph(), query, iterator.next());
this.removeExpiredIndexIfNeeded(index, query.showExpired());
// Memory backend might return empty BackendEntry
if (index.elementIds().isEmpty()) {
return false;
}
LOG.debug("Already has existed unique index record {}", index.elementId());
}
while (iterator.hasNext()) {
LOG.warn("Unique constraint conflict found by record {}", iterator.next());
}
} finally {
CloseableIterator.closeIterator(iterator);
}
return exist;
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class GraphIndexTransaction method hasEliminateInTx.
private boolean hasEliminateInTx(IndexLabel indexLabel, Object value, Id elementId) {
HugeIndex index = new HugeIndex(this.graph(), indexLabel);
index.fieldValues(value);
index.elementIds(elementId);
BackendEntry entry = this.serializer.writeIndex(index);
return this.mutation().contains(entry, Action.ELIMINATE);
}
use of com.baidu.hugegraph.backend.store.BackendEntry in project incubator-hugegraph by apache.
the class GraphTransaction method queryEdgesFromBackend.
protected Iterator<HugeEdge> queryEdgesFromBackend(Query query) {
assert query.resultType().isEdge();
QueryResults<BackendEntry> results = this.query(query);
Iterator<BackendEntry> entries = results.iterator();
Iterator<HugeEdge> edges = new FlatMapperIterator<>(entries, entry -> {
// Edges are in a vertex
HugeVertex vertex = this.parseEntry(entry);
if (vertex == null) {
return null;
}
if (query.idsSize() == 1) {
assert vertex.getEdges().size() == 1;
}
/*
* Copy to avoid ConcurrentModificationException when removing edge
* because HugeEdge.remove() will update edges in owner vertex
*/
return new ListIterator<>(ImmutableList.copyOf(vertex.getEdges()));
});
edges = this.filterExpiredResultFromFromBackend(query, edges);
if (!this.store().features().supportsQuerySortByInputIds()) {
// There is no id in BackendEntry, so sort after deserialization
edges = results.keepInputOrderIfNeeded(edges);
}
return edges;
}
Aggregations