@Override
    public void run() {
      logger.info("Aggregating account stats for local report");
      try {
        // Each time we collect account stats from blob stores, we will recalculate the delete tombstone related stats
        // as well. So before starting collecting account stats, let's reset the delete tombstone stats.
        resetDeleteTombstoneStats();
        long totalFetchAndAggregateStartTimeMs = time.milliseconds();
        List<PartitionId> unreachablePartitions = new ArrayList<>();
        Map<Long, Map<Short, Map<Short, ContainerStorageStats>>> hostStorageStatsMap = new HashMap<>();

        // 1. First, collect account stats from each replicas and aggregate the result to aggregatedSnapshot.
        Set<PartitionId> partitionIds = new HashSet<>(partitionToReplicaMap.keySet());
        Iterator<PartitionId> iterator = partitionIds.iterator();
        while (!cancelled && iterator.hasNext()) {
          PartitionId partitionId = iterator.next();
          logger.debug("Aggregating account stats for local report started for store {}", partitionId);
          collectAndAggregateAccountStorageStats(hostStorageStatsMap, partitionId, unreachablePartitions);
        }

        // 2. Second, filter out the unreachable partitions that are not in the map.
        List<String> unreachableStores = examineUnreachablePartitions(unreachablePartitions);

        // 3. Update the delete tombstone related stats.
        metrics.initDeleteStatsGaugesIfNeeded();
        if (!cancelled) {
          metrics.totalFetchAndAggregateTimeMs.update(time.milliseconds() - totalFetchAndAggregateStartTimeMs);
          // 4. Construct a StatsWrapper.
          StatsHeader statsHeader =
              new StatsHeader(StatsHeader.StatsDescription.STORED_DATA_SIZE, time.milliseconds(), partitionIds.size(),
                  partitionIds.size() - unreachableStores.size(), unreachableStores);
          HostAccountStorageStatsWrapper statsWrapper =
              new HostAccountStorageStatsWrapper(statsHeader, new HostAccountStorageStats(hostStorageStatsMap));
          // 5. Persist this statsWrapper to mysql database if connection exists.
          accountStatsStore.storeHostAccountStorageStats(statsWrapper);
        }
      } catch (Exception e) {
        metrics.statsAggregationFailureCount.inc();
        logger.error("Exception while aggregating account stats for local report", e);
      }
    }
Runnable class that collects, publish account stats to mysql database and local backup file.
ambry-server/src/main/java/com/github/ambry/server/StatsManager.java