forked from debezium/debezium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DBZ-PGYB][yugabyte/yugabyte-db#24200] Execute snapshot in chunks (#161)
## Problem For very large tables, the default `SELECT *` query can take a really long time to complete leading to longer time for snapshots. ## Solution This PR aims to implement snapshotting the table in parallel using an inbuilt method `yb_hash_code` to only run the query for a given hash range. The following 2 configuration properties are introduced with this PR: 1. A new `snapshot.mode` called `parallel` - this will behave exactly like `initial_only` but we will have the ability to launch multiple tasks. 2. `primary.key.hash.columns` - this config takes in a comma separated values of the primary key hash component of the table. > **Note:** When `snapshot.mode` is set to `parallel`, we will not support providing regex in the property `table.include.list` and the user will need to specify the full name of the table in the property. Additionally, we will only allow one table in the `table.include.list` if `snapshot.mode` is `parallel`.
- Loading branch information
1 parent
3ca8afd
commit 2cda9b7
Showing
7 changed files
with
227 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...postgres/src/main/java/io/debezium/connector/postgresql/snapshot/ParallelSnapshotter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.debezium.connector.postgresql.snapshot; | ||
|
||
import io.debezium.connector.postgresql.PostgresConnectorConfig; | ||
import io.debezium.connector.postgresql.spi.OffsetState; | ||
import io.debezium.connector.postgresql.spi.SlotState; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Snapshotter class to take snapshot using parallel tasks. | ||
* | ||
* @author Vaibhav Kushwaha ([email protected]) | ||
*/ | ||
public class ParallelSnapshotter extends QueryingSnapshotter { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(ParallelSnapshotter.class); | ||
private OffsetState sourceInfo; | ||
|
||
@Override | ||
public void init(PostgresConnectorConfig config, OffsetState sourceInfo, SlotState slotState) { | ||
super.init(config, sourceInfo, slotState); | ||
this.sourceInfo = sourceInfo; | ||
|
||
LOGGER.info("Initialised ParallelSnapshotter for task {}", config.taskId()); | ||
} | ||
|
||
@Override | ||
public boolean shouldStream() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean shouldSnapshot() { | ||
if (sourceInfo == null) { | ||
LOGGER.info("Taking parallel snapshot for new datasource"); | ||
return true; | ||
} | ||
else if (sourceInfo.snapshotInEffect()) { | ||
LOGGER.info("Found previous incomplete snapshot"); | ||
return true; | ||
} | ||
else { | ||
LOGGER.info("Previous snapshot completed, no snapshot will be performed"); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters