Search in sources :

Example 56 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OPaginatedCluster method updateClusterState.

private void updateClusterState(long fileId, long pinnedStateEntryIndex, long sizeDiff, long recordsSizeDiff, OAtomicOperation atomicOperation) throws IOException {
    final OCacheEntry pinnedStateEntry = loadPage(atomicOperation, fileId, pinnedStateEntryIndex, true);
    pinnedStateEntry.acquireExclusiveLock();
    try {
        OPaginatedClusterState paginatedClusterState = new OPaginatedClusterState(pinnedStateEntry, getChanges(atomicOperation, pinnedStateEntry));
        paginatedClusterState.setSize(paginatedClusterState.getSize() + sizeDiff);
        paginatedClusterState.setRecordsSize(paginatedClusterState.getRecordsSize() + recordsSizeDiff);
    } finally {
        pinnedStateEntry.releaseExclusiveLock();
        releasePage(atomicOperation, pinnedStateEntry);
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry)

Example 57 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OPaginatedCluster method updateFreePagesList.

private void updateFreePagesList(long fileId, long pinnedStateEntryIndex, int freeListIndex, long pageIndex, OAtomicOperation atomicOperation) throws IOException {
    final OCacheEntry pinnedStateEntry = loadPage(atomicOperation, fileId, pinnedStateEntryIndex, true);
    pinnedStateEntry.acquireExclusiveLock();
    try {
        OPaginatedClusterState paginatedClusterState = new OPaginatedClusterState(pinnedStateEntry, getChanges(atomicOperation, pinnedStateEntry));
        paginatedClusterState.setFreeListPage(freeListIndex, pageIndex);
    } finally {
        pinnedStateEntry.releaseExclusiveLock();
        releasePage(atomicOperation, pinnedStateEntry);
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry)

Example 58 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class OPaginatedCluster method readDebug.

public OPaginatedClusterDebug readDebug(long clusterPosition) throws IOException {
    startOperation();
    try {
        OPaginatedClusterDebug debug = new OPaginatedClusterDebug();
        debug.clusterPosition = clusterPosition;
        debug.fileId = fileId;
        OAtomicOperation atomicOperation = storageLocal.getAtomicOperationsManager().getCurrentOperation();
        OClusterPositionMapBucket.PositionEntry positionEntry = clusterPositionMap.get(clusterPosition, 1);
        if (positionEntry == null) {
            debug.empty = true;
            return debug;
        }
        long pageIndex = positionEntry.getPageIndex();
        int recordPosition = positionEntry.getRecordPosition();
        if (getFilledUpTo(atomicOperation, fileId) <= pageIndex) {
            debug.empty = true;
            return debug;
        }
        debug.pages = new ArrayList<OClusterPageDebug>();
        int contentSize = 0;
        long nextPagePointer;
        boolean firstEntry = true;
        do {
            OClusterPageDebug debugPage = new OClusterPageDebug();
            debugPage.pageIndex = pageIndex;
            OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
            cacheEntry.acquireSharedLock();
            try {
                final OClusterPage localPage = new OClusterPage(cacheEntry, false, getChanges(atomicOperation, cacheEntry));
                if (localPage.isDeleted(recordPosition)) {
                    if (debug.pages.isEmpty()) {
                        debug.empty = true;
                        return debug;
                    } else
                        throw new OPaginatedClusterException("Content of record " + new ORecordId(id, clusterPosition) + " was broken", this);
                }
                debugPage.inPagePosition = recordPosition;
                debugPage.inPageSize = localPage.getRecordSize(recordPosition);
                byte[] content = localPage.getRecordBinaryValue(recordPosition, 0, debugPage.inPageSize);
                debugPage.content = content;
                if (firstEntry && content[content.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE] == 0) {
                    debug.empty = true;
                    return debug;
                }
                debug.pages.add(debugPage);
                nextPagePointer = OLongSerializer.INSTANCE.deserializeNative(content, content.length - OLongSerializer.LONG_SIZE);
                contentSize += content.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE;
                firstEntry = false;
            } finally {
                cacheEntry.releaseSharedLock();
                releasePage(atomicOperation, cacheEntry);
            }
            pageIndex = getPageIndex(nextPagePointer);
            recordPosition = getRecordPosition(nextPagePointer);
        } while (nextPagePointer >= 0);
        debug.contentSize = contentSize;
        return debug;
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OPaginatedClusterException(com.orientechnologies.orient.core.exception.OPaginatedClusterException) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry)

Example 59 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class ConcurrentLRUListConcurrentTest method assertListConsistency.

private void assertListConsistency() {
    int expectedSize = list.size();
    int count = 0;
    List<OCacheEntry> items = new ArrayList<OCacheEntry>();
    for (OCacheEntry entry : list) {
        items.add(entry);
        count++;
    }
    Assert.assertEquals(count, expectedSize);
    Collections.reverse(items);
    for (OCacheEntry item : items) {
        OCacheEntry actual = list.removeLRU();
        Assert.assertEquals(actual, item);
    }
    Assert.assertNull(list.removeLRU());
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) ArrayList(java.util.ArrayList)

Example 60 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.

the class ConcurrentLRUListConcurrentTest method assertListConsistency.

private void assertListConsistency(int expectedSize) {
    Assert.assertEquals(list.size(), expectedSize);
    int count = 0;
    List<OCacheEntry> items = new ArrayList<OCacheEntry>();
    for (OCacheEntry entry : list) {
        items.add(entry);
        count++;
    }
    Assert.assertEquals(count, expectedSize);
    Collections.reverse(items);
    for (OCacheEntry item : items) {
        OCacheEntry actual = list.removeLRU();
        Assert.assertEquals(actual, item);
    }
    Assert.assertNull(list.removeLRU());
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) ArrayList(java.util.ArrayList)

Aggregations

OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)209 ByteBuffer (java.nio.ByteBuffer)77 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)76 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)74 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)69 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)65 IOException (java.io.IOException)61 OIndexException (com.orientechnologies.orient.core.index.OIndexException)23 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)20 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)19 OException (com.orientechnologies.common.exception.OException)17 Test (org.testng.annotations.Test)17 ORecordId (com.orientechnologies.orient.core.id.ORecordId)14 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)13 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)12 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)11 Lock (java.util.concurrent.locks.Lock)11 Random (java.util.Random)9 HashMap (java.util.HashMap)8