diff options
author | galaxycrab <UgnineSirdis@ydb.tech> | 2023-01-30 17:21:11 +0300 |
---|---|---|
committer | galaxycrab <UgnineSirdis@ydb.tech> | 2023-01-30 17:21:11 +0300 |
commit | f68f245e2281c24c14d352eff67c6e639faa150e (patch) | |
tree | 90d5ad46a9f2f36e3143a6a091510e4598ae3aa5 | |
parent | 3da8b6493e6d5b6c576cfdc3bb34866da3ac8f6f (diff) | |
download | ydb-f68f245e2281c24c14d352eff67c6e639faa150e.tar.gz |
Remove unused code for getting quotas for cloud during creation of rate limiter resource for query
4 files changed, 37 insertions, 26 deletions
diff --git a/ydb/core/yq/libs/control_plane_storage/internal/rate_limiter_resources.cpp b/ydb/core/yq/libs/control_plane_storage/internal/rate_limiter_resources.cpp index b4a0b20c09..aa8d10309a 100644 --- a/ydb/core/yq/libs/control_plane_storage/internal/rate_limiter_resources.cpp +++ b/ydb/core/yq/libs/control_plane_storage/internal/rate_limiter_resources.cpp @@ -162,22 +162,10 @@ public: STRICT_STFUNC(StateFunc, hFunc(TEvControlPlaneStorageInternal::TEvDbRequestResult, Handle); hFunc(TEvRateLimiter::TEvCreateResourceResponse, Handle); - hFunc(TEvQuotaService::TQuotaGetResponse, Handle); ) void OnDbRequestSuccess() { - CPS_LOG_D("Get quota value from quota service"); - Send(MakeQuotaServiceActorId(SelfId().NodeId()), new TEvQuotaService::TQuotaGetRequest(SUBJECT_TYPE_CLOUD, CloudId, true)); - } - - void Handle(TEvQuotaService::TQuotaGetResponse::TPtr& ev) { - CPS_LOG_D("Got response from quota service"); - if (auto quotaIt = ev->Get()->Quotas.find(QUOTA_CPU_PERCENT_LIMIT); quotaIt != ev->Get()->Quotas.end()) { - CloudLimit = static_cast<double>(quotaIt->second.Limit.Value * 10); // percent -> milliseconds - Send(RateLimiterControlPlaneServiceId(), new TEvRateLimiter::TEvCreateResource(CloudId, FolderId, QueryId, CloudLimit, QueryLimit)); - } else { - ReplyWithError("CPU quota for cloud was not found"); - } + Send(RateLimiterControlPlaneServiceId(), new TEvRateLimiter::TEvCreateResource(CloudId, FolderId, QueryId, QueryLimit)); } using TCreateRequestActorBase::Handle; @@ -199,9 +187,6 @@ public: static const TString RequestTypeName; static constexpr bool IsCreateRequest = true; - -private: - double CloudLimit = 0.0; }; const TString TRateLimiterCreateRequest::RequestTypeName = "CreateRateLimiterResource"; diff --git a/ydb/core/yq/libs/rate_limiter/control_plane_service/rate_limiter_control_plane_service.cpp b/ydb/core/yq/libs/rate_limiter/control_plane_service/rate_limiter_control_plane_service.cpp index ef724636fd..60e2ae6966 100644 --- a/ydb/core/yq/libs/rate_limiter/control_plane_service/rate_limiter_control_plane_service.cpp +++ b/ydb/core/yq/libs/rate_limiter/control_plane_service/rate_limiter_control_plane_service.cpp @@ -130,9 +130,9 @@ private: if (!ev->Get()->Scope && !ev->Get()->QueryId && !ev->Get()->QueryLimit) { // cloud path = GetRateLimiterResourcePath(ev->Get()->CloudId); limits = {ev->Get()->CloudLimit}; - } else { + } else { // query path = GetRateLimiterResourcePath(ev->Get()->CloudId, ev->Get()->Scope, ev->Get()->QueryId); - limits = {ev->Get()->CloudLimit, Nothing(), ev->Get()->QueryLimit}; + limits = {Nothing(), Nothing(), ev->Get()->QueryLimit}; // imply that cloud resource must already have been created } NActors::TActivationContext::AsActorContext().Register( MakeCreateRateLimiterResourceActor( diff --git a/ydb/core/yq/libs/rate_limiter/events/control_plane_events.h b/ydb/core/yq/libs/rate_limiter/events/control_plane_events.h index b14cbc802a..675d85bc5e 100644 --- a/ydb/core/yq/libs/rate_limiter/events/control_plane_events.h +++ b/ydb/core/yq/libs/rate_limiter/events/control_plane_events.h @@ -22,16 +22,16 @@ struct TEvRateLimiter { static_assert(EvEnd <= YqEventSubspaceEnd(TYqEventSubspace::RateLimiter), "All events must be in their subspace"); struct TEvCreateResource : NActors::TEventLocal<TEvCreateResource, EEv::EvCreateResource> { - explicit TEvCreateResource(const TString& cloudId, const TString& scope, const TString& queryId, double cloudLimit, TMaybe<double> queryLimit) + TEvCreateResource(const TString& cloudId, const TString& scope, const TString& queryId, TMaybe<double> queryLimit) : CloudId(cloudId) , Scope(scope) , QueryId(queryId) - , CloudLimit(cloudLimit) + , CloudLimit(Nothing()) , QueryLimit(queryLimit) { } - explicit TEvCreateResource(const TString& cloudId, double cloudLimit) + TEvCreateResource(const TString& cloudId, double cloudLimit) : CloudId(cloudId) , CloudLimit(cloudLimit) { @@ -40,7 +40,7 @@ struct TEvRateLimiter { const TString CloudId; const TString Scope; const TString QueryId; - const double CloudLimit; + const TMaybe<double> CloudLimit; const TMaybe<double> QueryLimit; }; diff --git a/ydb/core/yq/libs/ydb/schema.cpp b/ydb/core/yq/libs/ydb/schema.cpp index 14a21c8566..3a7d3fae62 100644 --- a/ydb/core/yq/libs/ydb/schema.cpp +++ b/ydb/core/yq/libs/ydb/schema.cpp @@ -118,15 +118,19 @@ public: ); } - template <class TEventPtr> - void ReplyAndDie(TEventPtr& ev) { - SCHEMA_LOG_DEBUG("Reply for " << GetActionName() << " " << GetEntityName() << ": " << ev->Get()->Result.GetIssues().ToOneLineString()); + void ReplyStatusAndDie(const NYdb::TStatus& status) { + SCHEMA_LOG_DEBUG("Reply for " << GetActionName() << " " << GetEntityName() << ": " << status.GetIssues().ToOneLineString()); if (Parent) { - this->Send(Parent, new TResponseEvent(ev->Get()->Result), 0, Cookie); + this->Send(Parent, new TResponseEvent(status), 0, Cookie); } this->PassAway(); } + template <class TEventPtr> + void ReplyAndDie(TEventPtr& ev) { + return ReplyStatusAndDie(ev->Get()->Result); + } + virtual TString GetEntityName() const = 0; virtual TStringBuf GetActionName() const = 0; // "create" or "delete" @@ -231,10 +235,17 @@ protected: return CallYdbSdk(RequestsPath[CurrentRequest]); } + virtual bool OnCurrentRequestChanged() { // extra validation + return true; + } + void Handle(TEvents::TEvSchemaCreated::TPtr& ev) override { if (CurrentRequest < RequestsPath.size() - 1 && IsTableCreated(ev->Get()->Result)) { SCHEMA_LOG_DEBUG("Successfully created " << GetEntityName(RequestsPath[CurrentRequest])); ++CurrentRequest; + if (!OnCurrentRequestChanged()) { + return; + } this->RetryState = nullptr; this->CallAndSubscribe(); return; @@ -242,6 +253,9 @@ protected: if (CurrentRequest > 0 && IsPathDoesNotExistError(ev->Get()->Result)) { if (!TriedPaths[CurrentRequest - 1]) { // Defence from cycles. --CurrentRequest; + if (!OnCurrentRequestChanged()) { + return; + } TriedPaths[CurrentRequest] = true; this->RetryState = nullptr; SCHEMA_LOG_DEBUG("Trying to recursively create " << GetEntityName(RequestsPath[CurrentRequest])); @@ -435,6 +449,18 @@ private: return TStringBuilder() << "rate limiter resource \"" << req.Path << "\""; } + bool OnCurrentRequestChanged() override { + if (CurrentRequest == 0 && !Limits[0]) { + SCHEMA_LOG_WARN("Create " << TRecursiveCreateActorBase<TCreateRateLimiterResourceRequestDesc>::GetEntityName() << ". Attempt to create rate limiter resource root without limit"); + NYql::TIssues issues; + issues.AddIssue(TStringBuilder() << "Internal error: attempt to create rate limiter resource root \"" << RequestsPath[0].Path << "\" without limit"); + NYdb::TStatus status(NYdb::EStatus::INTERNAL_ERROR, std::move(issues)); + ReplyStatusAndDie(status); + return false; + } + return true; + } + void FillRequestsPath(std::vector<TCreateRateLimiterResourceRequestDesc>& desc) override { std::vector<TString> components = NKikimr::SplitPath(ResourcePath); desc.resize(components.size()); |