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

Always add 'u-' prefix to the dedicated YDB database endpoint during resolving #4688

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions ydb/core/fq/libs/actors/database_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,20 @@ class TDatabaseResolver: public TActor<TDatabaseResolver>
Y_ENSURE(endpoint);

TVector<TString> split = StringSplitter(endpoint).Split(':');

Y_ENSURE(split.size() == 2);

return TDatabaseDescription{endpoint, split[0], FromString(split[1]), database, secure};
TString host = std::move(split[0]);
ui32 port = FromString(split[1]);

// There are two kinds of managed YDBs: serverless and dedicated.
// While working with dedicated databases, we have to use underlay network.
// That's why we add `u-` prefix to database fqdn.
if (bool isDedicatedDb = databaseInfo.GetMap().contains("dedicatedDatabase"); isDedicatedDb) {
vitalyisaev2 marked this conversation as resolved.
Show resolved Hide resolved
endpoint = "u-" + endpoint;
host = "u-" + host;
}

return TDatabaseDescription{endpoint, std::move(host), port, database, secure};
};
Parsers[NYql::EDatabaseType::Ydb] = ydbParser;
Parsers[NYql::EDatabaseType::DataStreams] = [ydbParser](
Expand All @@ -323,18 +333,14 @@ class TDatabaseResolver: public TActor<TDatabaseResolver>
bool useTls,
NConnector::NApi::EProtocol protocol)
{
bool isDedicatedDb = databaseInfo.GetMap().contains("storageConfig");
auto ret = ydbParser(databaseInfo, mdbEndpointGenerator, useTls, protocol);
// TODO: Take explicit field from MVP
bool isDedicatedDb = databaseInfo.GetMap().contains("storageConfig");
if (!isDedicatedDb && ret.Endpoint.StartsWith("ydb.")) {
// Replace "ydb." -> "yds."
ret.Endpoint[2] = 's';
ret.Host[2] = 's';
}
if (isDedicatedDb) {
ret.Endpoint = "u-" + ret.Endpoint;
ret.Host = "u-" + ret.Host;
}
return ret;
};
Parsers[NYql::EDatabaseType::ClickHouse] = [](
Expand Down
26 changes: 24 additions & 2 deletions ydb/core/fq/libs/actors/ut/database_resolver_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct TTestBootstrap : public TTestActorRuntime {
void CheckEqual(
const NHttp::TEvHttpProxy::TEvHttpOutgoingRequest& lhs,
const NHttp::TEvHttpProxy::TEvHttpOutgoingRequest& rhs) {
UNIT_ASSERT_EQUAL(lhs.Request->URL, rhs.Request->URL);
UNIT_ASSERT_EQUAL_C(lhs.Request->URL, rhs.Request->URL, "Compare: " << lhs.Request->URL << " " << rhs.Request->URL);
}

void CheckEqual(
Expand Down Expand Up @@ -234,6 +234,28 @@ Y_UNIT_TEST_SUITE(TDatabaseResolverTests) {
);
}

Y_UNIT_TEST(Ydb_Dedicated) {
Test(
NYql::EDatabaseType::Ydb,
NYql::NConnector::NApi::EProtocol::PROTOCOL_UNSPECIFIED,
"https://ydbc.ydb.cloud.yandex.net:8789/ydbc/cloud-prod/database?databaseId=etn021us5r9rhld1vgbh",
"200",
R"(
{
"endpoint":"grpcs://lb.etnbrtlini51k7cinbdr.ydb.mdb.yandexcloud.net:2135/?database=/ru-central1/b1gtl2kg13him37quoo6/etn021us5r9rhld1vgbh",
"dedicatedDatabase":{"resuorcePresetId": "medium"}
})",
NYql::TDatabaseResolverResponse::TDatabaseDescription{
TString{"u-lb.etnbrtlini51k7cinbdr.ydb.mdb.yandexcloud.net:2135"},
TString{"u-lb.etnbrtlini51k7cinbdr.ydb.mdb.yandexcloud.net"},
2135,
TString("/ru-central1/b1gtl2kg13him37quoo6/etn021us5r9rhld1vgbh"),
true
},
{}
);
}

Y_UNIT_TEST(DataStreams_Serverless) {
Test(
NYql::EDatabaseType::DataStreams,
Expand Down Expand Up @@ -264,7 +286,7 @@ Y_UNIT_TEST_SUITE(TDatabaseResolverTests) {
R"(
{
"endpoint":"grpcs://lb.etn021us5r9rhld1vgbh.ydb.mdb.yandexcloud.net:2135/?database=/ru-central1/b1g7jdjqd07qg43c4fmp/etn021us5r9rhld1vgbh",
"storageConfig":{"storageSizeLimit":107374182400}
"dedicatedDatabase":{"resuorcePresetId": "medium"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

думаю, тут норм был пример
и у тебя опечатка

Copy link
Member Author

Choose a reason for hiding this comment

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

Опечатку поправил. А по поводу того, что storageConfig заменился на dedicatedDatabase, я сознательно это сделал в парсере ответов, т. к. это выглядит более явно. Если в ответе API есть секция dedicatedDatabase, значит это со 100% вероятностью dedicated database. Со storageConfig это было не так очевидно.

})",
NYql::TDatabaseResolverResponse::TDatabaseDescription{
TString{"u-lb.etn021us5r9rhld1vgbh.ydb.mdb.yandexcloud.net:2135"},
Expand Down
Loading