Skip to content

Commit 794b5aa

Browse files
ZanderXuzengqiang.xu
authored andcommitted
HDFS-17405. [FGL] Using different metric name to trace performance for FGL and Global lock (#6600)
1 parent b688ac8 commit 794b5aa

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* to be true, metrics will be emitted into the FSNamesystem metrics registry
5757
* for each operation which acquires this lock indicating how long the operation
5858
* held the lock for. These metrics have names of the form
59-
* FSN(Read|Write)LockNanosOperationName, where OperationName denotes the name
59+
* ${LockName}(Read|Write)LockNanosOperationName, where OperationName denotes the name
6060
* of the operation that initiated the lock hold (this will be OTHER for certain
6161
* uncategorized operations) and they export the hold time values in
6262
* nanoseconds. Note that if a thread dies, metrics produced after the
@@ -67,6 +67,7 @@
6767
public class FSNamesystemLock {
6868
@VisibleForTesting
6969
protected ReentrantReadWriteLock coarseLock;
70+
private final String lockName;
7071

7172
private volatile boolean metricsEnabled;
7273
private final MutableRatesWithAggregation detailedHoldTimeMetrics;
@@ -123,23 +124,26 @@ public Long initialValue() {
123124

124125
@VisibleForTesting
125126
static final String OP_NAME_OTHER = "OTHER";
126-
private static final String READ_LOCK_METRIC_PREFIX = "FSNReadLock";
127-
private static final String WRITE_LOCK_METRIC_PREFIX = "FSNWriteLock";
127+
private final String readLockMetricPrefix;
128+
private final String writeLockMetricPrefix;
128129
private static final String LOCK_METRIC_SUFFIX = "Nanos";
129130

130131
private static final String OVERALL_METRIC_NAME = "Overall";
131132

132-
public FSNamesystemLock(Configuration conf,
133+
public FSNamesystemLock(Configuration conf, String lockName,
133134
MutableRatesWithAggregation detailedHoldTimeMetrics) {
134-
this(conf, detailedHoldTimeMetrics, new Timer());
135+
this(conf, lockName, detailedHoldTimeMetrics, new Timer());
135136
}
136137

137138
@VisibleForTesting
138-
FSNamesystemLock(Configuration conf,
139+
FSNamesystemLock(Configuration conf, String lockName,
139140
MutableRatesWithAggregation detailedHoldTimeMetrics, Timer timer) {
141+
this.lockName = lockName;
142+
this.readLockMetricPrefix = this.lockName + "ReadLock";
143+
this.writeLockMetricPrefix = this.lockName + "WriteLock";
140144
boolean fair = conf.getBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY,
141145
DFS_NAMENODE_FSLOCK_FAIR_DEFAULT);
142-
FSNamesystem.LOG.info("fsLock is fair: " + fair);
146+
FSNamesystem.LOG.info("{}Lock is fair: {}.", this.lockName, fair);
143147
this.coarseLock = new ReentrantReadWriteLock(fair);
144148
this.timer = timer;
145149

@@ -157,8 +161,8 @@ public FSNamesystemLock(Configuration conf,
157161
this.metricsEnabled = conf.getBoolean(
158162
DFS_NAMENODE_LOCK_DETAILED_METRICS_KEY,
159163
DFS_NAMENODE_LOCK_DETAILED_METRICS_DEFAULT);
160-
FSNamesystem.LOG.info("Detailed lock hold time metrics enabled: " +
161-
this.metricsEnabled);
164+
FSNamesystem.LOG.info("Detailed lock hold time metrics of {}Lock is {}.",
165+
this.lockName, this.metricsEnabled ? "enabled" : "disabled");
162166
this.detailedHoldTimeMetrics = detailedHoldTimeMetrics;
163167
}
164168

@@ -231,9 +235,9 @@ public void readUnlock(String opName,
231235
LockHeldInfo lockHeldInfo =
232236
longestReadLockHeldInfo.getAndSet(new LockHeldInfo());
233237
FSNamesystem.LOG.info(
234-
"\tNumber of suppressed read-lock reports: {}"
238+
"\tNumber of suppressed read-lock reports of {}Lock is {}"
235239
+ "\n\tLongest read-lock held at {} for {}ms by {}{} via {}",
236-
numSuppressedWarnings, Time.formatTime(lockHeldInfo.getStartTimeMs()),
240+
this.lockName, numSuppressedWarnings, Time.formatTime(lockHeldInfo.getStartTimeMs()),
237241
lockHeldInfo.getIntervalMs(), lockHeldInfo.getOpName(),
238242
lockHeldInfo.getLockReportInfo(), lockHeldInfo.getStackTrace());
239243
}
@@ -337,10 +341,10 @@ private void writeUnlock(String opName, boolean suppressWriteLockReport,
337341

338342
if (logAction.shouldLog()) {
339343
FSNamesystem.LOG.info(
340-
"\tNumber of suppressed write-lock reports: {}"
344+
"\tNumber of suppressed write-lock reports of {}Lock is {}"
341345
+ "\n\tLongest write-lock held at {} for {}ms by {}{} via {}"
342346
+ "\n\tTotal suppressed write-lock held time: {}",
343-
logAction.getCount() - 1,
347+
this.lockName, logAction.getCount() - 1,
344348
Time.formatTime(lockHeldInfo.getStartTimeMs()),
345349
lockHeldInfo.getIntervalMs(), lockHeldInfo.getOpName(),
346350
lockHeldInfo.getLockReportInfo(), lockHeldInfo.getStackTrace(),
@@ -456,8 +460,8 @@ private static void updateProcessingDetails(Timing type, long deltaNanos) {
456460
}
457461
}
458462

459-
private static String getMetricName(String operationName, boolean isWrite) {
460-
return (isWrite ? WRITE_LOCK_METRIC_PREFIX : READ_LOCK_METRIC_PREFIX) +
463+
private String getMetricName(String operationName, boolean isWrite) {
464+
return (isWrite ? this.writeLockMetricPrefix : this.readLockMetricPrefix) +
461465
org.apache.commons.lang3.StringUtils.capitalize(operationName) +
462466
LOCK_METRIC_SUFFIX;
463467
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class FineGrainedFSNamesystemLock implements FSNLockManager {
3535
private final FSNamesystemLock bmLock;
3636

3737
public FineGrainedFSNamesystemLock(Configuration conf, MutableRatesWithAggregation aggregation) {
38-
this.fsLock = new FSNamesystemLock(conf, aggregation);
39-
this.bmLock = new FSNamesystemLock(conf, aggregation);
38+
this.fsLock = new FSNamesystemLock(conf, "FS", aggregation);
39+
this.bmLock = new FSNamesystemLock(conf, "BM", aggregation);
4040
}
4141

4242
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class GlobalFSNamesystemLock implements FSNLockManager {
2929
private final FSNamesystemLock lock;
3030

3131
public GlobalFSNamesystemLock(Configuration conf, MutableRatesWithAggregation aggregation) {
32-
this.lock = new FSNamesystemLock(conf, aggregation);
32+
this.lock = new FSNamesystemLock(conf, "FSN", aggregation);
3333
}
3434

3535
@Override

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystemLock.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ public void testFsLockFairness() throws IOException, InterruptedException{
5757
Configuration conf = new Configuration();
5858

5959
conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, true);
60-
FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null);
60+
FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null);
6161
assertTrue(fsnLock.coarseLock.isFair());
6262

6363
conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, false);
64-
fsnLock = new FSNamesystemLock(conf, null);
64+
fsnLock = new FSNamesystemLock(conf, "FSN", null);
6565
assertFalse(fsnLock.coarseLock.isFair());
6666
}
6767

6868
@Test
6969
public void testFSNamesystemLockCompatibility() {
70-
FSNamesystemLock rwLock = new FSNamesystemLock(new Configuration(), null);
70+
FSNamesystemLock rwLock = new FSNamesystemLock(new Configuration(), "FSN", null);
7171

7272
assertEquals(0, rwLock.getReadHoldCount());
7373
rwLock.readLock();
@@ -107,7 +107,7 @@ public void testFSLockGetWaiterCount() throws InterruptedException {
107107
final CountDownLatch latch = new CountDownLatch(threadCount);
108108
final Configuration conf = new Configuration();
109109
conf.setBoolean(DFS_NAMENODE_FSLOCK_FAIR_KEY, true);
110-
final FSNamesystemLock rwLock = new FSNamesystemLock(conf, null);
110+
final FSNamesystemLock rwLock = new FSNamesystemLock(conf, "FSN", null);
111111
rwLock.writeLock();
112112
ExecutorService helper = Executors.newFixedThreadPool(threadCount);
113113

@@ -150,7 +150,7 @@ public void testFSWriteLockLongHoldingReport() throws Exception {
150150
writeLockSuppressWarningInterval, TimeUnit.MILLISECONDS);
151151

152152
final FakeTimer timer = new FakeTimer();
153-
final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null, timer);
153+
final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null, timer);
154154
timer.advance(writeLockSuppressWarningInterval);
155155

156156
LogCapturer logs = LogCapturer.captureLogs(FSNamesystem.LOG);
@@ -213,7 +213,7 @@ public void testFSWriteLockLongHoldingReport() throws Exception {
213213
"held at " + Time.formatTime(timer.now()).substring(0, 10);
214214
assertTrue(logs.getOutput().contains(startTimeStr));
215215
assertTrue(logs.getOutput().contains(
216-
"Number of suppressed write-lock reports: 2"));
216+
"Number of suppressed write-lock reports of FSNLock is 2"));
217217
}
218218

219219
/**
@@ -233,7 +233,7 @@ public void testFSReadLockLongHoldingReport() throws Exception {
233233
readLockSuppressWarningInterval, TimeUnit.MILLISECONDS);
234234

235235
final FakeTimer timer = new FakeTimer();
236-
final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null, timer);
236+
final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null, timer);
237237
timer.advance(readLockSuppressWarningInterval);
238238

239239
LogCapturer logs = LogCapturer.captureLogs(FSNamesystem.LOG);
@@ -304,7 +304,7 @@ public void run() {
304304
"held at " + Time.formatTime(timer.now()).substring(0, 10);
305305
assertTrue(logs.getOutput().contains(startTimeStr));
306306
assertTrue(logs.getOutput().contains(
307-
"Number of suppressed read-lock reports: 3"));
307+
"Number of suppressed read-lock reports of FSNLock is 3"));
308308

309309
// Report if it's held for a long time (and time since last report
310310
// exceeds the suppress warning interval) while another thread also has the
@@ -366,7 +366,7 @@ public void testDetailedHoldMetrics() throws Exception {
366366
MetricsRegistry registry = new MetricsRegistry("Test");
367367
MutableRatesWithAggregation rates =
368368
registry.newRatesWithAggregation("Test");
369-
FSNamesystemLock fsLock = new FSNamesystemLock(conf, rates, timer);
369+
FSNamesystemLock fsLock = new FSNamesystemLock(conf, "FSN", rates, timer);
370370

371371
fsLock.readLock();
372372
timer.advanceNanos(1300000);
@@ -419,7 +419,7 @@ public void testFSWriteLockReportSuppressed() throws Exception {
419419
writeLockSuppressWarningInterval, TimeUnit.MILLISECONDS);
420420

421421
final FakeTimer timer = new FakeTimer();
422-
final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, null, timer);
422+
final FSNamesystemLock fsnLock = new FSNamesystemLock(conf, "FSN", null, timer);
423423
timer.advance(writeLockSuppressWarningInterval);
424424

425425
LogCapturer logs = LogCapturer.captureLogs(FSNamesystem.LOG);

0 commit comments

Comments
 (0)