Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -17,7 +17,7 @@

package org.apache.hadoop.ozone.om;

import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource.S3_SECRET_LOCK;
import static org.apache.hadoop.ozone.om.lock.OzoneManagerLock.LeveledResource.S3_SECRET_LOCK;

import java.io.IOException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,128 @@
*/
public interface IOzoneManagerLock {

OMLockDetails acquireReadLock(OzoneManagerLock.Resource resource,
OMLockDetails acquireReadLock(Resource resource,
String... resources);

OMLockDetails acquireReadLocks(OzoneManagerLock.Resource resource, Collection<String[]> resources);
OMLockDetails acquireReadLocks(Resource resource, Collection<String[]> resources);

OMLockDetails acquireWriteLock(OzoneManagerLock.Resource resource,
OMLockDetails acquireWriteLock(Resource resource,
String... resources);

OMLockDetails acquireWriteLocks(OzoneManagerLock.Resource resource,
Collection<String[]> resources);
OMLockDetails acquireWriteLocks(Resource resource,
Collection<String[]> resources);

boolean acquireMultiUserLock(String firstUser, String secondUser);

void releaseMultiUserLock(String firstUser, String secondUser);

OMLockDetails releaseWriteLock(OzoneManagerLock.Resource resource,
String... resources);
OMLockDetails releaseWriteLock(Resource resource,
String... resources);

OMLockDetails releaseWriteLocks(OzoneManagerLock.Resource resource,
Collection<String[]> resources);
OMLockDetails releaseWriteLocks(Resource resource,
Collection<String[]> resources);

OMLockDetails releaseReadLock(OzoneManagerLock.Resource resource,
OMLockDetails releaseReadLock(Resource resource,
String... resources);

OMLockDetails releaseReadLocks(OzoneManagerLock.Resource resource,
Collection<String[]> resources);
OMLockDetails releaseReadLocks(Resource resource,
Collection<String[]> resources);

@VisibleForTesting
int getReadHoldCount(OzoneManagerLock.Resource resource,
String... resources);
int getReadHoldCount(Resource resource,
String... resources);

@VisibleForTesting
int getWriteHoldCount(OzoneManagerLock.Resource resource,
String... resources);
int getWriteHoldCount(Resource resource,
String... resources);

@VisibleForTesting
boolean isWriteLockedByCurrentThread(OzoneManagerLock.Resource resource,
String... resources);
boolean isWriteLockedByCurrentThread(Resource resource,
String... resources);

void cleanup();

OMLockMetrics getOMLockMetrics();

/**
* Defines a resource interface used to represent entities that can be
* associated with locks in the Ozone Manager Lock mechanism. A resource
* implementation provides a name and an associated {@link ResourceManager}
* to manage its locking behavior.
*/
interface Resource {

String getName();

ResourceManager getResourceManager();
}

/**
* The ResourceManager class provides functionality for managing
* information about resource read and write lock usage. It tracks the time of
* read and write locks acquired and held by individual threads, enabling
* more granular lock usage metrics.
*/
class ResourceManager {
// This helps in maintaining read lock related variables locally confined
// to a given thread.
private final ThreadLocal<LockUsageInfo> readLockTimeStampNanos =
ThreadLocal.withInitial(LockUsageInfo::new);

// This helps in maintaining write lock related variables locally confined
// to a given thread.
private final ThreadLocal<LockUsageInfo> writeLockTimeStampNanos =
ThreadLocal.withInitial(LockUsageInfo::new);

ResourceManager() {
}

/**
* Sets the time (ns) when the read lock holding period begins specific to a
* thread.
*
* @param startReadHeldTimeNanos read lock held start time (ns)
*/
void setStartReadHeldTimeNanos(long startReadHeldTimeNanos) {
readLockTimeStampNanos.get()
.setStartReadHeldTimeNanos(startReadHeldTimeNanos);
}

/**
* Sets the time (ns) when the write lock holding period begins specific to
* a thread.
*
* @param startWriteHeldTimeNanos write lock held start time (ns)
*/
void setStartWriteHeldTimeNanos(long startWriteHeldTimeNanos) {
writeLockTimeStampNanos.get()
.setStartWriteHeldTimeNanos(startWriteHeldTimeNanos);
}

/**
* Returns the time (ns) when the read lock holding period began specific to
* a thread.
*
* @return read lock held start time (ns)
*/
long getStartReadHeldTimeNanos() {
long startReadHeldTimeNanos =
readLockTimeStampNanos.get().getStartReadHeldTimeNanos();
readLockTimeStampNanos.remove();
return startReadHeldTimeNanos;
}

/**
* Returns the time (ns) when the write lock holding period began specific
* to a thread.
*
* @return write lock held start time (ns)
*/
long getStartWriteHeldTimeNanos() {
long startWriteHeldTimeNanos =
writeLockTimeStampNanos.get().getStartWriteHeldTimeNanos();
writeLockTimeStampNanos.remove();
return startWriteHeldTimeNanos;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.apache.hadoop.ozone.om.lock.OMLockDetails.EMPTY_DETAILS_LOCK_NOT_ACQUIRED;

import java.util.Collection;
import org.apache.hadoop.ozone.om.lock.OzoneManagerLock.Resource;

/**
* Read only "lock" for snapshots
Expand All @@ -42,7 +41,7 @@ public OMLockDetails acquireReadLocks(Resource resource, Collection<String[]> re

@Override
public OMLockDetails acquireWriteLock(Resource resource,
String... resources) {
String... resources) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change your IDE settings to avoid changing indent in method signatures like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done thanks for the tip!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncheck Method declaration parameters - Align when multiline like this:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smengcl Thanks for the tip, I was using the Ozone checkstyle.xml, and it seems this is checked by default. Maybe we can fix it in checkstyle.xml instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we should fix checkstyle.xml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#8494 please take a look at this pr

return EMPTY_DETAILS_LOCK_NOT_ACQUIRED;
}

Expand All @@ -63,7 +62,7 @@ public void releaseMultiUserLock(String firstUser, String secondUser) {

@Override
public OMLockDetails releaseWriteLock(Resource resource,
String... resources) {
String... resources) {
return EMPTY_DETAILS_LOCK_NOT_ACQUIRED;
}

Expand Down Expand Up @@ -94,7 +93,7 @@ public int getWriteHoldCount(Resource resource, String... resources) {

@Override
public boolean isWriteLockedByCurrentThread(Resource resource,
String... resources) {
String... resources) {
return false;
}

Expand Down
Loading
Loading