code: void doFinalize(File dnCurDir) throws IOException {
      File nsRoot = getNsRoot(namespaceID, dnCurDir);
      StorageDirectory nsSd = new StorageDirectory(nsRoot);
      // namespace level previous directory
      File prevDir = nsSd.getPreviousDir();
      if (!prevDir.exists()) {
        return; // already finalized
      }
      final String dataDirPath = nsSd.getRoot().getCanonicalPath();
      LOG.info("Finalizing upgrade for storage directory " + dataDirPath
          + ".\n   cur LV = " + this.getLayoutVersion() + "; cur CTime = "
          + this.getCTime());
      assert nsSd.getCurrentDir().exists() : "Current directory must exist.";
      
      // rename previous to finalized.tmp
      final File tmpDir = nsSd.getFinalizedTmp();
      rename(prevDir, tmpDir);
  
      // delete finalized.tmp dir in a separate thread
      new Daemon(new Runnable() {
        public void run() {
          try {
            deleteDir(tmpDir);
          } catch (IOException ex) {
            LOG.error("Finalize upgrade for " + dataDirPath + " failed.", ex);
          }
          LOG.info("Finalize upgrade for " + dataDirPath + " is complete.");
        }
  
        public String toString() {
          return "Finalize " + dataDirPath;
        }
      }).start();
    }
docs: /*
  Finalize the namespace storage by deleting <NS>/previous directory
  that holds the snapshot.