org.apache.ignite.internal.cdc

## Interface CdcManager

All Superinterfaces:
  DatabaseLifecycleListener, GridCacheSharedManager

All Known Implementing Classes:
  CdcUtilityActiveCdcManager

    public interface CdcManager
    extends GridCacheSharedManager, DatabaseLifecycleListener

CDC manager responsible for logic of capturing data within Ignite node. Communication between `CdcManager` and `CdcMain` components is established through CDC management WAL records. `CdcManager` logs them, while `CdcMain` listens to them:

- This manager can log `CdcManagerRecord` with committed consumer state. This record will be handled by `CdcMain` the same way it handles `CdcConsumer.onEvents(Iterator)` when it returns `true`.
- This manager must log `CdcManagerStopRecord` after it stopped handling records by any reason. `CdcMain` will start consume records instead since `CdcManagerRecord.walState()` of last consumed `CdcManagerRecord`.
- Apache Ignite provides a default implementation - `CdcUtilityActiveCdcManager`. It is disabled from the beginning, logs the `CdcManagerStopRecord` after Ignite node started, and then delegates consuming CDC events to the `CdcMain` utility.

Apache Ignite can be extended with custom CDC manager. It's required to implement this interface, create own `PluginProvider` that will return the implementation with `PluginProvider.createComponent(PluginContext, Class)` method. The `Class` parameter in the method is `CdcManager` class.

See Also:
  `CdcConsumer.onEvents(Iterator)`, `CdcConsumerState.saveCdcMode(CdcMode)`

### Method Summary

All Methods Instance Methods Abstract Methods Default Methods
`default void` `afterBinaryMemoryRestore(IgniteCacheDatabaseSharedManager mgr, GridCacheDatabaseSharedManager.RestoreBinaryState restoreState)` Callback is executed only once on Ignite node start when binary memory has fully restored and WAL logging is resumed.
`void` `collect(ByteBuffer dataBuf)` Callback to collect written WAL records.
`boolean` `enabled()` If this manager isn't enabled then Ignite skips notifying the manager with following methods.

### Methods inherited from interface org.apache.ignite.internal.processors.cache.GridCacheSharedManager

`onDisconnected, onKernalStart, onKernalStop, onReconnected, printMemoryStats, start, stop`

### Methods inherited from interface org.apache.ignite.internal.processors.cache.persistence.DatabaseLifecycleListener

`afterInitialise, afterLogicalUpdatesApplied, beforeBinaryMemoryRestore, beforeResumeWalLogging, beforeStop, onBaselineChange, onInitDataRegions`

### Method Detail

#### enabled

    boolean enabled()

If this manager isn't enabled then Ignite skips notifying the manager with following methods.

Returns:
  `true` if manager is enabled, otherwise `false`.

#### afterBinaryMemoryRestore

    default void afterBinaryMemoryRestore(IgniteCacheDatabaseSharedManager mgr,
                                          GridCacheDatabaseSharedManager.RestoreBinaryState restoreState)
                                   throws IgniteCheckedException

Callback is executed only once on Ignite node start when binary memory has fully restored and WAL logging is resumed. It's executed before the first call of `collect(ByteBuffer)`.

Implementation suggestions:

- Implementation must subscribe to the database events to get notified with this callback via `GridInternalSubscriptionProcessor.registerDatabaseListener(DatabaseLifecycleListener)`
- Callback can be used for restoring CDC state on Ignite node start, collecting missed events from WAL segments.
- Be aware, this method runs in the Ignite system thread and might get longer the Ignite start procedure.
- Ignite node will fail in case the method throws an exception.

Specified by:
  `afterBinaryMemoryRestore` in interface `DatabaseLifecycleListener`
  `restoreState` - Result of binary recovery.
Throws:
  `IgniteCheckedException` - If failed.

#### collect

    void collect(ByteBuffer dataBuf)

Callback to collect written WAL records. The provided buffer is a continuous part of WAL segment file. The buffer might contain full content of a segment or only piece of it. There are guarantees:

- This method is invoked sequentially.
- Provided `dataBuf` is a continuation of the previous one.
- `dataBuf` contains finite number of completed WAL records. No partially written WAL records are present.
- Records can be read from the buffer with `RecordSerializer.readRecord(FileInput, WALPointer)`.
- `dataBuf` must not be changed within this method.

Implementation suggestions:

- Frequence of calling the method depends on frequence of fsyncing WAL segment. See `IgniteSystemProperties.IGNITE_WAL_SEGMENT_SYNC_TIMEOUT`.
- It must handle the content of the `dataBuf` within the calling thread. Content of the buffer will not be changed before this method returns.
- It must not block the calling thread and work quickly.
- Ignite will ignore any `Throwable` throwed from this method.

Parameters:
  `dataBuf` - Buffer that contains data to collect.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.16.0
Release Date | : December 15 2023