@Override
    public void failedBulkLoad(final byte[] family, final String stagedPath) throws IOException {
      try {
        String src = origSources.get(stagedPath);
        if (StringUtils.isEmpty(src)) {
          LOG.debug(stagedPath + " was not moved to staging. No need to move back");
          return;
        }

        Path stageP = new Path(stagedPath);
        if (!fs.exists(stageP)) {
          throw new IOException(
            "Missing HFile: " + stageP + ", can't be moved back to it's original place");
        }

        // we should not move back files if the original exists
        Path srcPath = new Path(src);
        if (srcFs.exists(srcPath)) {
          LOG.debug(src + " is already at it's original place. No need to move.");
          return;
        }

        LOG.debug("Moving " + stageP + " back to " + srcPath);
        if (!fs.rename(stageP, srcPath)) {
          throw new IOException("Failed to move HFile: " + stageP + " to " + srcPath);
        }

        // restore original permission
        if (origPermissions.containsKey(stagedPath)) {
          fs.setPermission(srcPath, origPermissions.get(src));
        } else {
          LOG.warn("Can't find previous permission for path=" + stagedPath);
        }
      } finally {
        closeSrcFs();
      }
    }
Bulk loads in secure mode. This service addresses two issues:
<ol>
<li>Moving files in a secure filesystem wherein the HBase Client and HBase Server are different
filesystem users.</li>
<li>Does moving in a secure manner. Assuming that the filesystem is POSIX compliant.</li>
</ol>
The algorithm is as follows:
<ol>
<li>Create an hbase owned staging directory which is world traversable (711):
{@code /hbase/staging}</li>
<li>A user writes out data to his secure output directory: {@code /user/foo/data}</li>
<li>A call is made to hbase to create a secret staging directory which globally rwx (777):
{@code /user/staging/averylongandrandomdirectoryname}</li>
<li>The user moves the data into the random staging directory, then calls bulkLoadHFiles()</li>
</ol>
Like delegation tokens the strength of the security lies in the length and randomness of the
secret directory.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/SecureBulkLoadManager.java