Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBZ-8053 Handle empty shards #202

Merged
merged 5 commits into from
Jul 31, 2024
Merged

DBZ-8053 Handle empty shards #202

merged 5 commits into from
Jul 31, 2024

Conversation

twthorn
Copy link
Contributor

@twthorn twthorn commented Jul 11, 2024

DBZ-8053

In some cases, a Vitess keyspace can have empty shards (shards without tablets). Do the following to handle this:

  1. Provide a config exclude.empty.shards (boolean) to enable this behavior
  2. If enabled, and no shard list is specified, then auto detect the non-empty shards (shards with tablets)
  3. If enabled, and a shard list is specified, then route metadata queries (e.g., get tables) only to those listed shards. Although we could filter this to find the non-empty shards, we want to stay true to what the user configured (and fail loudly if a user is expecting to have a vstream for a certain set of shards, and some of those are empty). However, we can still route the queries such that they use the configured shards and do not risk failing because there are empty shards not in the list.
  4. For the detected non-empty shard list, use it for query routing and for setting up the vstreams.
  5. Refactor our metadata queries (eg getting shards/tables) into one class and do this empty shard handling there.

@twthorn
Copy link
Contributor Author

twthorn commented Jul 11, 2024

@jpechane can you take a look when you get the chance? thanks!

@jpechane
Copy link
Contributor

@twthorn Hi, I was OOO. Could you please rebase the PR on the latest main? Thanks

/**
* Class for getting metadata on Vitess, e.g., tables, shards. Supports shard-specific queries.
*/
public class VitessMetadata {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to convert this class to be no-static? A lot of methods uses VitessConnectorConfig so maybe an instance can be created that will receive the config in constructor.

@twthorn
Copy link
Contributor Author

twthorn commented Jul 29, 2024

@jpechane this is ready for re-review, thanks!

Copy link
Contributor

@jpechane jpechane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twthorn LGTM, thanks! I left just a couple of minor comments.

@@ -75,6 +76,21 @@ public Vtgate.ExecuteResponse execute(String sqlStatement) {
return newBlockingStub(channel).execute(request);
}

public Vtgate.ExecuteResponse execute(String sqlStatement, String shard) {
LOGGER.info("Executing sqlStament {}", sqlStatement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOGGER.info("Executing sqlStament {}", sqlStatement);
LOGGER.debug("Executing sqlStament {}", sqlStatement);


String target = String.format("%s:%s@%s", config.getKeyspace(), shard, config.getTabletType());
Vtgate.Session session = Vtgate.Session.newBuilder().setTargetString(target).setAutocommit(true).build();
LOGGER.info("Autocommit {}", session.getAutocommit());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOGGER.info("Autocommit {}", session.getAutocommit());
LOGGER.debug("Autocommit {}", session.getAutocommit());

@@ -1025,6 +1028,152 @@ public void shouldUseSameTransactionIdWhenMultiGrpcResponses() throws Exception
Testing.Print.enable();
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add a test to verify the behaviour when EXCLUDE_EMPTY_SHARDS is not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If EXCLUDE_EMPTY_SHARDS is not set, and we try to stream from the keyspace with an empty shard, it fails and brings down the test vitess instance, so subsequent unrelated tests would also fail. All other tests in the integration tests do not set this variable and it defaults to false so they are effectively testing it without EXCLUDE_EMPTY_SHARDS being set.

}

private static void logResponse(Vtgate.ExecuteResponse response, String query) {
LOGGER.info("Got response: {} for query: {}", response, query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOGGER.info("Got response: {} for query: {}", response, query);
LOGGER.debug("Got response: {} for query: {}", response, query);

}
}

private static List<String> getFlattenedRowsFromResponse(Vtgate.ExecuteResponse response) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make the rest of the methods non-static too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible, but I don't think we want to, since they don't rely on any instance variables. Static clearly conveys these methods do not rely on object state.

@twthorn twthorn requested a review from jpechane July 30, 2024 16:05
@jpechane jpechane merged commit c97042a into debezium:main Jul 31, 2024
3 checks passed
@jpechane
Copy link
Contributor

@twthorn Applied, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants