Class CachingGetSpaceUsed

java.lang.Object
org.apache.hadoop.fs.CachingGetSpaceUsed
All Implemented Interfaces:
Closeable, AutoCloseable, GetSpaceUsed
Direct Known Subclasses:
DFCachingGetSpaceUsed, DU, WindowsGetSpaceUsed

@LimitedPrivate({"HDFS","MapReduce"}) @Evolving public abstract class CachingGetSpaceUsed extends Object implements Closeable, GetSpaceUsed
Interface for class that can tell estimate much space is used in a directory.

The implementor is fee to cache space used. As such there are methods to update the cached value with any known changes.

  • Field Details

  • Constructor Details

    • CachingGetSpaceUsed

      public CachingGetSpaceUsed(GetSpaceUsed.Builder builder) throws IOException
      This is the constructor used by the builder. All overriding classes should implement this.
      Parameters:
      builder - builder.
      Throws:
      IOException - raised on errors performing I/O.
  • Method Details

    • refresh

      protected abstract void refresh()
    • setShouldFirstRefresh

      protected void setShouldFirstRefresh(boolean shouldFirstRefresh)
      Reset that if we need to do the first refresh.
      Parameters:
      shouldFirstRefresh - The flag value to set.
    • getUsed

      public long getUsed() throws IOException
      Specified by:
      getUsed in interface GetSpaceUsed
      Returns:
      an estimate of space used in the directory path.
      Throws:
      IOException
    • getDirPath

      public String getDirPath()
      Returns:
      The directory path being monitored.
    • incDfsUsed

      public void incDfsUsed(long value)
      Increment the cached value of used space.
      Parameters:
      value - dfs used value.
    • getRefreshInterval

      @VisibleForTesting public long getRefreshInterval()
      How long in between runs of the background refresh.
      Returns:
      refresh interval.
    • getJitter

      @VisibleForTesting public long getJitter()
      Randomize the refresh interval timing by this amount, the actual interval will be chosen uniformly between interval-jitter and interval+jitter.
      Returns:
      between interval-jitter and interval+jitter.
    • setUsed

      protected void setUsed(long usedValue)
      Reset the current used data amount. This should be called when the cached value is re-computed.
      Parameters:
      usedValue - new value that should be the disk usage.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException