use of org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext in project ignite by apache.
the class FileWriteAheadLogManager method log.
/**
* {@inheritDoc}
*/
@Override
public WALPointer log(WALRecord rec, RolloverType rolloverType) throws IgniteCheckedException {
if (serializer == null || mode == WALMode.NONE)
return null;
// Only delta-records, page snapshots and memory recovery are allowed to write in recovery mode.
if (cctx.kernalContext().recoveryMode() && !(rec instanceof PageDeltaRecord || rec instanceof PageSnapshot || rec instanceof MemoryRecoveryRecord))
return null;
FileWriteHandle currWrHandle = currentHandle();
WALDisableContext isDisable = walDisableContext;
// Logging was not resumed yet.
if (currWrHandle == null || (isDisable != null && isDisable.check()))
return null;
// Do page snapshots compression if configured.
if (pageCompression != DiskPageCompression.DISABLED && rec instanceof PageSnapshot) {
PageSnapshot pageSnapshot = (PageSnapshot) rec;
int pageSize = pageSnapshot.realPageSize();
ByteBuffer pageData = pageSnapshot.pageDataBuffer();
ByteBuffer compressedPage = cctx.kernalContext().compress().compressPage(pageData, pageSize, 1, pageCompression, pageCompressionLevel);
if (compressedPage != pageData) {
assert compressedPage.isDirect() : "Is direct buffer: " + compressedPage.isDirect();
rec = new PageSnapshot(pageSnapshot.fullPageId(), GridUnsafe.bufferAddress(compressedPage), compressedPage.limit(), pageSize);
}
}
// Need to calculate record size first.
rec.size(serializer.size(rec));
while (true) {
WALPointer ptr;
if (rolloverType == RolloverType.NONE)
ptr = currWrHandle.addRecord(rec);
else {
assert cctx.database().checkpointLockIsHeldByThread();
if (rolloverType == RolloverType.NEXT_SEGMENT) {
WALPointer pos = rec.position();
do {
// This will change rec.position() unless concurrent rollover happened.
currWrHandle = closeBufAndRollover(currWrHandle, rec, rolloverType);
} while (Objects.equals(pos, rec.position()));
ptr = rec.position();
} else if (rolloverType == RolloverType.CURRENT_SEGMENT) {
if ((ptr = currWrHandle.addRecord(rec)) != null)
currWrHandle = closeBufAndRollover(currWrHandle, rec, rolloverType);
} else
throw new IgniteCheckedException("Unknown rollover type: " + rolloverType);
}
if (ptr != null) {
metrics.onWalRecordLogged(rec.size());
if (walAutoArchiveAfterInactivity > 0 || walForceArchiveTimeout > 0) {
long millis = U.currentTimeMillis();
lastRecordLoggedMs.set(millis);
// No need to forcefully rollover for other record types.
if (walForceArchiveTimeout > 0 && rec.type() == DATA_RECORD_V2)
lastDataRecordLoggedMs.set(millis);
}
return ptr;
} else
currWrHandle = rollOver(currWrHandle, null);
checkNode();
if (isStopping())
throw new IgniteCheckedException("Stopping.");
}
}
use of org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext 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.WalStateManager.WALDisableContext in project ignite by apache.
the class WriteAheadLogManagerSelfTest method disableWal.
/**
* Disable WAL.
*
* @param n Node.
*/
private void disableWal(IgniteEx n) throws Exception {
WALDisableContext walDisableCtx = n.context().cache().context().walState().walDisableContext();
assertNotNull(walDisableCtx);
setFieldValue(walDisableCtx, "disableWal", true);
assertTrue(walDisableCtx.check());
assertNull(walMgr(n).log(new DataRecord(emptyList())));
}
use of org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext in project ignite by apache.
the class IgniteDataStorageMetricsSelfTest method testWalWrittenBytes.
/**
* Checking that the metrics of the total logged bytes are working correctly.
*
* @throws Exception If failed.
*/
@Test
public void testWalWrittenBytes() throws Exception {
IgniteEx n = startGrid(0, (UnaryOperator<IgniteConfiguration>) cfg -> {
cfg.getDataStorageConfiguration().setWalSegmentSize((int) (2 * U.MB));
return cfg;
});
n.cluster().state(ACTIVE);
awaitPartitionMapExchange();
for (int i = 0; i < 10; i++) n.cache("cache").put(ThreadLocalRandom.current().nextLong(), new byte[(int) (32 * U.KB)]);
WALDisableContext walDisableCtx = n.context().cache().context().walState().walDisableContext();
assertNotNull(walDisableCtx);
setFieldValue(walDisableCtx, "disableWal", true);
assertTrue(walDisableCtx.check());
assertNull(walMgr(n).log(new DataRecord(emptyList())));
assertEquals(-1, walMgr(n).lastArchivedSegment());
long exp = walMgr(n).lastWritePointer().fileOffset() - HEADER_RECORD_SIZE;
assertEquals(exp, dbMgr(n).persistentStoreMetrics().getWalWrittenBytes());
assertEquals(exp, dsMetricsMXBean(n).getWalWrittenBytes());
assertEquals(exp, ((LongAdderMetric) dsMetricRegistry(n).findMetric("WalWrittenBytes")).value());
}
use of org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext in project ignite by apache.
the class IgniteNodeStoppedDuringDisableWALTest method testStopNodeWithDisableWAL.
/**
* @param nodeStopPoint Stop point.
* @throws Exception If failed.
*/
private void testStopNodeWithDisableWAL(NodeStopPoint nodeStopPoint) throws Exception {
log.info("Start test crash " + nodeStopPoint);
IgniteEx ig0 = startGrid(0);
GridCacheSharedContext<Object, Object> sharedContext = ig0.context().cache().context();
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) sharedContext.database();
IgniteWriteAheadLogManager WALmgr = sharedContext.wal();
WALDisableContext walDisableContext = new WALDisableContext(dbMgr, sharedContext.pageStore(), log) {
@Override
protected void writeMetaStoreDisableWALFlag() throws IgniteCheckedException {
if (nodeStopPoint == NodeStopPoint.BEFORE_WRITE_KEY_TO_META_STORE)
failNode(nodeStopPoint);
super.writeMetaStoreDisableWALFlag();
if (nodeStopPoint == NodeStopPoint.AFTER_WRITE_KEY_TO_META_STORE)
failNode(nodeStopPoint);
}
@Override
protected void removeMetaStoreDisableWALFlag() throws IgniteCheckedException {
if (nodeStopPoint == NodeStopPoint.AFTER_CHECKPOINT_AFTER_ENABLE_WAL)
failNode(nodeStopPoint);
super.removeMetaStoreDisableWALFlag();
if (nodeStopPoint == NodeStopPoint.AFTER_REMOVE_KEY_TO_META_STORE)
failNode(nodeStopPoint);
}
@Override
protected void disableWAL(boolean disable) throws IgniteCheckedException {
if (disable) {
if (nodeStopPoint == NodeStopPoint.AFTER_CHECKPOINT_BEFORE_DISABLE_WAL)
failNode(nodeStopPoint);
super.disableWAL(disable);
if (nodeStopPoint == NodeStopPoint.AFTER_DISABLE_WAL)
failNode(nodeStopPoint);
} else {
super.disableWAL(disable);
if (nodeStopPoint == NodeStopPoint.AFTER_ENABLE_WAL)
failNode(nodeStopPoint);
}
}
};
setFieldValue(sharedContext.walState(), "walDisableContext", walDisableContext);
setFieldValue(WALmgr, "walDisableContext", walDisableContext);
ig0.context().internalSubscriptionProcessor().registerMetastorageListener(walDisableContext);
ig0.cluster().active(true);
try (IgniteDataStreamer<Integer, Integer> st = ig0.dataStreamer(DEFAULT_CACHE_NAME)) {
st.allowOverwrite(true);
for (int i = 0; i < GridTestUtils.SF.apply(10_000); i++) st.addData(i, -i);
}
boolean fail = false;
try (WALIterator it = sharedContext.wal().replay(null)) {
dbMgr.applyUpdatesOnRecovery(it, (ptr, rec) -> true, (entry) -> true);
} catch (IgniteCheckedException e) {
if (nodeStopPoint.needCleanUp)
fail = true;
}
Assert.assertEquals(nodeStopPoint.needCleanUp, fail);
Ignite ig1 = startGrid(0);
String msg = nodeStopPoint.toString();
int pageSize = ig1.configuration().getDataStorageConfiguration().getPageSize();
if (nodeStopPoint.needCleanUp) {
PdsFoldersResolver foldersResolver = ((IgniteEx) ig1).context().pdsFolderResolver();
File root = foldersResolver.resolveFolders().persistentStoreRootPath();
walkFileTree(root.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
String name = path.toFile().getName();
String filePath = path.toString();
String parentDirName = path.toFile().getParentFile().getName();
if (parentDirName.equals(METASTORAGE_DIR_NAME) || parentDirName.equals(TxLog.TX_LOG_CACHE_NAME))
return CONTINUE;
if (WAL_NAME_PATTERN.matcher(name).matches() || WAL_TEMP_NAME_PATTERN.matcher(name).matches())
return CONTINUE;
boolean failed = false;
if (name.endsWith(FilePageStoreManager.TMP_SUFFIX))
failed = true;
if (CP_FILE_NAME_PATTERN.matcher(name).matches())
failed = true;
if (name.startsWith(PART_FILE_PREFIX) && path.toFile().length() > pageSize)
failed = true;
if (name.startsWith(INDEX_FILE_NAME) && path.toFile().length() > pageSize)
failed = true;
if (failed)
fail(msg + " " + filePath + " " + path.toFile().length());
return CONTINUE;
}
});
}
}
Aggregations