rakeshadr commented on a change in pull request #1507:
URL: https://github.com/apache/hadoop-ozone/pull/1507#discussion_r509870311



##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
##########
@@ -1228,17 +1236,34 @@ public void restart() throws IOException {
       // Allow OM to start as Http Server failure is not fatal.
       LOG.error("OM HttpServer failed to start.", ex);
     }
-
     omRpcServer.start();
+
     isOmRpcServerRunning = true;
 
+    startTrashDeletingService();
+
     registerMXBean();
 
     startJVMPauseMonitor();
     setStartTime();
     omState = State.RUNNING;
   }
 
+  private void startTrashDeletingService() {
+    if (trashDeletingService == null) {
+      long serviceTimeout = configuration.getTimeDuration(
+              OZONE_TRASH_DELETING_SERVICE_TIMEOUT,
+              OZONE_TRASH_DELETING_SERVICE_TIMEOUT_DEFAULT,
+              TimeUnit.MILLISECONDS);
+      long trashDeletionInterval = configuration.getTimeDuration(
+              OZONE_TRASH_DELETING_SERVICE_INTERVAL,
+              OZONE_TRASH_DELETING_SERVICE_INTERVAL_DEFAULT,
+              TimeUnit.MILLISECONDS);
+      trashDeletingService = new TrashDeletingService(trashDeletionInterval, 
serviceTimeout, this);
+      trashDeletingService.start();

Review comment:
       Please shutdown the `trashDeletingService` during OM stop.

##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java
##########
@@ -1170,4 +1172,50 @@ public void testFileDelete() throws Exception {
     Boolean falseResult = fs.delete(parent, true);
     assertFalse(falseResult);
   }
+
+  /**
+   * @throws Exception
+   * 1.Move a Key to Trash
+   * 2.Start TrashDeletingService
+   * 3.Verify that the TrashDeletingService purges the key after minimum set 
TrashInterval of 1 min.
+   */
+  @Test
+  public void testTrashDeletingService() throws Exception {
+    String testKeyName = "keyToBeDeleted";
+    Path path = new Path(bucketPath, testKeyName);
+    try (FSDataOutputStream stream = fs.create(path)) {
+      stream.write(1);
+    }
+    // Call moveToTrash. We can't call protected fs.rename() directly
+    trash.moveToTrash(path);
+    TrashDeletingService trashDeletingService = new
+            TrashDeletingService(60,300,cluster.getOzoneManager());
+    conf.setLong(FS_TRASH_INTERVAL_KEY,1);
+    trashDeletingService.setFsConf(conf);
+    trashDeletingService.start();
+
+
+    // Construct paths
+    String username = UserGroupInformation.getCurrentUser().getShortUserName();
+    Path trashRoot = new Path(bucketPath, TRASH_PREFIX);
+    Path userTrash = new Path(trashRoot, username);
+    Path userTrashCurrent = new Path(userTrash, "Current");
+    String key = path.toString().substring(1);
+    Path trashPath = new Path(userTrashCurrent, key);
+
+    // Wait until the TrashDeletingService purges the key
+    GenericTestUtils.waitFor(()-> {
+      try {
+        return !ofs.exists(trashPath);
+      } catch (IOException e) {
+        LOG.error("Delete from Trash Failed");
+        Assert.fail();

Review comment:
       Please add failure message -> Assert.fail("Delete from Trash Failed");

##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/TrashDeletingService.java
##########
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Trash;
+import org.apache.hadoop.hdds.utils.BackgroundService;
+import org.apache.hadoop.hdds.utils.BackgroundTask;
+import org.apache.hadoop.hdds.utils.BackgroundTaskQueue;
+import org.apache.hadoop.hdds.utils.BackgroundTaskResult;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.security.SecurityUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
+
+/**
+ * Background Service to empty keys that are moved to Trash.
+ */
+public class TrashDeletingService extends BackgroundService {
+
+    private static final Logger LOG =
+            LoggerFactory.getLogger(TrashDeletingService.class);
+
+    // Use single thread for  now
+    private final static int KEY_DELETING_CORE_POOL_SIZE = 1;
+
+    private OzoneManager ozoneManager;
+
+    public void setFsConf(Configuration fsConf) {
+        this.fsConf = fsConf;
+    }
+
+    private Configuration fsConf;
+
+    public TrashDeletingService(long interval, long 
serviceTimeout,OzoneManager ozoneManager) {
+        super("TrashDeletingService", interval, TimeUnit.MILLISECONDS, 
KEY_DELETING_CORE_POOL_SIZE, serviceTimeout);
+        this.ozoneManager = ozoneManager;
+        fsConf = new Configuration();

Review comment:
       Please do `ozoneManager.getConfiguration()` instead of loading `new 
Configuration()` here.




----------------------------------------------------------------
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



---------------------------------------------------------------------
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