1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.master;
20
21 import java.util.Map;
22 import java.util.concurrent.ExecutorService;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.classification.InterfaceAudience;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.hbase.ScheduledChore;
30 import org.apache.hadoop.hbase.HColumnDescriptor;
31 import org.apache.hadoop.hbase.HTableDescriptor;
32 import org.apache.hadoop.hbase.TableDescriptors;
33 import org.apache.hadoop.hbase.mob.MobConstants;
34 import org.apache.hadoop.hbase.mob.MobUtils;
35
36
37
38
39 @InterfaceAudience.Private
40 public class MobFileCompactionChore extends ScheduledChore {
41
42 private static final Log LOG = LogFactory.getLog(MobFileCompactionChore.class);
43 private HMaster master;
44 private TableLockManager tableLockManager;
45 private ExecutorService pool;
46
47 public MobFileCompactionChore(HMaster master) {
48 super(master.getServerName() + "-MobFileCompactChore", master,
49 master.getConfiguration().getInt(
50 MobConstants.MOB_FILE_COMPACTION_CHORE_PERIOD,
51 MobConstants.DEFAULT_MOB_FILE_COMPACTION_CHORE_PERIOD));
52 this.master = master;
53 this.tableLockManager = master.getTableLockManager();
54 this.pool = MobUtils.createMobFileCompactorThreadPool(master.getConfiguration());
55 }
56
57 @Override
58 protected void chore() {
59 try {
60 TableDescriptors htds = master.getTableDescriptors();
61 Map<String, HTableDescriptor> map = htds.getAll();
62 for (HTableDescriptor htd : map.values()) {
63 if (!master.getConnection().isTableEnabled(htd.getTableName())) {
64 continue;
65 }
66 boolean reported = false;
67 try {
68 for (HColumnDescriptor hcd : htd.getColumnFamilies()) {
69 if (!hcd.isMobEnabled()) {
70 continue;
71 }
72 if (!reported) {
73 master.reportMobFileCompactionStart(htd.getTableName());
74 reported = true;
75 }
76 MobUtils.doMobFileCompaction(master.getConfiguration(), master.getFileSystem(),
77 htd.getTableName(), hcd, pool, tableLockManager, false);
78 }
79 } finally {
80 if (reported) {
81 master.reportMobFileCompactionEnd(htd.getTableName());
82 }
83 }
84 }
85 } catch (Exception e) {
86 LOG.error("Fail to clean the expired mob files", e);
87 }
88 }
89
90 @Override
91 protected void cleanup() {
92 super.cleanup();
93 pool.shutdown();
94 }
95 }