public abstract class HistorizedRelationalSnapshotChangeEventSource extends Object implements SnapshotChangeEventSource
SnapshotChangeEventSource for relational databases with 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 |
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext
Mutable context which is populated in the course of snapshotting.
|
static class |
HistorizedRelationalSnapshotChangeEventSource.SnapshottingTask
A configuration describing the task to be performed during snapshotting.
|
ChangeEventSource.ChangeEventSourceContext| Modifier and Type | Field and Description |
|---|---|
private 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 |
|---|
HistorizedRelationalSnapshotChangeEventSource(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(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Completes the snapshot, doing any required clean-up (resource disposal etc.).
|
protected void |
connectionCreated(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Executes steps which have to be taken just after the database connection is created.
|
private void |
createDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext,
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) |
private void |
createDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext,
HistorizedRelationalSnapshotChangeEventSource.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,
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) |
private void |
delaySnapshotIfNeeded(ChangeEventSource.ChangeEventSourceContext context)
Delays snapshot execution as per the
CommonConnectorConfig.SNAPSHOT_DELAY_MS parameter. |
private void |
determineCapturedTables(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext ctx) |
protected abstract void |
determineSnapshotOffset(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Determines the current offset (MySQL binlog position, Oracle SCN etc.), storing it into the passed context
object.
|
private String |
determineSnapshotSelect(HistorizedRelationalSnapshotChangeEventSource.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(HistorizedRelationalSnapshotChangeEventSource.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 abstract ChangeRecordEmitter |
getChangeRecordEmitter(HistorizedRelationalSnapshotChangeEventSource.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) |
private Object |
getColumnValue(ResultSet rs,
int columnIndex,
Column column) |
protected abstract SchemaChangeEvent |
getCreateTableEvent(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext,
Table table)
Creates a
SchemaChangeEvent representing the creation of the given table. |
protected abstract String |
getSnapshotSelect(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext,
TableId tableId)
Returns the SELECT statement to be used for scanning the given table
|
protected abstract HistorizedRelationalSnapshotChangeEventSource.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,
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Locks all tables to be captured, so that no concurrent schema changes can be applied to them.
|
protected abstract HistorizedRelationalSnapshotChangeEventSource.SnapshotContext |
prepare(ChangeEventSource.ChangeEventSourceContext changeEventSourceContext)
Prepares the taking of a snapshot and returns an initial
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext. |
private Statement |
readTableStatement() |
protected abstract void |
readTableStructure(ChangeEventSource.ChangeEventSourceContext sourceContext,
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Reads the structure of all the captured tables, writing it to
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext.tables. |
protected abstract void |
releaseSchemaSnapshotLocks(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
Releases all locks established in order to create a consistent schema snapshot.
|
private void |
rollbackTransaction(Connection connection) |
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
private final Clock clock
private final SnapshotProgressListener snapshotProgressListener
public HistorizedRelationalSnapshotChangeEventSource(RelationalDatabaseConnectorConfig connectorConfig, OffsetContext previousOffset, JdbcConnection jdbcConnection, HistorizedRelationalDatabaseSchema schema, 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 HistorizedRelationalSnapshotChangeEventSource.SnapshottingTask getSnapshottingTask(OffsetContext previousOffset)
private void delaySnapshotIfNeeded(ChangeEventSource.ChangeEventSourceContext context) throws InterruptedException
CommonConnectorConfig.SNAPSHOT_DELAY_MS parameter.InterruptedExceptionprotected abstract HistorizedRelationalSnapshotChangeEventSource.SnapshotContext prepare(ChangeEventSource.ChangeEventSourceContext changeEventSourceContext) throws Exception
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext.Exceptionprotected void connectionCreated(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprivate void determineCapturedTables(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext ctx) throws Exception
Exceptionprotected abstract Set<TableId> getAllTableIds(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract void lockTablesForSchemaSnapshot(ChangeEventSource.ChangeEventSourceContext sourceContext, HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract void determineSnapshotOffset(HistorizedRelationalSnapshotChangeEventSource.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, HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
HistorizedRelationalSnapshotChangeEventSource.SnapshotContext.tables.Exceptionprotected abstract void releaseSchemaSnapshotLocks(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprivate void createSchemaChangeEventsForTables(ChangeEventSource.ChangeEventSourceContext sourceContext, HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws Exception
Exceptionprotected abstract SchemaChangeEvent getCreateTableEvent(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, Table table) throws Exception
SchemaChangeEvent representing the creation of the given table.Exceptionprivate void createDataEvents(ChangeEventSource.ChangeEventSourceContext sourceContext, HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext) throws InterruptedException
InterruptedExceptionprivate void createDataEventsForTable(ChangeEventSource.ChangeEventSourceContext sourceContext, HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, EventDispatcher.SnapshotReceiver snapshotReceiver, Table table) throws InterruptedException
InterruptedExceptionprivate Threads.Timer getTableScanLogTimer()
protected abstract ChangeRecordEmitter getChangeRecordEmitter(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId, Object[] row)
ChangeRecordEmitter producing the change records for the given table row.private String determineSnapshotSelect(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId)
tableId - the table to generate a query forprotected abstract String getSnapshotSelect(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext, TableId tableId)
private Column[] getColumnsForResultSet(Table table, ResultSet rs) throws SQLException
SQLExceptionprivate Object getColumnValue(ResultSet rs, int columnIndex, Column column) throws SQLException
SQLExceptionprivate Statement readTableStatement() throws SQLException
SQLExceptionprotected abstract void complete(HistorizedRelationalSnapshotChangeEventSource.SnapshotContext snapshotContext)
snapshotContext - snapshot contextprivate void rollbackTransaction(Connection connection)
protected Clock getClock()
Copyright © 2019 JBoss by Red Hat. All rights reserved.