use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class ClusterPageTest method testAddThreeRecords.
public void testAddThreeRecords() 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();
try {
OClusterPage localPage = new OClusterPage(cacheEntry, true, new OWALChangesTree());
OClusterPage directLocalPage = new OClusterPage(directCacheEntry, true, null);
addThreeRecords(localPage);
addThreeRecords(directLocalPage);
assertChangesTracking(localPage, directBuffer, bufferPool);
} finally {
cacheEntry.releaseExclusiveLock();
directCacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
directCachePointer.decrementReferrer();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class ClusterPageTest method testReplaceOneRecordNoVersionUpdate.
public void testReplaceOneRecordNoVersionUpdate() 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();
try {
OClusterPage localPage = new OClusterPage(cacheEntry, true, new OWALChangesTree());
OClusterPage directLocalPage = new OClusterPage(directCacheEntry, true, null);
replaceOneRecordNoVersionUpdate(localPage);
replaceOneRecordNoVersionUpdate(directLocalPage);
assertChangesTracking(localPage, directBuffer, bufferPool);
} finally {
cacheEntry.releaseExclusiveLock();
directCacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
directCachePointer.decrementReferrer();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer 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();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer 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, true);
if (cacheEntry == null) {
cacheEntry = readBuffer.allocateNewPage(fileId, writeBuffer, true);
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.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class WOWCacheTest method testDataUpdate.
@Test
public void testDataUpdate() throws Exception {
final NavigableMap<Long, byte[]> pageIndexDataMap = new TreeMap<Long, byte[]>();
long fileId = wowCache.addFile(fileName);
Random random = new Random();
for (int i = 0; i < 600; i++) {
long pageIndex = random.nextInt(2048);
byte[] data = new byte[8];
random.nextBytes(data);
pageIndexDataMap.put(pageIndex, data);
final OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, true, new OModifiableBoolean(), true)[0];
cachePointer.acquireExclusiveLock();
ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.put(data);
cachePointer.releaseExclusiveLock();
wowCache.store(fileId, pageIndex, cachePointer);
cachePointer.decrementReadersReferrer();
}
for (Map.Entry<Long, byte[]> entry : pageIndexDataMap.entrySet()) {
long pageIndex = entry.getKey();
byte[] dataOne = entry.getValue();
OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, false, new OModifiableBoolean(), true)[0];
byte[] dataTwo = new byte[8];
ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.get(dataTwo);
cachePointer.decrementReadersReferrer();
Assert.assertEquals(dataTwo, dataOne);
}
for (int i = 0; i < 300; i++) {
long desiredIndex = random.nextInt(2048);
Long pageIndex = pageIndexDataMap.ceilingKey(desiredIndex);
if (pageIndex == null)
pageIndex = pageIndexDataMap.floorKey(desiredIndex);
byte[] data = new byte[8];
random.nextBytes(data);
pageIndexDataMap.put(pageIndex, data);
final OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, true, new OModifiableBoolean(), true)[0];
cachePointer.acquireExclusiveLock();
ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.put(data);
cachePointer.releaseExclusiveLock();
wowCache.store(fileId, pageIndex, cachePointer);
cachePointer.decrementReadersReferrer();
}
for (Map.Entry<Long, byte[]> entry : pageIndexDataMap.entrySet()) {
long pageIndex = entry.getKey();
byte[] dataOne = entry.getValue();
OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, false, new OModifiableBoolean(), true)[0];
byte[] dataTwo = new byte[8];
ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.get(dataTwo);
cachePointer.decrementReadersReferrer();
Assert.assertEquals(dataTwo, dataOne);
}
wowCache.flush();
for (Map.Entry<Long, byte[]> entry : pageIndexDataMap.entrySet()) {
assertFile(entry.getKey(), entry.getValue(), new OLogSequenceNumber(0, 0));
}
}
Aggregations