77 Any ,
88 Callable ,
99 Dict ,
10+ List ,
1011 Optional ,
1112 TypeAlias ,
1213 TypedDict ,
5051from snuba .query .allocation_policies .utils import get_max_bytes_to_read
5152from snuba .query .query_settings import HTTPQuerySettings
5253from snuba .state import record_query
53- from snuba .state .quota import ResourceQuota
5454from snuba .utils .metrics .timer import Timer
5555from snuba .utils .metrics .wrapper import MetricsWrapper
5656from snuba .utils .registered_class import import_submodules_in_directory
@@ -322,10 +322,7 @@ def merge_clickhouse_settings(
322322 """
323323
324324 for k , v in routing_decision .clickhouse_settings .items ():
325- if k == "max_threads" :
326- query_settings .set_resource_quota (ResourceQuota (max_threads = v ))
327- else :
328- query_settings .push_clickhouse_setting (k , v )
325+ query_settings .push_clickhouse_setting (k , v )
329326
330327 def _record_value_in_span_and_DD (
331328 self ,
@@ -351,30 +348,22 @@ def _update_routing_decision(
351348 raise NotImplementedError
352349
353350 def _get_combined_allocation_policies_recommendations (
354- self ,
355- routing_context : RoutingContext ,
351+ self , policy_recommendations : List [QuotaAllowance ]
356352 ) -> CombinedAllocationPoliciesRecommendations :
357- # decides how to combine the recommendations from the allocation policies with the cluster load
353+ # decides how to combine the recommendations from the allocation policies
358354 settings = {}
359355
360- max_bytes_to_read = get_max_bytes_to_read (
361- routing_context .allocation_policies_recommendations
362- )
356+ max_bytes_to_read = get_max_bytes_to_read (policy_recommendations )
363357 if max_bytes_to_read != 0 :
364358 settings ["max_bytes_to_read" ] = max_bytes_to_read
365359
366360 settings ["max_threads" ] = min (
367- [qa .max_threads for qa in routing_context . allocation_policies_recommendations . values () ],
361+ [qa .max_threads for qa in policy_recommendations ],
368362 )
369363
370364 return CombinedAllocationPoliciesRecommendations (
371- can_run = all (
372- qa .can_run for qa in routing_context .allocation_policies_recommendations .values ()
373- ),
374- is_throttled = any (
375- qa .is_throttled
376- for qa in routing_context .allocation_policies_recommendations .values ()
377- ),
365+ can_run = all (qa .can_run for qa in policy_recommendations ),
366+ is_throttled = any (qa .is_throttled for qa in policy_recommendations ),
378367 settings = settings ,
379368 )
380369
@@ -413,7 +402,9 @@ def get_routing_decision(self, routing_context: RoutingContext) -> RoutingDecisi
413402 self ._get_recommendations_from_allocation_policies (routing_context )
414403 )
415404 combined_allocation_policies_recommendations = (
416- self ._get_combined_allocation_policies_recommendations (routing_context )
405+ self ._get_combined_allocation_policies_recommendations (
406+ list (routing_context .allocation_policies_recommendations .values ())
407+ )
417408 )
418409
419410 routing_decision = RoutingDecision (
0 commit comments