Class GlobalFSNamesystemLock

java.lang.Object
org.apache.hadoop.hdfs.server.namenode.fgl.GlobalFSNamesystemLock
All Implemented Interfaces:
FSNLockManager

public class GlobalFSNamesystemLock extends Object implements FSNLockManager
  • Constructor Details

    • GlobalFSNamesystemLock

      public GlobalFSNamesystemLock(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation aggregation)
  • Method Details

    • readLock

      public void readLock(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Acquire read lock for an operation according to the lock mode.
      Specified by:
      readLock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
    • readLockInterruptibly

      public void readLockInterruptibly(RwLockMode lockMode) throws InterruptedException
      Description copied from interface: FSNLockManager
      Acquire read lock according to the lock mode, unless interrupted while waiting.
      Specified by:
      readLockInterruptibly in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      Throws:
      InterruptedException - If the thread is interrupted, an InterruptedException is thrown.
    • readUnlock

      public void readUnlock(RwLockMode lockMode, String opName)
      Description copied from interface: FSNLockManager
      Release read lock for the operation according to the lock mode.
      Specified by:
      readUnlock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      opName - operation name
    • readUnlock

      public void readUnlock(RwLockMode lockMode, String opName, Supplier<String> lockReportInfoSupplier)
      Description copied from interface: FSNLockManager
      Release read lock for the operation according to the lock mode.
      Specified by:
      readUnlock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      opName - operation name
      lockReportInfoSupplier - supplier used to report some information for this lock.
    • writeLock

      public void writeLock(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Acquire write lock for an operation according to the lock mode.
      Specified by:
      writeLock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
    • writeUnlock

      public void writeUnlock(RwLockMode lockMode, String opName)
      Description copied from interface: FSNLockManager
      Release write lock for the operation according to the lock mode.
      Specified by:
      writeUnlock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      opName - operation name
    • writeUnlock

      public void writeUnlock(RwLockMode lockMode, String opName, boolean suppressWriteLockReport)
      Description copied from interface: FSNLockManager
      Release write lock for the operation according to the lock mode.
      Specified by:
      writeUnlock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      opName - operation name
      suppressWriteLockReport - When false, event of write lock being held for long time will be logged in logs and metrics.
    • writeUnlock

      public void writeUnlock(RwLockMode lockMode, String opName, Supplier<String> lockReportInfoSupplier)
      Description copied from interface: FSNLockManager
      Release write lock for the operation according to the lock mode.
      Specified by:
      writeUnlock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      opName - operation name
      lockReportInfoSupplier - supplier used to report information for this lock.
    • writeLockInterruptibly

      public void writeLockInterruptibly(RwLockMode lockMode) throws InterruptedException
      Specified by:
      writeLockInterruptibly in interface FSNLockManager
      Throws:
      InterruptedException
    • hasWriteLock

      public boolean hasWriteLock(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Check if the current thread holds write lock according to the lock mode.
      Specified by:
      hasWriteLock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      Returns:
      true if the current thread is holding the write-lock, else false.
    • hasReadLock

      public boolean hasReadLock(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Check if the current thread holds read lock according to the lock mode.
      Specified by:
      hasReadLock in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      Returns:
      true if the current thread is holding the read-lock, else false.
    • getReadHoldCount

      public int getReadHoldCount(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Queries the number of reentrant read holds on this lock by the current thread. A reader thread has a hold on a lock for each lock action that is not matched by an unlock action.
      Specified by:
      getReadHoldCount in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      Returns:
      the number of holds on the read lock by the current thread, or zero if the read lock is not held by the current thread
    • getQueueLength

      public int getQueueLength(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Returns the QueueLength of waiting threads. A larger number indicates greater lock contention.
      Specified by:
      getQueueLength in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      Returns:
      int - Number of threads waiting on this lock
    • getNumOfReadLockLongHold

      public long getNumOfReadLockLongHold(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Returns the number of time the read lock has been held longer than the threshold.
      Specified by:
      getNumOfReadLockLongHold in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      Returns:
      long - Number of time the read lock has been held longer than the threshold
    • getNumOfWriteLockLongHold

      public long getNumOfWriteLockLongHold(RwLockMode lockMode)
      Description copied from interface: FSNLockManager
      Returns the number of time the write-lock has been held longer than the threshold.
      Specified by:
      getNumOfWriteLockLongHold in interface FSNLockManager
      Parameters:
      lockMode - locking mode
      Returns:
      long - Number of time the write-lock has been held longer than the threshold.
    • isMetricsEnabled

      public boolean isMetricsEnabled()
      Description copied from interface: FSNLockManager
      Check if the metrics is enabled.
      Specified by:
      isMetricsEnabled in interface FSNLockManager
      Returns:
      true if the metrics is enabled, else false.
    • setMetricsEnabled

      public void setMetricsEnabled(boolean metricsEnabled)
      Description copied from interface: FSNLockManager
      Reset the metricsEnabled according to the lock mode.
      Specified by:
      setMetricsEnabled in interface FSNLockManager
      Parameters:
      metricsEnabled - the new metricsEnabled
    • setReadLockReportingThresholdMs

      public void setReadLockReportingThresholdMs(long readLockReportingThresholdMs)
      Description copied from interface: FSNLockManager
      Try to set the reporting threshold of the read lock.
      Specified by:
      setReadLockReportingThresholdMs in interface FSNLockManager
      Parameters:
      readLockReportingThresholdMs - reporting threshold
    • getReadLockReportingThresholdMs

      public long getReadLockReportingThresholdMs()
      Description copied from interface: FSNLockManager
      Try to get the reporting threshold of the read lock.
      Specified by:
      getReadLockReportingThresholdMs in interface FSNLockManager
      Returns:
      the reporting threshold.
    • setWriteLockReportingThresholdMs

      public void setWriteLockReportingThresholdMs(long writeLockReportingThresholdMs)
      Description copied from interface: FSNLockManager
      Try to set the reporting threshold for the write lock.
      Specified by:
      setWriteLockReportingThresholdMs in interface FSNLockManager
      Parameters:
      writeLockReportingThresholdMs - reporting threshold.
    • getWriteLockReportingThresholdMs

      public long getWriteLockReportingThresholdMs()
      Description copied from interface: FSNLockManager
      Try to get the reporting threshold for the write lock.
      Specified by:
      getWriteLockReportingThresholdMs in interface FSNLockManager
      Returns:
      reporting threshold.
    • setLockForTests

      public void setLockForTests(ReentrantReadWriteLock testLock)
      Specified by:
      setLockForTests in interface FSNLockManager
    • getLockForTests

      public ReentrantReadWriteLock getLockForTests()
      Specified by:
      getLockForTests in interface FSNLockManager