Class LeaseManager

java.lang.Object
org.apache.hadoop.hdfs.server.namenode.LeaseManager

@Private public class LeaseManager extends Object
LeaseManager does the lease housekeeping for writing on files. This class also provides useful static methods for lease recovery. Lease Recovery Algorithm 1) Namenode retrieves lease information 2) For each file f in the lease, consider the last block b of f 2.1) Get the datanodes which contains b 2.2) Assign one of the datanodes as the primary datanode p 2.3) p obtains a new generation stamp from the namenode 2.4) p gets the block info from each datanode 2.5) p computes the minimum block length 2.6) p updates the datanodes, which have a valid generation stamp, with the new generation stamp and the minimum block length 2.7) p acknowledges the namenode the update results 2.8) Namenode updates the BlockInfo 2.9) Namenode removes f from the lease and removes the lease once all files have been removed 2.10) Namenode commit changes to edit log
  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
  • Method Details

    • getINodeWithLeases

      public Set<INodesInPath> getINodeWithLeases(INodeDirectory ancestorDir) throws IOException
      Get INodesInPath for all files under the ancestor directory which has valid lease. If the ancestor directory is null, then return all files in the system with valid lease. Callers must hold FSNamesystem read or write lock.
      Parameters:
      ancestorDir - the ancestor INodeDirectory
      Returns:
      Set<INodesInPath>
      Throws:
      IOException
    • getUnderConstructionFiles

      public org.apache.hadoop.fs.BatchedRemoteIterator.BatchedListEntries<org.apache.hadoop.hdfs.protocol.OpenFileEntry> getUnderConstructionFiles(long prevId) throws IOException
      Throws:
      IOException
    • getUnderConstructionFiles

      public org.apache.hadoop.fs.BatchedRemoteIterator.BatchedListEntries<org.apache.hadoop.hdfs.protocol.OpenFileEntry> getUnderConstructionFiles(long prevId, String path) throws IOException
      Get a batch of under construction files from the currently active leases. File INodeID is the cursor used to fetch new batch of results and the batch size is configurable using below config param. Since the list is fetched in batches, it does not represent a consistent view of all open files.
      Parameters:
      prevId - the INodeID cursor
      Throws:
      IOException
      See Also:
    • getLease

      public org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease getLease(INodeFile src)
      Returns:
      the lease containing src
    • countLease

      @VisibleForTesting public int countLease()
      Returns:
      the number of leases currently in the system
    • setLeasePeriod

      public void setLeasePeriod(long softLimit, long hardLimit)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • triggerMonitorCheckNow

      @VisibleForTesting public void triggerMonitorCheckNow()
      Trigger the currently-running Lease monitor to re-check its leases immediately. This is for use by unit tests.
    • runLeaseChecks

      @VisibleForTesting public void runLeaseChecks()