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

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/MobFileCleanerChore.java
 ##########
 @@ -0,0 +1,289 @@
+/**
+ * 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.master;
+
+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.mob.ExpiredMobFileCleaner;
+import org.apache.hadoop.hbase.mob.MobConstants;
+import org.apache.hadoop.hbase.mob.MobUtils;
+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.hadoop.hbase.util.HFileArchiveUtil;
+import 
org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class ExpiredMobFileCleanerChore for running cleaner regularly to 
remove the expired
+ * and obsolete (files which have no active references to) mob files.
+ */
[email protected]
+public class MobFileCleanerChore extends ScheduledChore {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(MobFileCleanerChore.class);
+  private final HMaster master;
+  private ExpiredMobFileCleaner cleaner;
+  private long minAgeToArchive;
+
+  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.master.mob.ttl.cleaner.period") != null) {
+      LOG.warn("'hbase.master.mob.ttl.cleaner.period' is obsolete and not used 
anymore.");
+    }
+    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() {
+    try {
+
+      TableDescriptors htds = master.getTableDescriptors();
+      Map<String, TableDescriptor> map = htds.getAll();
+      for (TableDescriptor htd : map.values()) {
+        for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) {
+          if (hcd.isMobEnabled() && hcd.getMinVersions() == 0) {
+            cleaner.cleanExpiredMobFiles(htd.getTableName().getNameAsString(), 
hcd);
+          }
+        }
+        // Now clean obsolete files for a table
+        LOG.info("Cleaning obsolete MOB files ...");
+        cleanupObsoleteMobFiles(master.getConfiguration(), htd.getTableName());
+        LOG.info("Cleaning obsolete MOB files finished");
+      }
+    } catch (Exception e) {
+      LOG.error("Fail to clean the expired mob files", e);
+    }
+  }
+  /**
+   * Performs housekeeping file cleaning (called by MOB Cleaner chore)
+   * @param conf configuration
+   * @param table table name
+   * @throws IOException
+   */
+  public void cleanupObsoleteMobFiles(Configuration conf, TableName table)
+      throws IOException {
+
+    this.minAgeToArchive = conf.getLong(MobConstants.MIN_AGE_TO_ARCHIVE_KEY,
+      MobConstants.DEFAULT_MIN_AGE_TO_ARCHIVE);
+    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;
+      }
+      // We check only those MOB files, which creation time is less
+      // than maxTimeToArchive. 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 less than {} will be 
archived",
+        maxCreationTimeToArchive);
+      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) {
 
 Review comment:
   Added the following code:
   while (!succeed) {
               if (!fs.exists(storePath)) {
                 LOG.warn("Directory {} was deleted during cleaner procedure 
execution," 
                     +" skipping.", storePath);
                 break;
               }
               RemoteIterator<LocatedFileStatus> rit = 
fs.listLocatedStatus(storePath);
               List<Path> storeFiles = new ArrayList<Path>();
   
   In the beginning of the loop I check if region directory exists, if doesn't  
- break out of loop
   If cf or table was deleted during run - we collect refs only partially and 
they will be preserved, but in any case, those files must be deleted by delete 
table/cf procedure
   
   Splits or merges are fine, because, at any given time, either daughter 
regions or parent regions are present physically in a file system and we need 
either of them to get full list of references
   
   If compaction happens and files get removed during cleaner run we will get 
FNFE and will resume this run from the beginning for a region. 

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


With regards,
Apache Git Services

Reply via email to