HDFS-15808. Add metrics for FSNamesystem read/write lock hold long time. (#2668) Contributed by tomscut.
(cherry picked from commit 9cb51bf106
)
This commit is contained in:
parent
1a33878279
commit
c498ef4b6d
|
@ -4758,6 +4758,20 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
||||||
return fsLock.getQueueLength();
|
return fsLock.getQueueLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Metric(value = {"ReadLockLongHoldCount", "The number of time " +
|
||||||
|
"the read lock has been held for longer than the threshold"},
|
||||||
|
type = Metric.Type.COUNTER)
|
||||||
|
public long getNumOfReadLockLongHold() {
|
||||||
|
return fsLock.getNumOfReadLockLongHold();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Metric(value = {"WriteLockLongHoldCount", "The number of time " +
|
||||||
|
"the write lock has been held for longer than the threshold"},
|
||||||
|
type = Metric.Type.COUNTER)
|
||||||
|
public long getNumOfWriteLockLongHold() {
|
||||||
|
return fsLock.getNumOfWriteLockLongHold();
|
||||||
|
}
|
||||||
|
|
||||||
int getNumberOfDatanodes(DatanodeReportType type) {
|
int getNumberOfDatanodes(DatanodeReportType type) {
|
||||||
readLock();
|
readLock();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -108,6 +108,16 @@ class FSNamesystemLock {
|
||||||
private final AtomicReference<LockHeldInfo> longestReadLockHeldInfo =
|
private final AtomicReference<LockHeldInfo> longestReadLockHeldInfo =
|
||||||
new AtomicReference<>(new LockHeldInfo(0, 0, null));
|
new AtomicReference<>(new LockHeldInfo(0, 0, null));
|
||||||
private LockHeldInfo longestWriteLockHeldInfo = new LockHeldInfo(0, 0, null);
|
private LockHeldInfo longestWriteLockHeldInfo = new LockHeldInfo(0, 0, null);
|
||||||
|
/**
|
||||||
|
* The number of time the read lock
|
||||||
|
* has been held longer than the threshold.
|
||||||
|
*/
|
||||||
|
private final AtomicLong numReadLockLongHold = new AtomicLong(0);
|
||||||
|
/**
|
||||||
|
* The number of time the write lock
|
||||||
|
* has been held for longer than the threshold.
|
||||||
|
*/
|
||||||
|
private final AtomicLong numWriteLockLongHold = new AtomicLong(0);
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String OP_NAME_OTHER = "OTHER";
|
static final String OP_NAME_OTHER = "OTHER";
|
||||||
|
@ -176,6 +186,7 @@ class FSNamesystemLock {
|
||||||
final long readLockIntervalMs =
|
final long readLockIntervalMs =
|
||||||
TimeUnit.NANOSECONDS.toMillis(readLockIntervalNanos);
|
TimeUnit.NANOSECONDS.toMillis(readLockIntervalNanos);
|
||||||
if (needReport && readLockIntervalMs >= this.readLockReportingThresholdMs) {
|
if (needReport && readLockIntervalMs >= this.readLockReportingThresholdMs) {
|
||||||
|
numReadLockLongHold.incrementAndGet();
|
||||||
LockHeldInfo localLockHeldInfo;
|
LockHeldInfo localLockHeldInfo;
|
||||||
do {
|
do {
|
||||||
localLockHeldInfo = longestReadLockHeldInfo.get();
|
localLockHeldInfo = longestReadLockHeldInfo.get();
|
||||||
|
@ -253,6 +264,7 @@ class FSNamesystemLock {
|
||||||
LogAction logAction = LogThrottlingHelper.DO_NOT_LOG;
|
LogAction logAction = LogThrottlingHelper.DO_NOT_LOG;
|
||||||
if (needReport &&
|
if (needReport &&
|
||||||
writeLockIntervalMs >= this.writeLockReportingThresholdMs) {
|
writeLockIntervalMs >= this.writeLockReportingThresholdMs) {
|
||||||
|
numWriteLockLongHold.incrementAndGet();
|
||||||
if (longestWriteLockHeldInfo.getIntervalMs() < writeLockIntervalMs) {
|
if (longestWriteLockHeldInfo.getIntervalMs() < writeLockIntervalMs) {
|
||||||
longestWriteLockHeldInfo =
|
longestWriteLockHeldInfo =
|
||||||
new LockHeldInfo(currentTimeMs, writeLockIntervalMs,
|
new LockHeldInfo(currentTimeMs, writeLockIntervalMs,
|
||||||
|
@ -302,6 +314,28 @@ class FSNamesystemLock {
|
||||||
return coarseLock.writeLock().newCondition();
|
return coarseLock.writeLock().newCondition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of time the read lock
|
||||||
|
* has been held longer than the threshold.
|
||||||
|
*
|
||||||
|
* @return long - Number of time the read lock
|
||||||
|
* has been held longer than the threshold
|
||||||
|
*/
|
||||||
|
public long getNumOfReadLockLongHold() {
|
||||||
|
return numReadLockLongHold.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of time the write lock
|
||||||
|
* has been held longer than the threshold.
|
||||||
|
*
|
||||||
|
* @return long - Number of time the write lock
|
||||||
|
* has been held longer than the threshold.
|
||||||
|
*/
|
||||||
|
public long getNumOfWriteLockLongHold() {
|
||||||
|
return numWriteLockLongHold.get();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the QueueLength of waiting threads.
|
* Returns the QueueLength of waiting threads.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue