use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testStoreCacheState.
public void testStoreCacheState() throws Exception {
final long fileId = readBuffer.addFile(fileName, writeBuffer);
Assert.assertEquals(readBuffer.getMaxSize(), 4);
//create file with 8 pages, we will push some of them in different queues later
for (int i = 0; i < 8; i++) {
OCacheEntry cacheEntry = readBuffer.allocateNewPage(fileId, writeBuffer);
cacheEntry.acquireExclusiveLock();
try {
byte[] userData = new byte[userDataSize];
for (int n = 0; n < userData.length; n++) {
userData[n] = (byte) (i + 1);
}
final ByteBuffer buffer = cacheEntry.getCachePointer().getSharedBuffer();
buffer.position(systemOffset);
buffer.put(userData);
setLsn(buffer, new OLogSequenceNumber(1, i));
cacheEntry.markDirty();
} finally {
cacheEntry.releaseExclusiveLock();
readBuffer.release(cacheEntry, writeBuffer);
}
}
readBuffer.clear();
writeBuffer.flush();
for (int i = 0; i < 8; i++) {
byte[] userData = new byte[userDataSize];
for (int n = 0; n < userData.length; n++) {
userData[n] = (byte) (i + 1);
}
assertFile(i, userData, new OLogSequenceNumber(1, i));
}
LRUList am = readBuffer.getAm();
LRUList a1in = readBuffer.getA1in();
LRUList a1out = readBuffer.getA1out();
Assert.assertEquals(am.size(), 0);
Assert.assertEquals(a1out.size(), 0);
Assert.assertEquals(a1in.size(), 0);
//put 1 and 2 pages to the a1out queue, page 0 is dropped from buffer
for (int i = 0; i < 7; i++) {
OCacheEntry cacheEntry = readBuffer.load(fileId, i, false, writeBuffer, 1);
readBuffer.release(cacheEntry, writeBuffer);
}
Assert.assertEquals(am.size(), 0);
// pages 1 - 2
Assert.assertEquals(a1out.size(), 2);
// pages 3 - 6
Assert.assertEquals(a1in.size(), 4);
//put 1-th page to the am queue
OCacheEntry cacheEntry = readBuffer.load(fileId, 1, false, writeBuffer, 1);
readBuffer.release(cacheEntry, writeBuffer);
//page 1
Assert.assertEquals(am.size(), 1);
// page 2 - 3 (removed from a1in because of size limit)
Assert.assertEquals(a1out.size(), 2);
// pages 4 - 6
Assert.assertEquals(a1in.size(), 3);
readBuffer.storeCacheState(writeBuffer);
readBuffer.closeStorage(writeBuffer);
final File stateFile = new File(storagePath, O2QCache.CACHE_STATE_FILE);
Assert.assertTrue(stateFile.exists());
initBuffer();
readBuffer.loadCacheState(writeBuffer);
am = readBuffer.getAm();
a1in = readBuffer.getA1in();
a1out = readBuffer.getA1out();
//page 1
Assert.assertEquals(am.size(), 1);
// page 2 - 3 (removed from a1in because of size limit)
Assert.assertEquals(a1out.size(), 2);
// pages 4 - 6
Assert.assertEquals(a1in.size(), 3);
for (OCacheEntry entry : am) {
Assert.assertEquals(entry.getFileId(), fileId);
Assert.assertEquals(entry.getPageIndex(), 1);
Assert.assertNotNull(entry.getCachePointer());
}
int counter = 3;
for (OCacheEntry entry : a1out) {
Assert.assertEquals(entry.getFileId(), fileId);
Assert.assertEquals(entry.getPageIndex(), counter);
Assert.assertNull(entry.getCachePointer());
counter--;
}
counter = 6;
for (OCacheEntry entry : a1in) {
Assert.assertEquals(entry.getFileId(), fileId);
Assert.assertEquals(entry.getPageIndex(), counter);
Assert.assertNotNull(entry.getCachePointer());
counter--;
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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.impl.local.paginated.wal.OLogSequenceNumber 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.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class ClusterPageTest method testReplaceOneRecordWithEqualSize.
public void testReplaceOneRecordWithEqualSize() 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);
replaceOneRecordWithEqualSize(localPage);
replaceOneRecordWithEqualSize(directLocalPage);
assertChangesTracking(localPage, directBuffer, bufferPool);
} finally {
cacheEntry.releaseExclusiveLock();
directCacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
directCachePointer.decrementReferrer();
}
}
Aggregations