1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.master.cleaner;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.fs.FileStatus;
25 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
26 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
27
28
29
30
31
32 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
33 public class TimeToLiveHFileCleaner extends BaseHFileCleanerDelegate {
34
35 private static final Log LOG = LogFactory.getLog(TimeToLiveHFileCleaner.class.getName());
36 public static final String TTL_CONF_KEY = "hbase.master.hfilecleaner.ttl";
37
38 public static final long DEFAULT_TTL = 60000 * 5;
39
40 private long ttl;
41
42 @Override
43 public void setConf(Configuration conf) {
44 this.ttl = conf.getLong(TTL_CONF_KEY, DEFAULT_TTL);
45 super.setConf(conf);
46 }
47
48 @Override
49 public boolean isFileDeletable(FileStatus fStat) {
50 long currentTime = EnvironmentEdgeManager.currentTime();
51 long time = fStat.getModificationTime();
52 long life = currentTime - time;
53 if (LOG.isTraceEnabled()) {
54 LOG.trace("HFile life:" + life + ", ttl:" + ttl + ", current:" + currentTime + ", from: "
55 + time);
56 }
57 if (life < 0) {
58 LOG.warn("Found a hfile (" + fStat.getPath() + ") newer than current time (" + currentTime
59 + " < " + time + "), probably a clock skew");
60 return false;
61 }
62 return life > ttl;
63 }
64 }