private static List<RegionInfo> createMetaEntries(final MasterServices masterServices,
    final List<RegionInfo> newRegionInfos) {

    final List<Either<List<RegionInfo>, IOException>> addMetaEntriesResults =
      newRegionInfos.stream().map(regionInfo -> {
        try {
          TableDescriptor td = masterServices.getTableDescriptors().get(regionInfo.getTable());

          // Add replicas if needed
          // we need to create regions with replicaIds starting from 1
          List<RegionInfo> newRegions = RegionReplicaUtil
            .addReplicas(Collections.singletonList(regionInfo), 1, td.getRegionReplication());

          // Add regions to META
          MetaTableAccessor.addRegionsToMeta(masterServices.getConnection(), newRegions,
            td.getRegionReplication());

          return Either.<List<RegionInfo>, IOException> ofLeft(newRegions);
        } catch (IOException e) {
          return Either.<List<RegionInfo>, IOException> ofRight(e);
        }
      }).collect(Collectors.toList());
    final List<RegionInfo> createMetaEntriesSuccesses =
      addMetaEntriesResults.stream().filter(Either::hasLeft).map(Either::getLeft)
        .flatMap(List::stream).collect(Collectors.toList());
    final List<IOException> createMetaEntriesFailures = addMetaEntriesResults.stream()
      .filter(Either::hasRight).map(Either::getRight).collect(Collectors.toList());
    LOG.debug("Added {}/{} entries to hbase:meta", createMetaEntriesSuccesses.size(),
      newRegionInfos.size());

    if (!createMetaEntriesFailures.isEmpty()) {
      LOG.warn(
        "Failed to create entries in hbase:meta for {}/{} RegionInfo descriptors. First"
          + " failure message included; full list of failures with accompanying stack traces is"
          + " available at log level DEBUG. message={}",
        createMetaEntriesFailures.size(), addMetaEntriesResults.size(),
        createMetaEntriesFailures.get(0).getMessage());
      if (LOG.isDebugEnabled()) {
        createMetaEntriesFailures
          .forEach(ioe -> LOG.debug("Attempt to fix region hole in hbase:meta failed.", ioe));
      }
    }

    return createMetaEntriesSuccesses;
  }
Create entries in the {@code hbase:meta} for each provided {@link RegionInfo}. Best effort.
@param masterServices used to connect to {@code hbase:meta}
@param newRegionInfos the new {@link RegionInfo} entries to add to the filesystem
@return a list of {@link RegionInfo} entries for which {@code hbase:meta} entries were
        successfully created
hbase-server/src/main/java/org/apache/hadoop/hbase/master/janitor/MetaFixer.java