Class InstrumentedLock

java.lang.Object
org.apache.hadoop.util.InstrumentedLock
All Implemented Interfaces:
Lock
Direct Known Subclasses:
InstrumentedReadLock, InstrumentedWriteLock

@Private @Unstable public class InstrumentedLock extends Object implements Lock
This is a debugging class that can be used by callers to track whether a specific lock is being held for too long and periodically log a warning and stack trace, if so. The logged warnings are throttled so that logs are not spammed. A new instance of InstrumentedLock can be created for each object that needs to be instrumented.
  • Constructor Details

    • InstrumentedLock

      public InstrumentedLock(String name, org.slf4j.Logger logger, long minLoggingGapMs, long lockWarningThresholdMs)
      Create a instrumented lock instance which logs a warning message when lock held time is above given threshold.
      Parameters:
      name - the identifier of the lock object
      logger - this class does not have its own logger, will log to the given logger instead
      minLoggingGapMs - the minimum time gap between two log messages, this is to avoid spamming to many logs
      lockWarningThresholdMs - the time threshold to view lock held time as being "too long"
    • InstrumentedLock

      public InstrumentedLock(String name, org.slf4j.Logger logger, Lock lock, long minLoggingGapMs, long lockWarningThresholdMs)
  • Method Details

    • lock

      public void lock()
      Specified by:
      lock in interface Lock
    • lockInterruptibly

      public void lockInterruptibly() throws InterruptedException
      Specified by:
      lockInterruptibly in interface Lock
      Throws:
      InterruptedException
    • tryLock

      public boolean tryLock()
      Specified by:
      tryLock in interface Lock
    • tryLock

      public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
      Specified by:
      tryLock in interface Lock
      Throws:
      InterruptedException
    • unlock

      public void unlock()
      Specified by:
      unlock in interface Lock
    • newCondition

      public Condition newCondition()
      Specified by:
      newCondition in interface Lock
    • startLockTiming

      protected void startLockTiming()
      Starts timing for the instrumented lock.
    • check

      protected void check(long acquireTime, long releaseTime, boolean checkLockHeld)
      Log a warning if the lock was held for too long. Should be invoked by the caller immediately AFTER releasing the lock.
      Parameters:
      acquireTime - - timestamp just after acquiring the lock.
      releaseTime - - timestamp just before releasing the lock.
      checkLockHeld - checkLockHeld.
    • getLock

      protected Lock getLock()
    • getTimer

      protected Timer getTimer()