VladRodionov commented on a change in pull request #921: HBASE-22749: 
Distributed MOB compactions
URL: https://github.com/apache/hbase/pull/921#discussion_r379072432
 
 

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/mob/MobFileCleanerChore.java
 ##########
 @@ -0,0 +1,310 @@
+/**
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.hbase.mob;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.LocatedFileStatus;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.RemoteIterator;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.TableDescriptors;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.backup.HFileArchiver;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.io.hfile.CacheConfig;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.apache.hadoop.hbase.regionserver.BloomType;
+import org.apache.hadoop.hbase.regionserver.HStoreFile;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.hbase.util.FSUtils;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import 
org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
+
+/**
+ * The class MobFileCleanerChore for running cleaner regularly to remove the 
expired
+ * and obsolete (files which have no active references to) mob files.
+ */
+@SuppressWarnings("deprecation")
+@InterfaceAudience.Private
+public class MobFileCleanerChore extends ScheduledChore {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(MobFileCleanerChore.class);
+  private final HMaster master;
+  private ExpiredMobFileCleaner cleaner;
+  
+  static {
+    Configuration.addDeprecation(MobConstants.DEPRECATED_MOB_CLEANER_PERIOD, 
+      MobConstants.MOB_CLEANER_PERIOD);
+  }
+
+  public MobFileCleanerChore(HMaster master) {
+    super(master.getServerName() + "-ExpiredMobFileCleanerChore", master,
+        master.getConfiguration().getInt(MobConstants.MOB_CLEANER_PERIOD,
+          MobConstants.DEFAULT_MOB_CLEANER_PERIOD),
+        master.getConfiguration().getInt(MobConstants.MOB_CLEANER_PERIOD,
+          MobConstants.DEFAULT_MOB_CLEANER_PERIOD),
+        TimeUnit.SECONDS);
+    this.master = master;
+    cleaner = new ExpiredMobFileCleaner();
+    cleaner.setConf(master.getConfiguration());
+    checkObsoleteConfigurations();
+  }
+
+  private void checkObsoleteConfigurations() {
+    Configuration conf = master.getConfiguration();
+
+    if (conf.get("hbase.mob.compaction.mergeable.threshold") != null) {
+      LOG.warn("'hbase.mob.compaction.mergeable.threshold' is obsolete and not 
used anymore.");
+    }
+    if (conf.get("hbase.mob.delfile.max.count") != null) {
+      LOG.warn("'hbase.mob.delfile.max.count' is obsolete and not used 
anymore.");
+    }
+    if (conf.get("hbase.mob.compaction.threads.max") != null) {
+      LOG.warn("'hbase.mob.compaction.threads.max' is obsolete and not used 
anymore.");
+    }
+    if (conf.get("hbase.mob.compaction.batch.size") != null) {
+      LOG.warn("'hbase.mob.compaction.batch.size' is obsolete and not used 
anymore.");
+    }
+  }
+
+  @VisibleForTesting
+  public MobFileCleanerChore() {
+    this.master = null;
+  }
+
+  @Override
+  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = 
"REC_CATCH_EXCEPTION",
+      justification = "Intentional")
+
+  protected void chore() {
+    TableDescriptors htds = master.getTableDescriptors();
+
+    Map<String, TableDescriptor> map = null;
+    try {
+      map = htds.getAll();
+    } catch (IOException e) {
+      LOG.error("MobFileCleanerChore failed", e);
+      return;
+    }
+    for (TableDescriptor htd : map.values()) {
+      for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) {
+        if (hcd.isMobEnabled() && hcd.getMinVersions() == 0) {
+          try {
+            cleaner.cleanExpiredMobFiles(htd.getTableName().getNameAsString(), 
hcd);
+          } catch (IOException e) {
+            LOG.error("Failed to clean the expired mob files table=" + 
htd.getTableName()
+                + " family=" + hcd.getNameAsString(), e);
+          }
+        }
+      }
+      try {
+        // Now clean obsolete files for a table
+        LOG.info("Cleaning obsolete MOB files from table={}", 
htd.getTableName());
+        cleanupObsoleteMobFiles(master.getConfiguration(), htd.getTableName());
+        LOG.info("Cleaning obsolete MOB files finished for table={}", 
htd.getTableName());
+      } catch (IOException e) {
+        LOG.error("Failed to clean the obsolete mob files for table=" + 
htd.getTableName(), e);
+      }
+    }
+  }
+
+  /**
+   * Performs housekeeping file cleaning (called by MOB Cleaner chore)
+   * @param conf configuration
+   * @param table table name
+   * @throws IOException exception
+   */
+  public void cleanupObsoleteMobFiles(Configuration conf, TableName table) 
throws IOException {
+
+    long minAgeToArchive =
+        conf.getLong(MobConstants.MIN_AGE_TO_ARCHIVE_KEY, 
MobConstants.DEFAULT_MIN_AGE_TO_ARCHIVE);
+    // We check only those MOB files, which creation time is less
+    // than maxCreationTimeToArchive. This is a current time - 1h. 1 hour gap
+    // gives us full confidence that all corresponding store files will
+    // exist at the time cleaning procedure begins and will be examined.
+    // So, if MOB file creation time is greater than this maxTimeToArchive,
+    // this will be skipped and won't be archived.
+    long maxCreationTimeToArchive = EnvironmentEdgeManager.currentTime() - 
minAgeToArchive;
+    LOG.info("Only MOB files whose creation time older than {} will be 
archived",
+      maxCreationTimeToArchive);
+    try (final Connection conn = ConnectionFactory.createConnection(conf);
+        final Admin admin = conn.getAdmin();) {
+      TableDescriptor htd = admin.getDescriptor(table);
+      List<ColumnFamilyDescriptor> list = MobUtils.getMobColumnFamilies(htd);
+      if (list.size() == 0) {
+        LOG.info("Skipping non-MOB table [{}]", table);
+        return;
+      }
+
+      Path rootDir = FSUtils.getRootDir(conf);
+      Path tableDir = FSUtils.getTableDir(rootDir, table);
+      // How safe is this call?
+      List<Path> regionDirs = FSUtils.getRegionDirs(FileSystem.get(conf), 
tableDir);
+
+      Set<String> allActiveMobFileName = new HashSet<String>();
+      FileSystem fs = FileSystem.get(conf);
+      for (Path regionPath : regionDirs) {
+        for (ColumnFamilyDescriptor hcd : list) {
+          String family = hcd.getNameAsString();
+          Path storePath = new Path(regionPath, family);
+          boolean succeed = false;
+          Set<String> regionMobs = new HashSet<String>();
+          while (!succeed) {
+            if (!fs.exists(storePath)) {
 
 Review comment:
   As far as I remember we disable Mob cleaner chore until migration is 
complete?

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

Reply via email to