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/20 17:33:57 UTC

[GitHub] [hadoop-ozone] mukul1987 commented on a change in pull request #1507: HDDS-4307.Start Background Service for Trash Deletion in Ozone Manager

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



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

Review comment:
       The indentation is at 4, it should be at 2.

##########
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();
+    }
+
+
+    @Override
+    public BackgroundTaskQueue getTasks() {
+        BackgroundTaskQueue queue = new BackgroundTaskQueue();
+        String rootPath = String.format("%s://%s/",
+                OzoneConsts.OZONE_OFS_URI_SCHEME, ozoneManager.getConfiguration().get(OZONE_OM_ADDRESS_KEY));
+        // Configuration object where the rootpath is set to an OFS Uri.
+        fsConf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, rootPath);
+        FileSystem fs = null;
+        try {
+            fs = SecurityUtil.doAsLoginUser(
+                    new PrivilegedExceptionAction<FileSystem>() {
+                        @Override
+                        public FileSystem run() throws IOException {
+                            return FileSystem.get(fsConf);
+                        }
+                    });
+        } catch (IOException e) {
+            LOG.error("Cannot instantiate filesystem instance");
+        }
+        queue.add(new TrashDeletingTask(fs,fsConf));
+        return queue;
+    }
+
+    /**
+     * This task creates an emptier thread that deletes all keys obtained from the trashRoots (fs.getTrashRoots)
+     */
+    private class TrashDeletingTask implements BackgroundTask {
+
+        FileSystem fs;
+        Configuration conf;
+
+        public TrashDeletingTask(FileSystem fs, Configuration conf) {
+            this.fs = fs;
+            this.conf = conf;
+        }
+
+        @Override
+        public BackgroundTaskResult call() throws Exception {
+            Thread emptier = new Thread(new Trash(fs,conf).getEmptier(),"Trash Emptier");

Review comment:
       This will start 1 thread for the entire filesystem for every run? why do we need this a background service ?




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