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 org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.fs.FileStatus;
25 import org.apache.hadoop.fs.FileSystem;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.classification.InterfaceAudience;
30 import org.apache.hadoop.hbase.io.HFileLink;
31 import org.apache.hadoop.hbase.mob.MobUtils;
32 import org.apache.hadoop.hbase.util.FSUtils;
33
34
35
36
37
38
39
40
41
42 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
43 public class HFileLinkCleaner extends BaseHFileCleanerDelegate {
44 private static final Log LOG = LogFactory.getLog(HFileLinkCleaner.class);
45
46 private FileSystem fs = null;
47
48 @Override
49 public synchronized boolean isFileDeletable(FileStatus fStat) {
50 if (this.fs == null) return false;
51 Path filePath = fStat.getPath();
52
53 if (HFileLink.isHFileLink(filePath)) return true;
54
55
56
57 Path parentDir = filePath.getParent();
58 if (HFileLink.isBackReferencesDir(parentDir)) {
59 Path hfilePath = null;
60 try {
61
62
63 hfilePath = HFileLink.getHFileFromBackReference(
64 new Path(FSUtils.getRootDir(getConf()), HConstants.HBASE_TEMP_DIRECTORY), filePath);
65 if (fs.exists(hfilePath)) {
66 return false;
67 }
68
69 hfilePath = HFileLink.getHFileFromBackReference(MobUtils.getMobHome(getConf()), filePath);
70 if (fs.exists(hfilePath)) {
71 return false;
72 }
73 hfilePath = HFileLink.getHFileFromBackReference(FSUtils.getRootDir(getConf()), filePath);
74 return !fs.exists(hfilePath);
75 } catch (IOException e) {
76 if (LOG.isDebugEnabled()) {
77 LOG.debug("Couldn't verify if the referenced file still exists, keep it just in case: "
78 + hfilePath);
79 }
80 return false;
81 }
82 }
83
84
85 Path backRefDir = null;
86 try {
87 backRefDir = HFileLink.getBackReferencesDir(parentDir, filePath.getName());
88 return FSUtils.listStatus(fs, backRefDir) == null;
89 } catch (IOException e) {
90 if (LOG.isDebugEnabled()) {
91 LOG.debug("Couldn't get the references, not deleting file, just in case. filePath="
92 + filePath + ", backRefDir=" + backRefDir);
93 }
94 return false;
95 }
96 }
97
98 @Override
99 public void setConf(Configuration conf) {
100 super.setConf(conf);
101
102
103 try {
104 this.fs = FileSystem.get(this.getConf());
105 } catch (IOException e) {
106 if (LOG.isDebugEnabled()) {
107 LOG.debug("Couldn't instantiate the file system, not deleting file, just in case. "
108 + FileSystem.FS_DEFAULT_NAME_KEY + "="
109 + getConf().get(FileSystem.FS_DEFAULT_NAME_KEY, FileSystem.DEFAULT_FS));
110 }
111 }
112 }
113 }