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