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 import java.util.LinkedList;
22 import java.util.List;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.classification.InterfaceAudience;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.FileStatus;
29 import org.apache.hadoop.fs.FileSystem;
30 import org.apache.hadoop.fs.Path;
31
32 import org.apache.hadoop.hbase.io.HFileLink;
33 import org.apache.hadoop.hbase.util.FSUtils;
34 import org.apache.hadoop.hbase.util.HFileArchiveUtil;
35 import org.apache.hadoop.hbase.master.cleaner.BaseHFileCleanerDelegate;
36
37
38
39
40
41
42
43
44
45 @InterfaceAudience.Private
46 public class HFileLinkCleaner extends BaseHFileCleanerDelegate {
47 private static final Log LOG = LogFactory.getLog(HFileLinkCleaner.class);
48
49 private FileSystem fs = null;
50
51 @Override
52 public synchronized boolean isFileDeletable(FileStatus fStat) {
53 if (this.fs == null) return false;
54 Path filePath = fStat.getPath();
55
56 if (HFileLink.isHFileLink(filePath)) return true;
57
58
59
60 Path parentDir = filePath.getParent();
61 if (HFileLink.isBackReferencesDir(parentDir)) {
62 try {
63 Path hfilePath = HFileLink.getHFileFromBackReference(getConf(), filePath);
64 return !fs.exists(hfilePath);
65 } catch (IOException e) {
66 LOG.error("Couldn't verify if the referenced file still exists, keep it just in case");
67 return false;
68 }
69 }
70
71
72 try {
73 Path backRefDir = HFileLink.getBackReferencesDir(parentDir, filePath.getName());
74 return FSUtils.listStatus(fs, backRefDir) == null;
75 } catch (IOException e) {
76 LOG.error("Couldn't get the references, not deleting file, just in case");
77 return false;
78 }
79 }
80
81 @Override
82 public void setConf(Configuration conf) {
83 super.setConf(conf);
84
85
86 try {
87 this.fs = FileSystem.get(this.getConf());
88 } catch (IOException e) {
89 LOG.error("Couldn't instantiate the file system, not deleting file, just in case");
90 }
91 }
92 }