1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver;
21
22 import java.io.IOException;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.hbase.RemoteExceptionHandler;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.apache.hadoop.util.StringUtils;
29
30 import com.google.common.base.Preconditions;
31
32
33
34
35 class SplitRequest implements Runnable {
36 static final Log LOG = LogFactory.getLog(SplitRequest.class);
37 private final HRegion parent;
38 private final byte[] midKey;
39 private final HRegionServer server;
40
41 SplitRequest(HRegion region, byte[] midKey, HRegionServer hrs) {
42 Preconditions.checkNotNull(hrs);
43 this.parent = region;
44 this.midKey = midKey;
45 this.server = hrs;
46 }
47
48 @Override
49 public String toString() {
50 return "regionName=" + parent + ", midKey=" + Bytes.toStringBinary(midKey);
51 }
52
53 @Override
54 public void run() {
55 if (this.server.isStopping() || this.server.isStopped()) {
56 LOG.debug("Skipping split because server is stopping=" +
57 this.server.isStopping() + " or stopped=" + this.server.isStopped());
58 return;
59 }
60 try {
61 final long startTime = System.currentTimeMillis();
62 SplitTransaction st = new SplitTransaction(parent, midKey);
63
64
65 if (!st.prepare()) return;
66 try {
67 st.execute(this.server, this.server);
68 } catch (Exception e) {
69 try {
70 LOG.info("Running rollback/cleanup of failed split of " +
71 parent.getRegionNameAsString() + "; " + e.getMessage());
72 if (st.rollback(this.server, this.server)) {
73 LOG.info("Successful rollback of failed split of " +
74 parent.getRegionNameAsString());
75 } else {
76 this.server.abort("Abort; we got an error after point-of-no-return");
77 }
78 } catch (RuntimeException ee) {
79 String msg = "Failed rollback of failed split of " +
80 parent.getRegionNameAsString() + " -- aborting server";
81
82 LOG.info(msg, ee);
83 this.server.abort(msg);
84 }
85 return;
86 }
87 LOG.info("Region split, META updated, and report to master. Parent="
88 + parent.getRegionInfo().getRegionNameAsString() + ", new regions: "
89 + st.getFirstDaughter().getRegionNameAsString() + ", "
90 + st.getSecondDaughter().getRegionNameAsString() + ". Split took "
91 + StringUtils.formatTimeDiff(System.currentTimeMillis(), startTime));
92 } catch (IOException ex) {
93 LOG.error("Split failed " + this, RemoteExceptionHandler
94 .checkIOException(ex));
95 server.checkFileSystem();
96 }
97 }
98 }