diff options
author | grachevkirill <grachevkirill@yandex-team.com> | 2025-01-10 13:08:01 +0300 |
---|---|---|
committer | grachevkirill <grachevkirill@yandex-team.com> | 2025-01-10 13:48:02 +0300 |
commit | 1fcf8fe3af79804f1afd9cab433e99f995f3b322 (patch) | |
tree | 2b2107028332eb55e5794843e045ac85088ee79b | |
parent | b5cbc28d1e5caf94434a43fb4d6d366c31821df1 (diff) | |
download | ydb-1fcf8fe3af79804f1afd9cab433e99f995f3b322.tar.gz |
YT-23284: Use bytes instead of bits in bundle controller
Add bytes
commit_hash:0c80284f4e717f15d452a3873d33ff3b5f4c9c91
3 files changed, 67 insertions, 8 deletions
diff --git a/yt/yt/client/bundle_controller_client/bundle_controller_settings.cpp b/yt/yt/client/bundle_controller_client/bundle_controller_settings.cpp index ce4f0e6383..e65b8b4f86 100644 --- a/yt/yt/client/bundle_controller_client/bundle_controller_settings.cpp +++ b/yt/yt/client/bundle_controller_client/bundle_controller_settings.cpp @@ -44,21 +44,50 @@ void TInstanceResources::Register(TRegistrar registrar) registrar.Parameter("memory", &TThis::Memory) .GreaterThanOrEqual(0) .Default(120_GB); - registrar.Parameter("net", &TThis::Net) + registrar.Parameter("net", &TThis::NetBits) + .Optional(); + registrar.Parameter("net_bytes", &TThis::NetBytes) .Optional(); registrar.Parameter("type", &TThis::Type) .Default(); + + registrar.Postprocessor([] (TThis* config) { + if (config->NetBits.has_value() && config->NetBytes.has_value() && *config->NetBits != *config->NetBytes * 8) { + THROW_ERROR_EXCEPTION("Net parameters are not equal") + << TErrorAttribute("net_bytes", config->NetBytes) + << TErrorAttribute("net_bits", config->NetBits); + } + + config->CanonizeNet(); + }); } void TInstanceResources::Clear() { Vcpu = 0; Memory = 0; + ResetNet(); +} + +void TInstanceResources::CanonizeNet() +{ + // COMPAT(grachevkirill) + if (NetBytes.has_value()) { + NetBits = *NetBytes * 8; + } else if (NetBits.has_value()) { + NetBytes = *NetBits / 8; + } +} + +void TInstanceResources::ResetNet() +{ + NetBits.reset(); + NetBytes.reset(); } bool TInstanceResources::operator==(const TInstanceResources& other) const { - return std::tie(Vcpu, Memory, Net) == std::tie(other.Vcpu, other.Memory, other.Net); + return std::tie(Vcpu, Memory, NetBytes) == std::tie(other.Vcpu, other.Memory, other.NetBytes); } void TDefaultInstanceConfig::Register(TRegistrar registrar) @@ -114,9 +143,27 @@ void TBundleResourceQuota::Register(TRegistrar registrar) .GreaterThanOrEqual(0) .Default(0); - registrar.Parameter("network", &TThis::Network) + registrar.Parameter("network", &TThis::NetworkBits) .GreaterThanOrEqual(0) .Default(0); + registrar.Parameter("network_bytes", &TThis::NetworkBytes) + .GreaterThanOrEqual(0) + .Default(0); + + registrar.Postprocessor([] (TThis* config) { + if (config->NetworkBits != 0 && config->NetworkBytes != 0 && config->NetworkBits != config->NetworkBytes * 8) { + THROW_ERROR_EXCEPTION("Network parameters are not equal") + << TErrorAttribute("network_bytes", config->NetworkBytes) + << TErrorAttribute("network_bits", config->NetworkBits); + } + + // COMPAT(grachevkirill) + if (config->NetworkBytes != 0) { + config->NetworkBits = config->NetworkBytes * 8; + } else if (config->NetworkBits != 0) { + config->NetworkBytes = config->NetworkBits / 8; + } + }); } //////////////////////////////////////////////////////////////////////////////// @@ -188,7 +235,9 @@ void ToProto(NBundleController::NProto::TInstanceResources* protoInstanceResourc { if (instanceResources == nullptr) return; protoInstanceResources->set_memory(instanceResources->Memory); - YT_TOPROTO_OPTIONAL_PTR(protoInstanceResources, net, instanceResources, Net); + // COMPAT(grachevkirill) + YT_VERIFY(instanceResources->NetBytes.has_value() || !instanceResources->NetBits.has_value()); + YT_TOPROTO_OPTIONAL_PTR(protoInstanceResources, net_bytes, instanceResources, NetBytes); protoInstanceResources->set_type(instanceResources->Type); protoInstanceResources->set_vcpu(instanceResources->Vcpu); } @@ -196,9 +245,11 @@ void ToProto(NBundleController::NProto::TInstanceResources* protoInstanceResourc void FromProto(NBundleControllerClient::TInstanceResourcesPtr instanceResources, const NBundleController::NProto::TInstanceResources* protoInstanceResources) { YT_FROMPROTO_OPTIONAL_PTR(protoInstanceResources, memory, instanceResources, Memory); - YT_FROMPROTO_OPTIONAL_PTR(protoInstanceResources, net, instanceResources, Net); + YT_FROMPROTO_OPTIONAL_PTR(protoInstanceResources, net_bytes, instanceResources, NetBytes); YT_FROMPROTO_OPTIONAL_PTR(protoInstanceResources, type, instanceResources, Type); YT_FROMPROTO_OPTIONAL_PTR(protoInstanceResources, vcpu, instanceResources, Vcpu); + // COMPAT(grachevkirill): Remove later. + instanceResources->CanonizeNet(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/client/bundle_controller_client/bundle_controller_settings.h b/yt/yt/client/bundle_controller_client/bundle_controller_settings.h index b05802c679..7473cdc7d5 100644 --- a/yt/yt/client/bundle_controller_client/bundle_controller_settings.h +++ b/yt/yt/client/bundle_controller_client/bundle_controller_settings.h @@ -57,7 +57,10 @@ struct TInstanceResources { i64 Memory; // Bits per second. - std::optional<i64> Net; + // TODO(grachevkirill): Remove this field. + std::optional<i64> NetBits; + // Bytes per second. + std::optional<i64> NetBytes; TString Type; int Vcpu; @@ -66,6 +69,9 @@ struct TInstanceResources void Clear(); + void CanonizeNet(); + void ResetNet(); + REGISTER_YSON_STRUCT(TInstanceResources); static void Register(TRegistrar registrar); @@ -146,7 +152,9 @@ struct TBundleResourceQuota { int Vcpu; i64 Memory; - i64 Network; + // TODO(grachevkirill): Remove it later. + i64 NetworkBits; + i64 NetworkBytes; REGISTER_YSON_STRUCT(TBundleResourceQuota); diff --git a/yt/yt_proto/yt/client/bundle_controller/proto/bundle_controller_service.proto b/yt/yt_proto/yt/client/bundle_controller/proto/bundle_controller_service.proto index 69e1894927..dd3de268ec 100644 --- a/yt/yt_proto/yt/client/bundle_controller/proto/bundle_controller_service.proto +++ b/yt/yt_proto/yt/client/bundle_controller/proto/bundle_controller_service.proto @@ -28,7 +28,7 @@ message TMemoryLimits message TInstanceResources { optional int64 memory = 1; - optional int64 net = 2; + optional int64 net_bytes = 2; optional string type = 3; optional int32 vcpu = 4; } |