if (lastPage < 0) {
lastPage = 0;
isNewPage = true;
}
OCacheEntry cacheEntry = diskCache.load(fileId, lastPage, false);
cacheEntry.acquireExclusiveLock();
try {
startAtomicOperation();
final ODurablePage.TrackMode trackMode = getTrackMode();
OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, trackMode);
if (bucket.isFull()) {
cacheEntry.releaseExclusiveLock();
diskCache.release(cacheEntry);
isNewPage = true;
cacheEntry = diskCache.allocateNewPage(fileId);
cacheEntry.acquireExclusiveLock();
bucket = new OClusterPositionMapBucket(cacheEntry, trackMode);
}
final long index = bucket.add(pageIndex, recordPosition);
final OClusterPosition result = OClusterPositionFactory.INSTANCE.valueOf(index + cacheEntry.getPageIndex()
* OClusterPositionMapBucket.MAX_ENTRIES);
logPageChanges(bucket, fileId, cacheEntry.getPageIndex(), isNewPage);
cacheEntry.markDirty();
endAtomicOperation(false);
return result;
} catch (Throwable e) {
endAtomicOperation(true);
throw new OStorageException("Error during creation of mapping between logical adn physical record position.", e);
} finally {
cacheEntry.releaseExclusiveLock();
diskCache.release(cacheEntry);
}
} finally {
releaseExclusiveLock();
}