NSAmelchev commented on code in PR #13649: URL: https://github.com/apache/ignite/pull/13649#discussion_r4250349935
########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/CdcLinkManager.java: ########## @@ -0,0 +1,156 @@ +/* + * 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.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 IgniteLogger log; + + /** */ + private final NodeFileTree ft; + + /** 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) throws IgniteCheckedException { + this.cctx = cctx; + + log = cctx.logger(CdcLinkManager.class); + ft = cctx.kernalContext().pdsFolderResolver().fileTree(); + + DataStorageConfiguration dsCfg = cctx.gridConfig().getDataStorageConfiguration(); + + // True on a node with persistence too, unlike FileWriteAheadLogManager#inMemoryCdc. + boolean 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); + }); + } + + /** */ + private void markDisableSegment() { Review Comment: Fixed. ########## 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() && !wal().cdcForceDisabled())); Review Comment: Fixed. ########## modules/core/src/test/java/org/apache/ignite/cdc/CdcSelfTest.java: ########## @@ -915,6 +951,12 @@ public void testCdcDirectoryMaxSize() throws Exception { f.cancel(); } + /** */ + private static List<Long> linkedSegments(NodeFileTree ft) { + return Arrays.stream(ft.walCdcSegments()).map(File::toPath).map(ft::walSegmentIndex).sorted() Review Comment: Fixed. -- 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]
