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.NavigableSet;
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.fs.FileStatus;
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.fs.FileUtil;
30 import org.apache.hadoop.fs.Path;
31 import org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher;
32 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
33 import org.apache.hadoop.hbase.regionserver.wal.HLogUtil;
34
35
36
37
38
39
40
41
42
43 @InterfaceAudience.Private
44 @InterfaceStability.Evolving
45 public class CopyRecoveredEditsTask extends SnapshotTask {
46
47 private static final Log LOG = LogFactory.getLog(CopyRecoveredEditsTask.class);
48 private final FileSystem fs;
49 private final Path regiondir;
50 private final Path outputDir;
51
52
53
54
55
56
57
58
59 public CopyRecoveredEditsTask(SnapshotDescription snapshot, ForeignExceptionDispatcher monitor,
60 FileSystem fs, Path regionDir, Path snapshotRegionDir) {
61 super(snapshot, monitor);
62 this.fs = fs;
63 this.regiondir = regionDir;
64 this.outputDir = HLogUtil.getRegionDirRecoveredEditsDir(snapshotRegionDir);
65 }
66
67 @Override
68 public Void call() throws IOException {
69 NavigableSet<Path> files = HLogUtil.getSplitEditFilesSorted(this.fs, regiondir);
70 if (files == null || files.size() == 0) return null;
71
72
73
74
75 for (Path source : files) {
76
77 FileStatus stat = fs.getFileStatus(source);
78 if (stat.getLen() <= 0) continue;
79
80
81 Path out = new Path(outputDir, source.getName());
82 LOG.debug("Copying " + source + " to " + out);
83 FileUtil.copy(fs, source, fs, out, true, fs.getConf());
84
85
86 this.rethrowException();
87 }
88 return null;
89 }
90 }