Search in sources :

Example 11 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.

the class OSBTreeBonsaiLeafBucketTest method testSetRightSibling.

public void testSetRightSibling() throws Exception {
    OByteBufferPool bufferPool = OByteBufferPool.instance();
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    cachePointer.incrementReferrer();
    OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
    cacheEntry.acquireExclusiveLock();
    OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, true, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
    final OBonsaiBucketPointer p = new OBonsaiBucketPointer(123, 8192 * 2);
    treeBucket.setRightSibling(p);
    Assert.assertEquals(treeBucket.getRightSibling(), p);
    cacheEntry.releaseExclusiveLock();
    cachePointer.decrementReferrer();
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 12 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.

the class ODistributedStorage method executeRecordOperationInLock.

private Object executeRecordOperationInLock(final boolean iUnlockAtTheEnd, final ORecordId rid, final OCallable<Object, OCallable<Void, ODistributedRequestId>> callback) throws Exception {
    final ORecordId rid2Lock;
    if (!rid.isPersistent())
        // CREATE A COPY TO MAINTAIN THE LOCK ON THE CLUSTER AVOIDING THE RID IS TRANSFORMED IN PERSISTENT. THIS ALLOWS TO HAVE
        // PARALLEL TX BECAUSE NEW RID LOCKS THE ENTIRE CLUSTER.
        rid2Lock = new ORecordId(rid.getClusterId(), -1l);
    else
        rid2Lock = rid;
    ODistributedRequestId requestId = null;
    final OLogSequenceNumber lastLSN = wrapped.getLSN();
    final AtomicBoolean lockReleased = new AtomicBoolean(false);
    try {
        requestId = acquireRecordLock(rid2Lock);
        final ODistributedRequestId finalReqId = requestId;
        final OCallable<Void, ODistributedRequestId> unlockCallback = new OCallable<Void, ODistributedRequestId>() {

            @Override
            public Void call(final ODistributedRequestId requestId) {
                // UNLOCK AS SOON AS THE REQUEST IS SENT
                if (lockReleased.compareAndSet(false, true)) {
                    releaseRecordLock(rid2Lock, finalReqId);
                    lockReleased.set(true);
                }
                return null;
            }
        };
        return OScenarioThreadLocal.executeAsDistributed(new Callable() {

            @Override
            public Object call() throws Exception {
                return callback.call(unlockCallback);
            }
        });
    } finally {
        if (iUnlockAtTheEnd) {
            if (lockReleased.compareAndSet(false, true)) {
                releaseRecordLock(rid2Lock, requestId);
            }
        }
        final OLogSequenceNumber currentLSN = wrapped.getLSN();
        if (!lastLSN.equals(currentLSN))
            // SAVE LAST LSN
            try {
                localDistributedDatabase.getSyncConfiguration().setLastLSN(getDistributedManager().getLocalNodeName(), ((OLocalPaginatedStorage) getUnderlying()).getLSN(), true);
            } catch (IOException e) {
                ODistributedServerLog.debug(this, dManager != null ? dManager.getLocalNodeName() : "?", null, ODistributedServerLog.DIRECTION.NONE, "Error on updating local LSN configuration for database '%s'", wrapped.getName());
            }
    }
}
Also used : OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) OIOException(com.orientechnologies.common.io.OIOException) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OCallable(com.orientechnologies.common.util.OCallable) Callable(java.util.concurrent.Callable) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) OException(com.orientechnologies.common.exception.OException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) HazelcastException(com.hazelcast.core.HazelcastException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OIOException(com.orientechnologies.common.io.OIOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OCallable(com.orientechnologies.common.util.OCallable)

Example 13 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.

the class NonDurableTxTest method testWalNotGrowingWhileWalDisabledInTx.

@Test
public void testWalNotGrowingWhileWalDisabledInTx() {
    db.newInstance().field("some-unrelated-key", "some-unrelated-value").save();
    wal.flush();
    final OLogSequenceNumber startLsn = wal.getFlushedLsn();
    db.begin();
    db.getTransaction().setUsingLog(false);
    db.newInstance().field("tx-key", "tx-value").save();
    db.commit();
    wal.flush();
    final OLogSequenceNumber endLsn = wal.getFlushedLsn();
    Assert.assertEquals(startLsn, endLsn);
}
Also used : OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) Test(org.junit.Test)

Example 14 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.

the class LRUListTest method testAddOneRemoveLRU.

@Test
public void testAddOneRemoveLRU() {
    final OByteBufferPool bufferPool = new OByteBufferPool(1);
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointerOne = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    lruList.putToMRU(new OCacheEntry(1, 10, cachePointerOne, false));
    lruList.removeLRU();
    Assert.assertEquals(lruList.size(), 0);
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    Assert.assertFalse(entryIterator.hasNext());
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) Test(org.testng.annotations.Test)

Example 15 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.

the class LRUListTest method testSingleAdd.

@Test
public void testSingleAdd() {
    final OByteBufferPool bufferPool = new OByteBufferPool(1);
    final ByteBuffer buffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    lruList.putToMRU(new OCacheEntry(1, 10, cachePointer, false));
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    Assert.assertTrue(entryIterator.hasNext());
    Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 10, cachePointer, false));
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) Test(org.testng.annotations.Test)

Aggregations

OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)95 ByteBuffer (java.nio.ByteBuffer)76 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)74 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)69 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)66 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)19 Test (org.testng.annotations.Test)15 ORecordId (com.orientechnologies.orient.core.id.ORecordId)10 Random (java.util.Random)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)4 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)3 HazelcastException (com.hazelcast.core.HazelcastException)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)2 OException (com.orientechnologies.common.exception.OException)2 OIOException (com.orientechnologies.common.io.OIOException)2