Skip to content

Commit

Permalink
DBZ-8053 Use configured shards for get tables
Browse files Browse the repository at this point in the history
  • Loading branch information
twthorn committed Jul 12, 2024
1 parent 8d46bfd commit a055e2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
25 changes: 8 additions & 17 deletions src/main/java/io/debezium/connector/vitess/VitessMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class VitessMetadata {
public static List<String> getShards(VitessConnectorConfig config) {
List<String> shards;
if (config.excludeEmptyShards()) {
LOGGER.info("Excluding empty shards from shard list");
LOGGER.info("Excluding empty shards");
shards = getVitessShardsFromTablets(config);
}
else {
Expand All @@ -51,18 +51,17 @@ public static List<String> getTables(VitessConnectorConfig config) {
if (config.excludeEmptyShards()) {
query = "SHOW TABLES";
List<String> shardsToQuery;
List<String> nonEmptyShards = getVitessShardsFromTablets(config);
// If there is a shard list specified, then query one of its non-empty shards
if (config.getShard() != null && !config.getShard().isEmpty()) {
List<String> shardList = config.getShard();
shardsToQuery = intersect(shardList, nonEmptyShards);
LOGGER.info("Getting tables from one of the configured shards");
shardsToQuery = config.getShard();
}
else {
shardsToQuery = nonEmptyShards;
LOGGER.info("Getting tables from a non-empty shard");
shardsToQuery = getVitessShardsFromTablets(config);
}
String randomNonEmptyShard = shardsToQuery.get(new Random().nextInt(shardsToQuery.size()));
LOGGER.info("Get table list from non-empty shard: {}", randomNonEmptyShard);
response = executeQuery(config, query, randomNonEmptyShard);
String randomShard = shardsToQuery.get(new Random().nextInt(shardsToQuery.size()));
LOGGER.info("Get tables from shard: {}", randomShard);
response = executeQuery(config, query, randomShard);
}
else {
query = String.format("SHOW TABLES FROM %s", config.getKeyspace());
Expand Down Expand Up @@ -194,12 +193,4 @@ protected static List<String> flattenAndConcat(List<List<String>> nestedList) {
.map(innerList -> String.join("", innerList))
.collect(Collectors.toList());
}

@VisibleForTesting
protected static List<String> intersect(List<String> list1, List<String> list2) {
List<String> intersection = new ArrayList<>(list1);
intersection.retainAll(list2);
return intersection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,4 @@ public void shouldFlattenAndConcat() {
List<List<String>> input = List.of(List.of("foo"), List.of("bar"));
assertThat(VitessMetadata.flattenAndConcat(input)).isEqualTo(expected);
}

@Test
public void shouldIntersect() {
assertThat(VitessMetadata.intersect(List.of("foo", "baz"), List.of("foo", "bar"))).isEqualTo(List.of("foo"));
}
}

0 comments on commit a055e2d

Please sign in to comment.