From 2dabc5cbc4d76c24114f5ee53b29bfe00e4a09a0 Mon Sep 17 00:00:00 2001 From: StekPerepolnen Date: Thu, 2 May 2024 16:28:05 +0000 Subject: [PATCH] autocomplete-improvement --- ydb/core/tx/scheme_board/cache.cpp | 38 ----------- ydb/core/tx/scheme_board/cache_ut.cpp | 27 -------- ydb/core/viewer/json_describe.h | 32 ++++------ ydb/core/viewer/viewer_ut.cpp | 92 ++++++++++++--------------- 4 files changed, 54 insertions(+), 135 deletions(-) diff --git a/ydb/core/tx/scheme_board/cache.cpp b/ydb/core/tx/scheme_board/cache.cpp index 797792383e5e..e036e5c9af0a 100644 --- a/ydb/core/tx/scheme_board/cache.cpp +++ b/ydb/core/tx/scheme_board/cache.cpp @@ -1603,36 +1603,6 @@ class TSchemeCache: public TMonitorableActor { break; } } - - // const auto& self = pathDesc.GetSelf(); - // bool needSysFolder = false; - // const auto& domainsInfo = AppData()->DomainsInfo; - // if (self.GetPathType() == NKikimrSchemeOp::EPathType::EPathTypeSubDomain || - // self.GetPathType() == NKikimrSchemeOp::EPathType::EPathTypeColumnStore || - // self.GetPathType() == NKikimrSchemeOp::EPathType::EPathTypeColumnTable) - // { - // needSysFolder = true; - // } else if (self.GetPathId() == NSchemeShard::RootPathId) { - // if (const auto& domain = domainsInfo->Domain; domain && domain->SchemeRoot == self.GetSchemeshardId()) { - // needSysFolder = true; - // } - // } - - // if (needSysFolder) { - // bool hasSysFolder = false; - - // const auto& children = pathDesc.GetChildren(); - // if (!children.empty()) { - // auto size = children.size(); - // if (children[size - 1].GetName() == NSysView::SysPathName) { - // hasSysFolder = true; - // } - // } - - // if (!hasSysFolder) { - // ListNodeEntry->Children.emplace_back(TString(NSysView::SysPathName), TPathId(self.GetSchemeshardId(), InvalidLocalPathId), TNavigate::KindPath); - // } - // } } } @@ -1948,7 +1918,6 @@ class TSchemeCache: public TMonitorableActor { << ", entry# " << entry.ToString() << ", props# " << props.ToString()); - Cerr << "IIII FillEntry " << Endl; TKeyDesc& keyDesc = *entry.KeyDescription; if (props.IsSync && props.Partial) { @@ -2203,16 +2172,13 @@ class TSchemeCache: public TMonitorableActor { TPathExtractor pathExtractor, TTabletIdExtractor tabletIdExtractor) { auto path = pathExtractor(entry); - Cerr << "IIII HandleEntry " << path << Endl; TCacheItem* cacheItem = Cache.FindPtr(path); if (!cacheItem) { - Cerr << "IIII !cacheItem " << Endl; const EPathType pathType = PathType(path); switch (pathType) { case EPathType::RegularPath: { - Cerr << "IIII RegularPath " << Endl; const ui64 tabletId = tabletIdExtractor(entry); if (tabletId == ui64(NSchemeShard::InvalidTabletId) || (tabletId >> 56) != 1) { return SetRootUnknown(context.Get(), entry); @@ -2246,13 +2212,11 @@ class TSchemeCache: public TMonitorableActor { break; } case EPathType::SysPath: - Cerr << "IIII SysPath " << Endl; cacheItem = &Cache.Upsert(path, TCacheItem(this, TSubscriber(), true)); cacheItem->FillAsSysPath(); break; case EPathType::SysLocksV1: case EPathType::SysLocksV2: - Cerr << "IIII SysLocks " << Endl; cacheItem = &Cache.Upsert(path, TCacheItem(this, TSubscriber(), true)); cacheItem->FillAsSysLocks(pathType == EPathType::SysLocksV2); break; @@ -2261,8 +2225,6 @@ class TSchemeCache: public TMonitorableActor { Cache.Promote(path); - Cerr << "IIII cacheItem->IsFilled() " << cacheItem->IsFilled() << Endl; - Cerr << "IIII !entry.SyncVersion " << !entry.SyncVersion << Endl; if (cacheItem->IsFilled() && !entry.SyncVersion) { cacheItem->FillEntry(context.Get(), entry); } diff --git a/ydb/core/tx/scheme_board/cache_ut.cpp b/ydb/core/tx/scheme_board/cache_ut.cpp index 2ee17c2124b4..18a0a781cd98 100644 --- a/ydb/core/tx/scheme_board/cache_ut.cpp +++ b/ydb/core/tx/scheme_board/cache_ut.cpp @@ -52,7 +52,6 @@ class TCacheTest: public TTestWithSchemeshard { UNIT_TEST(RacyRecreateAndSync); UNIT_TEST(RacyCreateAndSync); UNIT_TEST(CheckAccess); - UNIT_TEST(Check1000); UNIT_TEST(CheckSystemViewAccess); UNIT_TEST(SystemView); UNIT_TEST(SysLocks); @@ -73,7 +72,6 @@ class TCacheTest: public TTestWithSchemeshard { void RacyRecreateAndSync(); void RacyCreateAndSync(); void CheckAccess(); - void Check1000(); void CheckSystemViewAccess(); void SystemView(); void SysLocks(); @@ -302,21 +300,6 @@ void TCacheTest::CheckAccess() { TestNavigateByTableId(entry.TableId, TNavigate::EStatus::Ok, "/Root/DirA", "user0@builtin"); } -void TCacheTest::Check1000() { - ui64 txId = 100; - TestCreateSubDomain(*Context, ++txId, "/Root", "Name: \"SubDomainA\""); - TestWaitNotification(*Context, {txId}, CreateNotificationSubscriber(*Context, TTestTxConfig::SchemeShard)); - TestModifyACL(*Context, ++txId, "/Root", "SubDomainA", TString(), "user0@builtin"); - - auto entry = TestNavigate("/Root/SubDomainA", - TNavigate::EStatus::Ok, TString(), TNavigate::OpList, true, true, false); - - auto tableId = entry.TableId; - //UNIT_ASSERT_VALUES_EQUAL(tableId.SysViewInfo, "partition_stats"); - - //TestResolve(tableId, TResolve::EStatus::OkData); -} - void TCacheTest::CheckSystemViewAccess() { ui64 txId = 100; TestCreateSubDomain(*Context, ++txId, "/Root", "Name: \"SubDomainA\""); @@ -410,16 +393,6 @@ TNavigate::TEntry TCacheTest::TestNavigateImpl(THolder request, TNavi UNIT_ASSERT(!ev->Get()->Request->ResultSet.empty()); const TNavigate::TEntry result = ev->Get()->Request->ResultSet[0]; - - Cerr << "iiiii 1 " << Endl; - if (result.ListNodeEntry) { - Cerr << "iiiii 11 " << Endl; - Cerr << "iiiii size() " << result.ListNodeEntry->Children.size() << Endl; - for (auto& child: result.ListNodeEntry->Children) { - Cerr << "iiiii child.Name " << child.Name << Endl; - } - } - Cerr << "iiiii 2 " << Endl; UNIT_ASSERT_VALUES_EQUAL(result.Status, expectedStatus); return result; } diff --git a/ydb/core/viewer/json_describe.h b/ydb/core/viewer/json_describe.h index 244d85262b80..93103774ae21 100644 --- a/ydb/core/viewer/json_describe.h +++ b/ydb/core/viewer/json_describe.h @@ -66,25 +66,24 @@ class TJsonDescribe : public TViewerPipeClient { ExpandSubElements = FromStringWithDefault(params.Get("subs"), ExpandSubElements); InitConfig(params); - // if (params.Has("schemeshard_id")) { - // THolder request = MakeHolder(); - // FillParams(&request->Record, params); - // ui64 schemeShardId = FromStringWithDefault(params.Get("schemeshard_id")); - // SendRequestToPipe(ConnectTabletPipe(schemeShardId), request.Release()); - // } else { - // THolder request = MakeHolder(); - // FillParams(request->Record.MutableDescribePath(), params); - // request->Record.SetUserToken(Event->Get()->UserToken); - // SendRequest(MakeTxProxyID(), request.Release()); - // } - // ++Requests; + if (params.Has("schemeshard_id")) { + THolder request = MakeHolder(); + FillParams(&request->Record, params); + ui64 schemeShardId = FromStringWithDefault(params.Get("schemeshard_id")); + SendRequestToPipe(ConnectTabletPipe(schemeShardId), request.Release()); + } else { + THolder request = MakeHolder(); + FillParams(request->Record.MutableDescribePath(), params); + request->Record.SetUserToken(Event->Get()->UserToken); + SendRequest(MakeTxProxyID(), request.Release()); + } + ++Requests; if (params.Has("path")) { TAutoPtr request(new NSchemeCache::TSchemeCacheNavigate()); NSchemeCache::TSchemeCacheNavigate::TEntry entry; entry.Operation = NSchemeCache::TSchemeCacheNavigate::OpList; entry.SyncVersion = false; - entry.ShowPrivatePath = true; entry.Path = SplitPath(params.Get("path")); request->ResultSet.emplace_back(entry); SendRequest(MakeSchemeCacheID(), new TEvTxProxySchemeCache::TEvNavigateKeySet(request)); @@ -104,10 +103,8 @@ class TJsonDescribe : public TViewerPipeClient { } void Handle(TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev) { - Cerr << "aaaa TEvDescribeSchemeResult" << Endl; SchemeShardResult = ev->Release(); if (SchemeShardResult->GetRecord().GetStatus() == NKikimrScheme::EStatus::StatusSuccess) { - Cerr << "aaaa TEvDescribeSchemeResult 1" << Endl; ReplyAndPassAway(); } else { RequestDone("TEvDescribeSchemeResult"); @@ -115,7 +112,6 @@ class TJsonDescribe : public TViewerPipeClient { } void Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr &ev) { - Cerr << "aaaa TEvNavigateKeySetResult" << Endl; CacheResult = ev->Release(); RequestDone("TEvNavigateKeySetResult"); } @@ -237,13 +233,9 @@ class TJsonDescribe : public TViewerPipeClient { void ReplyAndPassAway() { TStringStream json; TString headers = Viewer->GetHTTPOKJSON(Event->Get()); - Cerr << "iiiiiiiiii ReplyAndPassAway" << Endl; - // Cerr << "iiiiiiiiii SchemeShardResult->GetRecord().GetStatus() " << SchemeShardResult->GetRecord().GetStatus() << Endl; if (SchemeShardResult != nullptr && SchemeShardResult->GetRecord().GetStatus() == NKikimrScheme::EStatus::StatusSuccess) { - Cerr << "iiiiiiiiii ReplyAndPassAway SchemeShardResult" << Endl; DescribeResult = GetSchemeShardDescribeSchemeInfo(); } else if (CacheResult != nullptr) { - Cerr << "iiiiiiiiii ReplyAndPassAway CacheResult" << Endl; NSchemeCache::TSchemeCacheNavigate *navigate = CacheResult->Request.Get(); Y_ABORT_UNLESS(navigate->ResultSet.size() == 1); if (navigate->ErrorCount == 0) { diff --git a/ydb/core/viewer/viewer_ut.cpp b/ydb/core/viewer/viewer_ut.cpp index 739bfd6f05c2..f6b1dc9a0f01 100644 --- a/ydb/core/viewer/viewer_ut.cpp +++ b/ydb/core/viewer/viewer_ut.cpp @@ -1049,64 +1049,55 @@ Y_UNIT_TEST_SUITE(Viewer) { UNIT_ASSERT_VALUES_EQUAL(LevenshteinDistance("/slice/db", "/slice/db26000"), 5); } - Y_UNIT_TEST(FuzzySearcher) - { - TVector dictionary = { "/slice", "/slice/db", "/slice/db26000" }; - - { - TVector expectations = { "/slice/db" }; - auto fuzzy = FuzzySearcher(dictionary); - auto result = fuzzy.Search("/slice/db", 1); - - UNIT_ASSERT_VALUES_EQUAL(expectations.size(), result.size()); - for (ui32 i = 0; i < expectations.size(); i++) { - UNIT_ASSERT_VALUES_EQUAL(expectations[i], result[i]); - } + TVector SimilarWordsDictionary = { "/slice", "/slice/db", "/slice/db26000" }; + TVector DifferentWordsDictionary = { "/orders", "/peoples", "/OrdinaryScheduleTables" }; + TVector DifferentWs = { "/.sys", "/.sys_health" }; + + void FuzzySearcherTest(TVector& dictionary, TString search, ui32 limit, TVector expectations) { + auto fuzzy = FuzzySearcher(dictionary); + auto result = fuzzy.Search(search, limit); + + UNIT_ASSERT_VALUES_EQUAL(expectations.size(), result.size()); + for (ui32 i = 0; i < expectations.size(); i++) { + Cerr << "expectations[i] " << expectations[i] << ", result[i] " << result[i] << Endl; + UNIT_ASSERT_VALUES_EQUAL(expectations[i], result[i]); } + } - { - TVector expectations = { "/slice/db", "/slice" }; - auto fuzzy = FuzzySearcher(dictionary); - auto result = fuzzy.Search("/slice/db", 2); - - UNIT_ASSERT_VALUES_EQUAL(expectations.size(), result.size()); - for (ui32 i = 0; i < expectations.size(); i++) { - UNIT_ASSERT_VALUES_EQUAL(expectations[i], result[i]); - } - } + Y_UNIT_TEST(FuzzySearcher10000) + { + FuzzySearcherTest(DifferentWs, "", 3, { "/.sys", "/.sys_health" }); + } - { - TVector expectations = { "/slice/db", "/slice", "/slice/db26000"}; - auto fuzzy = FuzzySearcher(dictionary); - auto result = fuzzy.Search("/slice/db", 3); + Y_UNIT_TEST(FuzzySearcherLimit1OutOf4) + { + FuzzySearcherTest(SimilarWordsDictionary, "/slice/db", 1, { "/slice/db" }); + } - UNIT_ASSERT_VALUES_EQUAL(expectations.size(), result.size()); - for (ui32 i = 0; i < expectations.size(); i++) { - UNIT_ASSERT_VALUES_EQUAL(expectations[i], result[i]); - } - } + Y_UNIT_TEST(FuzzySearcherLimit2OutOf4) + { + FuzzySearcherTest(SimilarWordsDictionary, "/slice/db", 2, { "/slice/db", "/slice/db26000" }); + } - { - TVector expectations = { "/slice/db", "/slice", "/slice/db26000" }; - auto fuzzy = FuzzySearcher(dictionary); - auto result = fuzzy.Search("/slice/db", 4); + Y_UNIT_TEST(FuzzySearcherLimit3OutOf4) + { + FuzzySearcherTest(SimilarWordsDictionary, "/slice/db", 3, { "/slice/db", "/slice/db26000", "/slice"}); + } - UNIT_ASSERT_VALUES_EQUAL(expectations.size(), result.size()); - for (ui32 i = 0; i < expectations.size(); i++) { - UNIT_ASSERT_VALUES_EQUAL(expectations[i], result[i]); - } - } + Y_UNIT_TEST(FuzzySearcherLimit4OutOf4) + { + FuzzySearcherTest(SimilarWordsDictionary, "/slice/db", 4, { "/slice/db", "/slice/db26000", "/slice"}); + } - { - TVector expectations = { "/slice/db26000", "/slice/db", "/slice" }; - auto fuzzy = FuzzySearcher(dictionary); - auto result = fuzzy.Search("/slice/db26001"); + Y_UNIT_TEST(FuzzySearcherLongWord) + { + FuzzySearcherTest(SimilarWordsDictionary, "/slice/db26001", 10, { "/slice/db26000", "/slice/db", "/slice"}); + } - UNIT_ASSERT_VALUES_EQUAL(expectations.size(), result.size()); - for (ui32 i = 0; i < expectations.size(); i++) { - UNIT_ASSERT_VALUES_EQUAL(expectations[i], result[i]); - } - } + Y_UNIT_TEST(FuzzySearcherPriority) + { + FuzzySearcherTest(DifferentWordsDictionary, "/ord", 10, { "/orders", "/OrdinaryScheduleTables", "/peoples"}); + FuzzySearcherTest(DifferentWordsDictionary, "Tables", 10, { "/OrdinaryScheduleTables", "/orders", "/peoples"}); } void JsonAutocompleteTest(HTTP_METHOD method, NJson::TJsonValue& value, TString prefix = "", TString database = "", TVector tables = {}, ui32 limit = 10, bool lowerCaseContentType = false) { @@ -1175,6 +1166,7 @@ Y_UNIT_TEST_SUITE(Viewer) { break; } case TEvTxProxySchemeCache::EvNavigateKeySetResult: { + Cerr << "iiiiiiiiiiiii EvNavigateKeySetResult 1" << Endl; auto *x = reinterpret_cast(&ev); (*x)->Get()->Request->ErrorCount = 0; for (auto& entry: (*x)->Get()->Request->ResultSet) {