use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testCheckSumIsBroken.
public void testCheckSumIsBroken() 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);
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, 7 });
entries[i].getCachePointer().releaseExclusiveLock();
readBuffer.release(entries[i], writeBuffer);
}
writeBuffer.flush();
byte[] brokenByte = new byte[1];
brokenByte[0] = 13;
updateFilePage(2, systemOffset + 2, brokenByte);
updateFilePage(4, systemOffset + 4, brokenByte);
OPageDataVerificationError[] pageErrors = writeBuffer.checkStoredPages(null);
Assert.assertEquals(2, pageErrors.length);
Assert.assertFalse(pageErrors[0].incorrectMagicNumber);
Assert.assertTrue(pageErrors[0].incorrectCheckSum);
Assert.assertEquals(2, pageErrors[0].pageIndex);
Assert.assertEquals("readWriteDiskCacheTest.tst", pageErrors[0].fileName);
Assert.assertFalse(pageErrors[1].incorrectMagicNumber);
Assert.assertTrue(pageErrors[1].incorrectCheckSum);
Assert.assertEquals(4, pageErrors[1].pageIndex);
Assert.assertEquals("readWriteDiskCacheTest.tst", pageErrors[1].fileName);
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry 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.OCacheEntry 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.OCacheEntry 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();
}
}
use of com.orientechnologies.orient.core.storage.cache.OCacheEntry in project orientdb by orientechnologies.
the class ClusterPageTest method testDeleteAddEqualVersion.
public void testDeleteAddEqualVersion() 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);
deleteAddEqualVersion(localPage);
deleteAddEqualVersion(directLocalPage);
assertChangesTracking(localPage, directBuffer, bufferPool);
} finally {
cacheEntry.releaseExclusiveLock();
directCacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
directCachePointer.decrementReferrer();
}
}
Aggregations