Skip to content

Commit bcd70e0

Browse files
authored
Added user message for incorrect connection_string (without database) (#26452)
1 parent 1f4f03e commit bcd70e0

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed

ydb/core/kqp/host/kqp_gateway_proxy.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,10 @@ class TKqpGatewayProxy : public IKikimrGateway {
25902590
consistency->Serialize(*config.MutableConsistencySettings()->MutableGlobal());
25912591
}
25922592

2593+
if (params.GetDatabase().empty()) {
2594+
return MakeFuture(ResultFromError<TGenericResult>("Database is not specified"));
2595+
}
2596+
25932597
auto& targets = *config.MutableSpecific();
25942598
for (const auto& [src, dst] : settings.Targets) {
25952599
auto& target = *targets.AddTargets();
@@ -2665,6 +2669,10 @@ class TKqpGatewayProxy : public IKikimrGateway {
26652669
params.SetEndpoint(TString{parseResult.Endpoint});
26662670
params.SetDatabase(TString{parseResult.Database});
26672671
params.SetEnableSsl(parseResult.EnableSsl);
2672+
2673+
if (params.GetDatabase().empty()) {
2674+
return MakeFuture(ResultFromError<TGenericResult>("Database is not specified"));
2675+
}
26682676
}
26692677
if (const auto& endpoint = settings.Settings.Endpoint) {
26702678
params.SetEndpoint(*endpoint);
@@ -2797,6 +2805,10 @@ class TKqpGatewayProxy : public IKikimrGateway {
27972805
params.SetCaCert(*caCert);
27982806
}
27992807

2808+
if (!params.GetEndpoint().empty() && params.GetDatabase().empty()) {
2809+
return MakeFuture(ResultFromError<TGenericResult>("Database is not specified"));
2810+
}
2811+
28002812
{
28012813
const auto& [src, dst, lambda] = settings.Target;
28022814
auto& target = *config.MutableTransferSpecific()->MutableTarget();
@@ -2900,6 +2912,10 @@ class TKqpGatewayProxy : public IKikimrGateway {
29002912
params.SetEndpoint(TString{parseResult.Endpoint});
29012913
params.SetDatabase(TString{parseResult.Database});
29022914
params.SetEnableSsl(parseResult.EnableSsl);
2915+
2916+
if (params.GetDatabase().empty()) {
2917+
return MakeFuture(ResultFromError<TGenericResult>("Database is not specified"));
2918+
}
29032919
}
29042920
if (const auto& endpoint = settings.Settings.Endpoint) {
29052921
params.SetEndpoint(*endpoint);

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10272,7 +10272,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
1027210272
CREATE TRANSFER `/Root/transfer_fi`
1027310273
FROM `/Root/topic` TO `/Root/table` USING ($x) -> { RETURN <| id:$x._offset |> }
1027410274
WITH (
10275-
CONNECTION_STRING = "%s",
10275+
CONNECTION_STRING = "%s/?database=/Root",
1027610276
FLUSH_INTERVAL = Interval('PT1S')
1027710277
);
1027810278
)", kikimr.GetEndpoint().c_str());
@@ -10461,6 +10461,21 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
1046110461
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToOneLineString(), "flush_interval must be Interval");
1046210462
}
1046310463

10464+
{
10465+
auto query = R"(
10466+
--!syntax_v1
10467+
CREATE TRANSFER `/Root/transfer`
10468+
FROM `/Root/topic` TO `/Root/table` USING ($x) -> { RETURN <| id:$x._offset |> }
10469+
WITH (
10470+
CONNECTION_STRING = "grpc://localhost:2135?database=/Root"
10471+
);
10472+
)";
10473+
10474+
const auto result = session.ExecuteQuery(query, NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
10475+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString());
10476+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToOneLineString(), "Database is not specified");
10477+
}
10478+
1046410479
{
1046510480
auto query = R"(
1046610481
--!syntax_v1
@@ -10560,7 +10575,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
1056010575
CREATE TRANSFER `/Root/transfer_fi`
1056110576
FROM `/Root/topic` TO `/Root/table` USING ($x) -> { RETURN <| id:$x._offset |> }
1056210577
WITH (
10563-
CONNECTION_STRING = "%s",
10578+
CONNECTION_STRING = "%s/?database=/Root",
1056410579
FLUSH_INTERVAL = Interval('PT1S')
1056510580
);
1056610581
)", kikimr.GetEndpoint().c_str());
@@ -10747,7 +10762,8 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
1074710762
--!syntax_v1
1074810763
ALTER TRANSFER `/Root/transfer`
1074910764
SET (
10750-
ENDPOINT = "localhost:2136"
10765+
ENDPOINT = "localhost:2136",
10766+
DATABASE = "/Root"
1075110767
);
1075210768
)";
1075310769

@@ -11133,7 +11149,8 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
1113311149
--!syntax_v1
1113411150
ALTER TRANSFER `/Root/transfer`
1113511151
SET (
11136-
ENDPOINT = "localhost:2136"
11152+
ENDPOINT = "localhost:2136",
11153+
DATABASE = "/Root"
1113711154
);
1113811155
)";
1113911156

ydb/core/transfer/ut/functional/transfer_ut.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Y_UNIT_TEST_SUITE(Transfer)
9292
CREATE TRANSFER %s
9393
FROM %s TO %s USING $l
9494
WITH (
95-
CONNECTION_STRING = "grp§c://localhost:2135"
95+
CONNECTION_STRING = "grp§c://localhost:2135/?database=/Root"
9696
)
9797
)", testCase.TransferName.data(), testCase.TopicName.data(), testCase.TableName.data()));
9898

@@ -130,7 +130,7 @@ Y_UNIT_TEST_SUITE(Transfer)
130130
CREATE TRANSFER %s
131131
FROM %s TO %s USING $l
132132
WITH (
133-
CONNECTION_STRING = "grpc://domain-not-exists-localhost.com.moc:2135"
133+
CONNECTION_STRING = "grpc://domain-not-exists-localhost.com.moc:2135/?database=/Root"
134134
)
135135
)", testCase.TransferName.data(), testCase.TopicName.data(), testCase.TableName.data()));
136136

@@ -992,6 +992,46 @@ Y_UNIT_TEST_SUITE(Transfer)
992992
CreateTransferSourceNotExists(true);
993993
}
994994

995+
void CreateTransferSourceDirNotExists(bool localTopic)
996+
{
997+
MainTestCase testCase;
998+
testCase.CreateTable(R"(
999+
CREATE TABLE `%s` (
1000+
Key Uint64 NOT NULL,
1001+
Message Utf8 NOT NULL,
1002+
PRIMARY KEY (Key)
1003+
) WITH (
1004+
STORE = ROW
1005+
);
1006+
)");
1007+
1008+
auto settings = MainTestCase::CreateTransferSettings::WithLocalTopic(localTopic);
1009+
settings.TopicName = "dir_not_exists/topic_name";
1010+
testCase.CreateTransfer(R"(
1011+
$l = ($x) -> {
1012+
return [
1013+
<|
1014+
Key:CAST($x._offset AS Uint64),
1015+
Message:CAST($x._data AS Utf8)
1016+
|>
1017+
];
1018+
};
1019+
)", settings);
1020+
1021+
testCase.CheckTransferStateError("Discovery error:");
1022+
1023+
testCase.DropTransfer();
1024+
testCase.DropTable();
1025+
}
1026+
1027+
Y_UNIT_TEST(CreateTransferSourceDirNotExists) {
1028+
CreateTransferSourceDirNotExists(false);
1029+
}
1030+
1031+
Y_UNIT_TEST(CreateTransferSourceDirNotExists_LocalTopic) {
1032+
CreateTransferSourceDirNotExists(true);
1033+
}
1034+
9951035
void TransferSourceDropped(bool localTopic)
9961036
{
9971037
MainTestCase testCase;

ydb/core/tx/replication/controller/replication.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class TReplication::TImpl: public TLagProvider {
159159

160160
if (endpoint.empty()) {
161161
ydbProxy.Reset(CreateLocalYdbProxy(Database));
162+
} else if (database.empty()) {
163+
ErrorState("Database is not specified.");
162164
} else {
163165
switch (params.GetCredentialsCase()) {
164166
case NKikimrReplication::TConnectionParams::kStaticCredentials:

0 commit comments

Comments
 (0)