Skip to content

Commit

Permalink
Always add 'u-' prefix to the dedicated YDB database endpoint during …
Browse files Browse the repository at this point in the history
…resolving (ydb-platform#4715)
  • Loading branch information
vitalyisaev2 authored and kardymonds committed Jun 10, 2024
1 parent 3ff62df commit d16b7b6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
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 (databaseInfo.GetMap().contains("dedicatedDatabase")) {
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("dedicatedDatabase");
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 @@ -65,7 +65,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 @@ -233,6 +233,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 @@ -263,7 +285,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":{"resourcePresetId": "medium"}
})",
NYql::TDatabaseResolverResponse::TDatabaseDescription{
TString{"u-lb.etn021us5r9rhld1vgbh.ydb.mdb.yandexcloud.net:2135"},
Expand Down

0 comments on commit d16b7b6

Please sign in to comment.