1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.snapshot;
19
20 import java.io.IOException;
21 import java.util.Arrays;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.classification.InterfaceAudience;
26 import org.apache.hadoop.classification.InterfaceStability;
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 import org.apache.hadoop.hbase.errorhandling.ForeignException;
32 import org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher;
33 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
34 import org.apache.hadoop.hbase.util.FSUtils;
35
36
37
38
39 @InterfaceAudience.Private
40 @InterfaceStability.Evolving
41 public class ReferenceServerWALsTask extends SnapshotTask {
42 private static final Log LOG = LogFactory.getLog(ReferenceServerWALsTask.class);
43 private final FileSystem fs;
44 private final Configuration conf;
45 private final String serverName;
46 private Path logDir;
47
48
49
50
51
52
53
54
55
56
57 public ReferenceServerWALsTask(SnapshotDescription snapshot,
58 ForeignExceptionDispatcher failureListener, final Path logDir, final Configuration conf,
59 final FileSystem fs) {
60 super(snapshot, failureListener);
61 this.fs = fs;
62 this.conf = conf;
63 this.serverName = logDir.getName();
64 this.logDir = logDir;
65 }
66
67
68
69
70
71
72 @Override
73 public Void call() throws IOException, ForeignException {
74
75
76
77
78 FileStatus[] serverLogs = FSUtils.listStatus(fs, logDir, null);
79 if (serverLogs == null) {
80 LOG.debug("No logs for server directory:" + logDir + ", done referencing files.");
81 return null;
82 }
83
84 if (LOG.isDebugEnabled()) {
85 LOG.debug("Adding references for WAL files:" + Arrays.toString(serverLogs));
86 }
87
88 for (FileStatus file : serverLogs) {
89 this.rethrowException();
90
91
92 Path rootDir = FSUtils.getRootDir(conf);
93 Path snapshotDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(this.snapshot, rootDir);
94 Path snapshotLogDir = TakeSnapshotUtils.getSnapshotHLogsDir(snapshotDir, serverName);
95
96 Path ref = new Path(snapshotLogDir, file.getPath().getName());
97 if (!fs.createNewFile(ref)) {
98 if (!fs.exists(ref)) {
99 throw new IOException("Couldn't create reference for:" + file.getPath());
100 }
101 }
102 LOG.debug("Completed WAL referencing for: " + file.getPath() + " to " + ref);
103 }
104
105 LOG.debug("Successfully completed WAL referencing for ALL files");
106 return null;
107 }
108 }