use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class OAtomicOperation method addPage.
public OCacheEntry addPage(long fileId) throws IOException {
fileId = checkFileIdCompatibilty(fileId, storageId);
if (deletedFiles.contains(fileId))
throw new OStorageException("File with id " + fileId + " is deleted.");
final FileChanges changesContainer = fileChanges.get(fileId);
assert changesContainer != null;
final long filledUpTo = internalFilledUpTo(fileId, changesContainer);
FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(filledUpTo);
assert pageChangesContainer == null;
pageChangesContainer = new FilePageChanges();
pageChangesContainer.isNew = true;
changesContainer.pageChangesMap.put(filledUpTo, pageChangesContainer);
changesContainer.maxNewPageIndex = filledUpTo;
return new OCacheEntry(fileId, filledUpTo, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, filledUpTo), false);
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class OAtomicOperation method loadPage.
public OCacheEntry loadPage(long fileId, long pageIndex, boolean checkPinnedPages, final int pageCount) throws IOException {
assert pageCount > 0;
fileId = checkFileIdCompatibilty(fileId, storageId);
if (deletedFiles.contains(fileId))
throw new OStorageException("File with id " + fileId + " is deleted.");
FileChanges changesContainer = fileChanges.get(fileId);
if (changesContainer == null) {
changesContainer = new FileChanges();
fileChanges.put(fileId, changesContainer);
}
if (changesContainer.isNew) {
if (pageIndex <= changesContainer.maxNewPageIndex)
return new OCacheEntry(fileId, pageIndex, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, pageIndex), false);
else
return null;
} else {
FilePageChanges pageChangesContainer = changesContainer.pageChangesMap.get(pageIndex);
final long filledUpTo = internalFilledUpTo(fileId, changesContainer);
if (pageIndex < filledUpTo) {
if (pageChangesContainer == null) {
pageChangesContainer = new FilePageChanges();
changesContainer.pageChangesMap.put(pageIndex, pageChangesContainer);
}
if (pageChangesContainer.isNew)
return new OCacheEntry(fileId, pageIndex, new OCachePointer(null, null, new OLogSequenceNumber(-1, -1), fileId, pageIndex), false);
else
return pageCache.loadPage(fileId, pageIndex, checkPinnedPages, writeCache, pageCount);
}
}
return null;
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class SBTreeValuePageTest method testFreeListPointer.
public void testFreeListPointer() throws Exception {
OByteBufferPool bufferPool = OByteBufferPool.instance();
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
OSBTreeValuePage valuePage = new OSBTreeValuePage(cacheEntry, null, true);
valuePage.setNextFreeListPage(124);
Assert.assertEquals(valuePage.getNextFreeListPage(), 124);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class OSBTreeBonsaiLeafBucketTest method testSetRightSibling.
public void testSetRightSibling() throws Exception {
OByteBufferPool bufferPool = OByteBufferPool.instance();
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, true, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
final OBonsaiBucketPointer p = new OBonsaiBucketPointer(123, 8192 * 2);
treeBucket.setRightSibling(p);
Assert.assertEquals(treeBucket.getRightSibling(), p);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class OSBTreeBonsaiLeafBucketTest method testShrink.
public void testShrink() throws Exception {
long seed = System.currentTimeMillis();
System.out.println("testShrink seed : " + seed);
TreeSet<Long> keys = new TreeSet<Long>();
Random random = new Random(seed);
while (keys.size() < 2 * OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES / OLongSerializer.LONG_SIZE) {
keys.add(random.nextLong());
}
OByteBufferPool bufferPool = OByteBufferPool.instance();
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
cachePointer.incrementReferrer();
OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, true, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
int index = 0;
for (Long key : keys) {
if (!treeBucket.addEntry(index, new OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true))
break;
index++;
}
int originalSize = treeBucket.size();
treeBucket.shrink(treeBucket.size() / 2);
Assert.assertEquals(treeBucket.size(), index / 2);
index = 0;
final Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
Iterator<Long> keysIterator = keys.iterator();
while (keysIterator.hasNext() && index < treeBucket.size()) {
Long key = keysIterator.next();
keyIndexMap.put(key, index);
index++;
}
for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
int bucketIndex = treeBucket.find(keyIndexEntry.getKey());
Assert.assertEquals(bucketIndex, (int) keyIndexEntry.getValue());
}
int keysToAdd = originalSize - treeBucket.size();
int addedKeys = 0;
while (keysIterator.hasNext() && index < originalSize) {
Long key = keysIterator.next();
if (!treeBucket.addEntry(index, new OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true))
break;
keyIndexMap.put(key, index);
index++;
addedKeys++;
}
for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable> entry = treeBucket.getEntry(keyIndexEntry.getValue());
Assert.assertEquals(entry, new OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, keyIndexEntry.getKey(), new ORecordId(keyIndexEntry.getValue(), keyIndexEntry.getValue())));
}
Assert.assertEquals(treeBucket.size(), originalSize);
Assert.assertEquals(addedKeys, keysToAdd);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
Aggregations