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


##########
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:
   I think metrics is already included in OMOpenKeysDeleteRequest.
   
   
https://github.com/apache/ozone/blob/377be9644fb2e7a1b6b6413a82ac15e3dc4c48d3/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMOpenKeysDeleteRequest.java#L67
   
   
https://github.com/apache/ozone/blob/377be9644fb2e7a1b6b6413a82ac15e3dc4c48d3/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMOpenKeysDeleteRequest.java#L81
   
   
https://github.com/apache/ozone/blob/377be9644fb2e7a1b6b6413a82ac15e3dc4c48d3/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMOpenKeysDeleteRequest.java#L130
   
   
https://github.com/apache/ozone/blob/377be9644fb2e7a1b6b6413a82ac15e3dc4c48d3/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMOpenKeysDeleteRequest.java#L171



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to