use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable20 method close.
@Override
public void close() {
acquireExclusiveLock();
try {
flush();
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
directory.close();
final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
try {
for (int i = 0; i < HASH_CODE_SIZE; i++) {
OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
if (!metadataPage.isRemoved(i)) {
readCache.closeFile(metadataPage.getFileId(i), true, writeCache);
}
}
} finally {
releasePage(atomicOperation, hashStateEntry);
}
readCache.closeFile(fileStateId, true, writeCache);
} catch (IOException e) {
throw OException.wrapException(new OIndexException("Error during hash table close"), e);
} finally {
releaseExclusiveLock();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable20 method higherEntries.
@Override
public OHashIndexBucket.Entry<K, V>[] higherEntries(K key, int limit) {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
key = keySerializer.preprocess(key, (Object[]) keyTypes);
final long hashCode = keyHashFunction.hashCode(key);
BucketPath bucketPath = getBucket(hashCode);
long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
int fileLevel = getFileLevel(bucketPointer);
long pageIndex = getPageIndex(bucketPointer);
OCacheEntry cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
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;
releasePage(atomicOperation, cacheEntry);
final long nextPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
fileLevel = getFileLevel(nextPointer);
pageIndex = getPageIndex(nextPointer);
cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
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 {
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OIndexException("Exception during data retrieval"), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OSBTree method iterateEntriesMinor.
public OSBTreeCursor<K, V> iterateEntriesMinor(K key, boolean inclusive, boolean ascSortOrder) {
final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
startOperation();
if (statistic != null)
statistic.startIndexEntryReadTimer();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
if (!ascSortOrder)
return iterateEntriesMinorDesc(key, inclusive, atomicOperation);
return iterateEntriesMinorAsc(key, inclusive, atomicOperation);
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OSBTreeException("Error during iteration of minor values for key " + key + " in sbtree " + getName(), this), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
if (statistic != null)
statistic.stopIndexEntryReadTimer();
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OSBTree method remove.
public V remove(K key) {
final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
startOperation();
if (statistic != null)
statistic.startIndexEntryDeletionTimer();
try {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(true);
} catch (IOException e) {
throw OException.wrapException(new OSBTreeException("Error during sbtree entrie remove", this), e);
}
acquireExclusiveLock();
try {
V removedValue;
if (key != null) {
key = keySerializer.preprocess(key, (Object[]) keyTypes);
BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
if (bucketSearchResult.itemIndex < 0) {
endAtomicOperation(false, null);
return null;
}
OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem(), false);
keyBucketCacheEntry.acquireExclusiveLock();
try {
OSBTreeBucket<K, V> keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
final OSBTreeValue<V> removed = keyBucket.getEntry(bucketSearchResult.itemIndex).value;
final V value = readValue(removed, atomicOperation);
long removedValueLink = keyBucket.remove(bucketSearchResult.itemIndex);
if (removedValueLink >= 0)
removeLinkedValue(removedValueLink, atomicOperation);
setSize(size() - 1, atomicOperation);
removedValue = value;
} finally {
keyBucketCacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, keyBucketCacheEntry);
}
} else {
if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
endAtomicOperation(false, null);
return null;
}
OCacheEntry nullCacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
nullCacheEntry.acquireExclusiveLock();
try {
ONullBucket<V> nullBucket = new ONullBucket<V>(nullCacheEntry, getChanges(atomicOperation, nullCacheEntry), valueSerializer, false);
OSBTreeValue<V> treeValue = nullBucket.getValue();
if (treeValue != null) {
removedValue = readValue(treeValue, atomicOperation);
nullBucket.removeValue();
} else
removedValue = null;
} finally {
nullCacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, nullCacheEntry);
}
if (removedValue != null)
setSize(size() - 1, atomicOperation);
}
endAtomicOperation(false, null);
return removedValue;
} catch (IOException e) {
rollback(e);
throw OException.wrapException(new OSBTreeException("Error during removing key " + key + " from sbtree " + getName(), this), e);
} catch (RuntimeException e) {
rollback(e);
throw e;
} finally {
releaseExclusiveLock();
}
} finally {
if (statistic != null)
statistic.stopIndexEntryDeletionTimer();
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OSBTree method create.
public void create(OBinarySerializer<K> keySerializer, OBinarySerializer<V> valueSerializer, OType[] keyTypes, int keySize, boolean nullPointerSupport) {
assert keySerializer != null;
startOperation();
try {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(false);
} catch (IOException e) {
throw OException.wrapException(new OSBTreeException("Error during sbtree creation", this), e);
}
acquireExclusiveLock();
try {
this.keySize = keySize;
if (keyTypes != null)
this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
else
this.keyTypes = null;
this.keySerializer = keySerializer;
this.valueSerializer = valueSerializer;
this.nullPointerSupport = nullPointerSupport;
fileId = addFile(atomicOperation, getFullName());
if (nullPointerSupport)
nullBucketFileId = addFile(atomicOperation, getName() + nullFileExtension);
OCacheEntry rootCacheEntry = addPage(atomicOperation, fileId);
rootCacheEntry.acquireExclusiveLock();
try {
OSBTreeBucket<K, V> rootBucket = new OSBTreeBucket<K, V>(rootCacheEntry, true, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, rootCacheEntry));
rootBucket.setTreeSize(0);
} finally {
rootCacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, rootCacheEntry);
}
endAtomicOperation(false, null);
} catch (IOException e) {
try {
endAtomicOperation(true, e);
} catch (IOException e1) {
OLogManager.instance().error(this, "Error during sbtree data rollback", e1);
}
throw OException.wrapException(new OSBTreeException("Error creation of sbtree with name " + getName(), this), e);
} catch (RuntimeException e) {
try {
endAtomicOperation(true, e);
} catch (IOException e1) {
OLogManager.instance().error(this, "Error during sbtree data rollback", e1);
}
throw e;
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
Aggregations