public class SnapshotProcessor extends AbstractProcessor
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| Modifier and Type | Field and Description |
|---|---|
private static String |
CASSANDRA_NOW_UNIXTIMESTAMP |
private CassandraClient |
cassandraClient |
private static Set<com.datastax.driver.core.DataType.Name> |
collectionTypes |
private com.datastax.driver.core.ConsistencyLevel |
consistencyLevel |
private static String |
EXECUTION_TIME_ALIAS |
private boolean |
initial |
private static org.slf4j.Logger |
LOGGER |
private SnapshotProcessorMetrics |
metrics |
private static String |
NAME |
private OffsetWriter |
offsetWriter |
private io.debezium.connector.base.ChangeEventQueue<Event> |
queue |
private RecordMaker |
recordMaker |
private SchemaHolder |
schemaHolder |
private CassandraConnectorConfig.SnapshotMode |
snapshotMode |
private Set<String> |
startedTableNames |
| Constructor and Description |
|---|
SnapshotProcessor(CassandraConnectorContext context) |
| Modifier and Type | Method and Description |
|---|---|
private static long |
calculateDeletionTs(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)
|
void |
destroy()
Override destroy to clean up resources after stopping the processor
|
private static RowData |
extractRowData(com.datastax.driver.core.Row row,
List<com.datastax.driver.core.ColumnMetadata> columns,
Set<String> partitionKeyNames,
Set<String> clusteringKeyNames,
Object executionTime)
This function extracts the relevant row data from
Row and updates the maximum writetime for each row. |
private static com.datastax.driver.core.querybuilder.BuiltStatement |
generateSnapshotStatement(com.datastax.driver.core.TableMetadata tableMetadata)
Build the SELECT query statement for execution.
|
private Set<com.datastax.driver.core.TableMetadata> |
getTablesToSnapshot()
Return a set of
TableMetadata for tables that have not been snapshotted but have CDC enabled. |
private static CellData.ColumnType |
getType(String name,
Set<String> partitionKeyNames,
Set<String> clusteringKeyNames) |
void |
initialize()
Override initialize to initialize resources before starting the processor
|
void |
process()
The actual work the processor is doing.
|
private void |
processResultSet(com.datastax.driver.core.TableMetadata tableMetadata,
com.datastax.driver.core.ResultSet resultSet)
Process the result set from the query.
|
private static Object |
readCol(com.datastax.driver.core.Row row,
String col,
com.datastax.driver.core.ColumnMetadata cm) |
private static Object |
readColTtl(com.datastax.driver.core.Row row,
String col) |
private static Object |
readExecutionTime(com.datastax.driver.core.Row row) |
(package private) void |
snapshot()
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 String |
tableName(com.datastax.driver.core.TableMetadata tm) |
private void |
takeTableSnapshot(com.datastax.driver.core.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 to
ChangeRecord |
private static String |
ttlAlias(String colName) |
private static String |
withQuotes(String s) |
getName, isRunning, start, stopprivate static final org.slf4j.Logger LOGGER
private static final String NAME
private static final String CASSANDRA_NOW_UNIXTIMESTAMP
private static final String EXECUTION_TIME_ALIAS
private static final Set<com.datastax.driver.core.DataType.Name> collectionTypes
private final CassandraClient cassandraClient
private final io.debezium.connector.base.ChangeEventQueue<Event> queue
private final OffsetWriter offsetWriter
private final SchemaHolder schemaHolder
private final RecordMaker recordMaker
private final CassandraConnectorConfig.SnapshotMode snapshotMode
private final com.datastax.driver.core.ConsistencyLevel consistencyLevel
private final SnapshotProcessorMetrics metrics
private boolean initial
public SnapshotProcessor(CassandraConnectorContext context)
public void initialize()
AbstractProcessorinitialize in class AbstractProcessorpublic void destroy()
AbstractProcessordestroy in class AbstractProcessorpublic void process()
AbstractProcessorprocess in class AbstractProcessorvoid snapshot()
private Set<com.datastax.driver.core.TableMetadata> getTablesToSnapshot()
TableMetadata for tables that have not been snapshotted but have CDC enabled.private void takeTableSnapshot(com.datastax.driver.core.TableMetadata tableMetadata)
throws IOException
ChangeRecordIOExceptionprivate static com.datastax.driver.core.querybuilder.BuiltStatement generateSnapshotStatement(com.datastax.driver.core.TableMetadata tableMetadata)
SELECT now() as execution_time, a, b, c, TTL(c) as c_ttl, WRITETIME(c) as c_writetime FROM t;
private void processResultSet(com.datastax.driver.core.TableMetadata tableMetadata,
com.datastax.driver.core.ResultSet resultSet)
throws IOException
ChangeRecord
and enqueued to the ChangeEventQueue.IOExceptionprivate static RowData extractRowData(com.datastax.driver.core.Row row, List<com.datastax.driver.core.ColumnMetadata> columns, Set<String> partitionKeyNames, Set<String> clusteringKeyNames, Object executionTime)
Row and updates the maximum writetime for each row.private static CellData.ColumnType getType(String name, Set<String> partitionKeyNames, Set<String> clusteringKeyNames)
private static Object readExecutionTime(com.datastax.driver.core.Row row)
private static Object readCol(com.datastax.driver.core.Row row, String col, com.datastax.driver.core.ColumnMetadata cm)
private static long calculateDeletionTs(Object executionTime, Object ttl)
private static String tableName(com.datastax.driver.core.TableMetadata tm)
Copyright © 2020 JBoss by Red Hat. All rights reserved.