def analyze_hbase_region_server_metrics(metric_task, metrics):
  region_server_name = None
  region_operation_metrics_dict = {}
  replication_metrics_dict = {}
  for bean in metrics['beans']:
    try:
      # because root and meta region have the names, we must use region server
      # name and region name to locate a region
      if bean['name'] == REGION_SERVER_BEAN_NAME:
        region_server_name = bean['ServerName']
      elif bean['name'] == REGION_SERVER_DYNAMIC_STATISTICS_BEAN_NAME:
        for metricName in bean.keys():
          if Region.is_region_operation_metric_name(metricName):
            encodeName = Region.get_encode_name_from_region_operation_metric_name(metricName)
            region_operation_metrics = region_operation_metrics_dict.setdefault(encodeName, {})
            region_operation_metrics[metricName] = bean[metricName]
      elif bean['name'].startswith(REGION_SERVER_REPLICATION_BEAN_NAME_PREFIX):
        peerId = metric_helper.parse_replication_source(bean['name'])
        replication_metrics = replication_metrics_dict.setdefault(peerId, {})
        for metricName in bean.keys():
          replication_metrics[metricName] = bean[metricName]
    except Exception as e:
      logger.warning("%r failed to analyze metrics: %r", metric_task, e)
      continue

  region_server = None
  if region_server_name is None:
    return
  else:
    try:
      region_server = RegionServer.objects.get(name = region_server_name)
    except RegionServer.DoesNotExist:
      logger.warning("%r failed to find region_server with region_server_name=%s",
        metric_task, region_server_name)
      return

  # save replication metrics for region server
  region_server.replication_last_attempt_time = metric_task.last_attempt_time
  region_server.replicationMetrics = json.dumps(replication_metrics_dict)
  region_server.save()

  region_record_need_save = []
  for encodeName, operationMetrics in region_operation_metrics_dict.iteritems():
    region_record = dbutil.get_region_by_regionserver_and_encodename(
      region_server, encodeName)
    # we must wait region saved after analyzing master task
    if region_record is None:
      continue
    region_record.analyze_from_region_server_operation_metrics(operationMetrics,
      metric_task.last_attempt_time)
    # we first buffer the regions needed to update, then do batch update
    region_record_need_save.append(region_record)

  # we do batch update
  begin = datetime.datetime.now()
  dbutil.update_regions_for_region_server_metrics(region_record_need_save)
  logger.info("%r batch save region record for region_server, " \
    "saved regions=%d, consume=%s",
    metric_task, len(region_record_need_save),
    str((begin - datetime.datetime.now()).total_seconds()))
dataset/ETHPy150Open XiaoMi/minos/owl/collector/management/commands/metrics_updater.py/analyze_hbase_region_server_metrics/swapped operands of `-`