use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class LRUListTest method testAddOneRemoveLRU.
@Test
public void testAddOneRemoveLRU() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointerOne = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, 10, cachePointerOne, false));
lruList.removeLRU();
Assert.assertEquals(lruList.size(), 0);
Iterator<OCacheEntry> entryIterator = lruList.iterator();
Assert.assertFalse(entryIterator.hasNext());
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class ONullBucketTest method testAddRemoveValue.
public void testAddRemoveValue() throws IOException {
OByteBufferPool bufferPool = new OByteBufferPool(1024);
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();
ONullBucket<String> bucket = new ONullBucket<String>(cacheEntry, null, OStringSerializer.INSTANCE, true);
bucket.setValue(new OSBTreeValue<String>(false, -1, "test"));
bucket.removeValue();
OSBTreeValue<String> treeValue = bucket.getValue();
Assert.assertNull(treeValue);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class ONullBucketTest method testAddRemoveAddValue.
public void testAddRemoveAddValue() throws IOException {
OByteBufferPool bufferPool = new OByteBufferPool(1024);
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();
ONullBucket<String> bucket = new ONullBucket<String>(cacheEntry, null, OStringSerializer.INSTANCE, true);
bucket.setValue(new OSBTreeValue<String>(false, -1, "test"));
bucket.removeValue();
OSBTreeValue<String> treeValue = bucket.getValue();
Assert.assertNull(treeValue);
bucket.setValue(new OSBTreeValue<String>(false, -1, "testOne"));
treeValue = bucket.getValue();
Assert.assertEquals(treeValue.getValue(), "testOne");
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class OWOWCache method cacheFileContent.
private OCachePointer[] cacheFileContent(final int intId, final long startPageIndex, final int pageCount, final boolean addNewPages, OModifiableBoolean cacheHit) throws IOException, InterruptedException {
final long fileId = composeFileId(id, intId);
final OClosableEntry<Long, OFileClassic> entry = files.acquire(fileId);
try {
final OFileClassic fileClassic = entry.get();
if (fileClassic == null)
throw new IllegalArgumentException("File with id " + intId + " not found in WOW Cache");
final OLogSequenceNumber lastLsn;
if (writeAheadLog != null)
lastLsn = writeAheadLog.getFlushedLsn();
else
lastLsn = new OLogSequenceNumber(-1, -1);
final long firstPageStartPosition = startPageIndex * pageSize;
final long firstPageEndPosition = firstPageStartPosition + pageSize;
if (fileClassic.getFileSize() >= firstPageEndPosition) {
final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager.getSessionPerformanceStatistic();
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.startPageReadFromFileTimer();
}
int pagesRead = 0;
try {
if (pageCount == 1) {
final ByteBuffer buffer = bufferPool.acquireDirect(false);
fileClassic.read(firstPageStartPosition, buffer);
buffer.position(0);
final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, lastLsn, fileId, startPageIndex);
pagesRead = 1;
return new OCachePointer[] { dataPointer };
}
final long maxPageCount = (fileClassic.getFileSize() - firstPageStartPosition) / pageSize;
final int realPageCount = Math.min((int) maxPageCount, pageCount);
final ByteBuffer[] buffers = new ByteBuffer[realPageCount];
for (int i = 0; i < buffers.length; i++) {
buffers[i] = bufferPool.acquireDirect(false);
assert buffers[i].position() == 0;
}
fileClassic.read(firstPageStartPosition, buffers);
final OCachePointer[] dataPointers = new OCachePointer[buffers.length];
for (int n = 0; n < buffers.length; n++) {
buffers[n].position(0);
dataPointers[n] = new OCachePointer(buffers[n], bufferPool, lastLsn, fileId, startPageIndex + n);
}
pagesRead = dataPointers.length;
return dataPointers;
} finally {
if (sessionStoragePerformanceStatistic != null) {
sessionStoragePerformanceStatistic.stopPageReadFromFileTimer(pagesRead);
}
}
} else if (addNewPages) {
final int space = (int) (firstPageEndPosition - fileClassic.getFileSize());
if (space > 0)
fileClassic.allocateSpace(space);
freeSpaceCheckAfterNewPageAdd();
final ByteBuffer buffer = bufferPool.acquireDirect(true);
final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, lastLsn, fileId, startPageIndex);
cacheHit.setValue(true);
return new OCachePointer[] { dataPointer };
} else
return new OCachePointer[0];
} finally {
files.release(entry);
}
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class SBTreeLeafBucketTest method testRemove.
public void testRemove() throws Exception {
long seed = System.currentTimeMillis();
System.out.println("testRemove seed : " + seed);
TreeSet<Long> keys = new TreeSet<Long>();
Random random = new Random(seed);
while (keys.size() < 2 * OSBTreeBucket.MAX_PAGE_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);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
OSBTreeBucket<Long, OIdentifiable> treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, true, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
int index = 0;
for (Long key : keys) {
if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry<Long, OIdentifiable>(-1, -1, key, new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(index, index))), true))
break;
index++;
}
int originalSize = treeBucket.size();
int itemsToDelete = originalSize / 2;
for (int i = 0; i < itemsToDelete; i++) {
treeBucket.remove(treeBucket.size() - 1);
}
Assert.assertEquals(treeBucket.size(), originalSize - itemsToDelete);
final Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
Iterator<Long> keysIterator = keys.iterator();
index = 0;
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 OSBTreeBucket.SBTreeEntry<Long, OIdentifiable>(-1, -1, key, new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(index, index))), true))
break;
keyIndexMap.put(key, index);
index++;
addedKeys++;
}
for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
OSBTreeBucket.SBTreeEntry<Long, OIdentifiable> entry = treeBucket.getEntry(keyIndexEntry.getValue());
Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry<Long, OIdentifiable>(-1, -1, keyIndexEntry.getKey(), new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(keyIndexEntry.getValue(), keyIndexEntry.getValue()))));
}
Assert.assertEquals(treeBucket.size(), originalSize);
Assert.assertEquals(addedKeys, keysToAdd);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
Aggregations