Search in sources :

Example 11 with OStorageException

use of com.orientechnologies.orient.core.exception.OStorageException 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 12 with OStorageException

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

the class OTransactionOptimistic method rollback.

@Override
public void rollback(boolean force, int commitLevelDiff) {
    if (txStartCounter < 0)
        throw new OStorageException("Invalid value of TX counter");
    checkTransaction();
    txStartCounter += commitLevelDiff;
    status = TXSTATUS.ROLLBACKING;
    if (!force && txStartCounter > 0) {
        OLogManager.instance().debug(this, "Nested transaction was closed but transaction itself was scheduled for rollback.");
        return;
    }
    if (txStartCounter < 0)
        throw new OTransactionException("Transaction was rolled back more times than it was started.");
    database.getStorage().callInLock(new Callable<Void>() {

        public Void call() throws Exception {
            database.getStorage().rollback(OTransactionOptimistic.this);
            return null;
        }
    }, true);
    // CLEAR THE CACHE
    database.getLocalCache().clear();
    // REMOVE ALL THE DIRTY ENTRIES AND UNDO ANY DIRTY DOCUMENT IF POSSIBLE.
    for (ORecordOperation v : allEntries.values()) {
        final ORecord rec = v.getRecord();
        if (rec.isDirty())
            if (rec instanceof ODocument && ((ODocument) rec).isTrackingChanges())
                ((ODocument) rec).undo();
            else
                rec.unload();
    }
    close();
    status = TXSTATUS.ROLLED_BACK;
}
Also used : ORecordOperation(com.orientechnologies.orient.core.db.record.ORecordOperation) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) ORecord(com.orientechnologies.orient.core.record.ORecord) OException(com.orientechnologies.common.exception.OException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 13 with OStorageException

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

the class ODirectMemoryOnlyDiskCache method addFile.

@Override
public long addFile(String fileName, long fileId, OWriteCache writeCache) {
    int intId = extractFileId(fileId);
    metadataLock.lock();
    try {
        if (files.containsKey(intId))
            throw new OStorageException("File with id " + intId + " already exists.");
        if (fileNameIdMap.containsKey(fileName))
            throw new OStorageException(fileName + " already exists.");
        files.put(intId, new MemoryFile(id, intId));
        fileNameIdMap.put(fileName, intId);
        fileIdNameMap.put(intId, fileName);
        return composeFileId(id, intId);
    } finally {
        metadataLock.unlock();
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 14 with OStorageException

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

the class ODiskWriteAheadLog method close.

public void close(boolean flush) throws IOException {
    syncObject.lock();
    try {
        if (closed)
            return;
        closed = true;
        for (OLogSegment logSegment : logSegments) logSegment.close(flush);
        if (!commitExecutor.isShutdown()) {
            commitExecutor.shutdown();
            try {
                if (!commitExecutor.awaitTermination(OGlobalConfiguration.WAL_SHUTDOWN_TIMEOUT.getValueAsInteger(), TimeUnit.MILLISECONDS))
                    throw new OStorageException("WAL flush task for '" + getStorage().getName() + "' storage cannot be stopped");
            } catch (InterruptedException e) {
                OLogManager.instance().error(this, "Cannot shutdown background WAL commit thread");
            }
        }
        if (!autoFileCloser.isShutdown()) {
            autoFileCloser.shutdown();
            try {
                if (!autoFileCloser.awaitTermination(OGlobalConfiguration.WAL_SHUTDOWN_TIMEOUT.getValueAsInteger(), TimeUnit.MILLISECONDS))
                    throw new OStorageException("WAL file auto close tasks '" + getStorage().getName() + "' storage cannot be stopped");
            } catch (InterruptedException e) {
                OLogManager.instance().error(this, "Shutdown of file auto close tasks was interrupted");
            }
        }
        masterRecordLSNHolder.close();
    } finally {
        syncObject.unlock();
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException)

Example 15 with OStorageException

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

the class ODiskWriteAheadLog method moveLsnAfter.

@Override
public void moveLsnAfter(OLogSequenceNumber lsn) throws IOException {
    syncObject.lock();
    try {
        if (!activeOperations.isEmpty())
            throw new OStorageException("Can not change end of WAL because there are active atomic operations in the log.");
        if (end() == null)
            throw new OStorageException("Can not change end of WAL because WAL is empty");
        if (end().compareTo(lsn) > 0)
            return;
        OLogSegment last = logSegments.get(logSegments.size() - 1);
        last.stopFlush(true);
        if (last.filledUpTo() == 0) {
            last.delete(false);
            logSegments.remove(logSegments.size() - 1);
        }
        last = new OLogSegment(this, new File(walLocation, getSegmentName(lsn.getSegment() + 1)), fileTTL, maxPagesCacheSize, performanceStatisticManager, new SubScheduledExecutorService(autoFileCloser), new SubScheduledExecutorService(commitExecutor));
        last.init(fileDataBuffer);
        last.startFlush();
        logSegments.add(last);
    } finally {
        syncObject.unlock();
    }
}
Also used : SubScheduledExecutorService(com.orientechnologies.common.concur.executors.SubScheduledExecutorService) 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