Search in sources :

Example 1 with BackendAction

use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.

the class RocksDBStore method mutate.

@Override
public void mutate(BackendMutation mutation) {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        this.checkOpened();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Store {} mutation: {}", this.store, mutation);
        }
        for (HugeType type : mutation.types()) {
            Session session = this.session(type);
            for (Iterator<BackendAction> it = mutation.mutation(type); it.hasNext(); ) {
                this.mutate(session, it.next());
            }
        }
    } finally {
        readLock.unlock();
    }
}
Also used : BackendAction(com.baidu.hugegraph.backend.store.BackendAction) HugeType(com.baidu.hugegraph.type.HugeType) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session)

Example 2 with BackendAction

use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.

the class HbaseStore method mutate.

@Override
public void mutate(BackendMutation mutation) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Store {} mutation: {}", this.store, mutation);
    }
    this.checkOpened();
    Session session = this.sessions.session();
    for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext(); ) {
        this.mutate(session, it.next());
    }
}
Also used : BackendAction(com.baidu.hugegraph.backend.store.BackendAction) Session(com.baidu.hugegraph.backend.store.hbase.HbaseSessions.Session)

Example 3 with BackendAction

use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.

the class MysqlStore method mutate.

@Override
public void mutate(BackendMutation mutation) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Store {} mutation: {}", this.store, mutation);
    }
    this.checkOpened();
    Session session = this.sessions.session();
    for (Iterator<BackendAction> it = mutation.mutation(); it.hasNext(); ) {
        this.mutate(session, it.next());
    }
}
Also used : BackendAction(com.baidu.hugegraph.backend.store.BackendAction) Session(com.baidu.hugegraph.backend.store.mysql.MysqlSessions.Session)

Example 4 with BackendAction

use of com.baidu.hugegraph.backend.store.BackendAction 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 5 with BackendAction

use of com.baidu.hugegraph.backend.store.BackendAction in project incubator-hugegraph by apache.

the class StoreSerializer method writeMutation.

public static byte[] writeMutation(BackendMutation mutation) {
    BytesBuffer buffer = BytesBuffer.allocate(MUTATION_SIZE);
    // write mutation size
    buffer.writeVInt(mutation.size());
    for (Iterator<BackendAction> items = mutation.mutation(); items.hasNext(); ) {
        BackendAction item = items.next();
        // write Action
        buffer.write(item.action().code());
        BackendEntry entry = item.entry();
        // write HugeType
        buffer.write(entry.type().code());
        // write id
        buffer.writeBytes(entry.id().asBytes());
        // write subId
        if (entry.subId() != null) {
            buffer.writeId(entry.subId());
        } else {
            buffer.writeId(IdGenerator.ZERO);
        }
        // write ttl
        buffer.writeVLong(entry.ttl());
        // write columns
        buffer.writeVInt(entry.columns().size());
        for (BackendColumn column : entry.columns()) {
            buffer.writeBytes(column.name);
            buffer.writeBytes(column.value);
        }
    }
    return buffer.bytes();
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BackendColumn(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn) BackendAction(com.baidu.hugegraph.backend.store.BackendAction) BytesBuffer(com.baidu.hugegraph.backend.serializer.BytesBuffer)

Aggregations

BackendAction (com.baidu.hugegraph.backend.store.BackendAction)6 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)2 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)2 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)2 HugeType (com.baidu.hugegraph.type.HugeType)2 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 Id (com.baidu.hugegraph.backend.id.Id)1 BackendColumn (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)1 BackendMutation (com.baidu.hugegraph.backend.store.BackendMutation)1 Session (com.baidu.hugegraph.backend.store.hbase.HbaseSessions.Session)1 Session (com.baidu.hugegraph.backend.store.mysql.MysqlSessions.Session)1 Session (com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session)1 ArrayList (java.util.ArrayList)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Test (org.junit.Test)1