diff options
author | komels <komels@ydb.tech> | 2022-09-22 22:06:49 +0300 |
---|---|---|
committer | komels <komels@ydb.tech> | 2022-09-22 22:06:49 +0300 |
commit | 98a1382db899fbe355299b2675734d5bf20adf19 (patch) | |
tree | fe4ee5395623e61300da52448759c37033f435b8 | |
parent | ba2a2a5b4931c54baa7a03996fe95e54bb11b62f (diff) | |
download | ydb-98a1382db899fbe355299b2675734d5bf20adf19.tar.gz |
Fix for topic names
-rw-r--r-- | ydb/library/persqueue/topic_parser/topic_parser.cpp | 24 | ||||
-rw-r--r-- | ydb/library/persqueue/topic_parser/ut/topic_names_converter_ut.cpp | 28 |
2 files changed, 44 insertions, 8 deletions
diff --git a/ydb/library/persqueue/topic_parser/topic_parser.cpp b/ydb/library/persqueue/topic_parser/topic_parser.cpp index 72fa54f93a..88c94dcc76 100644 --- a/ydb/library/persqueue/topic_parser/topic_parser.cpp +++ b/ydb/library/persqueue/topic_parser/topic_parser.cpp @@ -18,6 +18,18 @@ bool IsPathPrefix(TStringBuf normPath, TStringBuf prefix) { } +void SkipPathPrefix(TStringBuf& path, const TStringBuf& prefix) { + auto copy = path; + if (prefix.EndsWith('/')) { + path.SkipPrefix(prefix); + } else { + auto skip = path.SkipPrefix(prefix) && path.SkipPrefix("/"); + if (!skip) { + path = copy; + } + } +} + namespace { TString FullPath(const TMaybe<TString>& database, const TString& path) { if (database.Defined() && !path.StartsWith(*database) && !path.Contains('\0')) { @@ -193,21 +205,17 @@ void TDiscoveryConverter::BuildForFederation(const TStringBuf& databaseBuf, TStr if (IsPathPrefix(PQPrefix, databaseBuf)) { isRootDb = true; root = PQPrefix; - topicPath.SkipPrefix(PQPrefix); - topicPath.SkipPrefix("/"); + SkipPathPrefix(topicPath, PQPrefix); } else { - topicPath.SkipPrefix(databaseBuf); - topicPath.SkipPrefix("/"); + SkipPathPrefix(topicPath, databaseBuf); } } else if (IsPathPrefix(topicPath, PQPrefix)) { isRootDb = true; - topicPath.SkipPrefix(PQPrefix); - topicPath.SkipPrefix("/"); + SkipPathPrefix(topicPath, PQPrefix); root = PQPrefix; } if (!isRootDb) { - topicPath.SkipPrefix(databaseBuf); - topicPath.SkipPrefix("/"); + SkipPathPrefix(topicPath, databaseBuf); Database = databaseBuf; } diff --git a/ydb/library/persqueue/topic_parser/ut/topic_names_converter_ut.cpp b/ydb/library/persqueue/topic_parser/ut/topic_names_converter_ut.cpp index c8e3bbc804..118c81063b 100644 --- a/ydb/library/persqueue/topic_parser/ut/topic_names_converter_ut.cpp +++ b/ydb/library/persqueue/topic_parser/ut/topic_names_converter_ut.cpp @@ -140,6 +140,34 @@ Y_UNIT_TEST_SUITE(DiscoveryConverterTest) { // UNIT_ASSERT_VALUES_EQUAL(wrapper.GetClientsideName(), "rt3.dc3--account@dir1@dir2--topic"); } + Y_UNIT_TEST(CmWay) { + auto converterFactory = NPersQueue::TTopicNamesConverterFactory( + false, "/Root/PQ", "dc1", false + ); + auto converter = converterFactory.MakeDiscoveryConverter( + "account/account-topic", {}, "dc1", "account" + ); + UNIT_ASSERT_VALUES_EQUAL(converter->GetFullModernName(), "account-topic-mirrored-from-dc1"); + + converter = converterFactory.MakeDiscoveryConverter( + "account/topic", {}, "dc1", "account" + ); + UNIT_ASSERT_VALUES_EQUAL(converter->GetFullModernName(), "topic-mirrored-from-dc1"); + + converterFactory = NPersQueue::TTopicNamesConverterFactory( + false, "/Root/PQ", "dc1", true + ); + converter = converterFactory.MakeDiscoveryConverter( + "account/topic", {}, "dc1", "account" + ); + UNIT_ASSERT_VALUES_EQUAL(converter->GetFullModernName(), "topic"); + + converter = converterFactory.MakeDiscoveryConverter( + "account/account-topic", {}, "dc1", "account" + ); + UNIT_ASSERT_VALUES_EQUAL(converter->GetFullModernName(), "account-topic"); + + } Y_UNIT_TEST(FirstClass) { TConverterTestWrapper wrapper(true, "", ""); |