-
Notifications
You must be signed in to change notification settings - Fork 735
YDB FQ: Support MDB MySQL in DatabaseResolver #6257
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
288deea
[add] mysql parser
skywalker-jpg 9ce3140
[add] parser
skywalker-jpg 5888f72
[refactor]
skywalker-jpg a08a9b9
[refactor]
skywalker-jpg 9ef5dc7
[refactor]
skywalker-jpg 6af292f
[refactor]
skywalker-jpg ee678e8
[refactor]
skywalker-jpg 4a854f9
[refactor]
skywalker-jpg 64420c6
Revert "lol"
skywalker-jpg 1fa1ebb
revert
skywalker-jpg 777d3fc
[revert]
skywalker-jpg 2c9b82c
[refactor]
skywalker-jpg 52087da
[refactor]
skywalker-jpg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -459,6 +459,53 @@ class TDatabaseResolver: public TActor<TDatabaseResolver> | |
|
|
||
| return TDatabaseDescription{"", endpoint.first, endpoint.second, "", useTls}; | ||
| }; | ||
| Parsers[NYql::EDatabaseType::MySQL] = []( | ||
| NJson::TJsonValue& databaseInfo, | ||
| const NYql::IMdbEndpointGenerator::TPtr& mdbEndpointGenerator, | ||
| bool useTls, | ||
| NConnector::NApi::EProtocol protocol | ||
| ) { | ||
| NYql::IMdbEndpointGenerator::TEndpoint endpoint; | ||
| TVector<TString> aliveHosts; | ||
|
|
||
|
|
||
| for (const auto& host : databaseInfo.GetMap().at("hosts").GetArraySafe()) { | ||
| const auto& hostMap = host.GetMap(); | ||
|
|
||
| if (!hostMap.contains("services")) { | ||
| // indicates that cluster is down | ||
| continue; | ||
| } | ||
|
|
||
| // check if all services of a particular host are alive | ||
| bool alive = std::all_of( | ||
|
||
| hostMap.at("services").GetArraySafe().begin(), | ||
| hostMap.at("services").GetArraySafe().end(), | ||
| [](const auto& service) { | ||
| return service["health"].GetString() == "ALIVE"; | ||
| } | ||
| ); | ||
|
|
||
| if (alive) { | ||
| aliveHosts.push_back(host["name"].GetString()); | ||
| } | ||
| } | ||
|
|
||
| if (aliveHosts.empty()) { | ||
| ythrow TCodeLineException(TIssuesIds::INTERNAL_ERROR) << "No ALIVE MySQL hosts found"; | ||
| } | ||
|
|
||
| NYql::IMdbEndpointGenerator::TParams params = { | ||
| .DatabaseType = NYql::EDatabaseType::MySQL, | ||
| .MdbHost = aliveHosts[std::rand() % static_cast<int>(aliveHosts.size())], | ||
| .UseTls = useTls, | ||
| .Protocol = protocol, | ||
| }; | ||
|
|
||
| endpoint = mdbEndpointGenerator->ToEndpoint(params); | ||
|
|
||
| return TDatabaseDescription{"", endpoint.first, endpoint.second, "", useTls}; | ||
| }; | ||
| } | ||
|
|
||
| static constexpr char ActorName[] = "YQ_DATABASE_RESOLVER"; | ||
|
|
@@ -538,7 +585,7 @@ class TDatabaseResolver: public TActor<TDatabaseResolver> | |
| url = TUrlBuilder(ev->Get()->YdbMvpEndpoint + "/database") | ||
| .AddUrlParam("databaseId", databaseId) | ||
| .Build(); | ||
| } else if (IsIn({NYql::EDatabaseType::ClickHouse, NYql::EDatabaseType::PostgreSQL}, databaseType)) { | ||
| } else if (IsIn({NYql::EDatabaseType::ClickHouse, NYql::EDatabaseType::PostgreSQL, NYql::EDatabaseType::MySQL}, databaseType)) { | ||
| YQL_ENSURE(ev->Get()->MdbGateway, "empty MDB Gateway"); | ||
| url = TUrlBuilder( | ||
| ev->Get()->MdbGateway + "/managed-" + NYql::DatabaseTypeLowercase(databaseType) + "/v1/clusters/") | ||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.