use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OLocalHashTable method setKeySerializer.
@Override
public void setKeySerializer(OBinarySerializer<K> keySerializer) {
startOperation();
try {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(true);
} catch (IOException e) {
throw OException.wrapException(new OIndexException("Error during hash set serializer for index keys"), e);
}
acquireExclusiveLock();
try {
this.keySerializer = keySerializer;
OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
hashStateEntry.acquireExclusiveLock();
try {
OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
metadataPage.setKeySerializerId(keySerializer.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 keys"), e);
} catch (Exception e) {
rollback(e);
throw OException.wrapException(new OStorageException("Cannot set serializer for index keys"), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OLocalHashTable method put.
private boolean put(K key, V value, OIndexEngine.Validator<K, V> validator) {
final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
startOperation();
if (statistic != null)
statistic.startIndexEntryUpdateTimer();
try {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(true);
} catch (IOException e) {
throw OException.wrapException(new OIndexException("Error during hash table entry put"), e);
}
acquireExclusiveLock();
try {
checkNullSupport(key);
if (key != null) {
final int keySize = keySerializer.getObjectSize(key, (Object[]) keyTypes);
if (keySize > MAX_KEY_SIZE)
throw new OTooBigIndexKeyException("Key size is more than allowed, operation was canceled. Current key size " + keySize + ", allowed " + MAX_KEY_SIZE, getName());
}
key = keySerializer.preprocess(key, (Object[]) keyTypes);
final boolean putResult = doPut(key, value, validator, atomicOperation);
endAtomicOperation(false, null);
return putResult;
} catch (IOException e) {
rollback(e);
throw OException.wrapException(new OIndexException("Error during index update"), e);
} catch (Exception e) {
rollback(e);
throw OException.wrapException(new OStorageException("Error during index update"), e);
} finally {
releaseExclusiveLock();
}
} finally {
if (statistic != null)
statistic.stopIndexEntryUpdateTimer();
completeOperation();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OLocalHashTable20 method setValueSerializer.
@Override
public void setValueSerializer(OBinarySerializer<V> valueSerializer) {
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();
throw OException.wrapException(new OIndexException("Cannot set serializer for index values"), e);
} catch (Exception e) {
rollback();
throw OException.wrapException(new OStorageException("Cannot set serializer for index values"), e);
} finally {
releaseExclusiveLock();
}
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class ORecordSerializerNetworkV0 method deserialize.
@Override
public void deserialize(final ODocument document, final BytesContainer bytes) {
final String className = readString(bytes);
if (className.length() != 0)
ODocumentInternal.fillClassNameIfNeeded(document, className);
int last = 0;
String fieldName;
int valuePos;
OType type;
while (true) {
final int len = OVarIntSerializer.readAsInteger(bytes);
if (len == 0) {
// SCAN COMPLETED
break;
} else if (len > 0) {
// PARSE FIELD NAME
fieldName = stringFromBytes(bytes.bytes, bytes.offset, len).intern();
bytes.skip(len);
valuePos = readInteger(bytes);
type = readOType(bytes);
} else {
throw new OStorageException("property id not supported in network serialization");
}
if (ODocumentInternal.rawContainsField(document, fieldName)) {
continue;
}
if (valuePos != 0) {
int headerCursor = bytes.offset;
bytes.offset = valuePos;
final Object value = deserializeValue(bytes, type, document);
if (bytes.offset > last)
last = bytes.offset;
bytes.offset = headerCursor;
document.field(fieldName, value, type);
} else
document.field(fieldName, null, null);
}
ORecordInternal.clearSource(document);
if (last > bytes.offset)
bytes.offset = last;
}
use of com.orientechnologies.orient.core.exception.OStorageException in project orientdb by orientechnologies.
the class OWOWCache method delete.
public long[] delete() throws IOException {
final List<Long> result = new ArrayList<Long>();
filesLock.acquireWriteLock();
try {
for (int intId : nameIdMap.values()) {
if (intId < 0)
continue;
final long externalId = composeFileId(id, intId);
doDeleteFile(externalId);
result.add(externalId);
}
if (nameIdMapHolderFile != null) {
if (nameIdMapHolderFile.exists()) {
nameIdMapHolder.close();
if (!nameIdMapHolderFile.delete())
throw new OStorageException("Cannot delete disk cache file which contains name-id mapping.");
}
nameIdMapHolder = null;
nameIdMapHolderFile = null;
}
} finally {
filesLock.releaseWriteLock();
}
if (!commitExecutor.isShutdown()) {
commitExecutor.shutdown();
try {
if (!commitExecutor.awaitTermination(5, TimeUnit.MINUTES))
throw new OWriteCacheException("Background data flush task cannot be stopped.");
} catch (InterruptedException e) {
OLogManager.instance().error(this, "Data flush thread was interrupted");
Thread.interrupted();
throw new OInterruptedException("Data flush thread was interrupted");
}
}
final long[] ids = new long[result.size()];
int counter = 0;
for (long id : result) {
ids[counter] = id;
counter++;
}
return ids;
}
Aggregations