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