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

support keyspace feature #6816

Merged
merged 23 commits into from
Mar 12, 2023
Merged

support keyspace feature #6816

merged 23 commits into from
Mar 12, 2023

Conversation

iosmanthus
Copy link
Contributor

@iosmanthus iosmanthus commented Feb 14, 2023

Signed-off-by: iosmanthus myosmanthustree@gmail.com

What problem does this PR solve?

Issue Number: close #6815

TiKV API v2: https://tikv.org/docs/dev/concepts/explore-tikv-features/api-v2/

Problem Summary:
Deps:

What is changed and how it works?

This pull request separates each keyspace's db/tables by rewriting their name with a keyspace prefix.
For example, table 1 in keyspace 2 is stored in a directory named: ks_2_t_1, and the same as the schema SQL file.

The keyspace's information is decoded from the region range in the writing process, and from gRPC requests context in the reading process. Every time TiFlash syncSchema, it needs a keyspace id parameter. The persistent schema will also contain the keyspace id in case of restarting the server.

This pull request also introduces a new config named api-version, whose default value is 1 meaning the node is working in the legacy mode. In this mode, schema info will be fetched in the bootstrap stage. If the api-version is 2, then the node is working in the keyspace mode, which will fetch schema lazily.

The pull request does not support the PageStoreV3 format and needs to be tested in V2 for now. In the future, the pull request should be compatible with the UniversalPageStore feature.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviours
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

support keyspace feature

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 14, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JaySon-Huang
  • flowbehappy

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Feb 14, 2023
@sre-bot
Copy link
Collaborator

sre-bot commented Feb 14, 2023

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 14, 2023
storages.emplace(table_id, storage);
storages.emplace(keyspace_table_id, storage);
auto [it, _] = keyspaces.try_emplace(keyspace_id, 0);
it->second++;
Copy link
Member

Choose a reason for hiding this comment

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

What is this counter used for?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I get it.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 16, 2023
Comment on lines +797 to +831
// If the table_info_json has no keyspace id, we use the keyspace_id_ as the default value.
if (keyspace_id == NullspaceID)
{
keyspace_id = keyspace_id_;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not always set keyspace_id = keyspace_Id_ ? Is there any case that you will create a TableInfo without passing a valid keyspace_id_ when using api_v2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense, this logic intends to use the original keyspace id if the JSON object parameter has a keyspace id field. But this might useless since there is no keyspace id in the upstream table schema.

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 16, 2023
@@ -40,35 +40,42 @@ SchemaSyncService::SchemaSyncService(DB::Context & context_)
handle = background_pool.addTask(
[&, this] {
String stage;
auto keyspaces = context.getTMTContext().getStorages().getAllKeyspaces();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it contain NullspaceID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it will contain Nullspace.

}
catch (const std::exception & e)
{
LOG_ERROR(log, "{} failed by {}", stage, e.what());
LOG_ERROR(log, "[keyspace {}] {} failed by {}", cur_ks, stage, e.what());
}
return false;
},
Copy link
Member

Choose a reason for hiding this comment

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

It's better make the task running interval be configurable.

@JaySon-Huang JaySon-Huang mentioned this pull request Feb 20, 2023
12 tasks
next_table_id = iter->first;
LOG_DEBUG(log, "End GC and next gc will start with table id: {}", next_table_id);

if (iter != storages.end())
Copy link
Member

Choose a reason for hiding this comment

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

This if statement always be true, this line check seems useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This statement will be false if there is no storage to GC, for example, the TiFlash instance just starts up and there is no schema syncing happening before it receives some r/w request. Otherwise, an undefined value will be logged.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 21, 2023
auto * log = &Poco::Logger::get("HandleHttpRequestSyncStatus");
LOG_DEBUG(log, "handling sync status request, path: {}, api_name: {}", path, api_name);

// Query schema: /keyspace/{keyspace_id}/table/{table_id}
Copy link
Contributor

Choose a reason for hiding this comment

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

do we keep the old query schema without keyspace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the TiFlash replica status might be uncheckable in the rolling upgrade, we support the old schema.

Copy link
Contributor

@JaySon-Huang JaySon-Huang left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, please create the PRs to client-c and kvproto

@iosmanthus
Copy link
Contributor Author

@JaySon-Huang all comments have been addressed, PTAL. ❤️ The kvproto and client-c's PRs are listed in the PR description.

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 9, 2023
@JaySon-Huang
Copy link
Contributor

/rebuild

@JaySon-Huang
Copy link
Contributor

The client-c hash is not updated to 04d408143e5ceb01799ec642560c39dc1a0a373f

@JaySon-Huang
Copy link
Contributor

why the tiflash-proxy hash is updated?

@iosmanthus
Copy link
Contributor Author

The client-c hash is not updated to 04d408143e5ceb01799ec642560c39dc1a0a373f

This has been done.

Copy link
Contributor

@JaySon-Huang JaySon-Huang left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 10, 2023
@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2023
Signed-off-by: JaySon-Huang <tshent@qq.com>
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2023
@JaySon-Huang
Copy link
Contributor

/merge

@ti-chi-bot

This comment was marked as outdated.

@ti-chi-bot

This comment was marked as outdated.

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2023
@flowbehappy
Copy link
Contributor

/merge

@ti-chi-bot

This comment was marked as outdated.

@JaySon-Huang
Copy link
Contributor

pending for pingcap/kvproto#1076

Signed-off-by: JaySon-Huang <tshent@qq.com>
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2023
@JaySon-Huang
Copy link
Contributor

/merge

@ti-chi-bot

This comment was marked as outdated.

@ti-chi-bot

This comment was marked as outdated.

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2023
Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2023
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

@JaySon-Huang: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: a25cb09

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 12, 2023
@iosmanthus
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

@iosmanthus: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

@iosmanthus: /merge is only allowed for the committers, you can assign this pull request to the committer in list by filling /assign @committer in the comment to help merge this pull request.

In response to this:

/merge

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot merged commit 835ad98 into pingcap:master Mar 12, 2023
@ystaticy ystaticy mentioned this pull request Dec 6, 2023
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TiFlash support keyspace
7 participants