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