Class DirLock

java.lang.Object
org.apache.storm.hdfs.spout.DirLock

public class DirLock extends Object
Facility to synchronize access to HDFS directory. The lock itself is represented as a file in the same directory. Relies on atomic file creation.
  • Field Details

  • Method Details

    • tryLock

      public static DirLock tryLock(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir) throws IOException
      Get a lock on file if not already locked.
      Parameters:
      dir - the dir on which to get a lock
      Returns:
      The lock object if it the lock was acquired. Returns null if the dir is already locked.
      Throws:
      IOException - if there were errors
    • takeOwnershipIfStale

      public static DirLock takeOwnershipIfStale(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dirToLock, int lockTimeoutSec)
      if the lock on the directory is stale, take ownership.
    • release

      public void release() throws IOException
      Release lock on dir by deleting the lock file.
      Throws:
      IOException
    • getLockFile

      public org.apache.hadoop.fs.Path getLockFile()