NSAmelchev commented on code in PR #13649: URL: https://github.com/apache/ignite/pull/13649#discussion_r4256625546
########## 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: Done, added to the docs. -- 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]
