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;
}
}
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;
}
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);
}
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);
}
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());
}
Aggregations