Class FineGrainedFSNamesystemLock
java.lang.Object
org.apache.hadoop.hdfs.server.namenode.fgl.FineGrainedFSNamesystemLock
- All Implemented Interfaces:
FSNLockManager
Splitting the global FSN lock into FSLock and BMLock.
FSLock is used to protect directory tree-related operations.
BMLock is used to protect block-related and dn-related operations.
The lock order should be: FSLock,BMLock.
-
Constructor Summary
ConstructorsConstructorDescriptionFineGrainedFSNamesystemLock(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation aggregation) -
Method Summary
Modifier and TypeMethodDescriptionlonggetNumOfReadLockLongHold(RwLockMode lockMode) Returns the number of time the read lock has been held longer than the threshold.longgetNumOfWriteLockLongHold(RwLockMode lockMode) Returns the number of time the write-lock has been held longer than the threshold.intgetQueueLength(RwLockMode lockMode) Returns the QueueLength of waiting threads.intgetReadHoldCount(RwLockMode lockMode) This method is only used for ComputeDirectoryContentSummary.longTry to get the reporting threshold of the read lock.longTry to get the reporting threshold for the write lock.booleanhasReadLock(RwLockMode lockMode) Check if the current thread holds read lock according to the lock mode.booleanhasWriteLock(RwLockMode lockMode) Check if the current thread holds write lock according to the lock mode.booleanCheck if the metrics is enabled.voidreadLock(RwLockMode lockMode) Acquire read lock for an operation according to the lock mode.voidreadLockInterruptibly(RwLockMode lockMode) Acquire read lock according to the lock mode, unless interrupted while waiting.voidreadUnlock(RwLockMode lockMode, String opName) Release read lock for the operation according to the lock mode.voidreadUnlock(RwLockMode lockMode, String opName, Supplier<String> lockReportInfoSupplier) Release read lock for the operation according to the lock mode.voidvoidsetMetricsEnabled(boolean metricsEnabled) Reset the metricsEnabled according to the lock mode.voidsetReadLockReportingThresholdMs(long readLockReportingThresholdMs) Try to set the reporting threshold of the read lock.voidsetWriteLockReportingThresholdMs(long writeLockReportingThresholdMs) Try to set the reporting threshold for the write lock.voidwriteLock(RwLockMode lockMode) Acquire write lock for an operation according to the lock mode.voidwriteLockInterruptibly(RwLockMode lockMode) voidwriteUnlock(RwLockMode lockMode, String opName) Release write lock for the operation according to the lock mode.voidwriteUnlock(RwLockMode lockMode, String opName, boolean suppressWriteLockReport) Release write lock for the operation according to the lock mode.voidwriteUnlock(RwLockMode lockMode, String opName, Supplier<String> lockReportInfoSupplier) Release write lock for the operation according to the lock mode.
-
Constructor Details
-
FineGrainedFSNamesystemLock
public FineGrainedFSNamesystemLock(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.metrics2.lib.MutableRatesWithAggregation aggregation)
-
-
Method Details
-
readLock
Description copied from interface:FSNLockManagerAcquire read lock for an operation according to the lock mode.- Specified by:
readLockin interfaceFSNLockManager- Parameters:
lockMode- locking mode
-
readLockInterruptibly
Description copied from interface:FSNLockManagerAcquire read lock according to the lock mode, unless interrupted while waiting.- Specified by:
readLockInterruptiblyin interfaceFSNLockManager- Parameters:
lockMode- locking mode- Throws:
InterruptedException- If the thread is interrupted, an InterruptedException is thrown.
-
readUnlock
Description copied from interface:FSNLockManagerRelease read lock for the operation according to the lock mode.- Specified by:
readUnlockin interfaceFSNLockManager- Parameters:
lockMode- locking modeopName- operation name
-
readUnlock
Description copied from interface:FSNLockManagerRelease read lock for the operation according to the lock mode.- Specified by:
readUnlockin interfaceFSNLockManager- Parameters:
lockMode- locking modeopName- operation namelockReportInfoSupplier- supplier used to report some information for this lock.
-
writeLock
Description copied from interface:FSNLockManagerAcquire write lock for an operation according to the lock mode.- Specified by:
writeLockin interfaceFSNLockManager- Parameters:
lockMode- locking mode
-
writeUnlock
Description copied from interface:FSNLockManagerRelease write lock for the operation according to the lock mode.- Specified by:
writeUnlockin interfaceFSNLockManager- Parameters:
lockMode- locking modeopName- operation name
-
writeUnlock
Description copied from interface:FSNLockManagerRelease write lock for the operation according to the lock mode.- Specified by:
writeUnlockin interfaceFSNLockManager- Parameters:
lockMode- locking modeopName- operation namesuppressWriteLockReport- 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:FSNLockManagerRelease write lock for the operation according to the lock mode.- Specified by:
writeUnlockin interfaceFSNLockManager- Parameters:
lockMode- locking modeopName- operation namelockReportInfoSupplier- supplier used to report information for this lock.
-
writeLockInterruptibly
- Specified by:
writeLockInterruptiblyin interfaceFSNLockManager- Throws:
InterruptedException
-
hasWriteLock
Description copied from interface:FSNLockManagerCheck if the current thread holds write lock according to the lock mode.- Specified by:
hasWriteLockin interfaceFSNLockManager- Parameters:
lockMode- locking mode- Returns:
- true if the current thread is holding the write-lock, else false.
-
hasReadLock
Description copied from interface:FSNLockManagerCheck if the current thread holds read lock according to the lock mode.- Specified by:
hasReadLockin interfaceFSNLockManager- Parameters:
lockMode- locking mode- Returns:
- true if the current thread is holding the read-lock, else false.
-
getReadHoldCount
This method is only used for ComputeDirectoryContentSummary. For the GLOBAL mode, just return the FSLock's ReadHoldCount.- Specified by:
getReadHoldCountin interfaceFSNLockManager- 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
Description copied from interface:FSNLockManagerReturns the QueueLength of waiting threads. A larger number indicates greater lock contention.- Specified by:
getQueueLengthin interfaceFSNLockManager- Parameters:
lockMode- locking mode- Returns:
- int - Number of threads waiting on this lock
-
getNumOfReadLockLongHold
Description copied from interface:FSNLockManagerReturns the number of time the read lock has been held longer than the threshold.- Specified by:
getNumOfReadLockLongHoldin interfaceFSNLockManager- Parameters:
lockMode- locking mode- Returns:
- long - Number of time the read lock has been held longer than the threshold
-
getNumOfWriteLockLongHold
Description copied from interface:FSNLockManagerReturns the number of time the write-lock has been held longer than the threshold.- Specified by:
getNumOfWriteLockLongHoldin interfaceFSNLockManager- 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:FSNLockManagerCheck if the metrics is enabled.- Specified by:
isMetricsEnabledin interfaceFSNLockManager- Returns:
- true if the metrics is enabled, else false.
-
setMetricsEnabled
public void setMetricsEnabled(boolean metricsEnabled) Description copied from interface:FSNLockManagerReset the metricsEnabled according to the lock mode.- Specified by:
setMetricsEnabledin interfaceFSNLockManager- Parameters:
metricsEnabled- the new metricsEnabled
-
setReadLockReportingThresholdMs
public void setReadLockReportingThresholdMs(long readLockReportingThresholdMs) Description copied from interface:FSNLockManagerTry to set the reporting threshold of the read lock.- Specified by:
setReadLockReportingThresholdMsin interfaceFSNLockManager- Parameters:
readLockReportingThresholdMs- reporting threshold
-
getReadLockReportingThresholdMs
public long getReadLockReportingThresholdMs()Description copied from interface:FSNLockManagerTry to get the reporting threshold of the read lock.- Specified by:
getReadLockReportingThresholdMsin interfaceFSNLockManager- Returns:
- the reporting threshold.
-
setWriteLockReportingThresholdMs
public void setWriteLockReportingThresholdMs(long writeLockReportingThresholdMs) Description copied from interface:FSNLockManagerTry to set the reporting threshold for the write lock.- Specified by:
setWriteLockReportingThresholdMsin interfaceFSNLockManager- Parameters:
writeLockReportingThresholdMs- reporting threshold.
-
getWriteLockReportingThresholdMs
public long getWriteLockReportingThresholdMs()Description copied from interface:FSNLockManagerTry to get the reporting threshold for the write lock.- Specified by:
getWriteLockReportingThresholdMsin interfaceFSNLockManager- Returns:
- reporting threshold.
-
setLockForTests
- Specified by:
setLockForTestsin interfaceFSNLockManager
-
getLockForTests
- Specified by:
getLockForTestsin interfaceFSNLockManager
-