Skip to content

Commit dad185b

Browse files
committed
switch to json represenation
1 parent 9db56be commit dad185b

File tree

3 files changed

+48
-80
lines changed

3 files changed

+48
-80
lines changed

ydb/core/mind/hive/hive_schema.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ struct Schema : NIceDb::Schema {
301301
struct OperationsLog : Table<21> {
302302
struct Timestamp : Column<1, NScheme::NTypeIds::Uint64> {};
303303
struct User : Column<2, NScheme::NTypeIds::String> {};
304-
struct Operation : Column<3, NScheme::NTypeIds::String> { using Type = NKikimrHive::TOperation; };
304+
struct Operation : Column<3, NScheme::NTypeIds::String> {}; // JSON
305305

306306
using TKey = TableKey<Timestamp>;
307307
using TColumns = TableColumns<Timestamp, User, Operation>;

ydb/core/mind/hive/monitoring.cpp

+47-43
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ bool TLoggedMonTransaction::Prepare(NIceDb::TNiceDb& db) {
2727
return rowset.IsReady() && !rowset.HaveValue<Schema::OperationsLog::Operation>();
2828
}
2929

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());
3234
}
3335

3436
class TTxMonEvent_DbState : public TTransactionBase<THive> {
@@ -705,18 +707,14 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
705707

706708
TTxType GetTxType() const override { return NHive::TXTYPE_MON_SETTINGS; }
707709

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) {
709711
const auto& params(Event->Cgi());
710712
if (params.contains(param)) {
711713
const TString& value = params.Get(param);
712714
const google::protobuf::Reflection* reflection = Self->DatabaseConfig.GetReflection();
713715
const google::protobuf::FieldDescriptor* field = Self->DatabaseConfig.GetDescriptor()->FindFieldByName(param);
714716
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;
720718
if (value.empty()) {
721719
reflection->ClearField(&Self->DatabaseConfig, field);
722720
// compatibility
@@ -786,8 +784,8 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
786784
if (!Prepare(db)) {
787785
return false;
788786
}
789-
NKikimrHive::TOperation protoOperation;
790-
NKikimrHive::TConfigUpdates* configUpdates = protoOperation.MutableConfigUpdates();
787+
NJson::TJsonValue jsonOperation;
788+
auto& configUpdates = jsonOperation["ConfigUpdates"];
791789

792790
UpdateConfig(db, "MaxTabletsScheduled", configUpdates, TSchemeIds::State::MaxTabletsScheduled);
793791
UpdateConfig(db, "MaxBootBatchSize", configUpdates, TSchemeIds::State::MaxBootBatchSize);
@@ -864,9 +862,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
864862
field->Add(i);
865863
}
866864
ChangeRequest = true;
867-
auto* protoUpdate = configUpdates->AddConfigUpdate();
868-
protoUpdate->SetFieldNumber(NKikimrConfig::THiveConfig::kBalancerIgnoreTabletTypesFieldNumber);
869-
protoUpdate->SetValue(value);
865+
configUpdates["BalancerIgnoreTabletTypes"] = value;
870866
// Self->BalancerIgnoreTabletTypes will be replaced by Self->BuildCurrentConfig()
871867
}
872868
}
@@ -887,9 +883,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
887883
protoLimit->SetMaxCount(*maxCount);
888884
}
889885

890-
auto* protoUpdate = configUpdates->AddConfigUpdate();
891-
protoUpdate->SetFieldNumber(NKikimrConfig::THiveConfig::kDefaultTabletLimitFieldNumber);
892-
protoUpdate->SetValue(value);
886+
configUpdates["DefaultTabletLimit"] = value;
893887

894888
// Get rid of duplicates & default values
895889
google::protobuf::RepeatedPtrField<NKikimrConfig::THiveTabletLimit> cleanTabletLimits;
@@ -913,7 +907,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
913907
db.Table<Schema::State>().Key(TSchemeIds::State::DefaultState).Update<Schema::State::Config>(Self->DatabaseConfig);
914908
}
915909
if (params.contains("allowedMetrics")) {
916-
auto* protoAllowedMetrics = protoOperation.MutableAllowedMetricsUpdates();
910+
auto& jsonAllowedMetrics = jsonOperation["AllowedMetricsUpdate"];
917911
TVector<TString> allowedMetrics = SplitString(params.Get("allowedMetrics"), ";");
918912
for (TStringBuf tabletAllowedMetrics : allowedMetrics) {
919913
TStringBuf tabletType = tabletAllowedMetrics.NextTok(':');
@@ -941,9 +935,19 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
941935
}
942936
if (changed) {
943937
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));
947951
db.Table<Schema::TabletTypeMetrics>().Key(type).Update<Schema::TabletTypeMetrics::AllowedMetricIDs>(metrics);
948952
Self->TabletTypeAllowedMetrics[type] = metrics;
949953
}
@@ -953,7 +957,7 @@ class TTxMonEvent_Settings : public TTransactionBase<THive>, public TLoggedMonTr
953957
}
954958

955959
if (ChangeRequest) {
956-
WriteOperation(db, protoOperation);
960+
WriteOperation(db, jsonOperation);
957961
}
958962
return true;
959963
}
@@ -1336,19 +1340,19 @@ class TTxMonEvent_TabletAvailability : public TTransactionBase<THive>, public TL
13361340
return false;
13371341
}
13381342

1339-
NKikimrHive::TOperation protoOperation;
1340-
auto* protoNodeOperation = protoOperation.MutableNodeOperation();
1341-
protoNodeOperation->SetNodeId(NodeId);
1343+
NJson::TJsonValue jsonOperation;
1344+
jsonOperation["NodeId"] = NodeId;
13421345

13431346
const auto& cgi = Event->Cgi();
13441347
auto changeType = ParseTabletType(cgi.Get("changetype"));
13451348
auto maxCount = TryFromString<ui64>(cgi.Get("maxcount"));
13461349
auto resetType = ParseTabletType(cgi.Get("resettype"));
13471350
if (changeType != TTabletTypes::TypeInvalid && maxCount) {
13481351
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));
13521356
db.Table<Schema::TabletAvailabilityRestrictions>().Key(NodeId, changeType).Update<Schema::TabletAvailabilityRestrictions::MaxCount>(*maxCount);
13531357
Node->TabletAvailabilityRestrictions[changeType] = *maxCount;
13541358
auto it = Node->TabletAvailability.find(changeType);
@@ -1358,8 +1362,10 @@ class TTxMonEvent_TabletAvailability : public TTransactionBase<THive>, public TL
13581362
}
13591363
if (resetType != TTabletTypes::TypeInvalid) {
13601364
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));
13631369
Node->TabletAvailabilityRestrictions.erase(resetType);
13641370
auto it = Node->TabletAvailability.find(resetType);
13651371
if (it != Node->TabletAvailability.end()) {
@@ -1378,7 +1384,7 @@ class TTxMonEvent_TabletAvailability : public TTransactionBase<THive>, public TL
13781384
if (ChangeRequest) {
13791385
Self->ObjectDistributions.RemoveNode(*Node);
13801386
Self->ObjectDistributions.AddNode(*Node);
1381-
WriteOperation(db, protoOperation);
1387+
WriteOperation(db, jsonOperation);
13821388
}
13831389
return true;
13841390
}
@@ -2503,11 +2509,10 @@ class TTxMonEvent_SetDown : public TTransactionBase<THive>, public TLoggedMonTra
25032509
if (node != nullptr) {
25042510
node->SetDown(Down);
25052511
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);
25112516
Response = "{\"NodeId\":" + ToString(NodeId) + ',' + "\"Down\":" + (Down ? "true" : "false") + "}";
25122517
} else {
25132518
Response = "{\"Error\":\"Node " + ToString(NodeId) + " not found\"}";
@@ -2547,11 +2552,10 @@ class TTxMonEvent_SetFreeze : public TTransactionBase<THive>, public TLoggedMonT
25472552
if (node != nullptr) {
25482553
node->SetFreeze(Freeze);
25492554
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);
25552559
Response = "{\"NodeId\":" + ToString(NodeId) + ',' + "\"Freeze\":" + (Freeze ? "true" : "false") + "}";
25562560
} else {
25572561
Response = "{\"Error\":\"Node " + ToString(NodeId) + " not found\"}";
@@ -4280,7 +4284,7 @@ class TTxMonEvent_OperationsLog : public TTransactionBase<THive> {
42804284
MaxCount = FromStringWithDefault(Event->Cgi().Get("max"), MaxCount);
42814285
}
42824286

4283-
void WriteDescription(TStringStream& out, const NKikimrHive::TOperation& protoOperation) {
4287+
/*void WriteDescription(TStringStream& out, const NKikimrHive::TOperation& protoOperation) {
42844288
bool written = false;
42854289
if (protoOperation.HasConfigUpdates()) {
42864290
written = true;
@@ -4357,7 +4361,7 @@ class TTxMonEvent_OperationsLog : public TTransactionBase<THive> {
43574361
if (!written) {
43584362
out << "???";
43594363
}
4360-
}
4364+
}*/
43614365

43624366
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override {
43634367
TStringStream out;
@@ -4391,7 +4395,7 @@ class TTxMonEvent_OperationsLog : public TTransactionBase<THive> {
43914395
out << "<td>" << TInstant::MilliSeconds(operationsRowset.GetValue<Schema::OperationsLog::Timestamp>()) << "</td>";
43924396
out << "<td>" << (user.empty() ? "anonymous" : user.c_str()) << "</td>";
43934397
out << "<td>";
4394-
WriteDescription(out, operationsRowset.GetValue<Schema::OperationsLog::Operation>());
4398+
out << operationsRowset.GetValue<Schema::OperationsLog::Operation>();
43954399
out << "</td>";
43964400
out << "</tr>";
43974401
if (!operationsRowset.Next()) {

ydb/core/protos/hive.proto

-36
Original file line numberDiff line numberDiff line change
@@ -567,39 +567,3 @@ message TEvUpdateDomainReply {
567567
optional fixed64 Origin = 1;
568568
optional uint64 TxId = 2;
569569
}
570-
571-
message TConfigUpdate {
572-
optional uint64 FieldNumber = 1;
573-
optional string Value = 2;
574-
}
575-
576-
message TConfigUpdates {
577-
repeated TConfigUpdate ConfigUpdate = 1;
578-
}
579-
580-
message TTabletAvailabilityRestriction {
581-
optional NKikimrTabletBase.TTabletTypes.EType Type = 1;
582-
optional uint64 MaxCount = 2 [default = 1000000];
583-
}
584-
585-
message TNodeOperation {
586-
optional uint32 NodeId = 1;
587-
optional bool Down = 2;
588-
optional bool Freeze = 3;
589-
repeated TTabletAvailabilityRestriction TabletAvailability = 4;
590-
}
591-
592-
message TAllowedMetricsUpdate {
593-
optional NKikimrTabletBase.TTabletTypes.EType Type = 1;
594-
repeated uint64 AllowedMetrics = 2;
595-
}
596-
597-
message TAllowedMetricsUpdates {
598-
repeated TAllowedMetricsUpdate AllowedMetricsUpdate = 1;
599-
}
600-
601-
message TOperation {
602-
optional TConfigUpdates ConfigUpdates = 1;
603-
optional TNodeOperation NodeOperation = 2;
604-
optional TAllowedMetricsUpdates AllowedMetricsUpdates = 3;
605-
}

0 commit comments

Comments
 (0)