Search in sources :

Example 26 with OLogSequenceNumber

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);
}
Also used : OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OWriteAheadLog(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWriteAheadLog) OPerformanceStatisticManager(com.orientechnologies.orient.core.storage.impl.local.statistic.OPerformanceStatisticManager) Before(org.junit.Before)

Example 27 with OLogSequenceNumber

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();
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Example 28 with OLogSequenceNumber

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));
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer)

Example 29 with OLogSequenceNumber

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);
}
Also used : WriteAheadLogTest(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.WriteAheadLogTest) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ODiskWriteAheadLog(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OWOWCache(com.orientechnologies.orient.core.storage.cache.local.OWOWCache) OStorageSegmentConfiguration(com.orientechnologies.orient.core.config.OStorageSegmentConfiguration) File(java.io.File) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Example 30 with OLogSequenceNumber

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));
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer)

Aggregations

OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)95 ByteBuffer (java.nio.ByteBuffer)76 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)74 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)69 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)66 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)19 Test (org.testng.annotations.Test)15 ORecordId (com.orientechnologies.orient.core.id.ORecordId)10 Random (java.util.Random)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)4 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)3 HazelcastException (com.hazelcast.core.HazelcastException)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)2 OException (com.orientechnologies.common.exception.OException)2 OIOException (com.orientechnologies.common.io.OIOException)2