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 2022/06/07 11:27:55 UTC

[GitHub] [ozone] captainzmc commented on a diff in pull request #3319: HDDS-4123. Integrate OM Open Key Cleanup Service Into Existing Code

captainzmc commented on code in PR #3319:
URL: https://github.com/apache/ozone/pull/3319#discussion_r891089996


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSecureOzoneManager.java:
##########
@@ -85,8 +83,6 @@ public void init() throws Exception {
     omId = UUID.randomUUID().toString();
     conf.setBoolean(OZONE_ACL_ENABLED, true);
     conf.setBoolean(OZONE_SECURITY_ENABLED_KEY, true);
-    conf.setTimeDuration(OZONE_OM_OPEN_KEY_EXPIRE_THRESHOLD,
-        2, TimeUnit.SECONDS);

Review Comment:
   Does the OpenKey Clean Update Service cause this CI to fail?



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OpenKeyCleanupService.java:
##########
@@ -73,18 +165,72 @@ public int getPriority() {
 
     @Override
     public BackgroundTaskResult call() throws Exception {
-      // This method is currently never used. It will be implemented in
-      // HDDS-4122, and integrated into the rest of the code base in HDDS-4123.
+      if (!shouldRun()) {
+        return BackgroundTaskResult.EmptyTaskResult.newResult();
+      }
+
+      runCount.incrementAndGet();
+      long startTime = Time.monotonicNow();
+      List<OpenKeyBucket> openKeyBuckets = null;
       try {
-        // The new API for deleting expired open keys in OM HA will differ
-        // significantly from the old implementation.
-        // The old implementation has been removed so the code compiles.
-        keyManager.getExpiredOpenKeys(Duration.ZERO, 0, BucketLayout.DEFAULT);
+        openKeyBuckets = keyManager.getExpiredOpenKeys(expireThreshold,
+            cleanupLimitPerTask, bucketLayout);
       } catch (IOException e) {
-        LOG.error("Unable to get hanging open keys, retry in"
-            + " next interval", e);
+        LOG.error("Unable to get hanging open keys, retry in next interval", e);
+      }
+
+      if (openKeyBuckets != null && !openKeyBuckets.isEmpty()) {
+        int numOpenKeys = openKeyBuckets.stream()
+            .mapToInt(OpenKeyBucket::getKeysCount).sum();
+
+        OMRequest omRequest = createRequest(openKeyBuckets);
+        submitRequest(omRequest);
+
+        LOG.debug("Number of expired keys submitted for deletion: {}, elapsed"
+            + " time: {}ms", numOpenKeys, Time.monotonicNow() - startTime);
+        submittedOpenKeyCount.addAndGet(numOpenKeys);
       }
       return BackgroundTaskResult.EmptyTaskResult.newResult();
     }
+
+    private OMRequest createRequest(List<OpenKeyBucket> openKeyBuckets) {
+      DeleteOpenKeysRequest request =
+          DeleteOpenKeysRequest.newBuilder()
+              .addAllOpenKeysPerBucket(openKeyBuckets)
+              .setBucketLayout(bucketLayout.toProto())
+              .build();
+
+      OMRequest omRequest = OMRequest.newBuilder()
+          .setCmdType(Type.DeleteOpenKeys)
+          .setDeleteOpenKeysRequest(request)
+          .setClientId(clientId.toString())
+          .build();
+
+      return omRequest;
+    }
+
+    private void submitRequest(OMRequest omRequest) {
+      try {
+        if (isRatisEnabled()) {
+          OzoneManagerRatisServer server = ozoneManager.getOmRatisServer();
+
+          RaftClientRequest raftClientRequest = RaftClientRequest.newBuilder()
+              .setClientId(clientId)
+              .setServerId(server.getRaftPeerId())
+              .setGroupId(server.getRaftGroupId())
+              .setCallId(runCount.get())
+              .setMessage(Message.valueOf(
+                  OMRatisHelper.convertRequestToByteString(omRequest)))
+              .setType(RaftClientRequest.writeRequestType())
+              .build();
+
+          server.submitRequest(omRequest, raftClientRequest);

Review Comment:
   After successful deletion.  Can we add some metrics to show how many open keys has been deleted? This should be helpful in production.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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