Search in sources :

Example 1 with OReadCache

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

the class OIndexAbstract method removeValuesContainer.

private void removeValuesContainer() {
    if (valueContainerAlgorithm.equals(ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER)) {
        final OAtomicOperation atomicOperation = storage.getAtomicOperationsManager().getCurrentOperation();
        final OReadCache readCache = storage.getReadCache();
        final OWriteCache writeCache = storage.getWriteCache();
        if (atomicOperation == null) {
            try {
                final String fileName = getName() + OIndexRIDContainer.INDEX_FILE_EXTENSION;
                if (writeCache.exists(fileName)) {
                    final long fileId = writeCache.loadFile(fileName);
                    readCache.deleteFile(fileId, writeCache);
                }
            } catch (IOException e) {
                OLogManager.instance().error(this, "Cannot delete file for value containers", e);
            }
        } else {
            try {
                final String fileName = getName() + OIndexRIDContainer.INDEX_FILE_EXTENSION;
                if (atomicOperation.isFileExists(fileName)) {
                    final long fileId = atomicOperation.loadFile(fileName);
                    atomicOperation.deleteFile(fileId);
                }
            } catch (IOException e) {
                OLogManager.instance().error(this, "Cannot delete file for value containers", e);
            }
        }
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OReadCache(com.orientechnologies.orient.core.storage.cache.OReadCache) IOException(java.io.IOException)

Example 2 with OReadCache

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

the class OPerformanceStatisticManager method gerReadCache.

/**
 * @return Returns current instance of read cache and initializes local reference if such one is not initialized yet.
 */
private O2QCache gerReadCache() {
    if (readCacheInitialized)
        return readCache;
    final OReadCache cache = storage.getReadCache();
    if (cache instanceof O2QCache) {
        this.readCache = (O2QCache) cache;
    } else {
        this.readCache = null;
    }
    readCacheInitialized = true;
    return readCache;
}
Also used : OReadCache(com.orientechnologies.orient.core.storage.cache.OReadCache) O2QCache(com.orientechnologies.orient.core.storage.cache.local.twoq.O2QCache)

Example 3 with OReadCache

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

the class OIndexRIDContainer method resolveFileIdByName.

private long resolveFileIdByName(String fileName) {
    final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getUnderlying();
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = storage.getAtomicOperationsManager().startAtomicOperation(fileName, true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e);
    }
    try {
        final OReadCache readCache = storage.getReadCache();
        final OWriteCache writeCache = storage.getWriteCache();
        if (atomicOperation == null) {
            if (writeCache.exists(fileName))
                return writeCache.fileIdByName(fileName);
            return readCache.addFile(fileName, writeCache);
        } else {
            long fileId;
            if (atomicOperation.isFileExists(fileName))
                fileId = atomicOperation.loadFile(fileName);
            else
                fileId = atomicOperation.addFile(fileName);
            storage.getAtomicOperationsManager().endAtomicOperation(false, null, fileName);
            return fileId;
        }
    } catch (IOException e) {
        try {
            storage.getAtomicOperationsManager().endAtomicOperation(true, e, fileName);
        } catch (IOException ioe) {
            throw OException.wrapException(new OIndexEngineException("Error of rollback of atomic operation", fileName), ioe);
        }
        throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e);
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OReadCache(com.orientechnologies.orient.core.storage.cache.OReadCache) IOException(java.io.IOException) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException)

Example 4 with OReadCache

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

the class OLocalHashTableWALTest method restoreDataFromBatch.

private boolean restoreDataFromBatch(boolean atomicChangeIsProcessed, List<OWALRecord> atomicUnit, List<OWALRecord> records) throws IOException {
    final OReadCache expectedReadCache = ((OAbstractPaginatedStorage) expectedDatabaseDocumentTx.getStorage()).getReadCache();
    final OWriteCache expectedWriteCache = ((OAbstractPaginatedStorage) expectedDatabaseDocumentTx.getStorage()).getWriteCache();
    for (OWALRecord walRecord : records) {
        if (walRecord instanceof OOperationUnitBodyRecord)
            atomicUnit.add(walRecord);
        if (!atomicChangeIsProcessed && walRecord instanceof OAtomicUnitStartRecord) {
            atomicChangeIsProcessed = true;
        } else if (walRecord instanceof OAtomicUnitEndRecord) {
            atomicChangeIsProcessed = false;
            for (OWALRecord restoreRecord : atomicUnit) {
                if (restoreRecord instanceof OAtomicUnitStartRecord || restoreRecord instanceof OAtomicUnitEndRecord || restoreRecord instanceof ONonTxOperationPerformedWALRecord || restoreRecord instanceof OFullCheckpointStartRecord || restoreRecord instanceof OCheckpointEndRecord)
                    continue;
                if (restoreRecord instanceof OUpdatePageRecord) {
                    final OUpdatePageRecord updatePageRecord = (OUpdatePageRecord) restoreRecord;
                    final long fileId = updatePageRecord.getFileId();
                    final long pageIndex = updatePageRecord.getPageIndex();
                    OCacheEntry cacheEntry = expectedReadCache.load(fileId, pageIndex, true, expectedWriteCache, 1, false);
                    if (cacheEntry == null)
                        do {
                            cacheEntry = expectedReadCache.allocateNewPage(fileId, expectedWriteCache, false);
                        } while (cacheEntry.getPageIndex() != pageIndex);
                    cacheEntry.acquireExclusiveLock();
                    try {
                        ODurablePage durablePage = new ODurablePage(cacheEntry, null);
                        durablePage.restoreChanges(updatePageRecord.getChanges());
                        durablePage.setLsn(updatePageRecord.getLsn());
                    } finally {
                        cacheEntry.releaseExclusiveLock();
                        expectedReadCache.release(cacheEntry, expectedWriteCache);
                    }
                } else if (restoreRecord instanceof OFileCreatedWALRecord) {
                    final OFileCreatedWALRecord fileCreatedCreatedRecord = (OFileCreatedWALRecord) restoreRecord;
                    String fileName = fileCreatedCreatedRecord.getFileName().replace("actualLocalHashTable", "expectedLocalHashTable");
                    if (!expectedWriteCache.exists(fileName))
                        expectedReadCache.addFile(fileName, fileCreatedCreatedRecord.getFileId(), expectedWriteCache);
                }
            }
            atomicUnit.clear();
        } else {
            Assert.assertTrue(walRecord instanceof OUpdatePageRecord || walRecord instanceof OFileCreatedWALRecord || walRecord instanceof ONonTxOperationPerformedWALRecord || walRecord instanceof OFullCheckpointStartRecord || walRecord instanceof OCheckpointEndRecord || walRecord instanceof OFuzzyCheckpointStartRecord || walRecord instanceof OFuzzyCheckpointEndRecord);
        }
    }
    return atomicChangeIsProcessed;
}
Also used : ODurablePage(com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OReadCache(com.orientechnologies.orient.core.storage.cache.OReadCache) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)

Aggregations

OReadCache (com.orientechnologies.orient.core.storage.cache.OReadCache)4 OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)3 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)2 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)2 IOException (java.io.IOException)2 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)1 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)1 O2QCache (com.orientechnologies.orient.core.storage.cache.local.twoq.O2QCache)1 ODurablePage (com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage)1