use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testIfNotEnoughSpaceOldPagesShouldBeMovedToA1Out.
public void testIfNotEnoughSpaceOldPagesShouldBeMovedToA1Out() throws Exception {
long fileId = readBuffer.addFile(fileName, writeBuffer);
OCacheEntry[] entries = new OCacheEntry[6];
for (int i = 0; i < 6; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
if (entries[i] == null) {
entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer, true);
Assert.assertEquals(entries[i].getPageIndex(), i);
}
entries[i].getCachePointer().acquireExclusiveLock();
entries[i].markDirty();
final ByteBuffer buffer = entries[i].getCachePointer().getSharedBuffer();
buffer.position(systemOffset);
buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, 7 });
entries[i].getCachePointer().releaseExclusiveLock();
readBuffer.release(entries[i], writeBuffer);
}
LRUList am = readBuffer.getAm();
LRUList a1in = readBuffer.getA1in();
LRUList a1out = readBuffer.getA1out();
Assert.assertEquals(am.size(), 0);
for (int i = 0; i < 2; i++) {
OCacheEntry entry = generateRemovedEntry(fileId, i);
Assert.assertEquals(a1out.get(entry.getFileId(), entry.getPageIndex()), entry);
}
final OByteBufferPool bufferPool = OByteBufferPool.instance();
for (int i = 2; i < 6; i++) {
OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
}
Assert.assertEquals(writeBuffer.getFilledUpTo(fileId), 6);
writeBuffer.flush();
for (int i = 0; i < 6; i++) {
assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, 7 }, new OLogSequenceNumber(0, 0));
}
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testCloseFileShouldFlushData.
public void testCloseFileShouldFlushData() throws Exception {
long fileId = readBuffer.addFile(fileName, writeBuffer);
OCacheEntry[] entries = new OCacheEntry[4];
for (int i = 0; i < 4; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
if (entries[i] == null) {
entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer, true);
Assert.assertEquals(entries[i].getPageIndex(), i);
}
entries[i].getCachePointer().acquireExclusiveLock();
entries[i].markDirty();
ByteBuffer buffer = entries[i].getCachePointer().getSharedBuffer();
buffer.position(systemOffset);
buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i });
entries[i].getCachePointer().releaseExclusiveLock();
readBuffer.release(entries[i], writeBuffer);
}
LRUList am = readBuffer.getAm();
LRUList a1in = readBuffer.getA1in();
LRUList a1out = readBuffer.getA1out();
Assert.assertEquals(am.size(), 0);
Assert.assertEquals(a1out.size(), 0);
final OByteBufferPool bufferPool = OByteBufferPool.instance();
for (int i = 0; i < 4; i++) {
OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
}
Assert.assertEquals(writeBuffer.getFilledUpTo(fileId), 4);
readBuffer.closeFile(fileId, true, writeBuffer);
for (int i = 0; i < 4; i++) {
assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }, new OLogSequenceNumber(0, 0));
}
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method initBuffer.
private void initBuffer() throws IOException {
writeBuffer = new OWOWCache(false, PAGE_SIZE, new OByteBufferPool(PAGE_SIZE), -1, writeAheadLog, -1, WRITE_CACHE_MAX_SIZE, WRITE_CACHE_MAX_SIZE + READ_CACHE_MAX_MEMORY, storageLocal, false, files, 1);
writeBuffer.loadRegisteredFiles();
readBuffer = new O2QCache(READ_CACHE_MAX_MEMORY, PAGE_SIZE, false, 50);
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testFrequentlyReadItemsAreMovedInAm.
public void testFrequentlyReadItemsAreMovedInAm() throws Exception {
long fileId = readBuffer.addFile(fileName, writeBuffer);
OCacheEntry[] entries = new OCacheEntry[10];
for (int i = 0; i < 10; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
if (entries[i] == null) {
entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer, true);
Assert.assertEquals(entries[i].getPageIndex(), i);
}
entries[i].getCachePointer().acquireExclusiveLock();
entries[i].markDirty();
final ByteBuffer buffer = entries[i].getCachePointer().getSharedBuffer();
buffer.position(systemOffset);
buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i });
setLsn(buffer, new OLogSequenceNumber(1, i));
entries[i].getCachePointer().releaseExclusiveLock();
readBuffer.release(entries[i], writeBuffer);
}
writeBuffer.flush();
readBuffer.clear();
for (int i = 0; i < 10; i++) assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }, new OLogSequenceNumber(1, i));
for (int i = 0; i < 8; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
readBuffer.release(entries[i], writeBuffer);
}
for (int i = 2; i < 4; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
readBuffer.release(entries[i], writeBuffer);
}
LRUList am = readBuffer.getAm();
LRUList a1in = readBuffer.getA1in();
LRUList a1out = readBuffer.getA1out();
Assert.assertEquals(am.size(), 2);
Assert.assertEquals(a1in.size(), 2);
Assert.assertEquals(a1out.size(), 2);
final OByteBufferPool bufferPool = OByteBufferPool.instance();
for (int i = 2; i < 4; i++) {
OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(1, i));
Assert.assertEquals(am.get(fileId, i), lruEntry);
}
for (int i = 4; i < 6; i++) {
OCacheEntry lruEntry = generateRemovedEntry(fileId, i);
Assert.assertEquals(a1out.get(fileId, i), lruEntry);
}
for (int i = 6; i < 8; i++) {
OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(1, i));
Assert.assertEquals(a1in.get(fileId, i), lruEntry);
}
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testLoadAndLockForReadShouldHitCache.
public void testLoadAndLockForReadShouldHitCache() throws Exception {
long fileId = readBuffer.addFile(fileName, writeBuffer);
OCacheEntry cacheEntry = readBuffer.load(fileId, 0, false, writeBuffer, 1, true);
if (cacheEntry == null) {
cacheEntry = readBuffer.allocateNewPage(fileId, writeBuffer, true);
Assert.assertEquals(cacheEntry.getPageIndex(), 0);
}
readBuffer.release(cacheEntry, writeBuffer);
LRUList am = readBuffer.getAm();
LRUList a1in = readBuffer.getA1in();
LRUList a1out = readBuffer.getA1out();
Assert.assertEquals(am.size(), 0);
Assert.assertEquals(a1out.size(), 0);
final OByteBufferPool bufferPool = OByteBufferPool.instance();
final OCacheEntry entry = generateEntry(fileId, 0, cacheEntry.getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
Assert.assertEquals(a1in.size(), 1);
Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
}
Aggregations