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