Search in sources :

Example 21 with OStorageException

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

the class OWOWCache method loadFile.

public long loadFile(final String fileName) throws IOException {
    filesLock.acquireWriteLock();
    try {
        Integer fileId = nameIdMap.get(fileName);
        OFileClassic fileClassic;
        //check that file is already registered
        if (!(fileId == null || fileId < 0)) {
            final long externalId = composeFileId(id, fileId);
            fileClassic = files.get(externalId);
            if (fileClassic != null)
                return externalId;
            else
                throw new OStorageException("File with given name " + fileName + " only partially registered in storage");
        }
        fileClassic = createFileInstance(fileName);
        if (!fileClassic.exists())
            throw new OStorageException("File with name " + fileName + " does not exist in storage " + storageLocal.getName());
        else {
            // REGISTER THE FILE
            OLogManager.instance().debug(this, "File '" + fileName + "' is not registered in 'file name - id' map, but exists in file system. Registering it");
            if (fileId == null) {
                ++fileCounter;
                fileId = fileCounter;
            } else
                fileId = -fileId;
            long externalId = composeFileId(id, fileId);
            while (files.get(externalId) != null) {
                ++fileCounter;
                fileId = fileCounter;
                externalId = composeFileId(id, fileId);
            }
            openFile(fileClassic);
            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 22 with OStorageException

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

the class O2QCache method clearFile.

private void clearFile(long fileId) {
    final Set<Long> pageEntries = filePages.get(fileId);
    if (pageEntries == null || pageEntries.isEmpty()) {
        assert get(fileId, 0, true) == null;
        return;
    }
    for (Long pageIndex : pageEntries) {
        OCacheEntry cacheEntry = get(fileId, pageIndex, true);
        if (cacheEntry == null)
            cacheEntry = pinnedPages.get(new PinnedPage(fileId, pageIndex));
        if (cacheEntry != null) {
            if (cacheEntry.getUsagesCount() == 0) {
                cacheEntry = remove(fileId, pageIndex);
                if (cacheEntry == null) {
                    MemoryData memoryData = memoryDataContainer.get();
                    cacheEntry = pinnedPages.remove(new PinnedPage(fileId, pageIndex));
                    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);
                    }
                }
                final OCachePointer cachePointer = cacheEntry.getCachePointer();
                if (cachePointer != null) {
                    cachePointer.decrementReadersReferrer();
                    cacheEntry.clearCachePointer();
                }
            } else
                throw new OStorageException("Page with index " + pageIndex + " for file with id " + fileId + " cannot be freed because it is used.");
        } else
            throw new OStorageException("Page with index " + pageIndex + " was  not found in cache for file with id " + fileId);
    }
    assert get(fileId, 0, true) == null;
    pageEntries.clear();
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 23 with OStorageException

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

the class OClusterPositionMapBucket method set.

public void set(final int index, final PositionEntry entry) throws IOException {
    final int size = getIntValue(SIZE_OFFSET);
    if (index >= size)
        throw new OStorageException("Provided index " + index + " is out of range");
    final int position = entryPosition(index);
    final byte flag = getByteValue(position);
    if (flag == ALLOCATED)
        setByteValue(position, FILLED);
    else if (flag != FILLED)
        throw new OStorageException("Provided index " + index + " points to removed entry");
    updateEntry(position, entry);
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 24 with OStorageException

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

the class OClusterPositionMapBucket method resurrect.

public void resurrect(final int index, final PositionEntry entry) throws IOException {
    final int size = getIntValue(SIZE_OFFSET);
    if (index >= size)
        throw new OStorageException("Cannot resurrect a record: provided index " + index + " is out of range");
    final int position = entryPosition(index);
    final byte flag = getByteValue(position);
    if (flag == REMOVED)
        setByteValue(position, FILLED);
    else
        throw new OStorageException("Cannot resurrect a record: provided index " + index + " points to a non removed entry");
    updateEntry(position, entry);
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 25 with OStorageException

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

the class OWOWCache method checkStoredPages.

public OPageDataVerificationError[] checkStoredPages(OCommandOutputListener commandOutputListener) {
    final int notificationTimeOut = 5000;
    final List<OPageDataVerificationError> errors = new ArrayList<OPageDataVerificationError>();
    filesLock.acquireWriteLock();
    try {
        for (Integer intId : nameIdMap.values()) {
            if (intId < 0)
                continue;
            boolean fileIsCorrect;
            final long externalId = composeFileId(id, intId);
            final OClosableEntry<Long, OFileClassic> entry = files.acquire(externalId);
            final OFileClassic fileClassic = entry.get();
            try {
                if (commandOutputListener != null)
                    commandOutputListener.onMessage("Flashing file " + fileClassic.getName() + "... ");
                flush(intId);
                if (commandOutputListener != null)
                    commandOutputListener.onMessage("Start verification of content of " + fileClassic.getName() + "file ...");
                long time = System.currentTimeMillis();
                long filledUpTo = fileClassic.getFileSize();
                fileIsCorrect = true;
                for (long pos = 0; pos < filledUpTo; pos += pageSize) {
                    boolean checkSumIncorrect = false;
                    boolean magicNumberIncorrect = false;
                    byte[] data = new byte[pageSize];
                    fileClassic.read(pos, data, data.length);
                    long magicNumber = OLongSerializer.INSTANCE.deserializeNative(data, 0);
                    if (magicNumber != MAGIC_NUMBER) {
                        magicNumberIncorrect = true;
                        if (commandOutputListener != null)
                            commandOutputListener.onMessage("Error: Magic number for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " does not much !!!");
                        fileIsCorrect = false;
                    }
                    final int storedCRC32 = OIntegerSerializer.INSTANCE.deserializeNative(data, OLongSerializer.LONG_SIZE);
                    final int calculatedCRC32 = calculatePageCrc(data);
                    if (storedCRC32 != calculatedCRC32) {
                        checkSumIncorrect = true;
                        if (commandOutputListener != null)
                            commandOutputListener.onMessage("Error: Checksum for page " + (pos / pageSize) + " in file " + fileClassic.getName() + " is incorrect !!!");
                        fileIsCorrect = false;
                    }
                    if (magicNumberIncorrect || checkSumIncorrect)
                        errors.add(new OPageDataVerificationError(magicNumberIncorrect, checkSumIncorrect, pos / pageSize, fileClassic.getName()));
                    if (commandOutputListener != null && System.currentTimeMillis() - time > notificationTimeOut) {
                        time = notificationTimeOut;
                        commandOutputListener.onMessage((pos / pageSize) + " pages were processed ...");
                    }
                }
            } catch (IOException ioe) {
                if (commandOutputListener != null)
                    commandOutputListener.onMessage("Error: Error during processing of file " + fileClassic.getName() + ". " + ioe.getMessage());
                fileIsCorrect = false;
            } finally {
                files.release(entry);
            }
            if (!fileIsCorrect) {
                if (commandOutputListener != null)
                    commandOutputListener.onMessage("Verification of file " + fileClassic.getName() + " is finished with errors.");
            } else {
                if (commandOutputListener != null)
                    commandOutputListener.onMessage("Verification of file " + fileClassic.getName() + " is successfully finished.");
            }
        }
        return errors.toArray(new OPageDataVerificationError[errors.size()]);
    } catch (InterruptedException e) {
        throw OException.wrapException(new OStorageException("Thread was interrupted"), e);
    } finally {
        filesLock.releaseWriteLock();
    }
}
Also used : OPageDataVerificationError(com.orientechnologies.orient.core.storage.cache.OPageDataVerificationError) IOException(java.io.IOException) OFileClassic(com.orientechnologies.orient.core.storage.fs.OFileClassic) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) AtomicLong(java.util.concurrent.atomic.AtomicLong)

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