Search in sources :

Example 36 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OWOWCache method close.

public void close(long fileId, boolean flush) throws IOException {
    final int intId = extractFileId(fileId);
    fileId = composeFileId(id, intId);
    filesLock.acquireWriteLock();
    try {
        if (flush)
            flush(intId);
        else
            removeCachedPages(intId);
        if (!files.close(fileId))
            throw new OStorageException("Can not close file with id " + internalFileId(fileId) + " because it is still in use");
    } finally {
        filesLock.releaseWriteLock();
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 37 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OWOWCache method initNameIdMapping.

private void initNameIdMapping() throws IOException, InterruptedException {
    if (nameIdMapHolder == null) {
        final File storagePath = new File(storageLocal.getStoragePath());
        if (!storagePath.exists())
            if (!storagePath.mkdirs())
                throw new OStorageException("Cannot create directories for the path '" + storagePath + "'");
        nameIdMapHolderFile = new File(storagePath, NAME_ID_MAP);
        nameIdMapHolder = new RandomAccessFile(nameIdMapHolderFile, "rw");
        readNameIdMap();
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 38 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OWOWCache method load.

public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages, OModifiableBoolean cacheHit) throws IOException {
    final int intId = extractFileId(fileId);
    if (pageCount < 1)
        throw new IllegalArgumentException("Amount of pages to load should be not less than 1 but provided value is " + pageCount);
    filesLock.acquireReadLock();
    try {
        final PageKey[] pageKeys = new PageKey[pageCount];
        for (int i = 0; i < pageCount; i++) {
            pageKeys[i] = new PageKey(intId, startPageIndex + i);
        }
        Lock[] pageLocks = lockManager.acquireSharedLocksInBatch(pageKeys);
        try {
            PageGroup pageGroup = writeCachePages.get(pageKeys[0]);
            if (pageGroup == null) {
                final OCachePointer[] pagePointers = cacheFileContent(intId, startPageIndex, pageCount, addNewPages, cacheHit);
                if (pagePointers.length == 0)
                    return pagePointers;
                for (int n = 0; n < pagePointers.length; n++) {
                    pagePointers[n].incrementReadersReferrer();
                    if (n > 0) {
                        pageGroup = writeCachePages.get(pageKeys[n]);
                        assert pageKeys[n].pageIndex == pagePointers[n].getPageIndex();
                        if (pageGroup != null) {
                            pagePointers[n].decrementReadersReferrer();
                            pagePointers[n] = pageGroup.page;
                            pagePointers[n].incrementReadersReferrer();
                        }
                    }
                }
                return pagePointers;
            }
            final OCachePointer pagePointer = pageGroup.page;
            pagePointer.incrementReadersReferrer();
            cacheHit.setValue(true);
            return new OCachePointer[] { pagePointer };
        } catch (InterruptedException e) {
            throw OException.wrapException(new OStorageException("Thread was interrupted"), e);
        } finally {
            for (Lock lock : pageLocks) {
                lock.unlock();
            }
        }
    } finally {
        filesLock.releaseReadLock();
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) Lock(java.util.concurrent.locks.Lock)

Example 39 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class OWOWCache method addFile.

public long addFile(String fileName) throws IOException {
    filesLock.acquireWriteLock();
    try {
        Integer fileId = nameIdMap.get(fileName);
        OFileClassic fileClassic;
        if (fileId != null && fileId >= 0)
            throw new OStorageException("File with name " + fileName + " already exists in storage " + storageLocal.getName());
        if (fileId == null) {
            ++fileCounter;
            fileId = fileCounter;
        } else
            fileId = -fileId;
        fileClassic = createFileInstance(fileName);
        createFile(fileClassic);
        final long externalId = composeFileId(id, fileId);
        files.add(externalId, fileClassic);
        nameIdMap.put(fileName, fileId);
        writeNameIdEntry(new NameFileIdEntry(fileName, fileId), true);
        return externalId;
    } catch (InterruptedException e) {
        throw OException.wrapException(new OStorageException("Thread was interrupted"), e);
    } finally {
        filesLock.releaseWriteLock();
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OFileClassic(com.orientechnologies.orient.core.storage.fs.OFileClassic)

Example 40 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.

the class O2QCache method clearPinnedPages.

private void clearPinnedPages() {
    for (OCacheEntry pinnedEntry : pinnedPages.values()) {
        if (pinnedEntry.getUsagesCount() == 0) {
            final OCachePointer cachePointer = pinnedEntry.getCachePointer();
            cachePointer.decrementReadersReferrer();
            pinnedEntry.clearCachePointer();
            MemoryData memoryData = memoryDataContainer.get();
            MemoryData newMemoryData = new MemoryData(memoryData.maxSize, memoryData.pinnedPages - 1);
            while (!memoryDataContainer.compareAndSet(memoryData, newMemoryData)) {
                memoryData = memoryDataContainer.get();
                newMemoryData = new MemoryData(memoryData.maxSize, memoryData.pinnedPages - 1);
            }
        } else
            throw new OStorageException("Page with index " + pinnedEntry.getPageIndex() + " for file with id " + pinnedEntry.getFileId() + "cannot be freed because it is used.");
    }
    pinnedPages.clear();
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Aggregations

OStorageException (com.orientechnologies.orient.core.exception.OStorageException)46 OException (com.orientechnologies.common.exception.OException)13 IOException (java.io.IOException)13 OIndexException (com.orientechnologies.orient.core.index.OIndexException)10 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)10 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)10 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)5 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)5 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)5 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)5 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)3 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 SubScheduledExecutorService (com.orientechnologies.common.concur.executors.SubScheduledExecutorService)2 OType (com.orientechnologies.orient.core.metadata.schema.OType)2 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)2 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1