use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testFlushData.
public void testFlushData() throws Exception {
long fileId = readBuffer.addFile(fileName, writeBuffer);
OCacheEntry[] entries = new OCacheEntry[4];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; ++j) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1);
if (entries[i] == null) {
entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer);
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, (byte) j, (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++) {
final ByteBuffer buffer = entries[i].getCachePointer().getSharedBuffer();
OCacheEntry entry = generateEntry(fileId, i, buffer, bufferPool, false, new OLogSequenceNumber(0, 0));
Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
}
Assert.assertEquals(writeBuffer.getFilledUpTo(fileId), 4);
writeBuffer.flush(fileId);
for (int i = 0; i < 4; i++) {
assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 3, (byte) i }, new OLogSequenceNumber(0, 0));
}
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testFlushTillLSN.
public void testFlushTillLSN() throws Exception {
closeBufferAndDeleteFile();
File file = new File(storageLocal.getConfiguration().getDirectory());
if (!file.exists())
file.mkdir();
writeAheadLog = new ODiskWriteAheadLog(1024, -1, 10 * 1024, null, true, storageLocal, 10);
final OStorageSegmentConfiguration segmentConfiguration = new OStorageSegmentConfiguration(storageLocal.getConfiguration(), "readWriteDiskCacheTest.tst", 0);
segmentConfiguration.fileType = OFileClassic.NAME;
writeBuffer = new OWOWCache(false, 8 + systemOffset, new OByteBufferPool(8 + systemOffset), 10000, writeAheadLog, 100, 2 * (8 + systemOffset), 2 * (8 + systemOffset) + 4 * (8 + systemOffset), storageLocal, false, files, 10);
writeBuffer.loadRegisteredFiles();
readBuffer = new O2QCache(4 * (8 + systemOffset), 8 + systemOffset, false, 20);
long fileId = readBuffer.addFile(fileName, writeBuffer);
OLogSequenceNumber lsnToFlush = null;
for (int i = 0; i < 8; i++) {
OCacheEntry cacheEntry = readBuffer.load(fileId, i, false, writeBuffer, 1);
if (cacheEntry == null) {
cacheEntry = readBuffer.allocateNewPage(fileId, writeBuffer);
Assert.assertEquals(cacheEntry.getPageIndex(), i);
}
OCachePointer dataPointer = cacheEntry.getCachePointer();
dataPointer.acquireExclusiveLock();
OLogSequenceNumber pageLSN = writeAheadLog.log(new WriteAheadLogTest.TestRecord(30, false));
setLsn(dataPointer.getSharedBuffer(), pageLSN);
lsnToFlush = pageLSN;
cacheEntry.markDirty();
dataPointer.releaseExclusiveLock();
readBuffer.release(cacheEntry, writeBuffer);
}
Thread.sleep(1000);
Assert.assertEquals(writeAheadLog.getFlushedLsn(), lsnToFlush);
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testAddFourItems.
public void testAddFourItems() throws IOException {
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);
if (entries[i] == null) {
entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer);
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 });
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);
writeBuffer.flush();
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 testReadFourItems.
public void testReadFourItems() throws IOException {
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);
if (entries[i] == null) {
entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer);
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);
}
readBuffer.clear();
writeBuffer.flush();
for (int i = 0; i < 4; i++) {
assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }, new OLogSequenceNumber(1, i));
}
for (int i = 0; i < 4; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1);
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);
OByteBufferPool bufferPool = OByteBufferPool.instance();
for (int i = 0; i < 4; i++) {
OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(1, i));
Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
}
Assert.assertEquals(writeBuffer.getFilledUpTo(fileId), 4);
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ClusterPageTest method testFindLastRecord.
public void testFindLastRecord() 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();
ByteBuffer directBuffer = bufferPool.acquireDirect(true);
OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
directCachePointer.incrementReferrer();
OCacheEntry directCacheEntry = new OCacheEntry(0, 0, directCachePointer, false);
directCacheEntry.acquireExclusiveLock();
final long seed = System.currentTimeMillis();
try {
OClusterPage localPage = new OClusterPage(cacheEntry, true, new OWALChangesTree());
OClusterPage directLocalPage = new OClusterPage(directCacheEntry, true, null);
findLastRecord(seed, localPage);
findLastRecord(seed, directLocalPage);
assertChangesTracking(localPage, directBuffer, bufferPool);
} finally {
cacheEntry.releaseExclusiveLock();
directCacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
directCachePointer.decrementReferrer();
}
}
Aggregations