Search in sources :

Example 31 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class FsyncFileWriteHandle method flush.

/**
 * @param expHead Expected head of chain. If head was changed, flush is not performed in this thread
 * @throws StorageException If failed.
 */
private boolean flush(WALRecord expHead, boolean stop) throws StorageException {
    if (expHead.previous() == null) {
        FakeRecord frHead = (FakeRecord) expHead;
        if (// Protects from CASing terminal FakeRecord(true) to FakeRecord(false)
        !stop || frHead.stop)
            return false;
    }
    // Fail-fast before CAS.
    checkNode();
    if (!head.compareAndSet(expHead, new FakeRecord(new WALPointer(getSegmentId(), (int) nextPosition(expHead), 0), stop)))
        return false;
    if (expHead.chainSize() == 0)
        return false;
    // Any failure in this code must invalidate the environment.
    try {
        // We can safely allow other threads to start building next chains while we are doing flush here.
        ByteBuffer buf;
        boolean tmpBuf = false;
        if (expHead.chainSize() > tlbSize) {
            buf = GridUnsafe.allocateBuffer(expHead.chainSize());
            // We need to manually release this temporary direct buffer.
            tmpBuf = true;
        } else
            buf = tlb.get();
        try {
            long pos = fillBuffer(buf, expHead);
            writeBuffer(pos, buf);
        } finally {
            if (tmpBuf)
                GridUnsafe.freeBuffer(buf);
        }
        return true;
    } catch (Throwable e) {
        StorageException se = e instanceof StorageException ? (StorageException) e : new StorageException("Unable to write", new IOException(e));
        cctx.kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, se));
        // All workers waiting for a next segment must be woken up and stopped
        signalNextAvailable();
        throw se;
    }
}
Also used : FailureContext(org.apache.ignite.failure.FailureContext) IOException(java.io.IOException) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException)

Example 32 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class FsyncFileHandleManagerImpl method flush.

/**
 * {@inheritDoc}
 */
@Override
public WALPointer flush(WALPointer ptr, boolean explicitFsync) throws IgniteCheckedException, StorageException {
    if (serializer == null || mode == WALMode.NONE)
        return null;
    FsyncFileWriteHandle cur = currentHandle();
    // WAL manager was not started (client node).
    if (cur == null)
        return null;
    WALPointer filePtr;
    if (ptr == null) {
        WALRecord rec = cur.head.get();
        if (rec instanceof FsyncFileWriteHandle.FakeRecord)
            return null;
        filePtr = rec.position();
    } else
        filePtr = ptr;
    // No need to sync if was rolled over.
    if (!cur.needFsync(filePtr))
        return filePtr;
    cur.fsync(filePtr, false);
    return filePtr;
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 33 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class GridCommonAbstractTest method disableWal.

/**
 * Disable/enable VAL.
 *
 * @param n Node.
 * @param disable Disable flag.
 * @throws Exception If failed.
 */
protected static void disableWal(IgniteEx n, boolean disable) throws Exception {
    WALDisableContext walDisableCtx = n.context().cache().context().walState().walDisableContext();
    setFieldValue(walDisableCtx, "disableWal", disable);
    assertEquals(disable, walDisableCtx.check());
    WALPointer logPtr = walMgr(n).log(new DataRecord(emptyList()));
    if (disable)
        assertNull(logPtr);
    else
        assertNotNull(logPtr);
}
Also used : DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) WALDisableContext(org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext)

Example 34 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class IgnitePdsReserveWalSegmentsTest method testWalDoesNotTruncatedWhenSegmentReserved.

/**
 * Tests that grid cache manager correctly truncates unused WAL segments;
 *
 * @throws Exception if failed.
 */
@Test
public void testWalDoesNotTruncatedWhenSegmentReserved() throws Exception {
    IgniteEx n = prepareGrid(2);
    IgniteWriteAheadLogManager wal = n.context().cache().context().wal();
    assertNotNull(wal);
    long resIdx = getReservedWalSegmentIndex(wal);
    assertTrue("Expected that at least resIdx greater than 0, real is " + resIdx, resIdx > 0);
    WALPointer lowPtr = lastCheckpointPointer(n);
    assertTrue("Expected that dbMbr returns valid resIdx", lowPtr.index() == resIdx);
    // Reserve previous WAL segment.
    wal.reserve(new WALPointer(resIdx - 1, 0, 0));
    int numDel = wal.truncate(lowPtr);
    int expNumDel = (int) resIdx - 1;
    assertTrue("Expected del segments is " + expNumDel + ", real is " + numDel, expNumDel == numDel);
}
Also used : IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteEx(org.apache.ignite.internal.IgniteEx) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 35 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class IgnitePdsReserveWalSegmentsTest method testMinReserveIdx.

/**
 * Check that the minimum reserved index will not be greater than the actual deleted segment.
 *
 * @throws Exception If failed.
 */
@Test
public void testMinReserveIdx() throws Exception {
    IgniteEx n = prepareGrid(1);
    forceCheckpoint();
    FileWriteAheadLogManager wal = (FileWriteAheadLogManager) n.context().cache().context().wal();
    assertNotNull(wal);
    if (compactionEnabled(n))
        assertTrue(waitForCondition(() -> wal.lastCompactedSegment() >= 1, 10_000));
    assertEquals(1, wal.truncate(new WALPointer(1, 0, 0)));
    Long minReserveIdx = getFieldValueHierarchy(wal, "segmentAware", "reservationStorage", "minReserveIdx");
    assertEquals(0L, minReserveIdx.longValue());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)122 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)44 Test (org.junit.Test)41 IgniteEx (org.apache.ignite.internal.IgniteEx)38 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)24 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)23 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)23 ArrayList (java.util.ArrayList)20 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)20 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)19 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)19 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)19 File (java.io.File)18 T2 (org.apache.ignite.internal.util.typedef.T2)16 ByteBuffer (java.nio.ByteBuffer)15 UUID (java.util.UUID)15 IOException (java.io.IOException)14