Package 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 theCdcConsumerto consume events(CdcEvent) from WAL segments. The user should provideCdcConsumerimplementation with custom consumption logic. Ignite node should be explicitly configured for usingCdcMain.- Set
DataRegionConfiguration.setCdcEnabled(boolean)to true. - Optional: Set
DataStorageConfiguration.setCdcWalPath(String)to path to the directory to store WAL segments for CDC. - Optional: Set
DataStorageConfiguration.setWalForceArchiveTimeout(long)to configure timeout for force WAL rollover, so new events will be available for consumptions with the predicted time.
DataStorageConfiguration.getCdcWalPath()is true then Ignite node on each WAL segment rollover creates hard link to archive WAL segment inDataStorageConfiguration.getCdcWalPath()directory.CdcMainapplication takes segment file and consumes events from it. After successful consumption (seeCdcConsumer.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 viaIgniteConfiguration.setConsistentId(Serializable)in providedIgniteConfiguration. Application works as follows:- Searches node work directory based on provided
IgniteConfiguration. - Awaits for the creation of CDC directory if it not exists.
- Acquires file lock to ensure exclusive consumption.
- Loads state of consumption if it exists.
- Infinitely waits for new available segment and processes it.
-
-
Field Summary
Fields Modifier and Type Field Description static StringBINARY_META_DIRBinary metadata metric name.static StringCDC_DIRCdc directory metric name.static StringCDC_MODECdc mode metric name.protected CdcConfigurationcdcCfgChange Data Capture configuration.static StringCOMMITTED_SEG_IDXCommitted segment index metric name.static StringCOMMITTED_SEG_OFFSETCommitted segment offset metric name.static StringCUR_SEG_IDXCurrent segment index metric name.static StringERR_MSGstatic StringEVT_CAPTURE_TIMEEvent capture time.static StringLAST_SEG_CONSUMPTION_TIMELast segment consumption time.static StringMARSHALLER_DIRMarshaller metric name.static StringMETA_UPDATEMetadata update time.static StringSEGMENT_CONSUMING_TIMEWal segment iterator consuming time.static StringSTATE_DIRState dir.
-
Constructor Summary
Constructors Constructor Description CdcMain(IgniteConfiguration cfg, GridSpringResourceContext ctx, CdcConfiguration cdcCfg)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringcdcInstanceName(String igniteInstanceName)voidconsumeWalSegmentsUntilStopped()Waits and consumes new WAL segments until stopped.protected CdcConsumerStatecreateState(Path stateDir)Creates consumer state.voidrun()Runs Change Data Capture.voidrunX()Runs Change Data Capture application with possible exception.voidstop()Stops the application.static Iterator<TypeMapping>typeMappingIterator(File[] files, Predicate<TypeMapping> filter)
-
-
-
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
-
EVT_CAPTURE_TIME
public static final String EVT_CAPTURE_TIME
Event capture time.- See Also:
- Constant Field Values
-
SEGMENT_CONSUMING_TIME
public static final String SEGMENT_CONSUMING_TIME
Wal segment iterator consuming 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
-
CDC_MODE
public static final String CDC_MODE
Cdc mode 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
-
runX
public void runX() throws ExceptionRuns 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.
-
typeMappingIterator
public static Iterator<TypeMapping> typeMappingIterator(File[] files, Predicate<TypeMapping> filter)
- Parameters:
files- Mapping files.filter- Filter.- Returns:
- Type mapping iterator.
-
-