@@ -27,8 +27,10 @@ bool TLoggedMonTransaction::Prepare(NIceDb::TNiceDb& db) {
27
27
return rowset.IsReady () && !rowset.HaveValue <Schema::OperationsLog::Operation>();
28
28
}
29
29
30
- void TLoggedMonTransaction::WriteOperation (NIceDb::TNiceDb& db, const NKikimrHive::TOperation& op) {
31
- db.Table <Schema::OperationsLog>().Key (Timestamp.MilliSeconds ()).Update <Schema::OperationsLog::User, Schema::OperationsLog::Operation>(User, op);
30
+ void TLoggedMonTransaction::WriteOperation (NIceDb::TNiceDb& db, const NJson::TJsonValue& op) {
31
+ TStringStream str;
32
+ NJson::WriteJson (&str, &op);
33
+ db.Table <Schema::OperationsLog>().Key (Timestamp.MilliSeconds ()).Update <Schema::OperationsLog::User, Schema::OperationsLog::Operation>(User, str.Str ());
32
34
}
33
35
34
36
class TTxMonEvent_DbState : public TTransactionBase <THive> {
@@ -705,18 +707,14 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
705
707
706
708
TTxType GetTxType () const override { return NHive::TXTYPE_MON_SETTINGS; }
707
709
708
- void UpdateConfig (NIceDb::TNiceDb& db, const TString& param, NKikimrHive::TConfigUpdates* protoLog , TSchemeIds::State compatibilityParam = TSchemeIds::State::DefaultState) {
710
+ void UpdateConfig (NIceDb::TNiceDb& db, const TString& param, NJson::TJsonValue& jsonLog , TSchemeIds::State compatibilityParam = TSchemeIds::State::DefaultState) {
709
711
const auto & params (Event->Cgi ());
710
712
if (params.contains (param)) {
711
713
const TString& value = params.Get (param);
712
714
const google::protobuf::Reflection* reflection = Self->DatabaseConfig .GetReflection ();
713
715
const google::protobuf::FieldDescriptor* field = Self->DatabaseConfig .GetDescriptor ()->FindFieldByName (param);
714
716
if (reflection != nullptr && field != nullptr ) {
715
- auto * protoUpdate = protoLog->AddConfigUpdate ();
716
- protoUpdate->SetFieldNumber (field->number ());
717
- if (!value.empty ()) {
718
- protoUpdate->SetValue (value);
719
- }
717
+ jsonLog[param] = value;
720
718
if (value.empty ()) {
721
719
reflection->ClearField (&Self->DatabaseConfig , field);
722
720
// compatibility
@@ -786,8 +784,8 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
786
784
if (!Prepare (db)) {
787
785
return false ;
788
786
}
789
- NKikimrHive::TOperation protoOperation ;
790
- NKikimrHive::TConfigUpdates* configUpdates = protoOperation. MutableConfigUpdates () ;
787
+ NJson::TJsonValue jsonOperation ;
788
+ auto & configUpdates = jsonOperation[ " ConfigUpdates " ] ;
791
789
792
790
UpdateConfig (db, " MaxTabletsScheduled" , configUpdates, TSchemeIds::State::MaxTabletsScheduled);
793
791
UpdateConfig (db, " MaxBootBatchSize" , configUpdates, TSchemeIds::State::MaxBootBatchSize);
@@ -864,9 +862,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
864
862
field->Add (i);
865
863
}
866
864
ChangeRequest = true ;
867
- auto * protoUpdate = configUpdates->AddConfigUpdate ();
868
- protoUpdate->SetFieldNumber (NKikimrConfig::THiveConfig::kBalancerIgnoreTabletTypesFieldNumber );
869
- protoUpdate->SetValue (value);
865
+ configUpdates[" BalancerIgnoreTabletTypes" ] = value;
870
866
// Self->BalancerIgnoreTabletTypes will be replaced by Self->BuildCurrentConfig()
871
867
}
872
868
}
@@ -887,9 +883,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
887
883
protoLimit->SetMaxCount (*maxCount);
888
884
}
889
885
890
- auto * protoUpdate = configUpdates->AddConfigUpdate ();
891
- protoUpdate->SetFieldNumber (NKikimrConfig::THiveConfig::kDefaultTabletLimitFieldNumber );
892
- protoUpdate->SetValue (value);
886
+ configUpdates[" DefaultTabletLimit" ] = value;
893
887
894
888
// Get rid of duplicates & default values
895
889
google::protobuf::RepeatedPtrField<NKikimrConfig::THiveTabletLimit> cleanTabletLimits;
@@ -913,7 +907,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
913
907
db.Table <Schema::State>().Key (TSchemeIds::State::DefaultState).Update <Schema::State::Config>(Self->DatabaseConfig );
914
908
}
915
909
if (params.contains (" allowedMetrics" )) {
916
- auto * protoAllowedMetrics = protoOperation. MutableAllowedMetricsUpdates () ;
910
+ auto & jsonAllowedMetrics = jsonOperation[ " AllowedMetricsUpdate " ] ;
917
911
TVector<TString> allowedMetrics = SplitString (params.Get (" allowedMetrics" ), " ;" );
918
912
for (TStringBuf tabletAllowedMetrics : allowedMetrics) {
919
913
TStringBuf tabletType = tabletAllowedMetrics.NextTok (' :' );
@@ -941,9 +935,19 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
941
935
}
942
936
if (changed) {
943
937
ChangeRequest = true ;
944
- auto * protoUpdate = protoAllowedMetrics->AddAllowedMetricsUpdate ();
945
- protoUpdate->SetType (type);
946
- protoUpdate->MutableAllowedMetrics ()->Add (metrics.begin (), metrics.end ());
938
+ NJson::TJsonValue jsonUpdate;
939
+ jsonUpdate[" Type" ] = tabletType;
940
+ const auto * descriptor = NKikimrTabletBase::TMetrics::descriptor ();
941
+ auto & jsonMetrics = jsonUpdate[" AllowedMetrics" ];
942
+ for (auto metricNum : metrics) {
943
+ const auto * field = descriptor->FindFieldByNumber (metricNum);
944
+ if (field) {
945
+ jsonMetrics.AppendValue (field->name ());
946
+ } else {
947
+ jsonMetrics.AppendValue (metricNum);
948
+ }
949
+ }
950
+ jsonAllowedMetrics.AppendValue (std::move (jsonUpdate));
947
951
db.Table <Schema::TabletTypeMetrics>().Key (type).Update <Schema::TabletTypeMetrics::AllowedMetricIDs>(metrics);
948
952
Self->TabletTypeAllowedMetrics [type] = metrics;
949
953
}
@@ -953,7 +957,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
953
957
}
954
958
955
959
if (ChangeRequest) {
956
- WriteOperation (db, protoOperation );
960
+ WriteOperation (db, jsonOperation );
957
961
}
958
962
return true ;
959
963
}
@@ -1336,19 +1340,19 @@ class TTxMonEvent_TabletAvailability : public TTransactionBase<THive>, public TL
1336
1340
return false ;
1337
1341
}
1338
1342
1339
- NKikimrHive::TOperation protoOperation;
1340
- auto * protoNodeOperation = protoOperation.MutableNodeOperation ();
1341
- protoNodeOperation->SetNodeId (NodeId);
1343
+ NJson::TJsonValue jsonOperation;
1344
+ jsonOperation[" NodeId" ] = NodeId;
1342
1345
1343
1346
const auto & cgi = Event->Cgi ();
1344
1347
auto changeType = ParseTabletType (cgi.Get (" changetype" ));
1345
1348
auto maxCount = TryFromString<ui64>(cgi.Get (" maxcount" ));
1346
1349
auto resetType = ParseTabletType (cgi.Get (" resettype" ));
1347
1350
if (changeType != TTabletTypes::TypeInvalid && maxCount) {
1348
1351
ChangeRequest = true ;
1349
- auto * protoTabletAvailability = protoNodeOperation->AddTabletAvailability ();
1350
- protoTabletAvailability->SetType (changeType);
1351
- protoTabletAvailability->SetMaxCount (*maxCount);
1352
+ NJson::TJsonValue jsonUpdate;
1353
+ jsonUpdate[" Type" ] = GetTabletTypeShortName (changeType);
1354
+ jsonUpdate[" MaxCount" ] = *maxCount;
1355
+ jsonOperation[" TabletAvailability" ].AppendValue (std::move (jsonUpdate));
1352
1356
db.Table <Schema::TabletAvailabilityRestrictions>().Key (NodeId, changeType).Update <Schema::TabletAvailabilityRestrictions::MaxCount>(*maxCount);
1353
1357
Node->TabletAvailabilityRestrictions [changeType] = *maxCount;
1354
1358
auto it = Node->TabletAvailability .find (changeType);
@@ -1358,8 +1362,10 @@ class TTxMonEvent_TabletAvailability : public TTransactionBase<THive>, public TL
1358
1362
}
1359
1363
if (resetType != TTabletTypes::TypeInvalid) {
1360
1364
ChangeRequest = true ;
1361
- auto * protoTabletAvailability = protoNodeOperation->AddTabletAvailability ();
1362
- protoTabletAvailability->SetType (resetType);
1365
+ NJson::TJsonValue jsonUpdate;
1366
+ jsonUpdate[" Type" ] = GetTabletTypeShortName (resetType);
1367
+ jsonUpdate[" MaxCount" ] = " [default]" ;
1368
+ jsonOperation[" TabletAvailability" ].AppendValue (std::move (jsonUpdate));
1363
1369
Node->TabletAvailabilityRestrictions .erase (resetType);
1364
1370
auto it = Node->TabletAvailability .find (resetType);
1365
1371
if (it != Node->TabletAvailability .end ()) {
@@ -1378,7 +1384,7 @@ class TTxMonEvent_TabletAvailability : public TTransactionBase<THive>, public TL
1378
1384
if (ChangeRequest) {
1379
1385
Self->ObjectDistributions .RemoveNode (*Node);
1380
1386
Self->ObjectDistributions .AddNode (*Node);
1381
- WriteOperation (db, protoOperation );
1387
+ WriteOperation (db, jsonOperation );
1382
1388
}
1383
1389
return true ;
1384
1390
}
@@ -2503,11 +2509,10 @@ class TTxMonEvent_SetDown : public TTransactionBase<THive>, public TLoggedMonTra
2503
2509
if (node != nullptr ) {
2504
2510
node->SetDown (Down);
2505
2511
db.Table <Schema::Node>().Key (NodeId).Update (NIceDb::TUpdate<Schema::Node::Down>(Down));
2506
- NKikimrHive::TOperation protoOperation;
2507
- auto * protoNodeOperation = protoOperation.MutableNodeOperation ();
2508
- protoNodeOperation->SetNodeId (NodeId);
2509
- protoNodeOperation->SetDown (Down);
2510
- WriteOperation (db, protoOperation);
2512
+ NJson::TJsonValue jsonOperation;
2513
+ jsonOperation[" NodeId" ] = NodeId;
2514
+ jsonOperation[" Down" ] = Down;
2515
+ WriteOperation (db, jsonOperation);
2511
2516
Response = " {\" NodeId\" :" + ToString (NodeId) + ' ,' + " \" Down\" :" + (Down ? " true" : " false" ) + " }" ;
2512
2517
} else {
2513
2518
Response = " {\" Error\" :\" Node " + ToString (NodeId) + " not found\" }" ;
@@ -2547,11 +2552,10 @@ class TTxMonEvent_SetFreeze : public TTransactionBase<THive>, public TLoggedMonT
2547
2552
if (node != nullptr ) {
2548
2553
node->SetFreeze (Freeze);
2549
2554
db.Table <Schema::Node>().Key (NodeId).Update (NIceDb::TUpdate<Schema::Node::Freeze>(Freeze));
2550
- NKikimrHive::TOperation protoOperation;
2551
- auto * protoNodeOperation = protoOperation.MutableNodeOperation ();
2552
- protoNodeOperation->SetNodeId (NodeId);
2553
- protoNodeOperation->SetFreeze (Freeze);
2554
- WriteOperation (db, protoOperation);
2555
+ NJson::TJsonValue jsonOperation;
2556
+ jsonOperation[" NodeId" ] = NodeId;
2557
+ jsonOperation[" Freeze" ] = Freeze;
2558
+ WriteOperation (db, jsonOperation);
2555
2559
Response = " {\" NodeId\" :" + ToString (NodeId) + ' ,' + " \" Freeze\" :" + (Freeze ? " true" : " false" ) + " }" ;
2556
2560
} else {
2557
2561
Response = " {\" Error\" :\" Node " + ToString (NodeId) + " not found\" }" ;
@@ -4280,7 +4284,7 @@ class TTxMonEvent_OperationsLog : public TTransactionBase<THive> {
4280
4284
MaxCount = FromStringWithDefault (Event->Cgi ().Get (" max" ), MaxCount);
4281
4285
}
4282
4286
4283
- void WriteDescription (TStringStream& out, const NKikimrHive::TOperation& protoOperation) {
4287
+ /* void WriteDescription(TStringStream& out, const NKikimrHive::TOperation& protoOperation) {
4284
4288
bool written = false;
4285
4289
if (protoOperation.HasConfigUpdates()) {
4286
4290
written = true;
@@ -4357,7 +4361,7 @@ class TTxMonEvent_OperationsLog : public TTransactionBase<THive> {
4357
4361
if (!written) {
4358
4362
out << "???";
4359
4363
}
4360
- }
4364
+ }*/
4361
4365
4362
4366
bool Execute (TTransactionContext& txc, const TActorContext& ctx) override {
4363
4367
TStringStream out;
@@ -4391,7 +4395,7 @@ class TTxMonEvent_OperationsLog : public TTransactionBase<THive> {
4391
4395
out << " <td>" << TInstant::MilliSeconds (operationsRowset.GetValue <Schema::OperationsLog::Timestamp>()) << " </td>" ;
4392
4396
out << " <td>" << (user.empty () ? " anonymous" : user.c_str ()) << " </td>" ;
4393
4397
out << " <td>" ;
4394
- WriteDescription ( out, operationsRowset.GetValue <Schema::OperationsLog::Operation>() );
4398
+ out << operationsRowset.GetValue <Schema::OperationsLog::Operation>();
4395
4399
out << " </td>" ;
4396
4400
out << " </tr>" ;
4397
4401
if (!operationsRowset.Next ()) {
0 commit comments