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 org.apache.hadoop.fs.Path;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27
28
29
30
31 public class TimeToLiveLogCleaner implements LogCleanerDelegate {
32
33 static final Log LOG =
34 LogFactory.getLog(TimeToLiveLogCleaner.class.getName());
35 private Configuration conf;
36
37 private long ttl;
38
39 @Override
40 public boolean isLogDeletable(Path filePath) {
41 long time = 0;
42 long currentTime = System.currentTimeMillis();
43 String[] parts = filePath.getName().split("\\.");
44 try {
45 time = Long.parseLong(parts[parts.length-1]);
46 } catch (NumberFormatException e) {
47 LOG.error("Unable to parse the timestamp in " + filePath.getName() +
48 ", deleting it since it's invalid and may not be a hlog", e);
49 return true;
50 }
51 long life = currentTime - time;
52 if (life < 0) {
53 LOG.warn("Found a log newer than current time, " +
54 "probably a clock skew");
55 return false;
56 }
57 return life > ttl;
58 }
59
60 @Override
61 public void setConf(Configuration conf) {
62 this.conf = conf;
63 this.ttl = conf.getLong("hbase.master.logcleaner.ttl", 600000);
64 }
65
66 @Override
67 public Configuration getConf() {
68 return conf;
69 }
70 }