parameters: (
              self,
              osdmap: OSDMap,
              pools: Dict[str, Dict[str, Any]],
              crush_map: CRUSHMap,
              root_map: Dict[int, CrushSubtreeResourceStatus],
              pool_stats: Dict[int, Dict[str, int]],
              ret: List[Dict[str, Any]],
              threshold: float,
              func_pass: 'PassT',
              overlapped_roots: Set[int],
      )
return_statement: return ret, bulk_pools, even_pools
docstring: Calculates final_pg_target of each pools and determine if it needs
          scaling, this depends on the profile of the autoscaler. For scale-down,
          we start out with a full complement of pgs and only descrease it when other
          pools needs more pgs due to increased usage. For scale-up, we start out with
          the minimal amount of pgs and only scale when there is increase in usage.
docstring_summary: Calculates final_pg_target of each pools and determine if it needs
          scaling, this depends on the profile of the autoscaler. For scale-down,
          we start out with a full complement of pgs and only descrease it when other
          pools needs more pgs due to increased usage. For scale-up, we start out with
          the minimal amount of pgs and only scale when there is increase in usage.
docstring_tokens: Calculates final_pg_target of each pools and determine if it needs scaling this depends on the profile of the autoscaler . For scale - down we start out with a full complement of pgs and only descrease it when other pools needs more pgs due to increased usage . For scale - up we start out with the minimal amount of pgs and only scale when there is increase in usage .
function: def _get_pool_pg_targets(
              self,
              osdmap: OSDMap,
              pools: Dict[str, Dict[str, Any]],
              crush_map: CRUSHMap,
              root_map: Dict[int, CrushSubtreeResourceStatus],
              pool_stats: Dict[int, Dict[str, int]],
              ret: List[Dict[str, Any]],
              threshold: float,
              func_pass: 'PassT',
              overlapped_roots: Set[int],
      ) -> Tuple[List[Dict[str, Any]], Dict[str, Dict[str, Any]] , Dict[str, Dict[str, Any]]]:
          """
          Calculates final_pg_target of each pools and determine if it needs
          scaling, this depends on the profile of the autoscaler. For scale-down,
          we start out with a full complement of pgs and only descrease it when other
          pools needs more pgs due to increased usage. For scale-up, we start out with
          the minimal amount of pgs and only scale when there is increase in usage.
          """
          even_pools: Dict[str, Dict[str, Any]] = {}
          bulk_pools: Dict[str, Dict[str, Any]] = {}
          for pool_name, p in pools.items():
              pool_id = p['pool']
              if pool_id not in pool_stats:
                  # race with pool deletion; skip
                  continue
  
              # FIXME: we assume there is only one take per pool, but that
              # may not be true.
              crush_rule = crush_map.get_rule_by_id(p['crush_rule'])
              assert crush_rule is not None
              cr_name = crush_rule['rule_name']
              root_id = crush_map.get_rule_root(cr_name)
              assert root_id is not None
              if root_id in overlapped_roots:
                  # skip pools
                  # with overlapping roots
                  self.log.warn("pool %d contains an overlapping root %d"
                                "... skipping scaling", pool_id, root_id)
                  continue
              capacity = root_map[root_id].capacity
              assert capacity is not None
              if capacity == 0:
                  self.log.debug('skipping empty subtree %s', cr_name)
                  continue
  
              raw_used_rate = osdmap.pool_raw_used_rate(pool_id)
  
              pool_logical_used = pool_stats[pool_id]['stored']
              bias = p['options'].get('pg_autoscale_bias', 1.0)
              target_bytes = 0
              # ratio takes precedence if both are set
              if p['options'].get('target_size_ratio', 0.0) == 0.0:
                  target_bytes = p['options'].get('target_size_bytes', 0)
  
              # What proportion of space are we using?
              actual_raw_used = pool_logical_used * raw_used_rate
              actual_capacity_ratio = float(actual_raw_used) / capacity
  
              pool_raw_used = max(pool_logical_used, target_bytes) * raw_used_rate
              capacity_ratio = float(pool_raw_used) / capacity
  
              self.log.info("effective_target_ratio {0} {1} {2} {3}".format(
                  p['options'].get('target_size_ratio', 0.0),
                  root_map[root_id].total_target_ratio,
                  root_map[root_id].total_target_bytes,
                  capacity))
  
              target_ratio = effective_target_ratio(p['options'].get('target_size_ratio', 0.0),
                                                    root_map[root_id].total_target_ratio,
                                                    root_map[root_id].total_target_bytes,
                                                    capacity)
  
              # determine if the pool is a bulk
              bulk = False
              flags = p['flags_names'].split(",")
              if "bulk" in flags:
                  bulk = True
  
              capacity_ratio = max(capacity_ratio, target_ratio)
              final_ratio, pool_pg_target, final_pg_target = self._calc_final_pg_target(
                  p, pool_name, root_map, root_id,
                  capacity_ratio, bias, even_pools,
                  bulk_pools, func_pass, bulk)
  
              if final_ratio is None:
                  continue
  
              adjust = False
              if (final_pg_target > p['pg_num_target'] * threshold or
                      final_pg_target < p['pg_num_target'] / threshold) and \
                      final_ratio >= 0.0 and \
                      final_ratio <= 1.0:
                  adjust = True
  
              assert pool_pg_target is not None
              ret.append({
                  'pool_id': pool_id,
                  'pool_name': p['pool_name'],
                  'crush_root_id': root_id,
                  'pg_autoscale_mode': p['pg_autoscale_mode'],
                  'pg_num_target': p['pg_num_target'],
                  'logical_used': pool_logical_used,
                  'target_bytes': target_bytes,
                  'raw_used_rate': raw_used_rate,
                  'subtree_capacity': capacity,
                  'actual_raw_used': actual_raw_used,
                  'raw_used': pool_raw_used,
                  'actual_capacity_ratio': actual_capacity_ratio,
                  'capacity_ratio': capacity_ratio,
                  'target_ratio': p['options'].get('target_size_ratio', 0.0),
                  'effective_target_ratio': target_ratio,
                  'pg_num_ideal': int(pool_pg_target),
                  'pg_num_final': final_pg_target,
                  'would_adjust': adjust,
                  'bias': p.get('options', {}).get('pg_autoscale_bias', 1.0),
                  'bulk': bulk,
              })
  
          return ret, bulk_pools, even_pools
function_tokens: def _get_pool_pg_targets ( self , osdmap : OSDMap , pools : Dict [ str , Dict [ str , Any ] ] , crush_map : CRUSHMap , root_map : Dict [ int , CrushSubtreeResourceStatus ] , pool_stats : Dict [ int , Dict [ str , int ] ] , ret : List [ Dict [ str , Any ] ] , threshold : float , func_pass : 'PassT' , overlapped_roots : Set [ int ] , ) -> Tuple [ List [ Dict [ str , Any ] ] , Dict [ str , Dict [ str , Any ] ] , Dict [ str , Dict [ str , Any ] ] ] : even_pools : Dict [ str , Dict [ str , Any ] ] = { } bulk_pools : Dict [ str , Dict [ str , Any ] ] = { } for pool_name , p in pools . items ( ) : pool_id = p [ 'pool' ] if pool_id not in pool_stats : # race with pool deletion; skip continue # FIXME: we assume there is only one take per pool, but that # may not be true. crush_rule = crush_map . get_rule_by_id ( p [ 'crush_rule' ] ) assert crush_rule is not None cr_name = crush_rule [ 'rule_name' ] root_id = crush_map . get_rule_root ( cr_name ) assert root_id is not None if root_id in overlapped_roots : # skip pools # with overlapping roots self . log . warn ( "pool %d contains an overlapping root %d" "... skipping scaling" , pool_id , root_id ) continue capacity = root_map [ root_id ] . capacity assert capacity is not None if capacity == 0 : self . log . debug ( 'skipping empty subtree %s' , cr_name ) continue raw_used_rate = osdmap . pool_raw_used_rate ( pool_id ) pool_logical_used = pool_stats [ pool_id ] [ 'stored' ] bias = p [ 'options' ] . get ( 'pg_autoscale_bias' , 1.0 ) target_bytes = 0 # ratio takes precedence if both are set if p [ 'options' ] . get ( 'target_size_ratio' , 0.0 ) == 0.0 : target_bytes = p [ 'options' ] . get ( 'target_size_bytes' , 0 ) # What proportion of space are we using? actual_raw_used = pool_logical_used * raw_used_rate actual_capacity_ratio = float ( actual_raw_used ) / capacity pool_raw_used = max ( pool_logical_used , target_bytes ) * raw_used_rate capacity_ratio = float ( pool_raw_used ) / capacity self . log . info ( "effective_target_ratio {0} {1} {2} {3}" . format ( p [ 'options' ] . get ( 'target_size_ratio' , 0.0 ) , root_map [ root_id ] . total_target_ratio , root_map [ root_id ] . total_target_bytes , capacity ) ) target_ratio = effective_target_ratio ( p [ 'options' ] . get ( 'target_size_ratio' , 0.0 ) , root_map [ root_id ] . total_target_ratio , root_map [ root_id ] . total_target_bytes , capacity ) # determine if the pool is a bulk bulk = False flags = p [ 'flags_names' ] . split ( "," ) if "bulk" in flags : bulk = True capacity_ratio = max ( capacity_ratio , target_ratio ) final_ratio , pool_pg_target , final_pg_target = self . _calc_final_pg_target ( p , pool_name , root_map , root_id , capacity_ratio , bias , even_pools , bulk_pools , func_pass , bulk ) if final_ratio is None : continue adjust = False if ( final_pg_target > p [ 'pg_num_target' ] * threshold or final_pg_target < p [ 'pg_num_target' ] / threshold ) and final_ratio >= 0.0 and final_ratio <= 1.0 : adjust = True assert pool_pg_target is not None ret . append ( { 'pool_id' : pool_id , 'pool_name' : p [ 'pool_name' ] , 'crush_root_id' : root_id , 'pg_autoscale_mode' : p [ 'pg_autoscale_mode' ] , 'pg_num_target' : p [ 'pg_num_target' ] , 'logical_used' : pool_logical_used , 'target_bytes' : target_bytes , 'raw_used_rate' : raw_used_rate , 'subtree_capacity' : capacity , 'actual_raw_used' : actual_raw_used , 'raw_used' : pool_raw_used , 'actual_capacity_ratio' : actual_capacity_ratio , 'capacity_ratio' : capacity_ratio , 'target_ratio' : p [ 'options' ] . get ( 'target_size_ratio' , 0.0 ) , 'effective_target_ratio' : target_ratio , 'pg_num_ideal' : int ( pool_pg_target ) , 'pg_num_final' : final_pg_target , 'would_adjust' : adjust , 'bias' : p . get ( 'options' , { } ) . get ( 'pg_autoscale_bias' , 1.0 ) , 'bulk' : bulk , } ) return ret , bulk_pools , even_pools