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 TimeToLiveLogCleaner extends BaseLogCleanerDelegate {
34 static final Log LOG = LogFactory.getLog(TimeToLiveLogCleaner.class.getName());
35
36 private long ttl;
37 private boolean stopped = false;
38
39 @Override
40 public boolean isLogDeletable(FileStatus fStat) {
41 long currentTime = EnvironmentEdgeManager.currentTime();
42 long time = fStat.getModificationTime();
43 long life = currentTime - time;
44
45 if (LOG.isTraceEnabled()) {
46 LOG.trace("Log life:" + life + ", ttl:" + ttl + ", current:" + currentTime + ", from: "
47 + time);
48 }
49 if (life < 0) {
50 LOG.warn("Found a log (" + fStat.getPath() + ") newer than current time (" + currentTime
51 + " < " + time + "), probably a clock skew");
52 return false;
53 }
54 return life > ttl;
55 }
56
57 @Override
58 public void setConf(Configuration conf) {
59 super.setConf(conf);
60 this.ttl = conf.getLong("hbase.master.logcleaner.ttl", 600000);
61 }
62
63
64 @Override
65 public void stop(String why) {
66 this.stopped = true;
67 }
68
69 @Override
70 public boolean isStopped() {
71 return this.stopped;
72 }
73 }