public abstract class RelationalSnapshotChangeEventSource extends AbstractSnapshotChangeEventSource
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.RelationalSnapshotContext
Mutable context which is populated in the course of snapshotting.
|
AbstractSnapshotChangeEventSource.SnapshotContext, AbstractSnapshotChangeEventSource.SnapshottingTaskChangeEventSource.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(AbstractSnapshotChangeEventSource.SnapshotContext snapshotContext)
Completes the snapshot, doing any required clean-up (resource disposal etc.).
|
protected void |
connectionCreated(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext)
Executes steps which have to be taken just after the database connection is created.
|
private void |
createDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext) |
private void |
createDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.RelationalSnapshotContext 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.RelationalSnapshotContext snapshotContext,
AbstractSnapshotChangeEventSource.SnapshottingTask snapshottingTask) |
private void |
determineCapturedTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext ctx) |
protected abstract void |
determineSnapshotOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext)
Determines the current offset (MySQL binlog position, Oracle SCN etc.), storing it into the passed context
object.
|
private Optional<String> |
determineSnapshotSelect(AbstractSnapshotChangeEventSource.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 |
doExecute(ChangeEventSource.ChangeEventSourceContext context,
AbstractSnapshotChangeEventSource.SnapshotContext snapshotContext,
AbstractSnapshotChangeEventSource.SnapshottingTask snapshottingTask)
Executes this source.
|
protected abstract Set<TableId> |
getAllTableIds(RelationalSnapshotChangeEventSource.RelationalSnapshotContext 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(AbstractSnapshotChangeEventSource.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.RelationalSnapshotContext snapshotContext,
Table table)
Creates a
SchemaChangeEvent representing the creation of the given table. |
protected abstract Optional<String> |
getSnapshotSelect(AbstractSnapshotChangeEventSource.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
|
private Threads.Timer |
getTableScanLogTimer() |
protected abstract void |
lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext)
Locks all tables to be captured, so that no concurrent schema changes can be applied to them.
|
private Statement |
readTableStatement() |
protected abstract void |
readTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext,
RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext)
Reads the structure of all the captured tables, writing it to
RelationalSnapshotChangeEventSource.RelationalSnapshotContext.tables. |
protected abstract void |
releaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext 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 void |
tryStartingSnapshot(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext) |
delaySnapshotIfNeeded, execute, getSnapshottingTask, prepareprivate 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 doExecute(ChangeEventSource.ChangeEventSourceContext context, AbstractSnapshotChangeEventSource.SnapshotContext snapshotContext, AbstractSnapshotChangeEventSource.SnapshottingTask snapshottingTask) throws Exception
AbstractSnapshotChangeEventSourcedoExecute in class AbstractSnapshotChangeEventSourcecontext - contextual information for this source's executionsnapshotContext - mutable context information populated throughout the snapshot processsnapshottingTask - immutable information about what tasks should be performed during snapshotExceptionprotected void connectionCreated(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext) throws Exception
Exceptionprivate void determineCapturedTables(RelationalSnapshotChangeEventSource.RelationalSnapshotContext ctx) throws Exception
Exceptionprotected abstract Set<TableId> getAllTableIds(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract void lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract void determineSnapshotOffset(RelationalSnapshotChangeEventSource.RelationalSnapshotContext 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.RelationalSnapshotContext snapshotContext) throws Exception
RelationalSnapshotChangeEventSource.RelationalSnapshotContext.tables.Exceptionprotected abstract void releaseSchemaSnapshotLocks(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext) throws Exception
Exceptionprivate void createSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext, AbstractSnapshotChangeEventSource.SnapshottingTask snapshottingTask) throws Exception
Exceptionprotected abstract SchemaChangeEvent getCreateTableEvent(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext, Table table) throws Exception
SchemaChangeEvent representing the creation of the given table.Exceptionprivate void createDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext) throws InterruptedException
InterruptedExceptionprivate void tryStartingSnapshot(RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext)
private void createDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext, RelationalSnapshotChangeEventSource.RelationalSnapshotContext snapshotContext, EventDispatcher.SnapshotReceiver snapshotReceiver, Table table) throws InterruptedException
InterruptedExceptionprivate Threads.Timer getTableScanLogTimer()
protected ChangeRecordEmitter getChangeRecordEmitter(AbstractSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId, Object[] row)
ChangeRecordEmitter producing the change records for the given table row.private Optional<String> determineSnapshotSelect(AbstractSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId)
tableId - the table to generate a query forprotected abstract Optional<String> getSnapshotSelect(AbstractSnapshotChangeEventSource.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(AbstractSnapshotChangeEventSource.SnapshotContext snapshotContext)
complete in class AbstractSnapshotChangeEventSourcesnapshotContext - snapshot contextprivate void rollbackTransaction(Connection connection)
protected Clock getClock()
Copyright © 2020 JBoss by Red Hat. All rights reserved.