use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class PageCacheTest method before.
@Before
public void before() throws IOException {
this.writeCache = new WriteCache();
this.readCache = new ReadCache();
this.pageCache = case_.createPageCache(readCache);
this.atomicOperation = new AtomicOperation(new OLogSequenceNumber(0, 0), null, readCache, writeCache, -1, new OPerformanceStatisticManager(null, 10000, 10000));
this.writeAheadLog = new WriteAheadLog();
writeCache.addFile("file");
readCache.allocateNewPage(0, writeCache);
readCache.allocateNewPage(0, writeCache);
readCache.allocateNewPage(0, writeCache);
readCache.allocateNewPage(0, writeCache);
readCache.allocateNewPage(0, writeCache);
readCache.allocateNewPage(0, writeCache);
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class ClusterPageTest method assertChangesTracking.
private void assertChangesTracking(OClusterPage localPage, ByteBuffer buffer, OByteBufferPool bufferPool) throws IOException {
ByteBuffer restoredBuffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(restoredBuffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
try {
OClusterPage restoredPage = new OClusterPage(cacheEntry, false, null);
OWALChanges changes = localPage.getChanges();
restoredPage.restoreChanges(changes);
Assert.assertEquals(getBytes(restoredBuffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET), getBytes(buffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET));
} finally {
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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));
}
}
Aggregations