public abstract class RelationalSnapshotChangeEventSource extends Object implements SnapshotChangeEventSource
SnapshotChangeEventSource for relational databases with or without a schema history.
A transaction is managed by this base class, sub-classes shouldn't rollback or commit this transaction. They are free to use nested transactions or savepoints, though.
| Modifier and Type | Class and Description |
|---|---|
static class |
RelationalSnapshotChangeEventSource.SnapshotContext
Mutable context which is populated in the course of snapshotting.
|
static class |
RelationalSnapshotChangeEventSource.SnapshottingTask
A configuration describing the task to be performed during snapshotting.
|
ChangeEventSource.ChangeEventSourceContext| Modifier and Type | Field and Description |
|---|---|
protected Clock |
clock |
private RelationalDatabaseConnectorConfig |
connectorConfig |
private EventDispatcher<TableId> |
dispatcher |
private JdbcConnection |
jdbcConnection |
private static Duration |
LOG_INTERVAL
Interval for showing a log statement with the progress while scanning a single table.
|
private static org.slf4j.Logger |
LOGGER |
private OffsetContext |
previousOffset |
private HistorizedRelationalDatabaseSchema |
schema |
private SnapshotProgressListener |
snapshotProgressListener |
| Constructor and Description |
|---|
RelationalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig connectorConfig,
OffsetContext previousOffset,
JdbcConnection jdbcConnection,
EventDispatcher<TableId> dispatcher,
Clock clock,
SnapshotProgressListener snapshotProgressListener) |
RelationalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig connectorConfig,
OffsetContext previousOffset,
JdbcConnection jdbcConnection,
HistorizedRelationalDatabaseSchema schema,
EventDispatcher<TableId> dispatcher,
Clock clock,
SnapshotProgressListener snapshotProgressListener) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
complete(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Completes the snapshot, doing any required clean-up (resource disposal etc.).
|
protected void |
connectionCreated(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Executes steps which have to be taken just after the database connection is created.
|
private void |
createDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) |
private void |
createDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext,
EventDispatcher.SnapshotReceiver snapshotReceiver,
Table table)
Dispatches the data change events for the records of a single table.
|
private void |
createSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) |
private void |
delaySnapshotIfNeeded(ChangeEventSource.ChangeEventSourceContext context)
Delays snapshot execution as per the
CommonConnectorConfig.SNAPSHOT_DELAY_MS parameter. |
private void |
determineCapturedTables(RelationalSnapshotChangeEventSource.SnapshotContext ctx) |
protected abstract void |
determineSnapshotOffset(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Determines the current offset (MySQL binlog position, Oracle SCN etc.), storing it into the passed context
object.
|
private Optional<String> |
determineSnapshotSelect(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext,
TableId tableId)
Returns a valid query string for the specified table, either given by the user via snapshot select overrides or
defaulting to a statement provided by the DB-specific change event source.
|
SnapshotResult |
execute(ChangeEventSource.ChangeEventSourceContext context)
Executes this source.
|
protected abstract Set<TableId> |
getAllTableIds(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Returns all candidate tables; the current filter configuration will be applied to the result set, resulting in
the effective set of captured tables.
|
protected ChangeRecordEmitter |
getChangeRecordEmitter(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext,
TableId tableId,
Object[] row)
Returns a
ChangeRecordEmitter producing the change records for the given table row. |
protected Clock |
getClock() |
private Column[] |
getColumnsForResultSet(Table table,
ResultSet rs) |
protected Object |
getColumnValue(ResultSet rs,
int columnIndex,
Column column) |
protected abstract SchemaChangeEvent |
getCreateTableEvent(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext,
Table table)
Creates a
SchemaChangeEvent representing the creation of the given table. |
protected abstract Optional<String> |
getSnapshotSelect(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext,
TableId tableId)
Returns the SELECT statement to be used for scanning the given table or empty value if
the table will be streamed from but not snapshotted
|
protected abstract RelationalSnapshotChangeEventSource.SnapshottingTask |
getSnapshottingTask(OffsetContext previousOffset)
Returns the snapshotting task based on the previous offset (if available) and the connector's snapshotting mode.
|
private Threads.Timer |
getTableScanLogTimer() |
protected abstract void |
lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Locks all tables to be captured, so that no concurrent schema changes can be applied to them.
|
protected abstract RelationalSnapshotChangeEventSource.SnapshotContext |
prepare(ChangeEventSource.ChangeEventSourceContext changeEventSourceContext)
Prepares the taking of a snapshot and returns an initial
RelationalSnapshotChangeEventSource.SnapshotContext. |
private Statement |
readTableStatement() |
protected abstract void |
readTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Reads the structure of all the captured tables, writing it to
RelationalSnapshotChangeEventSource.SnapshotContext.tables. |
protected abstract void |
releaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Releases all locks established in order to create a consistent schema snapshot.
|
private void |
rollbackTransaction(Connection connection) |
private Set<TableId> |
sort(Set<TableId> capturedTables) |
private Stream<TableId> |
toTableIds(Set<TableId> tableIds,
Pattern pattern) |
private static final org.slf4j.Logger LOGGER
private static final Duration LOG_INTERVAL
private final RelationalDatabaseConnectorConfig connectorConfig
private final OffsetContext previousOffset
private final JdbcConnection jdbcConnection
private final HistorizedRelationalDatabaseSchema schema
private final EventDispatcher<TableId> dispatcher
protected final Clock clock
private final SnapshotProgressListener snapshotProgressListener
public RelationalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig connectorConfig, OffsetContext previousOffset, JdbcConnection jdbcConnection, HistorizedRelationalDatabaseSchema schema, EventDispatcher<TableId> dispatcher, Clock clock, SnapshotProgressListener snapshotProgressListener)
public RelationalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig connectorConfig, OffsetContext previousOffset, JdbcConnection jdbcConnection, EventDispatcher<TableId> dispatcher, Clock clock, SnapshotProgressListener snapshotProgressListener)
public SnapshotResult execute(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException
SnapshotChangeEventSourceexecute in interface SnapshotChangeEventSourcecontext - contextual information for this source's executionInterruptedException - in case the snapshot was aborted before completionprotected abstract RelationalSnapshotChangeEventSource.SnapshottingTask getSnapshottingTask(OffsetContext previousOffset)
private void delaySnapshotIfNeeded(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException
CommonConnectorConfig.SNAPSHOT_DELAY_MS parameter.InterruptedExceptionprotected abstract RelationalSnapshotChangeEventSource.SnapshotContext prepare(ChangeEventSource.ChangeEventSourceContext changeEventSourceContext) throws Exception
RelationalSnapshotChangeEventSource.SnapshotContext.Exceptionprotected void connectionCreated(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprivate void determineCapturedTables(RelationalSnapshotChangeEventSource.SnapshotContext ctx) throws Exception
Exceptionprotected abstract Set<TableId> getAllTableIds(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract void lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract void determineSnapshotOffset(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
StreamingChangeEventSource will be set up with this initial position to continue with stream
reading from there.Exceptionprotected abstract void readTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
RelationalSnapshotChangeEventSource.SnapshotContext.tables.Exceptionprotected abstract void releaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprivate void createSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract SchemaChangeEvent getCreateTableEvent(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, Table table) throws Exception
SchemaChangeEvent representing the creation of the given table.Exceptionprivate void createDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws InterruptedException
InterruptedExceptionprivate void createDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, EventDispatcher.SnapshotReceiver snapshotReceiver, Table table) throws InterruptedException
InterruptedExceptionprivate Threads.Timer getTableScanLogTimer()
protected ChangeRecordEmitter getChangeRecordEmitter(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId, Object[] row)
ChangeRecordEmitter producing the change records for the given table row.private Optional<String> determineSnapshotSelect(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId)
tableId - the table to generate a query forprotected abstract Optional<String> getSnapshotSelect(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId)
private Column[] getColumnsForResultSet(Table table, ResultSet rs) throws SQLException
SQLExceptionprotected Object getColumnValue(ResultSet rs, int columnIndex, Column column) throws SQLException
SQLExceptionprivate Statement readTableStatement() throws SQLException
SQLExceptionprotected abstract void complete(RelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
snapshotContext - snapshot contextprivate void rollbackTransaction(Connection connection)
protected Clock getClock()
Copyright © 2020 JBoss by Red Hat. All rights reserved.