Search in sources :

Example 26 with BackendEntry

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));
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BinarySerializer(com.baidu.hugegraph.backend.serializer.BinarySerializer) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 27 with BackendEntry

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());
    }
}
Also used : BackendMutation(com.baidu.hugegraph.backend.store.BackendMutation) BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BackendAction(com.baidu.hugegraph.backend.store.BackendAction) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BytesBuffer(com.baidu.hugegraph.backend.serializer.BytesBuffer) Test(org.junit.Test)

Example 28 with BackendEntry

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;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Example 29 with BackendEntry

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);
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) HugeIndex(com.baidu.hugegraph.structure.HugeIndex)

Example 30 with BackendEntry

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;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) FlatMapperIterator(com.baidu.hugegraph.iterator.FlatMapperIterator) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) ListIterator(com.baidu.hugegraph.iterator.ListIterator) HugeVertex(com.baidu.hugegraph.structure.HugeVertex)

Aggregations

BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)54 Test (org.junit.Test)27 TextBackendEntry (com.baidu.hugegraph.backend.serializer.TextBackendEntry)26 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)26 BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)21 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)7 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)7 Id (com.baidu.hugegraph.backend.id.Id)6 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)6 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 Query (com.baidu.hugegraph.backend.query.Query)4 BinarySerializer (com.baidu.hugegraph.backend.serializer.BinarySerializer)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)4 ArrayList (java.util.ArrayList)4 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)3 LockUtil (com.baidu.hugegraph.util.LockUtil)3 BackendException (com.baidu.hugegraph.backend.BackendException)2 Condition (com.baidu.hugegraph.backend.query.Condition)2