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.
[yugabyte/yugabyte-db#26107] Parellel streaming changes (#172)
This PR introduces the changes to stream changes in parallel using multiple tasks for a table given the user provides the hash_code ranges for it to stream. The following changes have been introduced in this PR: 1. New configurations: a. `streaming.mode`: This values takes the input as `default` or `parallel` which is then used to decide whether or not parallel streaming mode is supposed to be used. b. `slot.names`: A list of comma separated values for all the slot names which should be used by each task. c. `publication.names`: A list of comma separated values for all the publication names which should be used by each task. d. `slot.ranges`: A list of **semi-colon** separated values for slot ranges in the format `a,b;b,c;c,d`. 2. Validations in the class `YBValidate` have been introduced: a. To validate that the complete hash range is provided by the user and nothing is missing. b. To validate that the number of slot names is equal to the publication names as well as the number of slot ranges. c. To ensure that there's only one table provided in the `table.include.list` as parallel streaming will not work with multiple tables. 3. Support for snapshot with `streaming.mode` parallel. a. This will require providing the hash part of the primary key columns to the configuration parameter `primary.key.hash.columns`. 4. The `PostgresPartition` object will now also use the slot name to uniquely identify the source partition. ### Usage example If the connector configuration contains the following properties: ``` { ... "streaming.mode":"parallel", "slot.names":"rs1,rs1", "publication.names":"pb1,pb2", "slot.ranges":"0,32768;32768,65536" ... } ``` then we will have 2 tasks created: 1. `task 0`: `slot=rs1 publication=pb1 hash_range=0,32768` 2. `task 1`: `slot=rs2 publication=pb2 hash_range=32768,65536` ### Note: It is currently the user's responsibility to provide full hash ranges and maintain the order given in the configs for `slot.names`, `publication.names` and `slot.ranges` as the values will be picked sequentially and divided into tasks. Thus, in order to ensure that the task with a slot gets the same hash_range every time, the user needs to be careful with the order provided. This closes yugabyte/yugabyte-db#26107.
- Loading branch information
1 parent
615451f
commit 13c3b13
Showing
10 changed files
with
340 additions
and
17 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
66 changes: 66 additions & 0 deletions
66
debezium-connector-postgres/src/main/java/io/debezium/connector/postgresql/YBValidate.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,66 @@ | ||
package io.debezium.connector.postgresql; | ||
|
||
import io.debezium.DebeziumException; | ||
import io.debezium.connector.postgresql.transforms.yugabytedb.Pair; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Class to store all the validation methods. | ||
* | ||
* @author Vaibhav Kushwaha ([email protected]) | ||
*/ | ||
public class YBValidate { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(YBValidate.class); | ||
private static final String RANGE_BEGIN = "0"; | ||
private static final String RANGE_END = "65536"; | ||
|
||
public static void completeRangesProvided(List<String> slotRanges) { | ||
List<Pair<Integer, Integer>> pairList = slotRanges.stream() | ||
.map(entry -> { | ||
String[] parts = entry.split(","); | ||
return new Pair<>(Integer.valueOf(parts[0]), Integer.valueOf(parts[1])); | ||
}) | ||
.sorted(Comparator.comparing(Pair::getFirst)) | ||
.collect(Collectors.toList()); | ||
|
||
int rangeBegin = Integer.valueOf(RANGE_BEGIN); | ||
|
||
for (Pair<Integer, Integer> pair : pairList) { | ||
if (rangeBegin != pair.getFirst()) { | ||
LOGGER.error("Error while validating ranges: {}", pairList); | ||
throw new DebeziumException( | ||
String.format("Tablet range starting from hash_code %d is missing", rangeBegin)); | ||
} | ||
|
||
rangeBegin = pair.getSecond(); | ||
} | ||
|
||
// At this point, if the range is complete, rangeBegin will be pointing to the RANGE_END value. | ||
if (rangeBegin != Integer.valueOf(RANGE_END)) { | ||
LOGGER.error("Error while validating ranges: {}", pairList); | ||
throw new DebeziumException( | ||
String.format("Incomplete ranges provided. Range starting from hash_code %d is missing", rangeBegin)); | ||
} | ||
} | ||
|
||
public static void slotAndPublicationsAreEqual(List<String> slotNames, List<String> publicationNames) { | ||
if (slotNames.size() != publicationNames.size()) { | ||
throw new DebeziumException( | ||
String.format("Number of provided slots does not match the number of provided " + | ||
"publications. Slots: %s, Publications: %s", slotNames, publicationNames)); | ||
} | ||
} | ||
|
||
public static void slotRangesMatchSlotNames(List<String> slotNames, List<String> slotRanges) { | ||
if (slotNames.size() != slotRanges.size()) { | ||
throw new DebeziumException( | ||
String.format("Number of provided slots does not match the number of provided " + | ||
"slot ranges. Slots: %s, Slot ranges: %s", slotNames, slotRanges)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.