spacemonkd commented on code in PR #10852:
URL: https://github.com/apache/ozone/pull/10852#discussion_r3646181719
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/lock/OzoneManagerLock.java:
##########
@@ -97,41 +94,140 @@ public class OzoneManagerLock implements IOzoneManagerLock
{
private static final Logger LOG =
LoggerFactory.getLogger(OzoneManagerLock.class);
- private final Map<Class<? extends Resource>,
- Pair<Map<Resource, Striped<ReadWriteLock>>, ResourceLockTracker>>
resourcelockMap;
+ private final ResourceLocks<LeveledResource> leveledResourceLocks;
+ private final ResourceLocks<DAGLeveledResource> dagLeveledResourceLocks;
- private OMLockMetrics omLockMetrics;
+ private final OMLockMetrics omLockMetrics = OMLockMetrics.create();
+
+ class ResourceLocks<R extends Resource> {
+ private final Map<R, Striped<ReentrantReadWriteLock>> lockMap;
+ private final ResourceLockTracker<R> tracker;
+
+ ResourceLocks(Map<R, Striped<ReentrantReadWriteLock>> lockMap,
ResourceLockTracker<R> tracker) {
+ this.lockMap = lockMap;
+ this.tracker = tracker;
+ }
+
+ R assertAcquire(Resource resource) {
+ final R r = Preconditions.assertInstanceOf(resource,
tracker.getResourceClass());
+ tracker.clearLockDetails();
+ if (!tracker.canLockResource(r)) {
+ final String errorMessage = "Thread '" +
Thread.currentThread().getName() + "' cannot acquire "
+ + r.getName() + " lock while holding " + getCurrentLocks() + "
lock(s).";
+ LOG.error(errorMessage);
+ // TODO: change it to IllegalStateException
+ throw new RuntimeException(errorMessage);
+ }
+ return r;
+ }
+
+ private ReentrantReadWriteLock getLockForTesting(Resource resource,
String... keys) {
+ final R r = Preconditions.assertInstanceOf(resource,
tracker.getResourceClass());
+ return getLock(r, keys);
+ }
+
+ private ReentrantReadWriteLock getLock(R r, String... keys) {
+ return lockMap.get(r).get(CompositeKey.combineKeys(keys));
+ }
+
+ private void acquireLock(R resource, boolean isRead,
ReentrantReadWriteLock lock, long startWaitingTimeNanos) {
+ if (isRead) {
+ lock.readLock().lock();
+ updateReadLockMetrics(resource, tracker, lock, startWaitingTimeNanos);
+ } else {
+ lock.writeLock().lock();
+ updateWriteLockMetrics(resource, tracker, lock, startWaitingTimeNanos);
+ }
+ }
+
+ OMLockDetails acquire(Resource resource, boolean isRead,
+ Function<Striped<ReentrantReadWriteLock>,
Iterable<ReentrantReadWriteLock>> getLocks) {
+ final R r = assertAcquire(resource);
+ final long startWaitingTimeNanos = Time.monotonicNow();
Review Comment:
`monotonicNow()` is in miliseconds, but we need to have nanoseconds?
```suggestion
final long startWaitingTimeNanos = Time.monotonicNowNanos();
```
--
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]