private static StoreFileWriter initStoreFileWriter(Configuration conf, Cell cell,
    HFileContext hFileContext, CacheConfig cacheConf, BloomType bloomFilterType, FileSystem fs,
    Path outFile, AsyncTableRegionLocator loc) throws IOException {
    if (conf.getBoolean(LOCALITY_SENSITIVE_CONF_KEY, DEFAULT_LOCALITY_SENSITIVE)) {
      byte[] rowKey = CellUtil.cloneRow(cell);
      HRegionLocation hRegionLocation = FutureUtils.get(loc.getRegionLocation(rowKey));
      InetSocketAddress[] favoredNodes = null;
      if (null == hRegionLocation) {
        LOG.warn("Failed get region location for  rowkey {} , Using writer without favoured nodes.",
          Bytes.toString(rowKey));
        return new StoreFileWriter.Builder(conf, cacheConf, fs).withFilePath(outFile)
          .withBloomType(bloomFilterType).withFileContext(hFileContext).build();
      } else {
        LOG.debug("First rowkey: [{}]", Bytes.toString(rowKey));
        InetSocketAddress initialIsa =
          new InetSocketAddress(hRegionLocation.getHostname(), hRegionLocation.getPort());
        if (initialIsa.isUnresolved()) {
          LOG.warn("Failed get location for region {} , Using writer without favoured nodes.",
            hRegionLocation);
          return new StoreFileWriter.Builder(conf, cacheConf, fs).withFilePath(outFile)
            .withBloomType(bloomFilterType).withFileContext(hFileContext).build();
        } else {
          LOG.debug("Use favored nodes writer: {}", initialIsa.getHostString());
          favoredNodes = new InetSocketAddress[] { initialIsa };
          return new StoreFileWriter.Builder(conf, cacheConf, fs).withFilePath(outFile)
            .withBloomType(bloomFilterType).withFileContext(hFileContext)
            .withFavoredNodes(favoredNodes).build();
        }
      }
    } else {
      return new StoreFileWriter.Builder(conf, cacheConf, fs).withFilePath(outFile)
        .withBloomType(bloomFilterType).withFileContext(hFileContext).build();
    }
  }
Split a storefile into a top and bottom half with favored nodes, maintaining the metadata,
recreating bloom filters, etc.
hbase-server/src/main/java/org/apache/hadoop/hbase/tool/BulkLoadHFilesTool.java