use of com.orientechnologies.orient.core.index.OIndexException 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();
}
}
use of com.orientechnologies.orient.core.index.OIndexException 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.index.OIndexException 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.index.OIndexException 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.index.OIndexException in project orientdb by orientechnologies.
the class OLocalHashTable20 method clear.
@Override
public void clear() {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(true);
} catch (IOException e) {
throw OException.wrapException(new OIndexException("Error during hash table clear"), e);
}
acquireExclusiveLock();
try {
final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
hashStateEntry.acquireExclusiveLock();
try {
OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
for (int i = 0; i < HASH_CODE_SIZE; i++) {
if (!page.isRemoved(i)) {
truncateFile(atomicOperation, page.getFileId(i));
page.setBucketsCount(i, 0);
page.setTombstoneIndex(i, -1);
}
}
} finally {
hashStateEntry.releaseExclusiveLock();
releasePage(atomicOperation, hashStateEntry);
}
if (nullKeyIsSupported)
truncateFile(atomicOperation, nullBucketFileId);
initHashTreeState(atomicOperation);
endAtomicOperation(false, null);
} catch (IOException e) {
rollback();
throw OException.wrapException(new OIndexEngineException("Error during hash table clear", getName()), e);
} catch (Exception e) {
rollback();
throw OException.wrapException(new OIndexEngineException("Error during hash table clear", getName()), e);
} finally {
releaseExclusiveLock();
}
}
Aggregations