Skip to content

HDFS-15808. Add metrics for FSNamesystem read/write lock hold long time #2668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4824,6 +4824,20 @@ public int getFsLockQueueLength() {
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) {
readLock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ public Long initialValue() {
private final AtomicReference<LockHeldInfo> longestReadLockHeldInfo =
new AtomicReference<>(new LockHeldInfo());
private LockHeldInfo longestWriteLockHeldInfo = new LockHeldInfo();
/**
* 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
static final String OP_NAME_OTHER = "OTHER";
Expand Down Expand Up @@ -182,6 +192,7 @@ public void readUnlock(String opName,
final long readLockIntervalMs =
TimeUnit.NANOSECONDS.toMillis(readLockIntervalNanos);
if (needReport && readLockIntervalMs >= this.readLockReportingThresholdMs) {
numReadLockLongHold.incrementAndGet();
String lockReportInfo = null;
boolean done = false;
while (!done) {
Expand Down Expand Up @@ -298,6 +309,7 @@ private void writeUnlock(String opName, boolean suppressWriteLockReport,
LogAction logAction = LogThrottlingHelper.DO_NOT_LOG;
if (needReport &&
writeLockIntervalMs >= this.writeLockReportingThresholdMs) {
numWriteLockLongHold.incrementAndGet();
if (longestWriteLockHeldInfo.getIntervalMs() <= writeLockIntervalMs) {
String lockReportInfo = lockReportInfoSupplier != null ? " (" +
lockReportInfoSupplier.get() + ")" : "";
Expand Down Expand Up @@ -362,6 +374,28 @@ public int getQueueLength() {
return coarseLock.getQueueLength();
}

/**
* 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();
}

/**
* Add the lock hold time for a recent operation to the metrics.
* @param operationName Name of the operation for which to record the time
Expand Down