bharatviswa504 commented on a change in pull request #450: HDDS-2893. Handle 
replay of KeyPurge Request.
URL: https://github.com/apache/hadoop-ozone/pull/450#discussion_r372141435
 
 

 ##########
 File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyPurgeRequest.java
 ##########
 @@ -49,25 +57,76 @@ public OMKeyPurgeRequest(OMRequest omRequest) {
   public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager,
       long transactionLogIndex,
       OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
-    PurgeKeysRequest purgeKeysRequest = getOmRequest().getPurgeKeysRequest();
-    List<String> purgeKeysList = purgeKeysRequest.getKeysList();
 
-    LOG.debug("Processing Purge Keys for {} number of keys.",
-        purgeKeysList.size());
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+
+    PurgeKeysRequest purgeKeysRequest = getOmRequest().getPurgeKeysRequest();
+    List<DeletedKeys> bucketDeletedKeysList = purgeKeysRequest
+        .getDeletedKeysList();
+    List<String> keysToBePurgedList = new ArrayList<>();
 
-    OMResponse omResponse = OMResponse.newBuilder()
+    OMResponse.Builder omResponse = OMResponse.newBuilder()
         .setCmdType(Type.PurgeKeys)
-        .setPurgeKeysResponse(
-            OzoneManagerProtocolProtos.PurgeKeysResponse.newBuilder().build())
+        .setPurgeKeysResponse(PurgeKeysResponse.newBuilder().build())
         .setStatus(Status.OK)
-        .setSuccess(true)
-        .build();
+        .setSuccess(true);
+    OMClientResponse omClientResponse = null;
+    boolean success = true;
+    IOException exception = null;
+
+    // Filter the keys that objectID > transactionLogIndex. This is done so
+    // that in case this transaction is a replay, we do not purge keys
+    // created after the original purge request.
+    // PurgeKeys request has keys belonging to same bucket grouped together.
+    // We get each bucket lock and check the above condition.
+    for (DeletedKeys bucketWithDeleteKeys : bucketDeletedKeysList) {
+      boolean acquiredLock = false;
+      String volumeName = bucketWithDeleteKeys.getVolumeName();
+      String bucketName = bucketWithDeleteKeys.getBucketName();
+      try {
+        acquiredLock = 
omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+            volumeName, bucketName);
+        for (String deletedKey : bucketWithDeleteKeys.getKeysList()) {
+          RepeatedOmKeyInfo repeatedOmKeyInfo =
+              omMetadataManager.getDeletedTable().get(deletedKey);
+          boolean purgeKey = true;
+          if (repeatedOmKeyInfo != null) {
+            for (OmKeyInfo omKeyInfo : repeatedOmKeyInfo.getOmKeyInfoList()) {
+              // Discard those keys whose updateID is > transactionLogIndex.
+              // This could happen when the PurgeRequest is replayed.
+              if (isReplay(ozoneManager, omKeyInfo.getUpdateID(),
+                  transactionLogIndex)) {
+                purgeKey = false;
+                break;
+              }
+            }
+            if (purgeKey) {
+              keysToBePurgedList.add(deletedKey);
+            }
+          }
+        }
+      } catch (IOException ex) {
+        success = false;
+        exception = ex;
+        break;
+      } finally {
+        if (acquiredLock) {
+          omMetadataManager.getLock().releaseWriteLock(BUCKET_LOCK, volumeName,
+              bucketName);
 
 Review comment:
   Can we add some logging for replay case and normal logging also which will 
help in debugging

----------------------------------------------------------------
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: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to