public static boolean deleteSnapshotIfExists(DistributedFileSystem fs, Path snapshotPath, String snapshotName,
      HiveConf conf) throws IOException {
    Retryable retryable = Retryable.builder().withHiveConf(conf).withRetryOnException(IOException.class)
        .withFailOnException(SnapshotException.class).build();
    try {
      retryable.executeCallable(() -> {
        try {
          if (fs.exists(new Path(snapshotPath, ".snapshot/" + snapshotName))) {
            fs.deleteSnapshot(snapshotPath, snapshotName);
          }
        } catch (FileNotFoundException e) {
          // Ignore FileNotFoundException, Our intention is to make sure the snapshot doesn't exist and the FNF means
          // it already doesn't exist.
          LOG.warn("Couldn't create the snapshot {} under path {}. It doesn't exist", snapshotName, snapshotPath, e);
        } catch (SnapshotException e) {
          if (e.getMessage().contains("the snapshot does not exist") || e.getMessage()
              .contains("Directory is not a snapshottable directory")) {
            return true;
          }
        }
        return null;
      });
    } catch (Exception e) {
      throw new SnapshotException(
          "Unable to delete snapshot for path: " + snapshotPath + " snapshot name: " + snapshotName, e);
    }
    return true;
  }
Attempts deleting a snapshot if it exists, with retries.
@param fs FileSystem object.
@param snapshotPath Path of the snapshot.
@param snapshotName Name of the snapshot.
@param conf Hive Configuration.
@return true if snapshot is no longer available.
ql/src/java/org/apache/hadoop/hive/ql/exec/repl/util/SnapshotUtils.java