[GitHub] [hadoop] arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in OzoneManager.

2019-06-20 Thread GitBox
arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in 
OzoneManager.
URL: https://github.com/apache/hadoop/pull/949#discussion_r295942564
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/S3BucketManagerImpl.java
 ##
 @@ -101,34 +101,26 @@ public void createS3Bucket(String userName, String 
bucketName)
 // anonymous access to bucket where the user name is absent.
 String ozoneVolumeName = formatOzoneVolumeName(userName);
 
-omMetadataManager.getLock().acquireS3Lock(bucketName);
-try {
-  String bucket =
-  omMetadataManager.getS3Table().get(bucketName);
-
-  if (bucket != null) {
-LOG.debug("Bucket already exists. {}", bucketName);
-throw new OMException(
-"Unable to create S3 bucket. " + bucketName + " already exists.",
-OMException.ResultCodes.S3_BUCKET_ALREADY_EXISTS);
-  }
-  String ozoneBucketName = bucketName;
-  createOzoneBucket(ozoneVolumeName, ozoneBucketName);
-  String finalName = String.format("%s/%s", ozoneVolumeName,
-  ozoneBucketName);
+String bucket = omMetadataManager.getS3Table().get(bucketName);
 
-  omMetadataManager.getS3Table().put(bucketName, finalName);
-} finally {
-  omMetadataManager.getLock().releaseS3Lock(bucketName);
 
 Review comment:
   Sorry I didn't get why we removed the acquire/release bucket lock. Is the 
caller now supposed to get the lock?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in OzoneManager.

2019-06-20 Thread GitBox
arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in 
OzoneManager.
URL: https://github.com/apache/hadoop/pull/949#discussion_r295928408
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/OMVolumeDeleteRequest.java
 ##
 @@ -104,37 +104,23 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager,
 
 OmVolumeArgs omVolumeArgs = null;
 String owner = null;
-
+IOException exception = null;
+OzoneManagerProtocolProtos.VolumeList newVolumeList = null;
 omMetadataManager.getLock().acquireVolumeLock(volume);
 try {
   owner = getVolumeInfo(omMetadataManager, volume).getOwnerName();
-} catch (IOException ex) {
-  LOG.error("Volume deletion failed for volume:{}", volume, ex);
-  omMetrics.incNumVolumeDeleteFails();
-  auditLog(auditLogger, buildAuditMessage(OMAction.DELETE_VOLUME,
-  buildVolumeAuditMap(volume), ex, userInfo));
-  return new OMVolumeDeleteResponse(null, null, null,
-  createErrorOMResponse(omResponse, ex));
-} finally {
-  omMetadataManager.getLock().releaseVolumeLock(volume);
-}
 
-// Release and reacquire lock for now it will not be a problem for now, as
-// applyTransaction serializes the operation's.
-// TODO: Revisit this logic once HDDS-1672 checks in.
+  // Release and reacquire lock for now it will not be a problem for now, 
as
 
 Review comment:
   Obsolete comment?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in OzoneManager.

2019-06-20 Thread GitBox
arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in 
OzoneManager.
URL: https://github.com/apache/hadoop/pull/949#discussion_r295930273
 
 

 ##
 File path: 
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerLock.java
 ##
 @@ -154,79 +178,137 @@ public void releaseVolumeLock(String volume) {
   }
 
   /**
-   * Acquires S3 Bucket lock on the given resource.
+   * Acquires bucket lock on the given resource.
*
* If the lock is not available then the current thread becomes
-   * disabled for thread scheduling purposes and lies dormant until the lock 
has
-   * been acquired.
+   * disabled for thread scheduling purposes and lies dormant until the
+   * lock has been acquired.
*
-   * @param s3BucketName S3Bucket Name on which the lock has to be acquired
+   * @param bucket Bucket on which the lock has to be acquired
*/
-  public void acquireS3Lock(String s3BucketName) {
-// Calling thread should not hold any bucket lock.
-// You can take an Volume while holding S3 bucket lock, since
-// semantically an S3 bucket maps to the ozone volume. So we check here
-// only if ozone bucket lock is taken.
-if (hasAnyBucketLock()) {
+  public void acquireBucketLock(String volume, String bucket) {
+if (hasAnyUserLock()) {
   throw new RuntimeException(
   "Thread '" + Thread.currentThread().getName() +
-  "' cannot acquire S3 bucket lock while holding Ozone bucket " +
-  "lock(s).");
+  "' cannot acquire bucket lock while holding User lock.");
 }
-manager.lock(OM_S3_PREFIX + s3BucketName);
-myLocks.get().get(S3_BUCKET_LOCK).incrementAndGet();
+manager.lock(OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket);
+myLocks.get().get(BUCKET_LOCK).incrementAndGet();
   }
 
   /**
-   * Releases the volume lock on given resource.
+   * Releases the bucket lock on given resource.
*/
-  public void releaseS3Lock(String s3BucketName) {
-manager.unlock(OM_S3_PREFIX + s3BucketName);
-myLocks.get().get(S3_BUCKET_LOCK).decrementAndGet();
+  public void releaseBucketLock(String volume, String bucket) {
+manager.unlock(OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket);
+myLocks.get().get(BUCKET_LOCK).decrementAndGet();
   }
 
   /**
-   * Acquires bucket lock on the given resource.
+   * Acquires user lock on the given resource.
*
* If the lock is not available then the current thread becomes
* disabled for thread scheduling purposes and lies dormant until the
* lock has been acquired.
*
-   * @param bucket Bucket on which the lock has to be acquired
+   * @param user User on which the lock has to be acquired
*/
-  public void acquireBucketLock(String volume, String bucket) {
-manager.lock(OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket);
-myLocks.get().get(BUCKET_LOCK).incrementAndGet();
+  public void acquireUserLock(String user) {
+// In order to not maintain username's on which we have acquired lock,
+// just checking have we acquired userLock before. If user want's to
+// acquire user lock on multiple user's they should use
+// acquireMultiUserLock. This is just a protection logic, to let not users
+// use this if acquiring lock on multiple users. As currently, we have only
+// use case we have for this is during setOwner operation in VolumeManager.
+if (hasAnyUserLock()) {
+  LOG.error("Already have userLock");
+  throw new RuntimeException("For acquiring lock on multiple users, use " +
+  "acquireMultiLock method");
+}
+manager.lock(OM_USER_PREFIX + user);
+myLocks.get().get(USER_LOCK).incrementAndGet();
   }
 
   /**
-   * Releases the bucket lock on given resource.
+   * Releases the user lock on given resource.
*/
-  public void releaseBucketLock(String volume, String bucket) {
-manager.unlock(OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket);
-myLocks.get().get(BUCKET_LOCK).decrementAndGet();
+  public void releaseUserLock(String user) {
+manager.unlock(OM_USER_PREFIX + user);
+myLocks.get().get(USER_LOCK).decrementAndGet();
   }
 
   /**
-   * Returns true if the current thread holds any volume lock.
-   * @return true if current thread holds volume lock, else false
+   * Acquire user lock on 2 users. In this case, we compare 2 strings
+   * lexicographically, and acquire the locks according to the sorted order of
+   * the user names. In this way, when acquiring locks on multiple user's, we
+   * can avoid dead locks. This method should be called when single thread is
+   * acquiring lock on 2 users at a time.
+   *
+   * Example:
+   * ozone, hdfs -> lock acquire order will be hdfs, ozone
+   * hdfs, ozone -> lock acquire order will be hdfs, ozone
+   *
+   * @param newUser
+   * @param oldUser
*/
-  private boolean hasAnyVolumeLock() {
-return myLocks.get().get(VOLUME_LOCK).get() != 0;
+  public void 

[GitHub] [hadoop] arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in OzoneManager.

2019-06-20 Thread GitBox
arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in 
OzoneManager.
URL: https://github.com/apache/hadoop/pull/949#discussion_r295928452
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/OMVolumeDeleteRequest.java
 ##
 @@ -104,37 +104,23 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager,
 
 OmVolumeArgs omVolumeArgs = null;
 String owner = null;
-
+IOException exception = null;
+OzoneManagerProtocolProtos.VolumeList newVolumeList = null;
 omMetadataManager.getLock().acquireVolumeLock(volume);
 try {
   owner = getVolumeInfo(omMetadataManager, volume).getOwnerName();
-} catch (IOException ex) {
-  LOG.error("Volume deletion failed for volume:{}", volume, ex);
-  omMetrics.incNumVolumeDeleteFails();
-  auditLog(auditLogger, buildAuditMessage(OMAction.DELETE_VOLUME,
-  buildVolumeAuditMap(volume), ex, userInfo));
-  return new OMVolumeDeleteResponse(null, null, null,
-  createErrorOMResponse(omResponse, ex));
-} finally {
-  omMetadataManager.getLock().releaseVolumeLock(volume);
-}
 
-// Release and reacquire lock for now it will not be a problem for now, as
-// applyTransaction serializes the operation's.
-// TODO: Revisit this logic once HDDS-1672 checks in.
+  // Release and reacquire lock for now it will not be a problem for now, 
as
+  // applyTransaction serializes the operation's.
 
-// We cannot acquire user lock holding volume lock, so released volume
-// lock, and acquiring user and volume lock.
+  // We cannot acquire user lock holding volume lock, so released volume
 
 Review comment:
   Obsolete comment?


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in OzoneManager.

2019-06-20 Thread GitBox
arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in 
OzoneManager.
URL: https://github.com/apache/hadoop/pull/949#discussion_r295932106
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
 ##
 @@ -2564,6 +2564,9 @@ public void createS3Bucket(String userName, String 
s3BucketName)
   }
   metrics.incNumBucketCreates();
   try {
+metadataManager.getLock().acquireS3BucketLock(s3BucketName);
+metadataManager.getLock().acquireVolumeLock(
 
 Review comment:
   If getting the volume lock fails, the finally block will still attempt to 
release it. Same with the S3 bucket lock.
   
   You will either need to use nested try-catch or a boolean flag per lock 
indicating it was successfully acquired.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in OzoneManager.

2019-06-20 Thread GitBox
arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in 
OzoneManager.
URL: https://github.com/apache/hadoop/pull/949#discussion_r295927322
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/volume/OMVolumeDeleteRequest.java
 ##
 @@ -104,37 +104,23 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager,
 
 OmVolumeArgs omVolumeArgs = null;
 String owner = null;
-
+IOException exception = null;
+OzoneManagerProtocolProtos.VolumeList newVolumeList = null;
 omMetadataManager.getLock().acquireVolumeLock(volume);
 try {
   owner = getVolumeInfo(omMetadataManager, volume).getOwnerName();
-} catch (IOException ex) {
-  LOG.error("Volume deletion failed for volume:{}", volume, ex);
-  omMetrics.incNumVolumeDeleteFails();
-  auditLog(auditLogger, buildAuditMessage(OMAction.DELETE_VOLUME,
-  buildVolumeAuditMap(volume), ex, userInfo));
-  return new OMVolumeDeleteResponse(null, null, null,
-  createErrorOMResponse(omResponse, ex));
-} finally {
-  omMetadataManager.getLock().releaseVolumeLock(volume);
-}
 
-// Release and reacquire lock for now it will not be a problem for now, as
-// applyTransaction serializes the operation's.
-// TODO: Revisit this logic once HDDS-1672 checks in.
+  // Release and reacquire lock for now it will not be a problem for now, 
as
+  // applyTransaction serializes the operation's.
 
-// We cannot acquire user lock holding volume lock, so released volume
-// lock, and acquiring user and volume lock.
+  // We cannot acquire user lock holding volume lock, so released volume
+  // lock, and acquiring user and volume lock.
 
-omMetadataManager.getLock().acquireUserLock(owner);
-omMetadataManager.getLock().acquireVolumeLock(volume);
+  omMetadataManager.getLock().acquireUserLock(owner);
 
 Review comment:
   If `acquireUserLock` throws an exception, we can try to release a lock in 
the finally block that we don't actually hold. You may need nested try catch 
here, or alternative a boolean flag that is set to true when the user lock is 
acquired.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in OzoneManager.

2019-06-20 Thread GitBox
arp7 commented on a change in pull request #949: HDDS-1672. Improve locking in 
OzoneManager.
URL: https://github.com/apache/hadoop/pull/949#discussion_r295938346
 
 

 ##
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
 ##
 @@ -2564,6 +2564,9 @@ public void createS3Bucket(String userName, String 
s3BucketName)
   }
   metrics.incNumBucketCreates();
   try {
+metadataManager.getLock().acquireS3BucketLock(s3BucketName);
+metadataManager.getLock().acquireVolumeLock(
 
 Review comment:
   Many of these bugs around proper releasing on failure have always been in 
the codebase. However this is a good time to fix them.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org