|
18 | 18 | package org.apache.seatunnel.connectors.seatunnel.cdc.mysql.source.reader.fetch;
|
19 | 19 |
|
20 | 20 | import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
|
| 21 | +import org.apache.seatunnel.common.utils.ReflectionUtils; |
21 | 22 | import org.apache.seatunnel.connectors.cdc.base.config.JdbcSourceConfig;
|
22 | 23 | import org.apache.seatunnel.connectors.cdc.base.dialect.JdbcDataSourceDialect;
|
23 | 24 | import org.apache.seatunnel.connectors.cdc.base.relational.JdbcSourceEventDispatcher;
|
|
70 | 71 | import java.util.ArrayList;
|
71 | 72 | import java.util.List;
|
72 | 73 | import java.util.Map;
|
| 74 | +import java.util.Optional; |
73 | 75 |
|
74 | 76 | import static org.apache.seatunnel.connectors.seatunnel.cdc.mysql.source.offset.BinlogOffset.BINLOG_FILENAME_OFFSET_KEY;
|
75 | 77 | import static org.apache.seatunnel.connectors.seatunnel.cdc.mysql.utils.MySqlConnectionUtils.createBinaryClient;
|
@@ -326,13 +328,27 @@ public MySqlTaskContextImpl(
|
326 | 328 | MySqlDatabaseSchema schema,
|
327 | 329 | BinaryLogClient reusedBinaryLogClient) {
|
328 | 330 | super(config, schema);
|
329 |
| - this.reusedBinaryLogClient = reusedBinaryLogClient; |
| 331 | + this.reusedBinaryLogClient = resetBinaryLogClient(reusedBinaryLogClient); |
330 | 332 | }
|
331 | 333 |
|
332 | 334 | @Override
|
333 | 335 | public BinaryLogClient getBinaryLogClient() {
|
334 | 336 | return reusedBinaryLogClient;
|
335 | 337 | }
|
| 338 | + |
| 339 | + /** reset the listener of binaryLogClient before fetch task start. */ |
| 340 | + private BinaryLogClient resetBinaryLogClient(BinaryLogClient binaryLogClient) { |
| 341 | + Optional<Object> eventListenersField = |
| 342 | + ReflectionUtils.getField( |
| 343 | + binaryLogClient, BinaryLogClient.class, "eventListeners"); |
| 344 | + eventListenersField.ifPresent(o -> ((List<BinaryLogClient.EventListener>) o).clear()); |
| 345 | + Optional<Object> lifecycleListeners = |
| 346 | + ReflectionUtils.getField( |
| 347 | + binaryLogClient, BinaryLogClient.class, "lifecycleListeners"); |
| 348 | + lifecycleListeners.ifPresent( |
| 349 | + o -> ((List<BinaryLogClient.LifecycleListener>) o).clear()); |
| 350 | + return binaryLogClient; |
| 351 | + } |
336 | 352 | }
|
337 | 353 |
|
338 | 354 | /** Copied from debezium for accessing here. */
|
|
0 commit comments