Package io.debezium.connector.cassandra
Class SnapshotProcessor
java.lang.Object
io.debezium.connector.cassandra.AbstractProcessor
io.debezium.connector.cassandra.SnapshotProcessor
This reader is responsible for initial bootstrapping of a table,
which entails converting each row into a change event and enqueueing
that event to the
ChangeEventQueue.
IMPORTANT: Currently, only when a snapshot is completed will the OffsetWriter record the table in the offset.properties file (with filename "" and position -1). This means if the SnapshotProcessor is terminated midway, upon restart it will skip all the tables that are already recorded in offset.properties
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final CassandraClientprivate final com.datastax.oss.driver.api.core.ConsistencyLevelprivate static final Stringprivate booleanprivate static final org.slf4j.Loggerprivate final SnapshotProcessorMetricsprivate static final Stringprivate final OffsetWriterprivate final RecordMakerprivate final SchemaHolderprivate final CassandraConnectorConfig.SnapshotMode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static longcalculateDeletionTs(Object executionTime, Object ttl) it is not possible to query deletion time via cql, so instead calculate it from execution time (in milliseconds) + ttl (in seconds)voiddestroy()Override destroy to clean up resources after stopping the processorprivate static RowDataextractRowData(com.datastax.oss.driver.api.core.cql.Row row, Collection<com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata> columns, Set<String> partitionKeyNames, Set<String> clusteringKeyNames, Object executionTime) This function extracts the relevant row data fromRowand updates the maximum writetime for each row.private static com.datastax.oss.driver.api.core.cql.SimpleStatementgenerateSnapshotStatement(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata tableMetadata) Build the SELECT query statement for execution.private Set<com.datastax.oss.driver.api.core.metadata.schema.TableMetadata>Return a set ofTableMetadatafor tables that have not been snapshotted but have CDC enabled.private static CellData.ColumnTypevoidOverride initialize to initialize resources before starting the processorvoidprocess()The actual work the processor is doing.private voidprocessResultSet(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata tableMetadata, com.datastax.oss.driver.api.core.cql.ResultSet resultSet) Process the result set from the query.private static ObjectreadCol(com.datastax.oss.driver.api.core.cql.Row row, String col, com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata cm) private static ObjectreadColTtl(com.datastax.oss.driver.api.core.cql.Row row, String col) private static ObjectreadExecutionTime(com.datastax.oss.driver.api.core.cql.Row row) (package private) voidsnapshot()Fetch for all new tables that have not yet been snapshotted, and then iterate through the tables to snapshot each one of them.private static StringtableName(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata tm) private voidtakeTableSnapshot(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata tableMetadata) Runs a SELECT query on a given table and process each row in the result set by converting the row into a record and enqueue it toChangeRecordprivate static Stringprivate static StringwithQuotes(String s) Methods inherited from class io.debezium.connector.cassandra.AbstractProcessor
getName, isRunning, start, stop
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
NAME
- See Also:
-
CASSANDRA_NOW_UNIXTIMESTAMP
- See Also:
-
EXECUTION_TIME_ALIAS
- See Also:
-
collectionTypes
-
cassandraClient
-
queues
-
offsetWriter
-
schemaHolder
-
recordMaker
-
snapshotMode
-
consistencyLevel
private final com.datastax.oss.driver.api.core.ConsistencyLevel consistencyLevel -
startedTableNames
-
metrics
-
initial
private boolean initial
-
-
Constructor Details
-
SnapshotProcessor
-
-
Method Details
-
initialize
public void initialize()Description copied from class:AbstractProcessorOverride initialize to initialize resources before starting the processor- Overrides:
initializein classAbstractProcessor
-
destroy
public void destroy()Description copied from class:AbstractProcessorOverride destroy to clean up resources after stopping the processor- Overrides:
destroyin classAbstractProcessor
-
process
Description copied from class:AbstractProcessorThe actual work the processor is doing. This method will be executed in a while loop until processor stops or encounters exception.- Specified by:
processin classAbstractProcessor- Throws:
IOException
-
snapshot
Fetch for all new tables that have not yet been snapshotted, and then iterate through the tables to snapshot each one of them.- Throws:
IOException
-
getTablesToSnapshot
Return a set ofTableMetadatafor tables that have not been snapshotted but have CDC enabled. -
takeTableSnapshot
private void takeTableSnapshot(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata tableMetadata) throws IOException Runs a SELECT query on a given table and process each row in the result set by converting the row into a record and enqueue it toChangeRecord- Throws:
IOException
-
generateSnapshotStatement
private static com.datastax.oss.driver.api.core.cql.SimpleStatement generateSnapshotStatement(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata tableMetadata) Build the SELECT query statement for execution. For every non-primary-key column, the TTL, WRITETIME, and execution time are also queried.For example, a table t with columns a, b, and c, where A is the partition key, B is the clustering key, and C is a regular column, looks like the following:
SELECT now() as execution_time, a, b, c, TTL(c) as c_ttl, WRITETIME(c) as c_writetime FROM t; -
processResultSet
private void processResultSet(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata tableMetadata, com.datastax.oss.driver.api.core.cql.ResultSet resultSet) throws IOException Process the result set from the query. Each row is converted into aChangeRecordand enqueued to theChangeEventQueue.- Throws:
IOException
-
extractRowData
private static RowData extractRowData(com.datastax.oss.driver.api.core.cql.Row row, Collection<com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata> columns, Set<String> partitionKeyNames, Set<String> clusteringKeyNames, Object executionTime) This function extracts the relevant row data fromRowand updates the maximum writetime for each row. -
getType
-
readExecutionTime
-
readCol
-
readColTtl
-
calculateDeletionTs
it is not possible to query deletion time via cql, so instead calculate it from execution time (in milliseconds) + ttl (in seconds) -
ttlAlias
-
withQuotes
-
tableName
-