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();
}
}
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();
}
}
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;
}
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();
}
}
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();
}
}
Aggregations