use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable method higherEntries.
@Override
public OHashIndexBucket.Entry<K, V>[] higherEntries(K key, int limit) {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
key = keySerializer.preprocess(key, (Object[]) keyTypes);
final long hashCode = keyHashFunction.hashCode(key);
OHashTable.BucketPath bucketPath = getBucket(hashCode);
long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
long pageIndex = getPageIndex(bucketPointer);
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
try {
OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
while (bucket.size() == 0 || comparator.compare(bucket.getKey(bucket.size() - 1), key) <= 0) {
bucketPath = nextBucketToFind(bucketPath, bucket.getDepth());
if (bucketPath == null)
return OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
final long nextPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
pageIndex = getPageIndex(nextPointer);
cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
}
final int index = bucket.getIndex(hashCode, key);
final int startIndex;
if (index >= 0)
startIndex = index + 1;
else
startIndex = -index - 1;
final int endIndex;
if (limit <= 0)
endIndex = bucket.size();
else
endIndex = Math.min(bucket.size(), startIndex + limit);
return convertBucketToEntries(bucket, startIndex, endIndex);
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OLocalHashTableException("Exception during data retrieval", this), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation 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.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable method firstEntry.
@Override
public OHashIndexBucket.Entry<K, V> firstEntry() {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
OHashTable.BucketPath bucketPath = getBucket(HASH_CODE_MIN_VALUE);
long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex);
long pageIndex = getPageIndex(bucketPointer);
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
try {
OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
while (bucket.size() == 0) {
bucketPath = nextBucketToFind(bucketPath, bucket.getDepth());
if (bucketPath == null)
return null;
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
final long nextPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
pageIndex = getPageIndex(nextPointer);
cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
}
return bucket.getEntry(0);
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OLocalHashTableException("Exception during data read", this), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OSBTreeBonsaiLocal method load.
public boolean load(OBonsaiBucketPointer rootBucketPointer) {
OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
startOperation();
if (statistic != null)
statistic.startRidBagEntryLoadTimer();
try {
Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
try {
this.rootBucketPointer = rootBucketPointer;
final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
this.fileId = openFile(atomicOperation, getFullName());
OCacheEntry rootCacheEntry = loadPage(atomicOperation, this.fileId, this.rootBucketPointer.getPageIndex(), false);
rootCacheEntry.acquireSharedLock();
try {
OSBTreeBonsaiBucket<K, V> rootBucket = new OSBTreeBonsaiBucket<K, V>(rootCacheEntry, this.rootBucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, rootCacheEntry), this);
keySerializer = (OBinarySerializer<K>) storage.getComponentsFactory().binarySerializerFactory.getObjectSerializer(rootBucket.getKeySerializerId());
valueSerializer = (OBinarySerializer<V>) storage.getComponentsFactory().binarySerializerFactory.getObjectSerializer(rootBucket.getValueSerializerId());
return !rootBucket.isDeleted();
} finally {
rootCacheEntry.releaseSharedLock();
releasePage(atomicOperation, rootCacheEntry);
}
} catch (IOException e) {
throw OException.wrapException(new OSBTreeBonsaiLocalException("Exception during loading of sbtree " + fileId, this), e);
} finally {
lock.unlock();
}
} finally {
if (statistic != null)
statistic.stopRidBagEntryLoadTimer();
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OSBTreeBonsaiLocal method put.
@Override
public boolean put(K key, V value) {
final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
startOperation();
if (statistic != null)
statistic.startRidBagEntryUpdateTimer();
try {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(true);
} catch (IOException e) {
throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during sbtree entrie put", this), e);
}
final Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
try {
BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
OBonsaiBucketPointer bucketPointer = bucketSearchResult.getLastPathItem();
OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
keyBucketCacheEntry.acquireExclusiveLock();
OSBTreeBonsaiBucket<K, V> keyBucket = new OSBTreeBonsaiBucket<K, V>(keyBucketCacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry), this);
final boolean itemFound = bucketSearchResult.itemIndex >= 0;
boolean result = true;
if (itemFound) {
final int updateResult = keyBucket.updateValue(bucketSearchResult.itemIndex, value);
assert updateResult == 0 || updateResult == 1;
result = updateResult != 0;
} else {
int insertionIndex = -bucketSearchResult.itemIndex - 1;
while (!keyBucket.addEntry(insertionIndex, new OSBTreeBonsaiBucket.SBTreeEntry<K, V>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, value), true)) {
keyBucketCacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, keyBucketCacheEntry);
bucketSearchResult = splitBucket(bucketSearchResult.path, insertionIndex, key, atomicOperation);
bucketPointer = bucketSearchResult.getLastPathItem();
insertionIndex = bucketSearchResult.itemIndex;
keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem().getPageIndex(), false);
keyBucketCacheEntry.acquireExclusiveLock();
keyBucket = new OSBTreeBonsaiBucket<K, V>(keyBucketCacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry), this);
}
}
keyBucketCacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, keyBucketCacheEntry);
if (!itemFound)
setSize(size() + 1, atomicOperation);
endAtomicOperation(false, null);
return result;
} catch (IOException e) {
rollback(e);
throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during index update with key " + key + " and value " + value, this), e);
} finally {
lock.unlock();
}
} finally {
if (statistic != null)
statistic.stopRidBagEntryUpdateTimer();
completeOperation();
}
}
Aggregations