use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OHashTableDirectory method deleteWithoutOpen.
public void deleteWithoutOpen() throws IOException {
startOperation();
try {
final OAtomicOperation atomicOperation = startAtomicOperation(false);
acquireExclusiveLock();
try {
if (isFileExists(atomicOperation, getFullName())) {
fileId = openFile(atomicOperation, getFullName());
deleteFile(atomicOperation, fileId);
}
endAtomicOperation(false, null);
} catch (IOException e) {
endAtomicOperation(true, e);
throw e;
} catch (Exception e) {
endAtomicOperation(true, e);
throw OException.wrapException(new OHashTableDirectoryException("Error during deletion of hash table", this), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OHashTableDirectory method deleteNode.
public void deleteNode(int nodeIndex) throws IOException {
startOperation();
try {
final OAtomicOperation atomicOperation = startAtomicOperation(true);
acquireExclusiveLock();
try {
OCacheEntry firstEntry = loadPage(atomicOperation, fileId, firstEntryIndex, true);
firstEntry.acquireExclusiveLock();
try {
ODirectoryFirstPage firstPage = new ODirectoryFirstPage(firstEntry, getChanges(atomicOperation, firstEntry), firstEntry);
if (nodeIndex < ODirectoryFirstPage.NODES_PER_PAGE) {
firstPage.setPointer(nodeIndex, 0, firstPage.getTombstone());
firstPage.setTombstone(nodeIndex);
} else {
final int pageIndex = nodeIndex / ODirectoryPage.NODES_PER_PAGE;
final int localNodeIndex = nodeIndex % ODirectoryPage.NODES_PER_PAGE;
final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, true);
cacheEntry.acquireExclusiveLock();
try {
ODirectoryPage page = new ODirectoryPage(cacheEntry, getChanges(atomicOperation, cacheEntry), cacheEntry);
page.setPointer(localNodeIndex, 0, firstPage.getTombstone());
firstPage.setTombstone(nodeIndex);
} finally {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
}
}
} finally {
firstEntry.releaseExclusiveLock();
releasePage(atomicOperation, firstEntry);
}
endAtomicOperation(false, null);
} catch (IOException e) {
endAtomicOperation(true, e);
throw e;
} catch (Exception e) {
endAtomicOperation(true, e);
throw OException.wrapException(new OHashTableDirectoryException("Error during node deletion", this), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OHashTableDirectory method create.
public void create() throws IOException {
startOperation();
try {
OAtomicOperation atomicOperation = startAtomicOperation(false);
acquireExclusiveLock();
try {
fileId = addFile(atomicOperation, getFullName());
init();
endAtomicOperation(false, null);
} catch (IOException e) {
endAtomicOperation(true, e);
throw e;
} catch (Exception e) {
endAtomicOperation(true, e);
throw OException.wrapException(new OHashTableDirectoryException("Error during creation of hash table", this), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable20 method lowerEntries.
@Override
public OHashIndexBucket.Entry<K, V>[] lowerEntries(K key) {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
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);
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
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(0), key) >= 0) {
final BucketPath prevBucketPath = prevBucketToFind(bucketPath, bucket.getDepth());
if (prevBucketPath == null)
return OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
releasePage(atomicOperation, cacheEntry);
final long prevPointer = directory.getNodePointer(prevBucketPath.nodeIndex, prevBucketPath.itemIndex + prevBucketPath.hashMapOffset);
fileLevel = getFileLevel(prevPointer);
pageIndex = getPageIndex(prevPointer);
cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
bucketPath = prevBucketPath;
}
final int startIndex = 0;
final int index = bucket.getIndex(hashCode, key);
final int endIndex;
if (index >= 0)
endIndex = index;
else
endIndex = -index - 1;
return convertBucketToEntries(bucket, startIndex, endIndex);
} finally {
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OIndexException("Exception during data read"), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable20 method firstEntry.
@Override
public OHashIndexBucket.Entry<K, V> firstEntry() {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
BucketPath bucketPath = getBucket(HASH_CODE_MIN_VALUE);
long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex);
int fileLevel = getFileLevel(bucketPointer);
long pageIndex = getPageIndex(bucketPointer);
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
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) {
bucketPath = nextBucketToFind(bucketPath, bucket.getDepth());
if (bucketPath == null)
return null;
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));
}
return bucket.getEntry(0);
} finally {
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OIndexException("Exception during data read"), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
}
Aggregations