37
37
import io .debezium .pipeline .source .spi .ChangeEventSource ;
38
38
import io .debezium .pipeline .source .spi .SnapshotProgressListener ;
39
39
import io .debezium .pipeline .spi .ChangeRecordEmitter ;
40
- import io .debezium .pipeline .spi .OffsetContext ;
41
40
import io .debezium .pipeline .spi .SnapshotResult ;
42
41
import io .debezium .relational .RelationalSnapshotChangeEventSource ;
43
42
import io .debezium .relational .SnapshotChangeRecordEmitter ;
@@ -130,19 +129,23 @@ public void execute(Context context) throws Exception {
130
129
}
131
130
// execute redoLog read task
132
131
if (snapshotResult .isCompletedOrSkipped ()) {
133
- final RedoLogSplitReadTask backfillBinlogReadTask =
134
- createBackfillRedoLogReadTask (backfillBinlogSplit , sourceFetchContext );
135
-
136
- final LogMinerOracleOffsetContextLoader loader =
137
- new LogMinerOracleOffsetContextLoader (
138
- ((OracleSourceFetchTaskContext ) context ).getDbzConnectorConfig ());
139
- final OracleOffsetContext oracleOffsetContext =
140
- loader .load (backfillBinlogSplit .getStartingOffset ().getOffset ());
141
- backfillBinlogReadTask .execute (
142
- new SnapshotBinlogSplitChangeEventSourceContext (),
143
- sourceFetchContext .getPartition (),
144
- oracleOffsetContext );
145
- taskRunning = false ;
132
+ try (OracleConnection connection =
133
+ createOracleConnection (
134
+ sourceFetchContext .getSourceConfig ().getDbzConfiguration ())) {
135
+ final RedoLogSplitReadTask backfillBinlogReadTask =
136
+ createBackfillRedoLogReadTask (
137
+ backfillBinlogSplit , sourceFetchContext , connection );
138
+ final LogMinerOracleOffsetContextLoader loader =
139
+ new LogMinerOracleOffsetContextLoader (
140
+ ((OracleSourceFetchTaskContext ) context ).getDbzConnectorConfig ());
141
+ final OracleOffsetContext oracleOffsetContext =
142
+ loader .load (backfillBinlogSplit .getStartingOffset ().getOffset ());
143
+ backfillBinlogReadTask .execute (
144
+ new SnapshotBinlogSplitChangeEventSourceContext (),
145
+ sourceFetchContext .getPartition (),
146
+ oracleOffsetContext );
147
+ taskRunning = false ;
148
+ }
146
149
} else {
147
150
taskRunning = false ;
148
151
throw new IllegalStateException (
@@ -162,11 +165,9 @@ private StreamSplit createBackfillRedoLogSplit(
162
165
}
163
166
164
167
private RedoLogSplitReadTask createBackfillRedoLogReadTask (
165
- StreamSplit backfillBinlogSplit , OracleSourceFetchTaskContext context ) {
166
- OracleConnectorConfig oracleConnectorConfig =
167
- context .getSourceConfig ().getDbzConnectorConfig ();
168
- final OffsetContext .Loader <OracleOffsetContext > loader =
169
- new LogMinerOracleOffsetContextLoader (oracleConnectorConfig );
168
+ StreamSplit backfillBinlogSplit ,
169
+ OracleSourceFetchTaskContext context ,
170
+ OracleConnection connection ) {
170
171
// we should only capture events for the current table,
171
172
// otherwise, we may can't find corresponding schema
172
173
Configuration dezConf =
@@ -180,7 +181,7 @@ private RedoLogSplitReadTask createBackfillRedoLogReadTask(
180
181
// task to read binlog and backfill for current split
181
182
return new RedoLogSplitReadTask (
182
183
new OracleConnectorConfig (dezConf ),
183
- createOracleConnection ( context . getSourceConfig (). getDbzConfiguration ()) ,
184
+ connection ,
184
185
context .getDispatcher (),
185
186
context .getErrorHandler (),
186
187
context .getDatabaseSchema (),
0 commit comments