Search in sources :

Example 41 with OCacheEntry

use of com.orientechnologies.orient.core.storage.cache.OCacheEntry 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)

Example 42 with OCacheEntry

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

the class OAtomicOperation method addPage.

public OCacheEntry addPage(long fileId) throws IOException {
    fileId = checkFileIdCompatibilty(fileId, storageId);
    if (deletedFiles.contains(fileId))
        throw new OStorageException("File with id " + fileId + " is deleted.");
    final FileChanges changesContainer = fileChanges.get(fileId);
    assert changesContainer != null;
    final long filledUpTo = internalFilledUpTo(fileId, changesContainer);
    FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(filledUpTo);
    assert pageChangesContainer == null;
    pageChangesContainer = new FilePageChanges();
    pageChangesContainer.isNew = true;
    changesContainer.pageChangesMap.put(filledUpTo, pageChangesContainer);
    changesContainer.maxNewPageIndex = filledUpTo;
    return new OCacheEntry(fileId, filledUpTo, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, filledUpTo), false);
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Example 43 with OCacheEntry

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

the class OAtomicOperation method commitChanges.

public void commitChanges(OWriteAheadLog writeAheadLog) throws IOException {
    final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager.getSessionPerformanceStatistic();
    if (sessionStoragePerformanceStatistic != null) {
        sessionStoragePerformanceStatistic.startCommitTimer();
        sessionStoragePerformanceStatistic.startComponentOperation("atomic operation", OSessionStoragePerformanceStatistic.ComponentType.GENERAL);
    }
    try {
        if (writeAheadLog != null) {
            for (long deletedFileId : deletedFiles) {
                writeAheadLog.log(new OFileDeletedWALRecord(operationUnitId, deletedFileId));
            }
            for (Map.Entry<Long, FileChanges> fileChangesEntry : fileChanges.entrySet()) {
                final FileChanges fileChanges = fileChangesEntry.getValue();
                final long fileId = fileChangesEntry.getKey();
                if (fileChanges.isNew)
                    writeAheadLog.log(new OFileCreatedWALRecord(operationUnitId, fileChanges.fileName, fileId));
                else if (fileChanges.truncate)
                    writeAheadLog.log(new OFileTruncatedWALRecord(operationUnitId, fileId));
                Iterator<Map.Entry<Long, FilePageChanges>> filePageChangesIterator = fileChanges.pageChangesMap.entrySet().iterator();
                while (filePageChangesIterator.hasNext()) {
                    Map.Entry<Long, FilePageChanges> filePageChangesEntry = filePageChangesIterator.next();
                    //I assume new pages have everytime changes
                    if (filePageChangesEntry.getValue().changes.hasChanges()) {
                        final long pageIndex = filePageChangesEntry.getKey();
                        final FilePageChanges filePageChanges = filePageChangesEntry.getValue();
                        filePageChanges.lsn = writeAheadLog.log(new OUpdatePageRecord(pageIndex, fileId, operationUnitId, filePageChanges.changes));
                    } else
                        filePageChangesIterator.remove();
                }
            }
        }
        for (long deletedFileId : deletedFiles) {
            readCache.deleteFile(deletedFileId, writeCache);
        }
        for (Map.Entry<Long, FileChanges> fileChangesEntry : fileChanges.entrySet()) {
            final FileChanges fileChanges = fileChangesEntry.getValue();
            final long fileId = fileChangesEntry.getKey();
            if (fileChanges.isNew)
                readCache.addFile(fileChanges.fileName, newFileNamesId.get(fileChanges.fileName), writeCache);
            else if (fileChanges.truncate)
                readCache.truncateFile(fileId, writeCache);
            for (Map.Entry<Long, FilePageChanges> filePageChangesEntry : fileChanges.pageChangesMap.entrySet()) {
                final FilePageChanges filePageChanges = filePageChangesEntry.getValue();
                if (!filePageChanges.changes.hasChanges())
                    continue;
                final long pageIndex = filePageChangesEntry.getKey();
                OCacheEntry cacheEntry = filePageChanges.isNew ? null : pageCache.purgePage(fileId, pageIndex, writeCache);
                if (cacheEntry == null) {
                    cacheEntry = readCache.load(fileId, pageIndex, true, writeCache, 1);
                    if (cacheEntry == null) {
                        assert filePageChanges.isNew;
                        do {
                            if (cacheEntry != null)
                                readCache.release(cacheEntry, writeCache);
                            cacheEntry = readCache.allocateNewPage(fileId, writeCache);
                        } while (cacheEntry.getPageIndex() != pageIndex);
                    }
                }
                cacheEntry.acquireExclusiveLock();
                try {
                    ODurablePage durablePage = new ODurablePage(cacheEntry, null);
                    durablePage.restoreChanges(filePageChanges.changes);
                    if (writeAheadLog != null)
                        durablePage.setLsn(filePageChanges.lsn);
                    if (filePageChanges.pinPage)
                        readCache.pinPage(cacheEntry);
                } finally {
                    cacheEntry.releaseExclusiveLock();
                    readCache.release(cacheEntry, writeCache);
                }
            }
        }
    } finally {
        pageCache.reset(writeCache);
        if (sessionStoragePerformanceStatistic != null) {
            sessionStoragePerformanceStatistic.stopCommitTimer();
            sessionStoragePerformanceStatistic.completeComponentOperation();
        }
    }
}
Also used : ODurablePage(com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 44 with OCacheEntry

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

the class OAtomicOperation method loadPage.

public OCacheEntry loadPage(long fileId, long pageIndex, boolean checkPinnedPages, final int pageCount) throws IOException {
    assert pageCount > 0;
    fileId = checkFileIdCompatibilty(fileId, storageId);
    if (deletedFiles.contains(fileId))
        throw new OStorageException("File with id " + fileId + " is deleted.");
    FileChanges changesContainer = fileChanges.get(fileId);
    if (changesContainer == null) {
        changesContainer = new FileChanges();
        fileChanges.put(fileId, changesContainer);
    }
    if (changesContainer.isNew) {
        if (pageIndex <= changesContainer.maxNewPageIndex)
            return new OCacheEntry(fileId, pageIndex, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, pageIndex), false);
        else
            return null;
    } else {
        FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(pageIndex);
        final long filledUpTo = internalFilledUpTo(fileId, changesContainer);
        if (pageIndex < filledUpTo) {
            if (pageChangesContainer == null) {
                pageChangesContainer = new FilePageChanges();
                changesContainer.pageChangesMap.put(pageIndex, pageChangesContainer);
            }
            if (pageChangesContainer.isNew)
                return new OCacheEntry(fileId, pageIndex, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, pageIndex), false);
            else
                return pageCache.loadPage(fileId, pageIndex, checkPinnedPages, writeCache, pageCount);
        }
    }
    return null;
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Example 45 with OCacheEntry

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

the class OPaginatedCluster method getPhysicalPosition.

@Override
public OPhysicalPosition getPhysicalPosition(OPhysicalPosition position) throws IOException {
    startOperation();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                long clusterPosition = position.clusterPosition;
                OClusterPositionMapBucket.PositionEntry positionEntry = clusterPositionMap.get(clusterPosition, 1);
                if (positionEntry == null)
                    return null;
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                long pageIndex = positionEntry.getPageIndex();
                int recordPosition = positionEntry.getRecordPosition();
                long pagesCount = getFilledUpTo(atomicOperation, fileId);
                if (pageIndex >= pagesCount)
                    return null;
                OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
                cacheEntry.acquireSharedLock();
                try {
                    final OClusterPage localPage = new OClusterPage(cacheEntry, false, getChanges(atomicOperation, cacheEntry));
                    if (localPage.isDeleted(recordPosition))
                        return null;
                    if (localPage.getRecordByteValue(recordPosition, -OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE) == 0)
                        return null;
                    final OPhysicalPosition physicalPosition = new OPhysicalPosition();
                    physicalPosition.recordSize = -1;
                    physicalPosition.recordType = localPage.getRecordByteValue(recordPosition, 0);
                    physicalPosition.recordVersion = localPage.getRecordVersion(recordPosition);
                    physicalPosition.clusterPosition = position.clusterPosition;
                    return physicalPosition;
                } finally {
                    cacheEntry.releaseSharedLock();
                    releasePage(atomicOperation, cacheEntry);
                }
            } finally {
                releaseSharedLock();
            }
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry)

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