1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.master.snapshot;
19
20 import java.io.IOException;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.classification.InterfaceAudience;
28 import org.apache.hadoop.classification.InterfaceStability;
29 import org.apache.hadoop.fs.Path;
30 import org.apache.hadoop.hbase.HRegionInfo;
31 import org.apache.hadoop.hbase.ServerName;
32 import org.apache.hadoop.hbase.errorhandling.ForeignException;
33 import org.apache.hadoop.hbase.errorhandling.TimeoutExceptionInjector;
34 import org.apache.hadoop.hbase.master.MasterServices;
35 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
36 import org.apache.hadoop.hbase.regionserver.HRegion;
37 import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
38 import org.apache.hadoop.hbase.snapshot.TableInfoCopyTask;
39 import org.apache.hadoop.hbase.snapshot.TakeSnapshotUtils;
40 import org.apache.hadoop.hbase.util.FSUtils;
41 import org.apache.hadoop.hbase.util.Pair;
42 import org.apache.zookeeper.KeeperException;
43
44
45
46
47
48
49 @InterfaceAudience.Private
50 @InterfaceStability.Evolving
51 public class DisabledTableSnapshotHandler extends TakeSnapshotHandler {
52 private static final Log LOG = LogFactory.getLog(DisabledTableSnapshotHandler.class);
53 private final TimeoutExceptionInjector timeoutInjector;
54
55
56
57
58
59
60 public DisabledTableSnapshotHandler(SnapshotDescription snapshot,
61 final MasterServices masterServices) throws IOException {
62 super(snapshot, masterServices);
63
64
65 timeoutInjector = TakeSnapshotUtils.getMasterTimerAndBindToMonitor(snapshot, conf, monitor);
66 }
67
68
69
70 @Override
71 public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocations) throws IOException,
72 KeeperException {
73 try {
74 timeoutInjector.start();
75
76
77
78
79 Set<HRegionInfo> regions = new HashSet<HRegionInfo>();
80 for (Pair<HRegionInfo, ServerName> p : regionsAndLocations) {
81 regions.add(p.getFirst());
82 }
83
84
85 LOG.info("Starting to write region info and WALs for regions for offline snapshot:"
86 + SnapshotDescriptionUtils.toString(snapshot));
87 for (HRegionInfo regionInfo : regions) {
88 snapshotDisabledRegion(regionInfo);
89 }
90
91
92 LOG.info("Starting to copy tableinfo for offline snapshot: " +
93 SnapshotDescriptionUtils.toString(snapshot));
94 TableInfoCopyTask tableInfoCopyTask = new TableInfoCopyTask(this.monitor, snapshot, fs,
95 FSUtils.getRootDir(conf));
96 tableInfoCopyTask.call();
97 monitor.rethrowException();
98 } catch (Exception e) {
99
100 String reason = "Failed snapshot " + SnapshotDescriptionUtils.toString(snapshot)
101 + " due to exception:" + e.getMessage();
102 ForeignException ee = new ForeignException(reason, e);
103 monitor.receive(ee);
104 } finally {
105 LOG.debug("Marking snapshot" + SnapshotDescriptionUtils.toString(snapshot)
106 + " as finished.");
107
108
109
110 timeoutInjector.complete();
111 }
112 }
113 }