Skip to content

Commit 7da0fc7

Browse files
committed
loop filter apply
1 parent 3e4b81c commit 7da0fc7

File tree

8 files changed

+298
-33
lines changed

8 files changed

+298
-33
lines changed

ydb/core/sys_view/auth/auth_scan_base.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class TAuthScanBase : public TScanActorBase<TDerived> {
5757
, RequireUserAdministratorAccess(requireUserAdministratorAccess)
5858
{
5959
if (applyPathTableRange) {
60-
if (auto cell = TBase::GetCellFrom(0)) {
61-
PathFrom = cell->AsBuf();
60+
if (auto cellsFrom = TBase::TableRange.From.GetCells(); cellsFrom.size() > 0 && !cellsFrom[0].IsNull()) {
61+
PathFrom = cellsFrom[0].AsBuf();
6262
}
63-
if (auto cell = TBase::GetCellTo(0)) {
64-
PathTo = cell->AsBuf();
63+
if (auto cellsTo = TBase::TableRange.To.GetCells(); cellsTo.size() > 0 && !cellsTo[0].IsNull()) {
64+
PathTo = cellsTo[0].AsBuf();
6565
}
6666
}
6767
}

ydb/core/sys_view/auth/group_members.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class TGroupMembersScan : public TAuthScanBase<TGroupMembersScan> {
3434
TVector<std::pair<const TDomainInfo::TGroup*, const TString*>> memberships;
3535
for (const auto& group : entry.DomainInfo->Groups) {
3636
for (const auto& member : group.Members) {
37-
memberships.emplace_back(&group, &member);
37+
if (StringKeyIsInTableRange({group.Sid, member})) {
38+
memberships.emplace_back(&group, &member);
39+
}
3840
}
3941
}
4042
SortBatch(memberships, [](const auto& left, const auto& right) {

ydb/core/sys_view/auth/groups.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ class TGroupsScan : public TAuthScanBase<TGroupsScan> {
3333

3434
TVector<const TDomainInfo::TGroup*> groups(::Reserve(entry.DomainInfo->Groups.size()));
3535
for (const auto& group : entry.DomainInfo->Groups) {
36-
if (!OneCellStringKeyIsInTableRange(group.Sid)) {
37-
continue;
36+
if (StringKeyIsInTableRange({group.Sid})) {
37+
groups.push_back(&group);
3838
}
39-
groups.push_back(&group);
4039
}
4140
SortBatch(groups, [](const auto* left, const auto* right) {
4241
return left->Sid < right->Sid;

ydb/core/sys_view/auth/owners.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TOwnersScan : public TAuthScanBase<TOwnersScan> {
3434

3535
auto entryPath = CanonizePath(entry.Path);
3636

37-
if (OneCellStringKeyIsInTableRange(entryPath)) {
37+
if (StringKeyIsInTableRange({entryPath})) {
3838
for (auto& column : Columns) {
3939
switch (column.Tag) {
4040
case Schema::AuthOwners::Path::ColumnId:

ydb/core/sys_view/auth/permissions.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class TPermissionsScan : public TAuthScanBase<TPermissionsScan> {
3636
batch.Finished = false;
3737
return;
3838
}
39+
40+
auto entryPath = CanonizePath(entry.Path);
3941

4042
TVector<std::pair<TString, TString>> permissions;
4143
for (const NACLibProto::TACE& ace : entry.SecurityObject->GetACL().GetACE()) {
@@ -45,10 +47,15 @@ class TPermissionsScan : public TAuthScanBase<TPermissionsScan> {
4547
if (!Effective && ace.GetInherited()) {
4648
continue;
4749
}
50+
if (!ace.HasSID()) {
51+
continue;
52+
}
4853

4954
auto acePermissions = ConvertACLMaskToYdbPermissionNames(ace.GetAccessRight());
5055
for (const auto& permission : acePermissions) {
51-
permissions.emplace_back(ace.HasSID() ? ace.GetSID() : TString{}, std::move(permission));
56+
if (StringKeyIsInTableRange({entryPath, ace.GetSID(), permission})) {
57+
permissions.emplace_back(ace.GetSID(), std::move(permission));
58+
}
5259
}
5360
}
5461
// Note: due to rights inheritance permissions may be duplicated
@@ -59,8 +66,6 @@ class TPermissionsScan : public TAuthScanBase<TPermissionsScan> {
5966

6067
TVector<TCell> cells(::Reserve(Columns.size()));
6168

62-
auto entryPath = CanonizePath(entry.Path);
63-
6469
for (const auto& [sid, permission] : permissions) {
6570
for (auto& column : Columns) {
6671
switch (column.Tag) {

ydb/core/sys_view/auth/users.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class TUsersScan : public TScanActorBase<TUsersScan> {
8989
if (!user.HasName() || !CanAccessUser(user.GetName())) {
9090
continue;
9191
}
92-
if (!OneCellStringKeyIsInTableRange(user.GetName())) {
92+
if (!StringKeyIsInTableRange({user.GetName()})) {
9393
continue;
9494
}
9595
users.push_back(&user);

ydb/core/sys_view/common/scan_actor_base_impl.h

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,52 @@ class TScanActorBase : public TActorBootstrapped<TDerived> {
162162
SendBatch(std::move(batch));
163163
}
164164

165-
std::optional<TCell> GetCellFrom(size_t index) const {
166-
return GetCell(TableRange.From.GetCells(), index);
167-
}
168-
169-
std::optional<TCell> GetCellTo(size_t index) const {
170-
return GetCell(TableRange.To.GetCells(), index);
171-
}
172-
173-
bool OneCellStringKeyIsInTableRange(const TString value) const {
174-
if (auto pathFrom = GetCellFrom(0); pathFrom) {
175-
if (int cmp = pathFrom->AsBuf().compare(value); cmp > 0 || cmp == 0 && !TableRange.FromInclusive) {
165+
bool StringKeyIsInTableRange(const TVector<TString>& key) const {
166+
{
167+
bool equalPrefixes = true;
168+
for (size_t index : xrange(Min(TableRange.From.GetCells().size(), key.size()))) {
169+
if (auto cellFrom = TableRange.From.GetCells()[index]; !cellFrom.IsNull()) {
170+
int cmp = cellFrom.AsBuf().compare(key[index]);
171+
if (cmp < 0) {
172+
equalPrefixes = false;
173+
break;
174+
}
175+
if (cmp > 0) {
176+
return false;
177+
}
178+
// cmp == 0, prefixes are equal, go further
179+
} else {
180+
equalPrefixes = false;
181+
break;
182+
}
183+
}
184+
if (equalPrefixes && !TableRange.FromInclusive) {
176185
return false;
177186
}
178187
}
179-
if (auto pathTo = GetCellTo(0); pathTo) {
180-
if (int cmp = pathTo->AsBuf().compare(value); cmp < 0 || cmp == 0 && !TableRange.ToInclusive) {
188+
189+
if (TableRange.To.GetCells().size()) {
190+
bool equalPrefixes = true;
191+
for (size_t index : xrange(Min(TableRange.To.GetCells().size(), key.size()))) {
192+
if (auto cellTo = TableRange.To.GetCells()[index]; !cellTo.IsNull()) {
193+
int cmp = cellTo.AsBuf().compare(key[index]);
194+
if (cmp > 0) {
195+
equalPrefixes = false;
196+
break;
197+
}
198+
if (cmp < 0) {
199+
return false;
200+
}
201+
// cmp == 0, prefixes are equal, go further
202+
} else {
203+
break;
204+
}
205+
}
206+
if (equalPrefixes && !TableRange.ToInclusive) {
181207
return false;
182208
}
183209
}
210+
184211
return true;
185212
}
186213

@@ -331,13 +358,6 @@ class TScanActorBase : public TActorBootstrapped<TDerived> {
331358
}
332359
}
333360

334-
std::optional<TCell> GetCell(TConstArrayRef<TCell> cells, size_t index) const {
335-
if (index < cells.size() && !cells[index].IsNull()) {
336-
return cells[index];
337-
}
338-
return {};
339-
}
340-
341361
protected:
342362
static constexpr TDuration Timeout = TDuration::Seconds(60);
343363

0 commit comments

Comments
 (0)