Skip to content

Commit db7b127

Browse files
committed
System views creation in SchemeShard under FeatureFlag
1 parent 6be8671 commit db7b127

File tree

17 files changed

+579
-49
lines changed

17 files changed

+579
-49
lines changed

ydb/core/protos/feature_flags.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,5 @@ message TFeatureFlags {
211211
optional bool EnableNodeBrokerDeltaProtocol = 185 [default = false];
212212
optional bool EnableAccessToIndexImplTables = 186 [default = false];
213213
optional bool EnableAddUniqueIndex = 187 [default = false];
214+
optional bool EnableRealSystemViewPaths = 188 [default = true, (RequireRestart) = true];
214215
}

ydb/core/sys_view/common/events.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@ struct TEvSysView {
7878
EvCalculateStorageStatsRequest,
7979
EvCalculateStorageStatsResponse,
8080

81+
EvRosterUpdateFinished,
82+
8183
EvEnd,
8284
};
8385

86+
struct TEvRosterUpdateFinished : public TEventLocal<
87+
TEvRosterUpdateFinished,
88+
EvRosterUpdateFinished>
89+
{
90+
};
91+
8492
struct TEvSendPartitionStats : public TEventLocal<
8593
TEvSendPartitionStats,
8694
EvSendPartitionStats>

ydb/core/sys_view/common/schema.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ class TSystemViewResolver : public ISystemViewResolver {
210210
return result;
211211
}
212212

213+
const THashMap<TString, ESysViewType>& GetSystemViewsTypes(ETarget target) const override {
214+
switch (target) {
215+
case ETarget::Domain:
216+
return DomainSystemViewTypes;
217+
case ETarget::SubDomain:
218+
return SubDomainSystemViewTypes;
219+
case ETarget::OlapStore:
220+
return OlapStoreSystemViewTypes;
221+
case ETarget::ColumnTable:
222+
return ColumnTableSystemViewTypes;
223+
}
224+
}
225+
213226
bool IsSystemView(const TStringBuf viewName) const override final {
214227
return DomainSystemViews.contains(viewName) ||
215228
SubDomainSystemViews.contains(viewName) ||
@@ -255,13 +268,16 @@ class TSystemViewResolver : public ISystemViewResolver {
255268
template <typename Table>
256269
void RegisterSystemView(const TStringBuf& name, ESysViewType type) {
257270
TSchemaFiller<Table>::Fill(DomainSystemViews[name]);
271+
DomainSystemViewTypes[name] = type;
258272
TSchemaFiller<Table>::Fill(SubDomainSystemViews[name]);
273+
SubDomainSystemViewTypes[name] = type;
259274
TSchemaFiller<Table>::Fill(SystemViews[type]);
260275
}
261276

262277
template <typename Table>
263278
void RegisterDomainSystemView(const TStringBuf& name, ESysViewType type) {
264279
TSchemaFiller<Table>::Fill(DomainSystemViews[name]);
280+
DomainSystemViewTypes[name] = type;
265281
TSchemaFiller<Table>::Fill(SystemViews[type]);
266282
}
267283

@@ -332,9 +348,13 @@ class TSystemViewResolver : public ISystemViewResolver {
332348

333349
private:
334350
THashMap<TString, TSchema> DomainSystemViews;
351+
THashMap<TString, ESysViewType> DomainSystemViewTypes;
335352
THashMap<TString, TSchema> SubDomainSystemViews;
353+
THashMap<TString, ESysViewType> SubDomainSystemViewTypes;
336354
THashMap<TString, TSchema> OlapStoreSystemViews;
355+
THashMap<TString, ESysViewType> OlapStoreSystemViewTypes;
337356
THashMap<TString, TSchema> ColumnTableSystemViews;
357+
THashMap<TString, ESysViewType> ColumnTableSystemViewTypes;
338358
THashMap<ESysViewType, TSchema> SystemViews;
339359
};
340360

@@ -375,12 +395,18 @@ class TSystemViewRewrittenResolver : public ISystemViewResolver {
375395
return {};
376396
}
377397

398+
const THashMap<TString, ESysViewType>& GetSystemViewsTypes(ETarget target) const override {
399+
Y_UNUSED(target);
400+
return SystemViewTypes;
401+
}
402+
378403
bool IsSystemView(const TStringBuf viewName) const override final {
379404
return SystemViews.contains(viewName);
380405
}
381406

382407
private:
383408
THashMap<TString, TSchema> SystemViews;
409+
THashMap<TString, ESysViewType> SystemViewTypes;
384410
};
385411

386412
ISystemViewResolver* CreateSystemViewResolver() {

ydb/core/sys_view/common/schema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,8 @@ class ISystemViewResolver {
837837
virtual bool IsSystemView(const TStringBuf viewName) const = 0;
838838

839839
virtual TVector<TString> GetSystemViewNames(ETarget target) const = 0;
840+
841+
virtual const THashMap<TString, NKikimrSysView::ESysViewType>& GetSystemViewsTypes(ETarget target) const = 0;
840842
};
841843

842844
ISystemViewResolver* CreateSystemViewResolver();

ydb/core/testlib/basics/feature_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class TTestFeatureFlagsHolder {
7777
FEATURE_FLAG_SETTER(EnableDatabaseAdmin)
7878
FEATURE_FLAG_SETTER(EnablePermissionsExport)
7979
FEATURE_FLAG_SETTER(EnableShowCreate)
80+
FEATURE_FLAG_SETTER(EnableRealSystemViewPaths)
8081

8182
#undef FEATURE_FLAG_SETTER
8283
};

ydb/core/tx/scheme_board/cache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ class TSchemeCache: public TMonitorableActor<TSchemeCache> {
21522152
}
21532153
keyDesc.Partitioning = std::move(partitions);
21542154
} else {
2155-
if (Partitioning) {
2155+
if (Partitioning && !Partitioning->empty()) {
21562156
keyDesc.Partitioning = FillRangePartitioning(keyDesc.Range);
21572157
}
21582158
}

ydb/core/tx/schemeshard/schemeshard__operation_create_sysview.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class TCreateSysView : public TSubOperation {
105105
THolder<TProposeResponse> Propose(const TString& owner, TOperationContext& context) override {
106106
const TTabletId ssId = context.SS->SelfTabletId();
107107

108+
const auto acceptExisting = !Transaction.GetFailOnExist();
108109
const TString& parentPathStr = Transaction.GetWorkingDir();
109110
const auto& sysViewDescription = Transaction.GetCreateSysView();
110111

@@ -150,7 +151,7 @@ class TCreateSysView : public TSubOperation {
150151
if (dstPath.IsResolved()) {
151152
checks
152153
.NotUnderDeleting()
153-
.FailOnExist(TPathElement::EPathType::EPathTypeSysView, /* acceptAlreadyExist */ false);
154+
.FailOnExist(TPathElement::EPathType::EPathTypeSysView, acceptExisting);
154155
} else {
155156
checks
156157
.NotEmpty();

ydb/core/tx/schemeshard/schemeshard_impl.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "olap/bg_tasks/events/global.h"
66
#include "schemeshard__data_erasure_manager.h"
77

8+
#include <ydb/core/sys_view/common/path.h>
9+
#include <ydb/core/sys_view/common/schema.h>
810
#include <ydb/core/tablet_flat/tablet_flat_executed.h>
911
#include <ydb/core/tablet/tablet_counters_aggregator.h>
1012
#include <ydb/core/tablet/tablet_counters_protobuf.h>
@@ -22,6 +24,8 @@
2224
#include <ydb/core/scheme/scheme_types_proto.h>
2325
#include <ydb/core/tx/columnshard/bg_tasks/events/events.h>
2426
#include <ydb/core/tx/scheme_board/events_schemeshard.h>
27+
#include <ydb/core/tx/schemeshard/schemeshard_path.h>
28+
#include <ydb/core/tx/schemeshard/schemeshard_sysviews_update.h>
2529
#include <ydb/core/keyvalue/keyvalue_events.h>
2630
#include <ydb/library/login/password_checker/password_checker.h>
2731
#include <ydb/library/login/account_lockout/account_lockout.h>
@@ -71,6 +75,12 @@ bool ResolvePoolNames(
7175
return true;
7276
}
7377

78+
struct TDirectoryEntry {
79+
NKikimrSchemeOp::EPathType Type;
80+
TString Owner;
81+
TMaybe<NKikimrSysView::ESysViewType> SysViewType;
82+
};
83+
7484
} // anonymous namespace
7585

7686
const TSchemeLimits TSchemeShard::DefaultLimits = {};
@@ -85,6 +95,87 @@ void TSchemeShard::SubscribeToTempTableOwners() {
8595
}
8696
}
8797

98+
void TSchemeShard::CollectSysViewUpdates(const TActorContext& ctx) {
99+
TVector<std::pair<TTxId, TModifySysViewRequestInfo>> sysViewUpdates;
100+
101+
const TPath rootPath = TPath::Root(this);
102+
const TPath sysViewDirPath = rootPath.Child(TString(NSysView::SysPathName));
103+
bool needToMakeSysViewDir = false;
104+
TMap<TString, TDirectoryEntry> sysViewDirContents;
105+
106+
// make system view dir or collect its contents
107+
const bool isSysViewDirNameVacant = !sysViewDirPath.Check().IsResolved().NotDeleted().NotUnderDeleting();
108+
const bool sysViewDirExists = bool(sysViewDirPath.Check().IsResolved().NotDeleted().NotUnderDeleting().IsDirectory());
109+
if (isSysViewDirNameVacant) {
110+
needToMakeSysViewDir = true;
111+
TModifySysViewRequestInfo makeSysViewDirRequest;
112+
makeSysViewDirRequest.OperationType = NKikimrSchemeOp::ESchemeOpMkDir;
113+
makeSysViewDirRequest.WorkingDir = rootPath.PathString();
114+
makeSysViewDirRequest.TargetName = sysViewDirPath.LeafName();
115+
116+
sysViewUpdates.emplace_back(GetCachedTxId(ctx), std::move(makeSysViewDirRequest));
117+
} else if (sysViewDirExists) {
118+
for (const auto& [name, pathId] : sysViewDirPath->GetChildren()) {
119+
const TPath dirEntryPath = TPath::Init(pathId, this);
120+
const auto checks = dirEntryPath.Check();
121+
if (checks.IsResolved().NotDeleted().NotUnderDeleting()) {
122+
TDirectoryEntry dirEntry;
123+
dirEntry.Type = dirEntryPath->PathType;
124+
dirEntry.Owner = dirEntryPath->Owner;
125+
if (checks.IsSysView()) {
126+
dirEntry.SysViewType = SysViews.at(pathId)->Type;
127+
}
128+
129+
sysViewDirContents.emplace(name, std::move(dirEntry));
130+
}
131+
}
132+
}
133+
134+
const auto sysViewDirType = IsDomainSchemeShard
135+
? NSysView::ISystemViewResolver::ETarget::Domain
136+
: NSysView::ISystemViewResolver::ETarget::SubDomain;
137+
const auto sysViewsRegistry = NSysView::CreateSystemViewResolver()->GetSystemViewsTypes(sysViewDirType);
138+
139+
// create absent system views
140+
if (needToMakeSysViewDir || sysViewDirExists) {
141+
for (const auto& [name, type] : sysViewsRegistry) {
142+
if (!sysViewDirContents.contains(name)) {
143+
TModifySysViewRequestInfo createSysViewRequest;
144+
createSysViewRequest.OperationType = NKikimrSchemeOp::ESchemeOpCreateSysView;
145+
createSysViewRequest.WorkingDir = sysViewDirPath.PathString();
146+
createSysViewRequest.TargetName = name;
147+
createSysViewRequest.SysViewType = type;
148+
149+
sysViewUpdates.emplace_back(GetCachedTxId(ctx), std::move(createSysViewRequest));
150+
}
151+
}
152+
}
153+
154+
THashSet<NKikimrSysView::ESysViewType> availableSysViewTypes;
155+
for (const auto& type : std::views::values(sysViewsRegistry)) {
156+
availableSysViewTypes.insert(type);
157+
}
158+
159+
// drop obsolete system views
160+
for (const auto& [name, dirEntry] : sysViewDirContents) {
161+
if (dirEntry.Type == NKikimrSchemeOp::EPathTypeSysView) {
162+
if (!dirEntry.SysViewType || !availableSysViewTypes.contains(*dirEntry.SysViewType) ||
163+
(dirEntry.Owner == BUILTIN_ACL_METADATA && !sysViewsRegistry.contains(name))) {
164+
TModifySysViewRequestInfo dropSysViewRequest;
165+
dropSysViewRequest.OperationType = NKikimrSchemeOp::ESchemeOpDropSysView;
166+
dropSysViewRequest.WorkingDir = sysViewDirPath.PathString();
167+
dropSysViewRequest.TargetName = name;
168+
169+
sysViewUpdates.emplace_back(GetCachedTxId(ctx), std::move(dropSysViewRequest));
170+
}
171+
}
172+
}
173+
174+
if (!sysViewUpdates.empty()) {
175+
Register(CreateSysViewsRosterUpdate(static_cast<TTabletId>(TabletID()), SelfId(), std::move(sysViewUpdates)).Release());
176+
}
177+
}
178+
88179
void TSchemeShard::ActivateAfterInitialization(const TActorContext& ctx, TActivationOpts&& opts) {
89180
TPathId subDomainPathId = GetCurrentSubDomainPathId();
90181
TSubDomainInfo::TPtr domainPtr = ResolveDomainInfo(subDomainPathId);
@@ -6680,6 +6771,12 @@ void TSchemeShard::Handle(TEvTxAllocatorClient::TEvAllocateResult::TPtr& ev, con
66806771
for (auto txId: ev->Get()->TxIds) {
66816772
CachedTxIds.push_back(TTxId(txId));
66826773
}
6774+
6775+
if (AppData()->FeatureFlags.GetEnableRealSystemViewPaths() && !SysViewsRosterUpdateStarted) {
6776+
SysViewsRosterUpdateStarted = true;
6777+
CollectSysViewUpdates(ctx);
6778+
}
6779+
66836780
return;
66846781
} else if (Exports.contains(id)) {
66856782
return Execute(CreateTxProgressExport(ev), ctx);

ydb/core/tx/schemeshard/schemeshard_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ class TSchemeShard
380380
bool TopicPersistStatsPending = false;
381381
TStatsQueue<TEvPersQueue::TEvPeriodicTopicStats> TopicStatsQueue;
382382

383+
bool SysViewsRosterUpdateStarted = false;
384+
383385
TSet<TPathId> CleanDroppedPathsCandidates;
384386
TSet<TPathId> CleanDroppedSubDomainsCandidates;
385387
bool CleanDroppedPathsInFly = false;
@@ -915,6 +917,8 @@ class TSchemeShard
915917

916918
void SubscribeToTempTableOwners();
917919

920+
void CollectSysViewUpdates(const TActorContext& ctx);
921+
918922
void ActivateAfterInitialization(const TActorContext& ctx, TActivationOpts&& opts);
919923

920924
struct TTxInitPopulator;

0 commit comments

Comments
 (0)