use of com.orientechnologies.orient.core.exception.OLocalHashTableException in project orientdb by orientechnologies.
the class OLocalHashTable method lastEntry.
@Override
public OHashIndexBucket.Entry<K, V> lastEntry() {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
OHashTable.BucketPath bucketPath = getBucket(HASH_CODE_MAX_VALUE);
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) {
final OHashTable.BucketPath prevBucketPath = prevBucketToFind(bucketPath, bucket.getDepth());
if (prevBucketPath == null)
return null;
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
final long prevPointer = directory.getNodePointer(prevBucketPath.nodeIndex, prevBucketPath.itemIndex + prevBucketPath.hashMapOffset);
pageIndex = getPageIndex(prevPointer);
cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
bucketPath = prevBucketPath;
}
return bucket.getEntry(bucket.size() - 1);
} 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.exception.OLocalHashTableException in project orientdb by orientechnologies.
the class OLocalHashTable method ceilingEntries.
@Override
public OHashIndexBucket.Entry<K, V>[] ceilingEntries(K key) {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
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) {
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;
else
startIndex = -index - 1;
final int endIndex = bucket.size();
return convertBucketToEntries(bucket, startIndex, endIndex);
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OLocalHashTableException("Error during data retrieval", this), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.exception.OLocalHashTableException 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.exception.OLocalHashTableException 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.exception.OLocalHashTableException in project orientdb by orientechnologies.
the class OLocalHashTable method load.
@Override
public void load(String name, OType[] keyTypes, boolean nullKeyIsSupported) {
startOperation();
try {
acquireExclusiveLock();
try {
if (keyTypes != null)
this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
else
this.keyTypes = null;
this.nullKeyIsSupported = nullKeyIsSupported;
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
fileStateId = openFile(atomicOperation, name + metadataConfigurationFileExtension);
final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, 0, true);
hashStateEntryIndex = hashStateEntry.getPageIndex();
directory = new OHashTableDirectory(treeStateFileExtension, name, getFullName(), durableInNonTxMode, storage);
directory.open();
pinPage(atomicOperation, hashStateEntry);
hashStateEntry.acquireSharedLock();
try {
OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
OBinarySerializerFactory serializerFactory = OBinarySerializerFactory.create(storage.getConfiguration().binaryFormatVersion);
keySerializer = (OBinarySerializer<K>) serializerFactory.getObjectSerializer(page.getKeySerializerId());
valueSerializer = (OBinarySerializer<V>) serializerFactory.getObjectSerializer(page.getValueSerializerId());
} finally {
hashStateEntry.releaseSharedLock();
releasePage(atomicOperation, hashStateEntry);
}
if (nullKeyIsSupported)
nullBucketFileId = openFile(atomicOperation, name + nullBucketFileExtension);
fileId = openFile(atomicOperation, getFullName());
} catch (IOException e) {
throw OException.wrapException(new OLocalHashTableException("Exception during hash table loading", this), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
Aggregations