Class FSNamesystemLock
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.FSNamesystemLock
Mimics a ReentrantReadWriteLock but does not directly implement the interface
so more sophisticated locking capabilities and logging/metrics are possible.
DFSConfigKeys.DFS_NAMENODE_LOCK_DETAILED_METRICS_KEY
to be true, metrics will be emitted into the FSNamesystem metrics registry
for each operation which acquires this lock indicating how long the operation
held the lock for. These metrics have names of the form
${LockName}(Read|Write)LockNanosOperationName, where OperationName denotes the name
of the operation that initiated the lock hold (this will be OTHER for certain
uncategorized operations) and they export the hold time values in
nanoseconds. Note that if a thread dies, metrics produced after the
most recent snapshot will be lost due to the use of
MutableRatesWithAggregation. However since threads are re-used
between operations this should not generally be an issue.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFSNamesystemLock(org.apache.hadoop.conf.Configuration conf, String lockName, org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation detailedHoldTimeMetrics) -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of time the read lock has been held longer than the threshold.longReturns the number of time the write lock has been held longer than the threshold.intReturns the QueueLength of waiting threads.intlongintlongbooleanbooleanvoidreadLock()voidvoidvoidreadUnlock(String opName) voidreadUnlock(String opName, Supplier<String> lockReportInfoSupplier) voidvoidsetMetricsEnabled(boolean metricsEnabled) voidsetReadLockReportingThresholdMs(long readLockReportingThresholdMs) voidsetWriteLockReportingThresholdMs(long writeLockReportingThresholdMs) voidvoidvoidUnlocks FSNameSystem write lock.voidwriteUnlock(String opName) Unlocks FSNameSystem write lock.voidwriteUnlock(String opName, boolean suppressWriteLockReport) Unlocks FSNameSystem write lock.voidwriteUnlock(String opName, Supplier<String> lockReportInfoSupplier) Unlocks FSNameSystem write lock.
-
Field Details
-
coarseLock
-
-
Constructor Details
-
FSNamesystemLock
public FSNamesystemLock(org.apache.hadoop.conf.Configuration conf, String lockName, org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation detailedHoldTimeMetrics)
-
-
Method Details
-
readLock
public void readLock() -
readLockInterruptibly
- Throws:
InterruptedException
-
readUnlock
public void readUnlock() -
readUnlock
-
readUnlock
-
writeLock
public void writeLock() -
writeLockInterruptibly
- Throws:
InterruptedException
-
writeUnlock
public void writeUnlock()Unlocks FSNameSystem write lock. This internally callswriteUnlock(String, boolean, Supplier) -
writeUnlock
Unlocks FSNameSystem write lock. This internally callswriteUnlock(String, boolean, Supplier)- Parameters:
opName- Operation name.
-
writeUnlock
Unlocks FSNameSystem write lock. This internally callswriteUnlock(String, boolean, Supplier)- Parameters:
opName- Operation name.lockReportInfoSupplier- The info shown in the lock report
-
writeUnlock
Unlocks FSNameSystem write lock. This internally callswriteUnlock(String, boolean, Supplier)- Parameters:
opName- Operation name.suppressWriteLockReport- When false, event of write lock being held for long time will be logged in logs and metrics.
-
getReadHoldCount
public int getReadHoldCount() -
getWriteHoldCount
public int getWriteHoldCount() -
isWriteLockedByCurrentThread
public boolean isWriteLockedByCurrentThread() -
newWriteLockCondition
-
getQueueLength
public int getQueueLength()Returns the QueueLength of waiting threads. A larger number indicates greater lock contention.- Returns:
- int - Number of threads waiting on this lock
-
getNumOfReadLockLongHold
public long getNumOfReadLockLongHold()Returns the number of time the read lock has been held longer than the threshold.- Returns:
- long - Number of time the read lock has been held longer than the threshold
-
getNumOfWriteLockLongHold
public long getNumOfWriteLockLongHold()Returns the number of time the write lock has been held longer than the threshold.- Returns:
- long - Number of time the write lock has been held longer than the threshold.
-
setMetricsEnabled
@VisibleForTesting public void setMetricsEnabled(boolean metricsEnabled) -
isMetricsEnabled
public boolean isMetricsEnabled() -
setReadLockReportingThresholdMs
public void setReadLockReportingThresholdMs(long readLockReportingThresholdMs) -
getReadLockReportingThresholdMs
@VisibleForTesting public long getReadLockReportingThresholdMs() -
setWriteLockReportingThresholdMs
public void setWriteLockReportingThresholdMs(long writeLockReportingThresholdMs) -
getWriteLockReportingThresholdMs
@VisibleForTesting public long getWriteLockReportingThresholdMs() -
setLockForTests
-
getLockForTests
-