Skip to content

Commit 68cccba

Browse files
tomscutshvachko
authored andcommitted
HDFS-15808. Add metrics for FSNamesystem read/write lock hold long time. (#2668) Contributed by tomscut.
(cherry picked from commit 9cb51bf)
1 parent 9c3c753 commit 68cccba

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,6 +4161,20 @@ public int getFsLockQueueLength() {
41614161
return fsLock.getQueueLength();
41624162
}
41634163

4164+
@Metric(value = {"ReadLockLongHoldCount", "The number of time " +
4165+
"the read lock has been held for longer than the threshold"},
4166+
type = Metric.Type.COUNTER)
4167+
public long getNumOfReadLockLongHold() {
4168+
return fsLock.getNumOfReadLockLongHold();
4169+
}
4170+
4171+
@Metric(value = {"WriteLockLongHoldCount", "The number of time " +
4172+
"the write lock has been held for longer than the threshold"},
4173+
type = Metric.Type.COUNTER)
4174+
public long getNumOfWriteLockLongHold() {
4175+
return fsLock.getNumOfWriteLockLongHold();
4176+
}
4177+
41644178
int getNumberOfDatanodes(DatanodeReportType type) {
41654179
readLock();
41664180
try {

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystemLock.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ public Long initialValue() {
101101
private final AtomicLong timeStampOfLastReadLockReportMs = new AtomicLong(0);
102102
/** Longest time (ms) a read lock was held since the last report. */
103103
private final AtomicLong longestReadLockHeldIntervalMs = new AtomicLong(0);
104+
/**
105+
* The number of time the read lock
106+
* has been held longer than the threshold.
107+
*/
108+
private final AtomicLong numReadLockLongHold = new AtomicLong(0);
109+
/**
110+
* The number of time the write lock
111+
* has been held for longer than the threshold.
112+
*/
113+
private final AtomicLong numWriteLockLongHold = new AtomicLong(0);
104114

105115
@VisibleForTesting
106116
static final String OP_NAME_OTHER = "OTHER";
@@ -168,6 +178,7 @@ public void readUnlock(String opName) {
168178
final long readLockIntervalMs =
169179
TimeUnit.NANOSECONDS.toMillis(readLockIntervalNanos);
170180
if (needReport && readLockIntervalMs >= this.readLockReportingThresholdMs) {
181+
numReadLockLongHold.incrementAndGet();
171182
long localLongestReadLock;
172183
do {
173184
localLongestReadLock = longestReadLockHeldIntervalMs.get();
@@ -224,6 +235,7 @@ public void writeUnlock(String opName) {
224235
LogAction logAction = LogThrottlingHelper.DO_NOT_LOG;
225236
if (needReport &&
226237
writeLockIntervalMs >= this.writeLockReportingThresholdMs) {
238+
numWriteLockLongHold.incrementAndGet();
227239
logAction = writeLockReportLogger
228240
.record("write", currentTimeMs, writeLockIntervalMs);
229241
}
@@ -263,6 +275,28 @@ public Condition newWriteLockCondition() {
263275
return coarseLock.writeLock().newCondition();
264276
}
265277

278+
/**
279+
* Returns the number of time the read lock
280+
* has been held longer than the threshold.
281+
*
282+
* @return long - Number of time the read lock
283+
* has been held longer than the threshold
284+
*/
285+
public long getNumOfReadLockLongHold() {
286+
return numReadLockLongHold.get();
287+
}
288+
289+
/**
290+
* Returns the number of time the write lock
291+
* has been held longer than the threshold.
292+
*
293+
* @return long - Number of time the write lock
294+
* has been held longer than the threshold.
295+
*/
296+
public long getNumOfWriteLockLongHold() {
297+
return numWriteLockLongHold.get();
298+
}
299+
266300
/**
267301
* Returns the QueueLength of waiting threads.
268302
*

0 commit comments

Comments
 (0)