RegionLoad createRegionLoad(final HRegion r, RegionLoad.Builder regionLoadBldr,
    RegionSpecifier.Builder regionSpecifier) throws IOException {
    byte[] name = r.getRegionInfo().getRegionName();
    String regionEncodedName = r.getRegionInfo().getEncodedName();
    int stores = 0;
    int storefiles = 0;
    int storeRefCount = 0;
    int maxCompactedStoreFileRefCount = 0;
    long storeUncompressedSize = 0L;
    long storefileSize = 0L;
    long storefileIndexSize = 0L;
    long rootLevelIndexSize = 0L;
    long totalStaticIndexSize = 0L;
    long totalStaticBloomSize = 0L;
    long totalCompactingKVs = 0L;
    long currentCompactedKVs = 0L;
    long totalRegionSize = 0L;
    List<HStore> storeList = r.getStores();
    stores += storeList.size();
    for (HStore store : storeList) {
      storefiles += store.getStorefilesCount();
      int currentStoreRefCount = store.getStoreRefCount();
      storeRefCount += currentStoreRefCount;
      int currentMaxCompactedStoreFileRefCount = store.getMaxCompactedStoreFileRefCount();
      maxCompactedStoreFileRefCount =
        Math.max(maxCompactedStoreFileRefCount, currentMaxCompactedStoreFileRefCount);
      storeUncompressedSize += store.getStoreSizeUncompressed();
      storefileSize += store.getStorefilesSize();
      totalRegionSize += store.getHFilesSize();
      // TODO: storefileIndexSizeKB is same with rootLevelIndexSizeKB?
      storefileIndexSize += store.getStorefilesRootLevelIndexSize();
      CompactionProgress progress = store.getCompactionProgress();
      if (progress != null) {
        totalCompactingKVs += progress.getTotalCompactingKVs();
        currentCompactedKVs += progress.currentCompactedKVs;
      }
      rootLevelIndexSize += store.getStorefilesRootLevelIndexSize();
      totalStaticIndexSize += store.getTotalStaticIndexSize();
      totalStaticBloomSize += store.getTotalStaticBloomSize();
    }

    int memstoreSizeMB = roundSize(r.getMemStoreDataSize(), unitMB);
    int storeUncompressedSizeMB = roundSize(storeUncompressedSize, unitMB);
    int storefileSizeMB = roundSize(storefileSize, unitMB);
    int storefileIndexSizeKB = roundSize(storefileIndexSize, unitKB);
    int rootLevelIndexSizeKB = roundSize(rootLevelIndexSize, unitKB);
    int totalStaticIndexSizeKB = roundSize(totalStaticIndexSize, unitKB);
    int totalStaticBloomSizeKB = roundSize(totalStaticBloomSize, unitKB);
    int regionSizeMB = roundSize(totalRegionSize, unitMB);
    final MutableFloat currentRegionCachedRatio = new MutableFloat(0.0f);
    getBlockCache().ifPresent(bc -> {
      bc.getRegionCachedInfo().ifPresent(regionCachedInfo -> {
        if (regionCachedInfo.containsKey(regionEncodedName)) {
          currentRegionCachedRatio.setValue(regionSizeMB == 0
            ? 0.0f
            : (float) roundSize(regionCachedInfo.get(regionEncodedName), unitMB) / regionSizeMB);
        }
      });
    });

    HDFSBlocksDistribution hdfsBd = r.getHDFSBlocksDistribution();
    float dataLocality = hdfsBd.getBlockLocalityIndex(serverName.getHostname());
    float dataLocalityForSsd = hdfsBd.getBlockLocalityIndexForSsd(serverName.getHostname());
    long blocksTotalWeight = hdfsBd.getUniqueBlocksTotalWeight();
    long blocksLocalWeight = hdfsBd.getBlocksLocalWeight(serverName.getHostname());
    long blocksLocalWithSsdWeight = hdfsBd.getBlocksLocalWithSsdWeight(serverName.getHostname());
    if (regionLoadBldr == null) {
      regionLoadBldr = RegionLoad.newBuilder();
    }
    if (regionSpecifier == null) {
      regionSpecifier = RegionSpecifier.newBuilder();
    }

    regionSpecifier.setType(RegionSpecifierType.REGION_NAME);
    regionSpecifier.setValue(UnsafeByteOperations.unsafeWrap(name));
    regionLoadBldr.setRegionSpecifier(regionSpecifier.build()).setStores(stores)
      .setStorefiles(storefiles).setStoreRefCount(storeRefCount)
      .setMaxCompactedStoreFileRefCount(maxCompactedStoreFileRefCount)
      .setStoreUncompressedSizeMB(storeUncompressedSizeMB).setStorefileSizeMB(storefileSizeMB)
      .setMemStoreSizeMB(memstoreSizeMB).setStorefileIndexSizeKB(storefileIndexSizeKB)
      .setRootIndexSizeKB(rootLevelIndexSizeKB).setTotalStaticIndexSizeKB(totalStaticIndexSizeKB)
      .setTotalStaticBloomSizeKB(totalStaticBloomSizeKB)
      .setReadRequestsCount(r.getReadRequestsCount()).setCpRequestsCount(r.getCpRequestsCount())
      .setFilteredReadRequestsCount(r.getFilteredReadRequestsCount())
      .setWriteRequestsCount(r.getWriteRequestsCount()).setTotalCompactingKVs(totalCompactingKVs)
      .setCurrentCompactedKVs(currentCompactedKVs).setDataLocality(dataLocality)
      .setDataLocalityForSsd(dataLocalityForSsd).setBlocksLocalWeight(blocksLocalWeight)
      .setBlocksLocalWithSsdWeight(blocksLocalWithSsdWeight).setBlocksTotalWeight(blocksTotalWeight)
      .setCompactionState(ProtobufUtil.createCompactionStateForRegionLoad(r.getCompactionState()))
      .setLastMajorCompactionTs(r.getOldestHfileTs(true)).setRegionSizeMB(regionSizeMB)
      .setCurrentRegionCachedRatio(currentRegionCachedRatio.floatValue());
    r.setCompleteSequenceId(regionLoadBldr);
    return regionLoadBldr.build();
  }
@param r               Region to get RegionLoad for.
@param regionLoadBldr  the RegionLoad.Builder, can be null
@param regionSpecifier the RegionSpecifier.Builder, can be null
@return RegionLoad instance.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java