Package org.apache.hadoop.util
Class InstrumentedLock
java.lang.Object
org.apache.hadoop.util.InstrumentedLock
- All Implemented Interfaces:
Lock
- Direct Known Subclasses:
InstrumentedReadLock,InstrumentedWriteLock
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classImmutable class to capture a snapshot of suppressed log message stats. -
Constructor Summary
ConstructorsConstructorDescriptionInstrumentedLock(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.InstrumentedLock(String name, org.slf4j.Logger logger, Lock lock, long minLoggingGapMs, long lockWarningThresholdMs) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheck(long acquireTime, long releaseTime, boolean checkLockHeld) Log a warning if the lock was held for too long.protected LockgetLock()protected TimergetTimer()voidlock()voidprotected voidStarts timing for the instrumented lock.booleantryLock()booleanvoidunlock()
-
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 objectlogger- this class does not have its own logger, will log to the given logger insteadminLoggingGapMs- the minimum time gap between two log messages, this is to avoid spamming to many logslockWarningThresholdMs- the time threshold to view lock held time as being "too long"
-
InstrumentedLock
-
-
Method Details
-
lock
public void lock() -
lockInterruptibly
- Specified by:
lockInterruptiblyin interfaceLock- Throws:
InterruptedException
-
tryLock
public boolean tryLock() -
tryLock
- Specified by:
tryLockin interfaceLock- Throws:
InterruptedException
-
unlock
public void unlock() -
newCondition
- Specified by:
newConditionin interfaceLock
-
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
-
getTimer
-