org.apache.ignite.internal.cdc

## Class CdcMain

- java.lang.Object
- - org.apache.ignite.internal.cdc.CdcMain

All Implemented Interfaces:
  Runnable

    public class CdcMain
    extends Object
    implements Runnable

Change Data Capture (CDC) application. The application runs independently of Ignite node process and provides the ability for the `CdcConsumer` to consume events(`CdcEvent`) from WAL segments. The user should provide `CdcConsumer` implementation with custom consumption logic. Ignite node should be explicitly configured for using `CdcMain`.

1. Set `DataRegionConfiguration.setCdcEnabled(boolean)` to true.
2. Optional: Set `DataStorageConfiguration.setCdcWalPath(String)` to path to the directory to store WAL segments for CDC.
3. Optional: Set `DataStorageConfiguration.setWalForceArchiveTimeout(long)` to configure timeout for force WAL rollover, so new events will be available for consumptions with the predicted time.

When `DataStorageConfiguration.getCdcWalPath()` is true then Ignite node on each WAL segment rollover creates hard link to archive WAL segment in `DataStorageConfiguration.getCdcWalPath()` directory. `CdcMain` application takes segment file and consumes events from it. After successful consumption (see `CdcConsumer.onEvents(Iterator)`) WAL segment will be deleted from directory. Several Ignite nodes can be started on the same host. If your deployment done with custom consistent id then you should specify it via `IgniteConfiguration.setConsistentId(Serializable)` in provided `IgniteConfiguration`. Application works as follows:

1. Searches node work directory based on provided `IgniteConfiguration`.
2. Awaits for the creation of CDC directory if it not exists.
3. Acquires file lock to ensure exclusive consumption.
4. Loads state of consumption if it exists.
5. Infinitely waits for new available segment and processes it.

See Also:
  `DataRegionConfiguration.setCdcEnabled(boolean)`, `DataStorageConfiguration.setCdcWalPath(String)`, `DataStorageConfiguration.setWalForceArchiveTimeout(long)`, `CdcCommandLineStartup`, `CdcConsumer`, `DataStorageConfiguration.DFLT_WAL_CDC_PATH`

### Field Summary

Fields
`static String` `BINARY_META_DIR` Binary metadata metric name.
`static String` `CDC_DIR` Cdc directory metric name.
`protected CdcConfiguration` `cdcCfg` Change Data Capture configuration.
`static String` `COMMITTED_SEG_IDX` Committed segment index metric name.
`static String` `COMMITTED_SEG_OFFSET` Committed segment offset metric name.
`static String` `CUR_SEG_IDX` Current segment index metric name.
`static String` `ERR_MSG`
`static String` `LAST_SEG_CONSUMPTION_TIME` Last segment consumption time.
`static String` `MARSHALLER_DIR` Marshaller metric name.
`static String` `META_UPDATE` Metadata update time.
`static String` `STATE_DIR` State dir.

### Constructor Summary

Constructors
Constructor and Description
`CdcMain(IgniteConfiguration cfg, GridSpringResourceContext ctx, CdcConfiguration cdcCfg)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static String` `cdcInstanceName(String igniteInstanceName)`
`void` `consumeWalSegmentsUntilStopped()` Waits and consumes new WAL segments until stopped.
`protected CdcConsumerState` `createState(Path stateDir)` Creates consumer state.
`void` `run()` Runs Change Data Capture.
`void` `runX()` Runs Change Data Capture application with possible exception.
`void` `stop()` Stops the application.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### ERR_MSG

    public static final String ERR_MSG

See Also:
  Constant Field Values

#### STATE_DIR

    public static final String STATE_DIR

State dir.

See Also:
  Constant Field Values

#### CUR_SEG_IDX

    public static final String CUR_SEG_IDX

Current segment index metric name.

See Also:
  Constant Field Values

#### COMMITTED_SEG_IDX

    public static final String COMMITTED_SEG_IDX

Committed segment index metric name.

See Also:
  Constant Field Values

#### COMMITTED_SEG_OFFSET

    public static final String COMMITTED_SEG_OFFSET

Committed segment offset metric name.

See Also:
  Constant Field Values

#### LAST_SEG_CONSUMPTION_TIME

    public static final String LAST_SEG_CONSUMPTION_TIME

Last segment consumption time.

See Also:
  Constant Field Values

#### META_UPDATE

    public static final String META_UPDATE

Metadata update time.

See Also:
  Constant Field Values

#### BINARY_META_DIR

    public static final String BINARY_META_DIR

Binary metadata metric name.

See Also:
  Constant Field Values

#### MARSHALLER_DIR

    public static final String MARSHALLER_DIR

Marshaller metric name.

See Also:
  Constant Field Values

#### CDC_DIR

    public static final String CDC_DIR

Cdc directory metric name.

See Also:
  Constant Field Values

#### cdcCfg

    protected final CdcConfiguration cdcCfg

Change Data Capture configuration.

### Constructor Detail

#### CdcMain

    public CdcMain(IgniteConfiguration cfg,
                   GridSpringResourceContext ctx,
                   CdcConfiguration cdcCfg)

Parameters:
  `cfg` - Ignite configuration.
  `ctx` - Spring resource context.
  `cdcCfg` - Change Data Capture configuration.

### Method Detail

#### run

    public void run()

Runs Change Data Capture.

Specified by:
  `run` in interface `Runnable`

#### runX

    public void runX()
              throws Exception

Runs Change Data Capture application with possible exception.

Throws:
  `Exception`

#### createState

    protected CdcConsumerState createState(Path stateDir)

Creates consumer state.

#### consumeWalSegmentsUntilStopped

    public void consumeWalSegmentsUntilStopped()

Waits and consumes new WAL segments until stopped.

#### stop

    public void stop()

Stops the application.

#### cdcInstanceName

    public static String cdcInstanceName(String igniteInstanceName)

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.15.0
Release Date | : April 25 2023