21
21
22
22
namespace NFq {
23
23
24
- using TQuotaCountExecuter = TDbExecuter<THashMap<TString, ui32>>;
25
24
26
25
void TYdbControlPlaneStorageActor::Handle (TEvQuotaService::TQuotaUsageRequest::TPtr& ev) {
27
26
@@ -31,7 +30,15 @@ void TYdbControlPlaneStorageActor::Handle(TEvQuotaService::TQuotaUsageRequest::T
31
30
}
32
31
33
32
if (QuotasUpdatedAt + Config->QuotaTtl > Now ()) {
34
- Send (ev->Sender , new TEvQuotaService::TQuotaUsageResponse (SUBJECT_TYPE_CLOUD, ev->Get ()->SubjectId , ev->Get ()->MetricName , QueryQuotas.Value (ev->Get ()->SubjectId , 0 )));
33
+ ui64 usage = 0 ;
34
+ auto quotaIt = this ->QueryQuotas .find (ev->Get ()->SubjectId );
35
+ if (quotaIt != this ->QueryQuotas .end ()) {
36
+ auto queryType = ev->Get ()->MetricName == QUOTA_ANALYTICS_COUNT_LIMIT
37
+ ? FederatedQuery::QueryContent::QueryType::QueryContent_QueryType_ANALYTICS
38
+ : FederatedQuery::QueryContent::QueryType::QueryContent_QueryType_STREAMING;
39
+ usage = quotaIt->second [queryType];
40
+ }
41
+ Send (ev->Sender , new TEvQuotaService::TQuotaUsageResponse (SUBJECT_TYPE_CLOUD, ev->Get ()->SubjectId , ev->Get ()->MetricName , usage));
35
42
}
36
43
37
44
QueryQuotaRequests[ev->Get ()->SubjectId ] = ev;
@@ -43,21 +50,24 @@ void TYdbControlPlaneStorageActor::Handle(TEvQuotaService::TQuotaUsageRequest::T
43
50
QuotasUpdating = true ;
44
51
QueryQuotas.clear ();
45
52
53
+ using TQuotaCountExecuter = TDbExecuter<TQueryQuotasMap>;
54
+
46
55
TDbExecutable::TPtr executable;
47
56
auto & executer = TQuotaCountExecuter::Create (executable, false , [](TQuotaCountExecuter& executer) { executer.State .clear (); } );
48
57
49
58
executer.Read (
50
59
[=](TQuotaCountExecuter&, TSqlQueryBuilder& builder) {
51
60
builder.AddText (
52
- " SELECT `" SCOPE_COLUMN_NAME " `, COUNT(`" SCOPE_COLUMN_NAME " `) AS PENDING_COUNT\n "
61
+ " SELECT `" SCOPE_COLUMN_NAME " `, ` " QUERY_TYPE_COLUMN_NAME " ` AS QUERY_TYPE, COUNT(`" SCOPE_COLUMN_NAME " `) AS PENDING_COUNT\n "
53
62
" FROM `" PENDING_SMALL_TABLE_NAME " `\n "
54
- " GROUP BY `" SCOPE_COLUMN_NAME " `\n "
63
+ " GROUP BY `" QUERY_TYPE_COLUMN_NAME " `, ` " SCOPE_COLUMN_NAME " `\n "
55
64
);
56
65
},
57
66
[=](TQuotaCountExecuter& executer, const TVector<NYdb::TResultSet>& resultSets) {
58
67
TResultSetParser parser (resultSets.front ());
59
68
while (parser.TryNextRow ()) {
60
69
auto scope = *parser.ColumnParser (SCOPE_COLUMN_NAME).GetOptionalString ();
70
+ auto queryType = static_cast <FederatedQuery::QueryContent::QueryType>(parser.ColumnParser (" QUERY_TYPE" ).GetOptionalInt64 ().value_or (1 ));
61
71
auto count = parser.ColumnParser (" PENDING_COUNT" ).GetUint64 ();
62
72
executer.Read (
63
73
[=](TQuotaCountExecuter&, TSqlQueryBuilder& builder) {
@@ -73,7 +83,7 @@ void TYdbControlPlaneStorageActor::Handle(TEvQuotaService::TQuotaUsageRequest::T
73
83
if (parser.TryNextRow ()) {
74
84
FederatedQuery::Internal::QueryInternal internal;
75
85
ParseProto (executer, internal, parser, INTERNAL_COLUMN_NAME);
76
- executer.State [internal.cloud_id ()] += count;
86
+ executer.State [internal.cloud_id ()][queryType] += count;
77
87
}
78
88
},
79
89
" GetScopeCloud_" + scope, true
@@ -87,8 +97,15 @@ void TYdbControlPlaneStorageActor::Handle(TEvQuotaService::TQuotaUsageRequest::T
87
97
this ->QueryQuotas .swap (executer.State );
88
98
for (auto & it : this ->QueryQuotaRequests ) {
89
99
auto ev = it.second ;
90
- this ->Send (ev->Sender , new TEvQuotaService::TQuotaUsageResponse (SUBJECT_TYPE_CLOUD, it.first , QUOTA_ANALYTICS_COUNT_LIMIT, this ->QueryQuotas .Value (it.first , 0 )));
91
- this ->Send (ev->Sender , new TEvQuotaService::TQuotaUsageResponse (SUBJECT_TYPE_CLOUD, it.first , QUOTA_STREAMING_COUNT_LIMIT, this ->QueryQuotas .Value (it.first , 0 )));
100
+ ui64 analyticCount = 0 ;
101
+ ui64 streamingCount = 0 ;
102
+ auto quotaIt = this ->QueryQuotas .find (it.first );
103
+ if (quotaIt != this ->QueryQuotas .end ()) {
104
+ analyticCount = quotaIt->second [FederatedQuery::QueryContent::QueryType::QueryContent_QueryType_ANALYTICS];
105
+ streamingCount = quotaIt->second [FederatedQuery::QueryContent::QueryType::QueryContent_QueryType_STREAMING];
106
+ }
107
+ this ->Send (ev->Sender , new TEvQuotaService::TQuotaUsageResponse (SUBJECT_TYPE_CLOUD, it.first , QUOTA_ANALYTICS_COUNT_LIMIT, analyticCount));
108
+ this ->Send (ev->Sender , new TEvQuotaService::TQuotaUsageResponse (SUBJECT_TYPE_CLOUD, it.first , QUOTA_STREAMING_COUNT_LIMIT, streamingCount));
92
109
}
93
110
this ->QueryQuotaRequests .clear ();
94
111
this ->QuotasUpdating = false ;
0 commit comments