1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
|
#include "console_configs_manager.h"
#include "console_configs_provider.h"
#include "console_impl.h"
#include "http.h"
#include <ydb/core/cms/console/validators/registry.h>
#include <ydb/library/yql/public/issue/protos/issue_severity.pb.h>
#include <util/generic/bitmap.h>
#include <util/random/random.h>
#include <util/string/split.h>
namespace NKikimr {
namespace NConsole {
void TConfigsManager::ClearState()
{
ConfigIndex.Clear();
}
void TConfigsManager::SetConfig(const NKikimrConsole::TConfigsConfig &config)
{
Config.Parse(config);
if (ConfigsProvider)
Send(ConfigsProvider, new TConfigsProvider::TEvPrivate::TEvSetConfig(Config));
}
bool TConfigsManager::CheckConfig(const NKikimrConsole::TConfigsConfig &config,
Ydb::StatusIds::StatusCode &code,
TString &error)
{
if (!TConfigsConfig::Check(config, error)) {
code = Ydb::StatusIds::BAD_REQUEST;
return false;
}
TConfigsConfig newConfig;
newConfig.Parse(config);
for (auto &pr : ConfigIndex.GetConfigItems()) {
if (!IsConfigItemScopeAllowed(pr.second, newConfig)) {
code = Ydb::StatusIds::BAD_REQUEST;
error = "config conflicts with usage scope of " + pr.second->ToString();
return false;
}
}
return true;
}
void TConfigsManager::Bootstrap(const TActorContext &ctx)
{
LOG_DEBUG(ctx, NKikimrServices::CMS_CONFIGS, "TConfigsManager::Bootstrap");
Become(&TThis::StateWork);
TxProcessor = Self.GetTxProcessor()->GetSubProcessor("configs",
ctx,
false,
NKikimrServices::CMS_CONFIGS);
ConfigsProvider = ctx.Register(new TConfigsProvider(ctx.SelfID));
}
void TConfigsManager::Detach()
{
Send(ConfigsProvider, new TEvents::TEvPoisonPill);
PassAway();
}
void TConfigsManager::ApplyPendingConfigModifications(const TActorContext &ctx,
TAutoPtr<IEventHandle> ev)
{
LOG_DEBUG(ctx, NKikimrServices::CMS_CONFIGS, "Applying pending config modifications");
for (auto id : PendingConfigModifications.RemovedItems)
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS, "Remove " << ConfigIndex.GetItem(id)->ToString());
for (auto &pr : PendingConfigModifications.ModifiedItems)
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS, "Remove modified " << pr.second->ToString());
for (auto &pr : PendingConfigModifications.ModifiedItems)
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS, "Add modified " << pr.second->ToString());
for (auto item : PendingConfigModifications.AddedItems)
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS, "Add new " << item->ToString());
PendingConfigModifications.ApplyTo(ConfigIndex);
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS, "Send configs update to configs provider.");
auto req = MakeHolder<TConfigsProvider::TEvPrivate::TEvUpdateConfigs>(PendingConfigModifications, ev);
ctx.Send(ConfigsProvider, req.Release());
PendingConfigModifications.Clear();
}
void TConfigsManager::ApplyPendingSubscriptionModifications(const TActorContext &ctx,
TAutoPtr<IEventHandle> ev)
{
LOG_DEBUG(ctx, NKikimrServices::CMS_CONFIGS, "Applying pending subscription midifications");
for (auto &id : PendingSubscriptionModifications.RemovedSubscriptions) {
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS,
"Remove subscription " << SubscriptionIndex.GetSubscription(id)->ToString());
SubscriptionIndex.RemoveSubscription(id);
}
for (auto &subscription : PendingSubscriptionModifications.AddedSubscriptions) {
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS,
"Add subscription " << subscription->ToString());
SubscriptionIndex.AddSubscription(subscription);
}
for (auto &pr : PendingSubscriptionModifications.ModifiedLastProvided) {
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS,
"Modify last provided config for subscription id=" << pr.first
<< " lastprovidedconfig=" << pr.second.ToString());
SubscriptionIndex.GetSubscription(pr.first)->LastProvidedConfig = pr.second;
}
for (auto &pr : PendingSubscriptionModifications.ModifiedCookies) {
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS,
"Modify cookie for subscription id=" << pr.first
<< " cookie=" << pr.second);
SubscriptionIndex.GetSubscription(pr.first)->Cookie = pr.second;
}
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS, "Send subscriptions update to configs provider.");
auto req = MakeHolder<TConfigsProvider::TEvPrivate::TEvUpdateSubscriptions>(PendingSubscriptionModifications, ev);
ctx.Send(ConfigsProvider, req.Release());
PendingSubscriptionModifications.Clear();
}
bool TConfigsManager::MakeNewSubscriptionChecks(TSubscription::TPtr subscription,
Ydb::StatusIds::StatusCode &code,
TString &error)
{
if (subscription->Id) {
code = Ydb::StatusIds::BAD_REQUEST;
error = "subscription id shouldn't be defined";
return false;
}
if (!subscription->Subscriber.TabletId && !subscription->Subscriber.ServiceId) {
code = Ydb::StatusIds::BAD_REQUEST;
error = "no subscriber specified";
return false;
}
if (subscription->Subscriber.ServiceId && !subscription->Subscriber.ServiceId.IsService()) {
code = Ydb::StatusIds::BAD_REQUEST;
error = "wrong service id";
return false;
}
if (subscription->ItemKinds.empty()) {
code = Ydb::StatusIds::BAD_REQUEST;
error = "no item kinds specified";
return false;
}
return true;
}
bool TConfigsManager::IsConfigItemScopeAllowed(TConfigItem::TPtr item)
{
return IsConfigItemScopeAllowed(item, Config);
}
bool TConfigsManager::IsConfigItemScopeAllowed(TConfigItem::TPtr item,
const TConfigsConfig &config)
{
if (item->UsageScope.NodeIds.size())
return config.AllowedNodeIdScopeKinds.contains(item->Kind);
if (item->UsageScope.Hosts.size()) {
for (auto &host : item->UsageScope.Hosts)
if (host.find(' ') != TString::npos)
return false;
return config.AllowedHostScopeKinds.contains(item->Kind);
}
if (item->UsageScope.Tenant && item->UsageScope.NodeType)
return (config.AllowedTenantScopeKinds.contains(item->Kind)
&& config.AllowedNodeTypeScopeKinds.contains(item->Kind));
if (item->UsageScope.Tenant)
return config.AllowedTenantScopeKinds.contains(item->Kind);
if (item->UsageScope.NodeType)
return config.AllowedNodeTypeScopeKinds.contains(item->Kind);
return !config.DisallowedDomainScopeKinds.contains(item->Kind);
}
bool TConfigsManager::IsSupportedMergeStrategy(ui32 value) const
{
return NKikimrConsole::TConfigItem::EMergeStrategy_IsValid(value);
}
void TConfigsManager::DumpStateHTML(IOutputStream &os) const
{
HTML(os) {
PRE() {
os << "Used config:" << Endl
<< Self.GetConfig().GetConfigsConfig().DebugString() << Endl;
}
COLLAPSED_REF_CONTENT("configs-items-div", "Config items by kind") {
DIV_CLASS("tab-left") {
TOrderedConfigItemsMap itemsByKind;
TSet<ui32> kinds;
for (auto &pr : ConfigIndex.GetConfigItems()) {
itemsByKind[pr.second->Kind].insert(pr.second);
kinds.insert(pr.second->Kind);
}
for (auto kind : kinds) {
auto &items = itemsByKind.at(kind);
TString id = TStringBuilder() << "configs-items-" << kind;
COLLAPSED_REF_CONTENT(id, TConfigItem::KindName(kind) + "s") {
DIV_CLASS("tab-left") {
for (auto item : items) {
PRE() {
os << "#" << item->Id << Endl
<< "Scope: " << item->UsageScope.ToString() << Endl
<< "Merge: " << item->MergeStrategyName() << Endl
<< "Cookie: " << item->Cookie << Endl
<< "Config: " << Endl
<< item->Config.DebugString();
}
}
}
}
os << "<br/>" << Endl;
}
}
}
os << "<br/>" << Endl;
COLLAPSED_REF_CONTENT("subscriptions-div", "Subscriptions") {
DIV_CLASS("tab-left") {
THashMap<TDynBitMap, TSubscriptionSet> subscriptionsByKind;
for (auto &pr : SubscriptionIndex.GetSubscriptions()) {
TDynBitMap kinds;
for (auto &kind : pr.second->ItemKinds)
kinds.Set(kind);
subscriptionsByKind[kinds].insert(pr.second);
}
for (auto &pr : subscriptionsByKind) {
TString kinds;
bool first = true;
Y_FOR_EACH_BIT(kind, pr.first) {
kinds += (first ? TString() : TString(", ")) + TConfigItem::KindName(kind);
first = false;
}
TString id = TStringBuilder() << "subscriptions-" << (void*)&pr.second;
COLLAPSED_REF_CONTENT(id, kinds) {
DIV_CLASS("tab-left") {
for (auto subscription : pr.second) {
PRE() {
os << "#" << subscription->Id << Endl
<< "Subscriber: ";
if (subscription->Subscriber.TabletId)
os << "tablet " << subscription->Subscriber.TabletId << Endl;
else
os << "service " << subscription->Subscriber.ServiceId << Endl;
os << "Config node ID: " << subscription->NodeId << Endl
<< "Config host: " << subscription->Host << Endl
<< "Config tenant: " << subscription->Tenant << Endl
<< "Config node type: " << subscription->NodeType << Endl
<< "LastProvidedConfig: " << subscription->LastProvidedConfig.ToString() << Endl
<< "CurrentConfigId: " << subscription->CurrentConfigId.ToString() << Endl
<< "Worker: " << subscription->Worker << Endl
<< "Cookie: " << subscription->Cookie << Endl
<< "Current config:" << Endl
<< subscription->CurrentConfig.DebugString();
}
}
}
}
os << "<br/>" << Endl;
}
}
}
}
}
void TConfigsManager::DbApplyPendingConfigModifications(TTransactionContext &txc,
const TActorContext &ctx) const
{
for (auto item : PendingConfigModifications.AddedItems)
DbUpdateItem(item, txc, ctx);
for (auto &pr : PendingConfigModifications.ModifiedItems)
DbUpdateItem(pr.second, txc, ctx);
for (auto id : PendingConfigModifications.RemovedItems)
DbRemoveItem(id, txc, ctx);
}
void TConfigsManager::DbApplyPendingSubscriptionModifications(TTransactionContext &txc,
const TActorContext &ctx) const
{
for (auto &id : PendingSubscriptionModifications.RemovedSubscriptions)
DbRemoveSubscription(id, txc, ctx);
for (auto &subscription : PendingSubscriptionModifications.AddedSubscriptions)
DbUpdateSubscription(subscription, txc, ctx);
for (auto &pr : PendingSubscriptionModifications.ModifiedLastProvided)
DbUpdateSubscriptionLastProvidedConfig(pr.first, pr.second, txc, ctx);
}
bool TConfigsManager::DbLoadState(TTransactionContext &txc,
const TActorContext &ctx)
{
LOG_DEBUG(ctx, NKikimrServices::CMS_CONFIGS, "Loading configs state");
NIceDb::TNiceDb db(txc.DB);
auto nextConfigItemIdRow = db.Table<Schema::Config>().Key(TConsole::ConfigKeyNextConfigItemId).Select<Schema::Config::Value>();
auto nextSubscriptionIdRow = db.Table<Schema::Config>().Key(TConsole::ConfigKeyNextSubscriptionId).Select<Schema::Config::Value>();
auto configItemRowset = db.Table<Schema::ConfigItems>().Range().Select<Schema::ConfigItems::TColumns>();
auto subscriptionRowset = db.Table<Schema::ConfigSubscriptions>().Range().Select<Schema::ConfigSubscriptions::TColumns>();
auto validatorsRowset = db.Table<Schema::DisabledValidators>().Range().Select<Schema::DisabledValidators::TColumns>();
if (!configItemRowset.IsReady()
|| !nextConfigItemIdRow.IsReady()
|| !nextSubscriptionIdRow.IsReady()
|| !subscriptionRowset.IsReady()
|| !validatorsRowset.IsReady())
return false;
if (nextConfigItemIdRow.IsValid()) {
TString value = nextConfigItemIdRow.GetValue<Schema::Config::Value>();
NextConfigItemId = FromString<ui64>(value);
} else {
NextConfigItemId = 1;
}
if (nextSubscriptionIdRow.IsValid()) {
TString value = nextSubscriptionIdRow.GetValue<Schema::Config::Value>();
NextSubscriptionId = FromString<ui64>(value);
} else {
NextSubscriptionId = 1;
}
while (!configItemRowset.EndOfSet()) {
ui64 id = configItemRowset.GetValue<Schema::ConfigItems::Id>();
ui64 generation = configItemRowset.GetValue<Schema::ConfigItems::Generation>();
ui32 kind = configItemRowset.GetValue<Schema::ConfigItems::Kind>();
TVector<ui32> nodes = configItemRowset.GetValue<Schema::ConfigItems::NodeIds>();
TString hostsVal = configItemRowset.GetValue<Schema::ConfigItems::Hosts>();
TVector<TString> hosts = StringSplitter(hostsVal).Split(' ').SkipEmpty().ToList<TString>();
TString tenant = configItemRowset.GetValue<Schema::ConfigItems::Tenant>();
TString nodeType = configItemRowset.GetValue<Schema::ConfigItems::NodeType>();
ui32 order = configItemRowset.GetValue<Schema::ConfigItems::Order>();
ui32 merge = configItemRowset.GetValue<Schema::ConfigItems::Merge>();
TString config = configItemRowset.GetValue<Schema::ConfigItems::Config>();
TString cookie = configItemRowset.GetValue<Schema::ConfigItems::Cookie>();
TConfigItem::TPtr item = new TConfigItem;
item->Id = id;
item->Generation = generation;
item->Kind = kind;
for (auto id : nodes)
item->UsageScope.NodeIds.insert(id);
for (auto &host : hosts)
item->UsageScope.Hosts.insert(host);
item->UsageScope.Tenant = tenant;
item->UsageScope.NodeType = nodeType;
item->UsageScope.Order = order;
item->MergeStrategy = merge;
Y_PROTOBUF_SUPPRESS_NODISCARD item->Config.ParseFromArray(config.data(), config.size());
item->Cookie = cookie;
ConfigIndex.AddItem(item);
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS, "Loaded " << item->ToString());
if (!configItemRowset.Next())
return false;
}
while (!subscriptionRowset.EndOfSet()) {
ui64 id = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::Id>();
ui64 tabletId = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::TabletId>();
TActorId serviceId = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::ServiceId>();
ui32 nodeId = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::NodeId>();
TString host = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::Host>();
TString tenant = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::Tenant>();
TString nodeType = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::NodeType>();
TVector<ui32> kinds = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::ItemKinds>();
TVector<std::pair<ui64, ui64>> configId = subscriptionRowset.GetValue<Schema::ConfigSubscriptions::LastProvidedConfig>();
TSubscription::TPtr subscription = new TSubscription;
subscription->Id = id;
subscription->Subscriber.TabletId = tabletId;
subscription->Subscriber.ServiceId = serviceId;
subscription->NodeId = nodeId;
subscription->Host = host;
subscription->Tenant = tenant;
subscription->NodeType = nodeType;
subscription->ItemKinds.insert(kinds.begin(), kinds.end());
subscription->LastProvidedConfig.ItemIds = std::move(configId);
subscription->Cookie = RandomNumber<ui64>();
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS,
"Loaded subscription: " << subscription->ToString());
SubscriptionIndex.AddSubscription(subscription);
if (!subscriptionRowset.Next())
return false;
}
auto registry = TValidatorsRegistry::Instance();
registry->EnableValidators();
DisabledValidators.clear();
while (!validatorsRowset.EndOfSet()) {
TString name = validatorsRowset.GetValue<Schema::DisabledValidators::Name>();
DisabledValidators.insert(name);
registry->DisableValidator(name);
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS,
"Disable validator " << name);
if (!validatorsRowset.Next())
return false;
}
return true;
}
void TConfigsManager::DbRemoveItem(ui64 id,
TTransactionContext &txc,
const TActorContext &ctx) const
{
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS, "Database: removing config item #" << id);
NIceDb::TNiceDb db(txc.DB);
db.Table<Schema::ConfigItems>().Key(id).Delete();
}
void TConfigsManager::DbRemoveSubscription(ui64 id,
TTransactionContext &txc,
const TActorContext &ctx) const
{
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS, "Database: removing subscription id=" << id);
NIceDb::TNiceDb db(txc.DB);
db.Table<Schema::ConfigSubscriptions>().Key(id).Delete();
}
void TConfigsManager::DbUpdateItem(TConfigItem::TPtr item,
TTransactionContext &txc,
const TActorContext &ctx) const
{
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS, "Database: "
<< (ConfigIndex.GetItem(item->Id) ? "updating " : "adding ") << item->ToString());
TString config;
Y_PROTOBUF_SUPPRESS_NODISCARD item->Config.SerializeToString(&config);
NIceDb::TNiceDb db(txc.DB);
db.Table<Schema::ConfigItems>().Key(item->Id)
.Update(NIceDb::TUpdate<Schema::ConfigItems::Generation>(item->Generation))
.Update(NIceDb::TUpdate<Schema::ConfigItems::Kind>(item->Kind))
.Update(NIceDb::TUpdate<Schema::ConfigItems::NodeIds>({item->UsageScope.NodeIds.begin(), item->UsageScope.NodeIds.end()}))
.Update(NIceDb::TUpdate<Schema::ConfigItems::Hosts>(JoinSeq(" ", item->UsageScope.Hosts)))
.Update(NIceDb::TUpdate<Schema::ConfigItems::Tenant>(item->UsageScope.Tenant))
.Update(NIceDb::TUpdate<Schema::ConfigItems::NodeType>(item->UsageScope.NodeType))
.Update(NIceDb::TUpdate<Schema::ConfigItems::Order>(item->UsageScope.Order))
.Update(NIceDb::TUpdate<Schema::ConfigItems::Merge>(item->MergeStrategy))
.Update(NIceDb::TUpdate<Schema::ConfigItems::Config>(config))
.Update(NIceDb::TUpdate<Schema::ConfigItems::Cookie>(item->Cookie));
}
void TConfigsManager::DbUpdateNextConfigItemId(TTransactionContext &txc,
const TActorContext &ctx) const
{
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS,
"Database: update NextConfigItemId: " << NextConfigItemId);
NIceDb::TNiceDb db(txc.DB);
db.Table<Schema::Config>().Key(TConsole::ConfigKeyNextConfigItemId)
.Update(NIceDb::TUpdate<Schema::Config::Value>(ToString(NextConfigItemId)));
}
void TConfigsManager::DbUpdateNextSubscriptionId(TTransactionContext &txc,
const TActorContext &ctx) const
{
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS,
"Database: update NextSubscriptionId: " << NextSubscriptionId);
NIceDb::TNiceDb db(txc.DB);
db.Table<Schema::Config>().Key(TConsole::ConfigKeyNextSubscriptionId)
.Update(NIceDb::TUpdate<Schema::Config::Value>(ToString(NextSubscriptionId)));
}
void TConfigsManager::DbUpdateSubscription(TSubscription::TPtr subscription,
TTransactionContext &txc,
const TActorContext &ctx) const
{
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS,
"Database: update subscription:" << subscription->ToString());
TVector<ui32> kinds(subscription->ItemKinds.begin(), subscription->ItemKinds.end());
NIceDb::TNiceDb db(txc.DB);
db.Table<Schema::ConfigSubscriptions>().Key(subscription->Id)
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::TabletId>(subscription->Subscriber.TabletId))
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::ServiceId>(subscription->Subscriber.ServiceId))
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::NodeId>(subscription->NodeId))
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::Host>(subscription->Host))
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::Tenant>(subscription->Tenant))
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::NodeType>(subscription->NodeType))
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::ItemKinds>(kinds))
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::LastProvidedConfig>(subscription->LastProvidedConfig.ItemIds));
}
void TConfigsManager::DbUpdateSubscriptionLastProvidedConfig(ui64 id,
const TConfigId &configId,
TTransactionContext &txc,
const TActorContext &ctx) const
{
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS, "Database: "
<< "update last provided config for subscription"
<< " id=" << id
<< " lastprovidedconfig=" << configId.ToString());
NIceDb::TNiceDb db(txc.DB);
db.Table<Schema::ConfigSubscriptions>().Key(id)
.Update(NIceDb::TUpdate<Schema::ConfigSubscriptions::LastProvidedConfig>(configId.ItemIds));
}
void TConfigsManager::Handle(TEvConsole::TEvAddConfigSubscriptionRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxAddConfigSubscription(ev), ctx);
}
void TConfigsManager::Handle(TEvConsole::TEvConfigNotificationResponse::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxUpdateLastProvidedConfig(ev), ctx);
}
void TConfigsManager::Handle(TEvConsole::TEvConfigureRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxConfigure(ev), ctx);
}
void TConfigsManager::Handle(TEvConsole::TEvListConfigValidatorsRequest::TPtr &ev, const TActorContext &ctx)
{
auto response = MakeHolder<TEvConsole::TEvListConfigValidatorsResponse>();
response->Record.MutableStatus()->SetCode(Ydb::StatusIds::SUCCESS);
auto registry = TValidatorsRegistry::Instance();
for (auto &pr : registry->GetValidators()) {
auto &entry = *response->Record.AddValidators();
entry.SetName(pr.first);
entry.SetDescription(pr.second->GetDescription());
for (auto kind : pr.second->GetCheckedConfigItemKinds())
entry.AddCheckedItemKinds(kind);
entry.SetEnabled(pr.second->IsEnabled());
}
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS,
"Send TEvListConfigValidatorsResponse: " << response->Record.ShortDebugString());
ctx.Send(ev->Sender, response.Release(), 0, ev->Cookie);
}
void TConfigsManager::Handle(TEvConsole::TEvRemoveConfigSubscriptionRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxRemoveConfigSubscription(ev), ctx);
}
void TConfigsManager::Handle(TEvConsole::TEvRemoveConfigSubscriptionsRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxRemoveConfigSubscriptions(ev), ctx);
}
void TConfigsManager::Handle(TEvConsole::TEvReplaceConfigSubscriptionsRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxReplaceConfigSubscriptions(ev), ctx);
}
void TConfigsManager::Handle(TEvConsole::TEvToggleConfigValidatorRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxToggleConfigValidator(ev), ctx);
}
void TConfigsManager::Handle(TEvInterconnect::TEvNodesInfo::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxCleanupSubscriptions(ev), ctx);
}
void TConfigsManager::Handle(TEvPrivate::TEvStateLoaded::TPtr &/*ev*/, const TActorContext &ctx)
{
ctx.Send(ConfigsProvider, new TConfigsProvider::TEvPrivate::TEvSetConfigs(ConfigIndex.GetConfigItems()));
ctx.Send(ConfigsProvider, new TConfigsProvider::TEvPrivate::TEvSetSubscriptions(SubscriptionIndex.GetSubscriptions()));
ctx.Send(GetNameserviceActorId(), new TEvInterconnect::TEvListNodes());
}
void TConfigsManager::Handle(TEvPrivate::TEvCleanupSubscriptions::TPtr &/*ev*/, const TActorContext &ctx)
{
ctx.Send(GetNameserviceActorId(), new TEvInterconnect::TEvListNodes());
}
void TConfigsManager::ForwardToConfigsProvider(TAutoPtr<IEventHandle> &ev, const TActorContext &ctx)
{
ctx.Send(ev->Forward(ConfigsProvider));
}
void TConfigsManager::ScheduleSubscriptionsCleanup(const TActorContext &ctx)
{
auto *event = new TConfigsManager::TEvPrivate::TEvCleanupSubscriptions;
SubscriptionsCleanupTimerCookieHolder.Reset(ISchedulerCookie::Make2Way());
CreateLongTimer(ctx, TDuration::Minutes(5),
new IEventHandle(SelfId(), SelfId(), event),
AppData(ctx)->SystemPoolId,
SubscriptionsCleanupTimerCookieHolder.Get());
}
} // namespace NConsole
} // namespace NKikimr
|