use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OClusterPositionMap method resurrect.
public void resurrect(final long clusterPosition, final OClusterPositionMapBucket.PositionEntry entry) throws IOException {
startOperation();
try {
OAtomicOperation atomicOperation = startAtomicOperation(true);
acquireExclusiveLock();
try {
final long pageIndex = clusterPosition / OClusterPositionMapBucket.MAX_ENTRIES;
final int index = (int) (clusterPosition % OClusterPositionMapBucket.MAX_ENTRIES);
if (pageIndex >= getFilledUpTo(atomicOperation, fileId))
throw new OClusterPositionMapException("Passed in cluster position " + clusterPosition + " is outside of range of cluster-position map", this);
final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, 1);
cacheEntry.acquireExclusiveLock();
try {
final OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
bucket.resurrect(index, entry);
} finally {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
}
endAtomicOperation(false, null);
} catch (IOException e) {
endAtomicOperation(true, e);
throw OException.wrapException(new OClusterPositionMapException("Error of resurrecting mapping between logical and physical record position", this), e);
} catch (RuntimeException e) {
endAtomicOperation(true, e);
throw OException.wrapException(new OClusterPositionMapException("Error of resurrecting mapping between logical and physical record position", this), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OClusterPositionMap method getStatus.
public byte getStatus(final long clusterPosition) throws IOException {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
final long pageIndex = clusterPosition / OClusterPositionMapBucket.MAX_ENTRIES;
final int index = (int) (clusterPosition % OClusterPositionMapBucket.MAX_ENTRIES);
final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
if (pageIndex >= getFilledUpTo(atomicOperation, fileId))
return OClusterPositionMapBucket.NOT_EXISTENT;
final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, 1);
cacheEntry.acquireSharedLock();
try {
final OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
return bucket.getStatus(index);
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OClusterPositionMap method ceilingPositions.
public long[] ceilingPositions(long clusterPosition) throws IOException {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
if (clusterPosition < 0)
clusterPosition = 0;
long pageIndex = clusterPosition / OClusterPositionMapBucket.MAX_ENTRIES;
int index = (int) (clusterPosition % OClusterPositionMapBucket.MAX_ENTRIES);
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
final long filledUpTo = getFilledUpTo(atomicOperation, fileId);
if (pageIndex >= filledUpTo)
return OCommonConst.EMPTY_LONG_ARRAY;
long[] result = null;
do {
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, 1);
cacheEntry.acquireSharedLock();
OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
int resultSize = bucket.getSize() - index;
if (resultSize <= 0) {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
pageIndex++;
index = 0;
} else {
int entriesCount = 0;
long startIndex = cacheEntry.getPageIndex() * OClusterPositionMapBucket.MAX_ENTRIES + index;
result = new long[resultSize];
for (int i = 0; i < resultSize; i++) {
if (bucket.exists(i + index)) {
result[entriesCount] = startIndex + i;
entriesCount++;
}
}
if (entriesCount == 0) {
result = null;
pageIndex++;
index = 0;
} else
result = Arrays.copyOf(result, entriesCount);
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} while (result == null && pageIndex < filledUpTo);
if (result == null)
result = OCommonConst.EMPTY_LONG_ARRAY;
return result;
} finally {
releaseSharedLock();
}
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OClusterPositionMap method allocate.
public long allocate() throws IOException {
startOperation();
try {
OAtomicOperation atomicOperation = startAtomicOperation(true);
acquireExclusiveLock();
try {
long lastPage = getFilledUpTo(atomicOperation, fileId) - 1;
OCacheEntry cacheEntry;
if (lastPage < 0)
cacheEntry = addPage(atomicOperation, fileId);
else
cacheEntry = loadPage(atomicOperation, fileId, lastPage, false, 1);
Exception exception = null;
cacheEntry.acquireExclusiveLock();
try {
OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
if (bucket.isFull()) {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
cacheEntry = addPage(atomicOperation, fileId);
cacheEntry.acquireExclusiveLock();
bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
}
final long index = bucket.allocate();
return index + cacheEntry.getPageIndex() * OClusterPositionMapBucket.MAX_ENTRIES;
} catch (Exception e) {
exception = e;
throw OException.wrapException(new OClusterPositionMapException("Error during creation of mapping between logical and physical record position", this), e);
} finally {
try {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
} finally {
endAtomicOperation(exception != null, exception);
}
}
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class OClusterPositionMap method getFirstPosition.
public long getFirstPosition() throws IOException {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
final long filledUpTo = getFilledUpTo(atomicOperation, fileId);
for (long pageIndex = 0; pageIndex < filledUpTo; pageIndex++) {
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, 1);
cacheEntry.acquireSharedLock();
try {
OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChanges(atomicOperation, cacheEntry));
int bucketSize = bucket.getSize();
for (int index = 0; index < bucketSize; index++) {
if (bucket.exists(index))
return pageIndex * OClusterPositionMapBucket.MAX_ENTRIES + index;
}
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
}
return ORID.CLUSTER_POS_INVALID;
} finally {
releaseSharedLock();
}
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
Aggregations