adoroszlai commented on a change in pull request #3180:
URL: https://github.com/apache/ozone/pull/3180#discussion_r830653688
##########
File path:
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java
##########
@@ -172,7 +176,16 @@ private boolean lock(Resource resource, String
resourceName,
LOG.error(errorMessage);
throw new RuntimeException(errorMessage);
} else {
+ long startWaitingTimeNanos = Time.monotonicNowNanos();
+ /**
+ * holdCount helps in metric updation only once in case of reentrant
+ * locks.
+ */
+ int holdCount = manager.getActiveLockCount(resourceName);
lockFn.accept(resourceName);
+ if (holdCount == 0) {
+ updateReadLockMetrics(resource, lockType, startWaitingTimeNanos);
+ }
Review comment:
Here's a test case to reproduce the multiple readers problem I mentioned:
```java
@Test
public void testReadLockConcurrentStats() throws InterruptedException {
// GIVEN
final int threadCount = 5;
OzoneManagerLock.Resource resource =
OzoneManagerLock.Resource.VOLUME_LOCK;
String[] resourceName = generateResourceName(resource);
OzoneManagerLock lock = new OzoneManagerLock(new OzoneConfiguration());
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
lock.acquireReadLock(resource, resourceName);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
lock.releaseReadLock(resource, resourceName);
});
threads[i].start();
}
for (Thread t : threads) {
t.join();
}
// WHEN
String heldStat = lock.getReadLockHeldTimeMsStat();
// THEN
Assert.assertTrue("Expected " + threadCount + " samples in " + heldStat,
heldStat.contains("Samples = " + threadCount));
}
```
Result:
```
[ERROR] Failures:
[ERROR] TestOzoneManagerLock.testReadLockConcurrentStats:389 Expected 5
samples in Samples = 1 Min = 1.26694054E8 Mean = 1.26694054E8 Std Dev = 0.0
Max = 1.26694054E8
```
Only one of the 5 threads that acquire the read lock are reflected by the
metrics stat.
Similar test case can be constructed for 1 writer + N readers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]