nizhikov commented on code in PR #13649: URL: https://github.com/apache/ignite/pull/13649#discussion_r4255814609
########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/CdcLinkManager.java: ########## @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.persistence.wal; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree; +import org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; + +import static java.lang.String.format; +import static org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager.CDC_DISABLED; +import static org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty.detachedBooleanProperty; +import static org.apache.ignite.internal.util.io.GridFileUtils.ensureHardLinkAvailable; + +/** + * Links the archived WAL segments to the CDC directory. The links are not created while CDC is disabled by the + * {@link FileWriteAheadLogManager#CDC_DISABLED} distributed property. Data regions without persistence do not log the + * changes while CDC is disabled, so on the nodes with such regions the segment that is current at the disabling is never + * linked either: the CDC application fails on the missed segment after CDC is enabled again. + */ +class CdcLinkManager { + /** */ + private final GridCacheSharedContext<?, ?> cctx; + + /** */ + private final IgniteWriteAheadLogManager wal; + + /** */ + private final IgniteLogger log; + + /** */ + private final NodeFileTree ft; + + /** + * {@code True} if a data region with CDC has no persistence. + * Unlike {@code FileWriteAheadLogManager#inMemoryCdc}, {@code true} on a node with persistence too. + */ + private final boolean inMemoryCdcRegion; + + /** CDC disabled flag. */ + private final DistributedBooleanProperty cdcDisabled = detachedBooleanProperty(CDC_DISABLED, + "CDC disabled flag. Disables CDC in the cluster to avoid disk overflow. " + + "Note that cache changes will be lost when CDC is disabled. Useful if the CDC application " + + "is down for a long time."); + + /** + * Index of the segment that was current at the last CDC disabling. It is never linked, so the CDC application detects + * the missed changes as a gap in the segments even if no segment is archived while CDC is disabled. Persistent + * regions log the changes anyway, so the gap is made only on the nodes with in-memory CDC regions. + */ + private volatile long disableSgmnt = -1; + + /** */ + CdcLinkManager(GridCacheSharedContext<?, ?> cctx, IgniteWriteAheadLogManager wal) throws IgniteCheckedException { + this.cctx = cctx; + this.wal = wal; + + log = cctx.logger(CdcLinkManager.class); + ft = cctx.kernalContext().pdsFolderResolver().fileTree(); + + DataStorageConfiguration dsCfg = cctx.gridConfig().getDataStorageConfiguration(); + + inMemoryCdcRegion = F.exist( + F.concat(false, dsCfg.getDefaultDataRegionConfiguration(), F.asList(dsCfg.getDataRegionConfigurations())), + reg -> reg.isCdcEnabled() && !reg.isPersistenceEnabled()); + + U.ensureDirectory(ft.walCdc(), "change data capture directory", log); + + ensureHardLinkAvailable(ft.walArchive().toPath(), ft.walCdc().toPath()); + + cctx.kernalContext().internalSubscriptionProcessor().registerDistributedConfigurationListener(dispatcher -> { + cdcDisabled.addListener((name, oldVal, newVal) -> { + if (log.isInfoEnabled()) + log.info(format("Distributed property '%s' was changed from '%s' to '%s'.", name, oldVal, newVal)); + + if (newVal != null && newVal) { + log.warning("CDC was disabled."); + + if (cctx.cdc() != null) + cctx.cdc().stop(true); + + if (inMemoryCdcRegion) + markDisableSegment(); Review Comment: **[Note, no change needed]** A gap is forced on every disable/enable cycle on a node with an in-memory CDC region, even when no in-memory CDC cache was updated while disabled, so the CDC application always fails with "Found missed segments" after a toggle and `delete_lost_segment_links` is required. We discussed this and agree it is intentional: the gap is the signal that changes may have been lost. Worth one sentence in the docs so operators expect it. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java: ########## @@ -980,7 +980,7 @@ public boolean persistenceEnabled() { * @return {@code True} if {@link DataRecord} should be loged in the WAL. */ public boolean logDataRecords() { - return walEnabled() && (persistenceEnabled || cdcEnabled()); + return walEnabled() && (persistenceEnabled || (cdcEnabled() && !ctx.wal(true).cdcForceDisabled())); Review Comment: **[Note, no change needed]** The flag is evaluated per entry, so a transaction that straddles the property flip is logged partially (some keys get a `DataRecord`, earlier ones do not). CDC does not guarantee per-transaction atomicity today, so this is consistent with existing behaviour. Leaving this here only so the trade-off is recorded. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/CdcLinkManager.java: ########## @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.persistence.wal; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree; +import org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; + +import static java.lang.String.format; +import static org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager.CDC_DISABLED; +import static org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty.detachedBooleanProperty; +import static org.apache.ignite.internal.util.io.GridFileUtils.ensureHardLinkAvailable; + +/** + * Links the archived WAL segments to the CDC directory. The links are not created while CDC is disabled by the + * {@link FileWriteAheadLogManager#CDC_DISABLED} distributed property. Data regions without persistence do not log the + * changes while CDC is disabled, so on the nodes with such regions the segment that is current at the disabling is never + * linked either: the CDC application fails on the missed segment after CDC is enabled again. + */ +class CdcLinkManager { + /** */ + private final GridCacheSharedContext<?, ?> cctx; + + /** */ + private final IgniteWriteAheadLogManager wal; + + /** */ + private final IgniteLogger log; + + /** */ + private final NodeFileTree ft; + + /** + * {@code True} if a data region with CDC has no persistence. + * Unlike {@code FileWriteAheadLogManager#inMemoryCdc}, {@code true} on a node with persistence too. + */ + private final boolean inMemoryCdcRegion; + + /** CDC disabled flag. */ + private final DistributedBooleanProperty cdcDisabled = detachedBooleanProperty(CDC_DISABLED, + "CDC disabled flag. Disables CDC in the cluster to avoid disk overflow. " + + "Note that cache changes will be lost when CDC is disabled. Useful if the CDC application " + + "is down for a long time."); + + /** + * Index of the segment that was current at the last CDC disabling. It is never linked, so the CDC application detects + * the missed changes as a gap in the segments even if no segment is archived while CDC is disabled. Persistent + * regions log the changes anyway, so the gap is made only on the nodes with in-memory CDC regions. + */ + private volatile long disableSgmnt = -1; + + /** */ + CdcLinkManager(GridCacheSharedContext<?, ?> cctx, IgniteWriteAheadLogManager wal) throws IgniteCheckedException { + this.cctx = cctx; + this.wal = wal; + + log = cctx.logger(CdcLinkManager.class); + ft = cctx.kernalContext().pdsFolderResolver().fileTree(); + + DataStorageConfiguration dsCfg = cctx.gridConfig().getDataStorageConfiguration(); + + inMemoryCdcRegion = F.exist( Review Comment: **[Should fix]** This re-implements the data-region walk from `CU.isCdcEnabled` but drops its null guard on the default region. With `setDefaultDataRegionConfiguration(null)` and a named region with `cdcEnabled=true`, `CU.isCdcEnabled` returns `true` (it checks `dfltReg != null`), `start0` constructs `CdcLinkManager`, `F.concat(false, null, ...)` puts a `null` into the list and `reg.isCdcEnabled()` throws NPE, failing node start. Suggest a helper next to `isCdcEnabled` (e.g. `CU.hasInMemoryCdcRegion(dsCfg)`) with the same null handling, and use it here. ########## modules/core/src/main/java/org/apache/ignite/internal/management/cdc/CdcCacheDataResendTask.java: ########## @@ -198,6 +201,7 @@ private void resendCacheData(IgniteInternalCache<?, ?> cache) throws IgniteCheck break; ensureTopologyNotChanged(); + ensureCdcEnabled(); Review Comment: **[Minor]** The flag is checked per row, but `wal.log(rec)` below is unconditional, so rows logged between the check and the flip land in a linked segment while the job reports failure. On a rerun the consumer receives those keys twice and has no indication of where the first run stopped. At minimum, include the number of entries already sent in the exception message, or document the at-least-once semantics of `resend` when CDC is disabled mid-run. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/CdcLinkManager.java: ########## @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.persistence.wal; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree; +import org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; + +import static java.lang.String.format; +import static org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager.CDC_DISABLED; +import static org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty.detachedBooleanProperty; +import static org.apache.ignite.internal.util.io.GridFileUtils.ensureHardLinkAvailable; + +/** + * Links the archived WAL segments to the CDC directory. The links are not created while CDC is disabled by the + * {@link FileWriteAheadLogManager#CDC_DISABLED} distributed property. Data regions without persistence do not log the + * changes while CDC is disabled, so on the nodes with such regions the segment that is current at the disabling is never + * linked either: the CDC application fails on the missed segment after CDC is enabled again. + */ +class CdcLinkManager { + /** */ + private final GridCacheSharedContext<?, ?> cctx; + + /** */ + private final IgniteWriteAheadLogManager wal; + + /** */ + private final IgniteLogger log; + + /** */ + private final NodeFileTree ft; + + /** + * {@code True} if a data region with CDC has no persistence. + * Unlike {@code FileWriteAheadLogManager#inMemoryCdc}, {@code true} on a node with persistence too. + */ + private final boolean inMemoryCdcRegion; + + /** CDC disabled flag. */ + private final DistributedBooleanProperty cdcDisabled = detachedBooleanProperty(CDC_DISABLED, + "CDC disabled flag. Disables CDC in the cluster to avoid disk overflow. " + + "Note that cache changes will be lost when CDC is disabled. Useful if the CDC application " + + "is down for a long time."); + + /** + * Index of the segment that was current at the last CDC disabling. It is never linked, so the CDC application detects + * the missed changes as a gap in the segments even if no segment is archived while CDC is disabled. Persistent + * regions log the changes anyway, so the gap is made only on the nodes with in-memory CDC regions. + */ + private volatile long disableSgmnt = -1; + + /** */ + CdcLinkManager(GridCacheSharedContext<?, ?> cctx, IgniteWriteAheadLogManager wal) throws IgniteCheckedException { + this.cctx = cctx; + this.wal = wal; + + log = cctx.logger(CdcLinkManager.class); + ft = cctx.kernalContext().pdsFolderResolver().fileTree(); + + DataStorageConfiguration dsCfg = cctx.gridConfig().getDataStorageConfiguration(); + + inMemoryCdcRegion = F.exist( + F.concat(false, dsCfg.getDefaultDataRegionConfiguration(), F.asList(dsCfg.getDataRegionConfigurations())), + reg -> reg.isCdcEnabled() && !reg.isPersistenceEnabled()); + + U.ensureDirectory(ft.walCdc(), "change data capture directory", log); + + ensureHardLinkAvailable(ft.walArchive().toPath(), ft.walCdc().toPath()); + + cctx.kernalContext().internalSubscriptionProcessor().registerDistributedConfigurationListener(dispatcher -> { + cdcDisabled.addListener((name, oldVal, newVal) -> { + if (log.isInfoEnabled()) + log.info(format("Distributed property '%s' was changed from '%s' to '%s'.", name, oldVal, newVal)); + + if (newVal != null && newVal) { + log.warning("CDC was disabled."); + + if (cctx.cdc() != null) + cctx.cdc().stop(true); + + if (inMemoryCdcRegion) + markDisableSegment(); + } + }); + + dispatcher.registerProperty(cdcDisabled); + }); + } + + /** + * The property listener runs before the WAL logging is resumed on a persistent node restarted with CDC disabled, and + * the gap made at the disabling is not guaranteed: the segment can be archived after CDC is enabled again. + */ + void resumeLogging() { + if (inMemoryCdcRegion && forceDisabled()) + markDisableSegment(); + } + + /** */ + private void markDisableSegment() { + // -1 before the WAL logging is resumed, see #resumeLogging. + disableSgmnt = Math.max(disableSgmnt, wal.currentSegment()); + } + + /** */ + boolean forceDisabled() { + return cdcDisabled.getOrDefault(false); + } + + /** + * The segment that was current at the CDC disabling is never linked, the changes in it are lost. It is closed before + * the next record, so the changes made after CDC is enabled again do not get into it. + */ + boolean shouldRollover(long idx) { + return idx == disableSgmnt; + } + + /** */ + void linkSegment(long idx, File segment) throws IOException { + if (forceDisabled()) + log.warning("Creation of segment CDC link skipped. '" + CDC_DISABLED + "' distributed property is 'true'."); + else if (idx == disableSgmnt) Review Comment: **[Blocker]** On a node with both a persistent CDC region and an in-memory CDC region, the segment that was current at the disabling is never linked, but it also holds persistent-region `DataRecord`s written *before* the disabling, while CDC was enabled and the consumer expected them. Before this PR they were delivered once the segment was archived after re-enable. Example: segment 7 is current, 10k updates to persistent region P land in 7, `cdc.disabled=true` (disableSgmnt=7), then `false`; the next record rolls 7 -> 8; the archiver reaches 7 and `linkSegment` skips it. The 10k pre-disable P updates never reach the CDC application. Same on restart: node stopped with CDC enabled, property flipped while it was down, after join the listener marks the restored segment that contains pre-shutdown P records. An alternative that keeps the gap but not the pre-disable data: force a rollover at the disabling (the existing `closeBufAndRollover` path) and mark / skip the *next* segment. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupContext.java: ########## @@ -980,7 +980,7 @@ public boolean persistenceEnabled() { * @return {@code True} if {@link DataRecord} should be loged in the WAL. */ public boolean logDataRecords() { - return walEnabled() && (persistenceEnabled || cdcEnabled()); + return walEnabled() && (persistenceEnabled || (cdcEnabled() && !ctx.wal(true).cdcForceDisabled())); Review Comment: **[Minor]** Every update of an in-memory CDC cache now pays `ctx.wal(true)` (assert + branch), a virtual `cdcForceDisabled()` call and a boxed-`Boolean` `getOrDefault` on the entry-update path (`GridCacheMapEntry.innerUpdate` / `logTxUpdate`, 1-2x per put). For in-memory CDC regions the `persistenceEnabled` short-circuit never fires, so this runs on 100% of writes, for a flag that changes only on a distributed-property event. Cheaper: a `volatile boolean` on `GridCacheSharedContext` (or `CacheGroupContext`) flipped by the `CDC_DISABLED` listener, read directly here. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java: ########## @@ -885,6 +864,12 @@ private boolean checkTimeout(AtomicLong lastEvt, long timeout) { if (currWrHandle == null || (isDisable != null && isDisable.check())) return null; + if (cdcLinkMgr != null && cdcLinkMgr.shouldRollover(currWrHandle.getSegmentId())) { Review Comment: **[Should fix]** The forced CDC rollover runs before `rolloverType` is handled. If the first record after re-enable is logged with `RolloverType.NEXT_SEGMENT` (e.g. the `CheckpointRecord` under checkpoint lock) while `shouldRollover()` is `true`, there are two consecutive rollovers: this line rolls N -> N+1, then `closeBufAndRollover` rolls N+1 -> N+2 with the record. N+1 holds only a header, is archived, hard-linked into `walCdc`, counts toward `cdcWalDirectoryMaxSize` and is read by the CDC app as an empty segment. Skip the forced rollover when `rolloverType == NEXT_SEGMENT`, the record rolls over anyway. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/CdcLinkManager.java: ########## @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.persistence.wal; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.persistence.filename.NodeFileTree; +import org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; + +import static java.lang.String.format; +import static org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager.CDC_DISABLED; +import static org.apache.ignite.internal.processors.configuration.distributed.DistributedBooleanProperty.detachedBooleanProperty; +import static org.apache.ignite.internal.util.io.GridFileUtils.ensureHardLinkAvailable; + +/** + * Links the archived WAL segments to the CDC directory. The links are not created while CDC is disabled by the + * {@link FileWriteAheadLogManager#CDC_DISABLED} distributed property. Data regions without persistence do not log the + * changes while CDC is disabled, so on the nodes with such regions the segment that is current at the disabling is never + * linked either: the CDC application fails on the missed segment after CDC is enabled again. + */ +class CdcLinkManager { + /** */ + private final GridCacheSharedContext<?, ?> cctx; + + /** */ + private final IgniteWriteAheadLogManager wal; + + /** */ + private final IgniteLogger log; + + /** */ + private final NodeFileTree ft; + + /** + * {@code True} if a data region with CDC has no persistence. + * Unlike {@code FileWriteAheadLogManager#inMemoryCdc}, {@code true} on a node with persistence too. + */ + private final boolean inMemoryCdcRegion; + + /** CDC disabled flag. */ + private final DistributedBooleanProperty cdcDisabled = detachedBooleanProperty(CDC_DISABLED, + "CDC disabled flag. Disables CDC in the cluster to avoid disk overflow. " + + "Note that cache changes will be lost when CDC is disabled. Useful if the CDC application " + + "is down for a long time."); + + /** + * Index of the segment that was current at the last CDC disabling. It is never linked, so the CDC application detects + * the missed changes as a gap in the segments even if no segment is archived while CDC is disabled. Persistent + * regions log the changes anyway, so the gap is made only on the nodes with in-memory CDC regions. + */ + private volatile long disableSgmnt = -1; + + /** */ + CdcLinkManager(GridCacheSharedContext<?, ?> cctx, IgniteWriteAheadLogManager wal) throws IgniteCheckedException { + this.cctx = cctx; + this.wal = wal; + + log = cctx.logger(CdcLinkManager.class); + ft = cctx.kernalContext().pdsFolderResolver().fileTree(); + + DataStorageConfiguration dsCfg = cctx.gridConfig().getDataStorageConfiguration(); + + inMemoryCdcRegion = F.exist( + F.concat(false, dsCfg.getDefaultDataRegionConfiguration(), F.asList(dsCfg.getDataRegionConfigurations())), + reg -> reg.isCdcEnabled() && !reg.isPersistenceEnabled()); + + U.ensureDirectory(ft.walCdc(), "change data capture directory", log); + + ensureHardLinkAvailable(ft.walArchive().toPath(), ft.walCdc().toPath()); + + cctx.kernalContext().internalSubscriptionProcessor().registerDistributedConfigurationListener(dispatcher -> { + cdcDisabled.addListener((name, oldVal, newVal) -> { + if (log.isInfoEnabled()) + log.info(format("Distributed property '%s' was changed from '%s' to '%s'.", name, oldVal, newVal)); + + if (newVal != null && newVal) { + log.warning("CDC was disabled."); + + if (cctx.cdc() != null) + cctx.cdc().stop(true); + + if (inMemoryCdcRegion) + markDisableSegment(); + } + }); + + dispatcher.registerProperty(cdcDisabled); + }); + } + + /** + * The property listener runs before the WAL logging is resumed on a persistent node restarted with CDC disabled, and + * the gap made at the disabling is not guaranteed: the segment can be archived after CDC is enabled again. + */ + void resumeLogging() { + if (inMemoryCdcRegion && forceDisabled()) + markDisableSegment(); + } + + /** */ + private void markDisableSegment() { + // -1 before the WAL logging is resumed, see #resumeLogging. + disableSgmnt = Math.max(disableSgmnt, wal.currentSegment()); + } + + /** */ + boolean forceDisabled() { + return cdcDisabled.getOrDefault(false); + } + + /** + * The segment that was current at the CDC disabling is never linked, the changes in it are lost. It is closed before + * the next record, so the changes made after CDC is enabled again do not get into it. + */ + boolean shouldRollover(long idx) { Review Comment: **[Minor]** `linkSegment()` re-spells this predicate as `idx == disableSgmnt`. Reuse one method in both places (e.g. rename to `isDisableSegment(idx)`), so a future change to how the disable segment is tracked is made once. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
