Search in sources :

Example 1 with Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBStore method commitTx.

@Override
public void commitTx() {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        this.checkOpened();
        // Unable to guarantee atomicity when committing multi sessions
        for (Session session : this.session()) {
            Object count = session.commit();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Store {} committed {} items", this.store, count);
            }
        }
    } finally {
        readLock.unlock();
    }
}
Also used : 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 Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBStore method rollbackTx.

@Override
public void rollbackTx() {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        this.checkOpened();
        for (Session session : this.session()) {
            session.rollback();
        }
    } finally {
        readLock.unlock();
    }
}
Also used : 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 3 with Session

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBStore method beginTx.

@Override
public void beginTx() {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        this.checkOpened();
        for (Session session : this.session()) {
            assert !session.hasChanges();
        }
    } finally {
        readLock.unlock();
    }
}
Also used : 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 4 with Session

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

use of com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session in project incubator-hugegraph by apache.

the class RocksDBPerfTest method testMultiGet3Keys.

@Test
public void testMultiGet3Keys() throws RocksDBException {
    put("person:1gname", "James");
    put("person:1gage", "19");
    put("person:1gcity", "Beijing");
    put("person:2gname", "Lisa");
    put("person:2gage", "20");
    put("person:2gcity", "Beijing");
    Session session = this.rocks.session();
    BackendColumnIterator iter;
    for (int i = 0; i < TIMES; i++) {
        List<byte[]> keys = Arrays.asList(getBytes("person:1gname"), getBytes("person:1gage"), getBytes("person:1gcity"));
        iter = session.get(TABLE, keys);
        iter.next();
        iter.next();
        iter.next();
    }
}
Also used : BackendColumnIterator(com.baidu.hugegraph.backend.store.BackendEntry.BackendColumnIterator) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session) Test(org.junit.Test)

Aggregations

Session (com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session)26 Test (org.junit.Test)21 BackendColumn (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumn)9 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)8 HashMap (java.util.HashMap)6 Lock (java.util.concurrent.locks.Lock)5 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)5 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 Id (com.baidu.hugegraph.backend.id.Id)2 HugeType (com.baidu.hugegraph.type.HugeType)2 ByteBuffer (java.nio.ByteBuffer)2 Query (com.baidu.hugegraph.backend.query.Query)1 MergeIterator (com.baidu.hugegraph.backend.serializer.MergeIterator)1 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)1 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 BackendColumnIterator (com.baidu.hugegraph.backend.store.BackendEntry.BackendColumnIterator)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1