Skip to content

Commit

Permalink
autocomplete-improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
StekPerepolnen committed May 8, 2024
1 parent 0ee8bbf commit 2dabc5c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 135 deletions.
38 changes: 0 additions & 38 deletions ydb/core/tx/scheme_board/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,36 +1603,6 @@ class TSchemeCache: public TMonitorableActor<TSchemeCache> {
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);
// }
// }
}
}

Expand Down Expand Up @@ -1948,7 +1918,6 @@ class TSchemeCache: public TMonitorableActor<TSchemeCache> {
<< ", entry# " << entry.ToString()
<< ", props# " << props.ToString());

Cerr << "IIII FillEntry " << Endl;
TKeyDesc& keyDesc = *entry.KeyDescription;

if (props.IsSync && props.Partial) {
Expand Down Expand Up @@ -2203,16 +2172,13 @@ class TSchemeCache: public TMonitorableActor<TSchemeCache> {
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);
Expand Down Expand Up @@ -2246,13 +2212,11 @@ class TSchemeCache: public TMonitorableActor<TSchemeCache> {
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;
Expand All @@ -2261,8 +2225,6 @@ class TSchemeCache: public TMonitorableActor<TSchemeCache> {

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);
}
Expand Down
27 changes: 0 additions & 27 deletions ydb/core/tx/scheme_board/cache_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -73,7 +72,6 @@ class TCacheTest: public TTestWithSchemeshard {
void RacyRecreateAndSync();
void RacyCreateAndSync();
void CheckAccess();
void Check1000();
void CheckSystemViewAccess();
void SystemView();
void SysLocks();
Expand Down Expand Up @@ -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\"");
Expand Down Expand Up @@ -410,16 +393,6 @@ TNavigate::TEntry TCacheTest::TestNavigateImpl(THolder<TNavigate> 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;
}
Expand Down
32 changes: 12 additions & 20 deletions ydb/core/viewer/json_describe.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,24 @@ class TJsonDescribe : public TViewerPipeClient<TJsonDescribe> {
ExpandSubElements = FromStringWithDefault<ui32>(params.Get("subs"), ExpandSubElements);
InitConfig(params);

// if (params.Has("schemeshard_id")) {
// THolder<TEvSchemeShard::TEvDescribeScheme> request = MakeHolder<TEvSchemeShard::TEvDescribeScheme>();
// FillParams(&request->Record, params);
// ui64 schemeShardId = FromStringWithDefault<ui64>(params.Get("schemeshard_id"));
// SendRequestToPipe(ConnectTabletPipe(schemeShardId), request.Release());
// } else {
// THolder<TEvTxUserProxy::TEvNavigate> request = MakeHolder<TEvTxUserProxy::TEvNavigate>();
// FillParams(request->Record.MutableDescribePath(), params);
// request->Record.SetUserToken(Event->Get()->UserToken);
// SendRequest(MakeTxProxyID(), request.Release());
// }
// ++Requests;
if (params.Has("schemeshard_id")) {
THolder<TEvSchemeShard::TEvDescribeScheme> request = MakeHolder<TEvSchemeShard::TEvDescribeScheme>();
FillParams(&request->Record, params);
ui64 schemeShardId = FromStringWithDefault<ui64>(params.Get("schemeshard_id"));
SendRequestToPipe(ConnectTabletPipe(schemeShardId), request.Release());
} else {
THolder<TEvTxUserProxy::TEvNavigate> request = MakeHolder<TEvTxUserProxy::TEvNavigate>();
FillParams(request->Record.MutableDescribePath(), params);
request->Record.SetUserToken(Event->Get()->UserToken);
SendRequest(MakeTxProxyID(), request.Release());
}
++Requests;

if (params.Has("path")) {
TAutoPtr<NSchemeCache::TSchemeCacheNavigate> 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));
Expand All @@ -104,18 +103,15 @@ class TJsonDescribe : public TViewerPipeClient<TJsonDescribe> {
}

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");
}
}

void Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr &ev) {
Cerr << "aaaa TEvNavigateKeySetResult" << Endl;
CacheResult = ev->Release();
RequestDone("TEvNavigateKeySetResult");
}
Expand Down Expand Up @@ -237,13 +233,9 @@ class TJsonDescribe : public TViewerPipeClient<TJsonDescribe> {
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) {
Expand Down
92 changes: 42 additions & 50 deletions ydb/core/viewer/viewer_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,64 +1049,55 @@ Y_UNIT_TEST_SUITE(Viewer) {
UNIT_ASSERT_VALUES_EQUAL(LevenshteinDistance("/slice/db", "/slice/db26000"), 5);
}

Y_UNIT_TEST(FuzzySearcher)
{
TVector<TString> dictionary = { "/slice", "/slice/db", "/slice/db26000" };

{
TVector<TString> expectations = { "/slice/db" };
auto fuzzy = FuzzySearcher<TString>(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<TString> SimilarWordsDictionary = { "/slice", "/slice/db", "/slice/db26000" };
TVector<TString> DifferentWordsDictionary = { "/orders", "/peoples", "/OrdinaryScheduleTables" };
TVector<TString> DifferentWs = { "/.sys", "/.sys_health" };

void FuzzySearcherTest(TVector<TString>& dictionary, TString search, ui32 limit, TVector<TString> expectations) {
auto fuzzy = FuzzySearcher<TString>(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<TString> expectations = { "/slice/db", "/slice" };
auto fuzzy = FuzzySearcher<TString>(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<TString> expectations = { "/slice/db", "/slice", "/slice/db26000"};
auto fuzzy = FuzzySearcher<TString>(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<TString> expectations = { "/slice/db", "/slice", "/slice/db26000" };
auto fuzzy = FuzzySearcher<TString>(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<TString> expectations = { "/slice/db26000", "/slice/db", "/slice" };
auto fuzzy = FuzzySearcher<TString>(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<TString> tables = {}, ui32 limit = 10, bool lowerCaseContentType = false) {
Expand Down Expand Up @@ -1175,6 +1166,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
break;
}
case TEvTxProxySchemeCache::EvNavigateKeySetResult: {
Cerr << "iiiiiiiiiiiii EvNavigateKeySetResult 1" << Endl;
auto *x = reinterpret_cast<TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr*>(&ev);
(*x)->Get()->Request->ErrorCount = 0;
for (auto& entry: (*x)->Get()->Request->ResultSet) {
Expand Down

0 comments on commit 2dabc5c

Please sign in to comment.