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 java.io.IOException;
21
22 import org.apache.hadoop.fs.FileStatus;
23 import org.apache.hadoop.fs.Path;
24 import org.apache.hadoop.classification.InterfaceAudience;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29
30
31
32
33 @InterfaceAudience.Private
34 public class TimeToLiveLogCleaner extends BaseLogCleanerDelegate {
35 static final Log LOG = LogFactory.getLog(TimeToLiveLogCleaner.class.getName());
36
37 private long ttl;
38 private boolean stopped = false;
39
40 @Override
41 public boolean isLogDeletable(Path filePath) {
42 long time = 0;
43 long currentTime = System.currentTimeMillis();
44 try {
45 FileStatus fStat = filePath.getFileSystem(this.getConf()).getFileStatus(filePath);
46 time = fStat.getModificationTime();
47 } catch (IOException e) {
48 LOG.error("Unable to get modification time of file " + filePath.getName() +
49 ", not deleting it.", e);
50 return false;
51 }
52 long life = currentTime - time;
53 if (life < 0) {
54 LOG.warn("Found a log newer than current time, " +
55 "probably a clock skew");
56 return false;
57 }
58 return life > ttl;
59 }
60
61 @Override
62 public void setConf(Configuration conf) {
63 super.setConf(conf);
64 this.ttl = conf.getLong("hbase.master.logcleaner.ttl", 600000);
65 }
66
67
68 @Override
69 public void stop(String why) {
70 this.stopped = true;
71 }
72
73 @Override
74 public boolean isStopped() {
75 return this.stopped;
76 }
77 }