Class TrashPolicy

java.lang.Object
org.apache.hadoop.conf.Configured
org.apache.hadoop.fs.TrashPolicy
All Implemented Interfaces:
Configurable

@Public @Evolving public abstract class TrashPolicy extends Configured
This interface is used for implementing different Trash policies. Provides factory method to create instances of the configured Trash policy.
  • Field Details

    • fs

      protected FileSystem fs
    • trash

      protected Path trash
    • deletionInterval

      protected long deletionInterval
  • Constructor Details

    • TrashPolicy

      public TrashPolicy()
  • Method Details

    • initialize

      @Deprecated public abstract void initialize(Configuration conf, FileSystem fs, Path home)
      Deprecated.
      Used to setup the trash policy. Must be implemented by all TrashPolicy implementations.
      Parameters:
      conf - the configuration to be used
      fs - the filesystem to be used
      home - the home directory
    • initialize

      public void initialize(Configuration conf, FileSystem fs)
      Used to setup the trash policy. Must be implemented by all TrashPolicy implementations. Different from initialize(conf, fs, home), this one does not assume trash always under /user/$USER due to HDFS encryption zone.
      Parameters:
      conf - the configuration to be used
      fs - the filesystem to be used
    • isEnabled

      public abstract boolean isEnabled()
      Returns whether the Trash Policy is enabled for this filesystem.
      Returns:
      if isEnabled true,not false.
    • moveToTrash

      public abstract boolean moveToTrash(Path path) throws IOException
      Move a file or directory to the current trash directory.
      Parameters:
      path - the path.
      Returns:
      false if the item is already in the trash or trash is disabled
      Throws:
      IOException - raised on errors performing I/O.
    • createCheckpoint

      public abstract void createCheckpoint() throws IOException
      Create a trash checkpoint.
      Throws:
      IOException - raised on errors performing I/O.
    • deleteCheckpoint

      public abstract void deleteCheckpoint() throws IOException
      Delete old trash checkpoint(s).
      Throws:
      IOException - raised on errors performing I/O.
    • deleteCheckpointsImmediately

      public abstract void deleteCheckpointsImmediately() throws IOException
      Delete all checkpoints immediately, ie empty trash.
      Throws:
      IOException - raised on errors performing I/O.
    • getCurrentTrashDir

      public abstract Path getCurrentTrashDir()
      Get the current working directory of the Trash Policy This API does not work with files deleted from encryption zone when HDFS data encryption at rest feature is enabled as rename file between encryption zones or encryption zone and non-encryption zone is not allowed. The caller is recommend to use the new API TrashPolicy#getCurrentTrashDir(Path path). It returns the trash location correctly for the path specified no matter the path is in encryption zone or not.
      Returns:
      the path.
    • getCurrentTrashDir

      public Path getCurrentTrashDir(Path path) throws IOException
      Get the current trash directory for path specified based on the Trash Policy
      Parameters:
      path - path to be deleted
      Returns:
      current trash directory for the path to be deleted
      Throws:
      IOException - raised on errors performing I/O.
    • getEmptier

      public abstract Runnable getEmptier() throws IOException
      Return a Runnable that periodically empties the trash of all users, intended to be run by the superuser.
      Returns:
      Runnable.
      Throws:
      IOException - raised on errors performing I/O.
    • getInstance

      @Deprecated public static TrashPolicy getInstance(Configuration conf, FileSystem fs, Path home)
      Deprecated.
      Get an instance of the configured TrashPolicy based on the value of the configuration parameter fs.trash.classname.
      Parameters:
      conf - the configuration to be used
      fs - the file system to be used
      home - the home directory
      Returns:
      an instance of TrashPolicy
    • getInstance

      public static TrashPolicy getInstance(Configuration conf, FileSystem fs)
      Get an instance of the configured TrashPolicy based on the value of the configuration parameter fs.trash.classname.
      Parameters:
      conf - the configuration to be used
      fs - the file system to be used
      Returns:
      an instance of TrashPolicy