Search in sources :

Example 26 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, long fileId) throws IOException {
    filesLock.acquireWriteLock();
    try {
        OFileClassic fileClassic;
        Integer existingFileId = nameIdMap.get(fileName);
        final int intId = extractFileId(fileId);
        if (existingFileId != null && existingFileId >= 0) {
            if (existingFileId == intId)
                throw new OStorageException("File with name '" + fileName + "'' already exists in storage '" + storageLocal.getName() + "'");
            else
                throw new OStorageException("File with given name already exists but has different id " + existingFileId + " vs. proposed " + fileId);
        }
        fileId = composeFileId(id, intId);
        fileClassic = files.get(fileId);
        if (fileClassic != null) {
            if (!fileClassic.getName().equals(fileName))
                throw new OStorageException("File with given id exists but has different name " + fileClassic.getName() + " vs. proposed " + fileName);
        } else {
            if (fileCounter < intId)
                fileCounter = intId;
            fileClassic = createFileInstance(fileName);
            createFile(fileClassic);
            files.add(fileId, fileClassic);
        }
        nameIdMap.put(fileName, intId);
        writeNameIdEntry(new NameFileIdEntry(fileName, intId), true);
        return fileId;
    } 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 27 with OStorageException

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

the class OWOWCache method renameFile.

public void renameFile(long fileId, String oldFileName, String newFileName) throws IOException {
    final int intId = extractFileId(fileId);
    fileId = composeFileId(id, intId);
    filesLock.acquireWriteLock();
    try {
        OClosableEntry<Long, OFileClassic> entry = files.acquire(fileId);
        if (entry == null)
            return;
        try {
            OFileClassic file = entry.get();
            final String osFileName = file.getName();
            if (osFileName.startsWith(oldFileName)) {
                final File newFile = new File(storageLocal.getStoragePath() + File.separator + newFileName + osFileName.substring(osFileName.lastIndexOf(oldFileName) + oldFileName.length()));
                boolean renamed = file.renameTo(newFile);
                while (!renamed) {
                    renamed = file.renameTo(newFile);
                }
            }
        } finally {
            files.release(entry);
        }
        nameIdMap.remove(oldFileName);
        nameIdMap.put(newFileName, intId);
        writeNameIdEntry(new NameFileIdEntry(oldFileName, -1), false);
        writeNameIdEntry(new NameFileIdEntry(newFileName, intId), true);
    } catch (InterruptedException e) {
        throw OException.wrapException(new OStorageException("Thread was interrupted"), e);
    } finally {
        filesLock.releaseWriteLock();
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException) AtomicLong(java.util.concurrent.atomic.AtomicLong) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) OFileClassic(com.orientechnologies.orient.core.storage.fs.OFileClassic)

Example 28 with OStorageException

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

the class OStorageConfiguration method load.

/**
   * This method load the record information by the internal cluster segment. It's for compatibility with older database than
   * 0.9.25.
   *
   * @param iProperties
   * @return
   * @throws OSerializationException
   * @compatibility 0.9.25
   */
public OStorageConfiguration load(final Map<String, Object> iProperties) throws OSerializationException {
    initConfiguration();
    final String compressionMethod = (String) iProperties.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey().toLowerCase());
    if (compressionMethod != null)
        // SAVE COMPRESSION METHOD IN CONFIGURATION
        configuration.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, compressionMethod);
    final String encryptionMethod = (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey().toLowerCase());
    if (encryptionMethod != null)
        // SAVE ENCRYPTION METHOD IN CONFIGURATION
        configuration.setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD, encryptionMethod);
    final String encryptionKey = (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey().toLowerCase());
    if (encryptionKey != null)
        // SAVE ENCRYPTION KEY IN CONFIGURATION
        configuration.setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY, encryptionKey);
    final byte[] record = storage.readRecord(CONFIG_RID, null, false, false, null).getResult().buffer;
    if (record == null)
        throw new OStorageException("Cannot load database configuration. The database seems corrupted");
    fromStream(record);
    this.loadProperties = new HashMap<String, Object>(iProperties);
    return this;
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 29 with OStorageException

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

the class OLocalHashTable method setValueSerializer.

@Override
public void setValueSerializer(OBinarySerializer<V> valueSerializer) {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OIndexException("Error during hash table set serializer for index values"), e);
        }
        acquireExclusiveLock();
        try {
            this.valueSerializer = valueSerializer;
            final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
            hashStateEntry.acquireExclusiveLock();
            try {
                OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                metadataPage.setValueSerializerId(valueSerializer.getId());
            } finally {
                hashStateEntry.releaseExclusiveLock();
                releasePage(atomicOperation, hashStateEntry);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OIndexException("Cannot set serializer for index values"), e);
        } catch (Exception e) {
            rollback(e);
            throw OException.wrapException(new OStorageException("Cannot set serializer for index values"), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 30 with OStorageException

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

the class OLocalHashTable method create.

@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
@Override
public void create(OBinarySerializer<K> keySerializer, OBinarySerializer<V> valueSerializer, OType[] keyTypes, boolean nullKeyIsSupported) {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(false);
        } catch (IOException e) {
            throw OException.wrapException(new OIndexException("Error during hash table creation"), e);
        }
        acquireExclusiveLock();
        try {
            try {
                if (keyTypes != null)
                    this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
                else
                    this.keyTypes = null;
                this.nullKeyIsSupported = nullKeyIsSupported;
                this.directory = new OHashTableDirectory(treeStateFileExtension, getName(), getFullName(), durableInNonTxMode, storage);
                fileStateId = addFile(atomicOperation, getName() + metadataConfigurationFileExtension);
                directory.create();
                final OCacheEntry hashStateEntry = addPage(atomicOperation, fileStateId);
                pinPage(atomicOperation, hashStateEntry);
                hashStateEntry.acquireExclusiveLock();
                try {
                    OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), true);
                    hashStateEntryIndex = hashStateEntry.getPageIndex();
                } finally {
                    hashStateEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, hashStateEntry);
                }
                final String fileName = getFullName();
                fileId = addFile(atomicOperation, fileName);
                setKeySerializer(keySerializer);
                setValueSerializer(valueSerializer);
                initHashTreeState(atomicOperation);
                if (nullKeyIsSupported)
                    nullBucketFileId = addFile(atomicOperation, getName() + nullBucketFileExtension);
                endAtomicOperation(false, null);
            } catch (IOException e) {
                endAtomicOperation(true, e);
                throw e;
            } catch (Exception e) {
                endAtomicOperation(true, e);
                throw OException.wrapException(new OStorageException("Error during local hash table creation"), e);
            }
        } catch (IOException e) {
            throw OException.wrapException(new OIndexException("Error during local hash table creation"), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

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