You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2020/10/28 02:22:52 UTC

[GitHub] [ozone] captainzmc commented on a change in pull request #1489: HDDS-4308. Fix issue with quota update

captainzmc commented on a change in pull request #1489:
URL: https://github.com/apache/ozone/pull/1489#discussion_r513140628



##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyRequest.java
##########
@@ -597,27 +596,40 @@ protected boolean checkDirectoryAlreadyExists(String volumeName,
   }
 
   /**
-   * Return volume info for the specified volume. If the volume does not
-   * exist, returns {@code null}.
+   * Return volume info that updated usageBytes for the specified volume.
    * @param omMetadataManager
    * @param volume
+   * @param updateUsage
    * @return OmVolumeArgs
    * @throws IOException
    */
-  protected OmVolumeArgs getVolumeInfo(OMMetadataManager omMetadataManager,
-      String volume) {
-
-    OmVolumeArgs volumeArgs = null;
-
-    CacheValue<OmVolumeArgs> value =
-        omMetadataManager.getVolumeTable().getCacheValue(
-        new CacheKey<>(omMetadataManager.getVolumeKey(volume)));
-
-    if (value != null) {
-      volumeArgs = value.getCacheValue();
-    }
+  protected static synchronized OmVolumeArgs syncUpdateUsage(
+      OMMetadataManager omMetadataManager, String volume, long updateUsage) {
+    OmVolumeArgs volumeArgs = omMetadataManager.getVolumeTable().getCacheValue(
+        new CacheKey<>(omMetadataManager.getVolumeKey(volume)))
+        .getCacheValue();
+    volumeArgs.getUsedBytes().add(updateUsage);
+    return volumeArgs.copyObject();
+  }
 
-    return volumeArgs;
+  /**
+   * Return volume info that updated usageBytes for the specified volume. And
+   * check Volume usageBytes quota.
+   * @param omMetadataManager
+   * @param volume
+   * @param updateUsage
+   * @return OmVolumeArgs
+   * @throws IOException
+   */
+  protected static synchronized OmVolumeArgs syncCheckAndUpdateUsage(

Review comment:
       Thanks for @linyiqun's review.
   Modifying getVolumeInfo to synchronized and get copyObject would not suffice. There is only one instance of volumeArgs in memory, and we need to update volumeArgs atomic after getVolumeInfo. Then get the value of the copyObject.
   So, I made a modification based on your suggestion, added update volumeArgs's usedBytes to the getVolumeInfo method.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org