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 this.server.getMetrics().incrementSplitSuccessCount();
69 } catch (Exception e) {
70 if (this.server.isStopping() || this.server.isStopped()) {
71 LOG.info(
72 "Skip rollback/cleanup of failed split of "
73 + parent.getRegionNameAsString() + " because server is"
74 + (this.server.isStopping() ? " stopping" : " stopped"), e);
75 return;
76 }
77 try {
78 LOG.info("Running rollback/cleanup of failed split of " +
79 parent.getRegionNameAsString() + "; " + e.getMessage(), e);
80 if (st.rollback(this.server, this.server)) {
81 LOG.info("Successful rollback of failed split of " +
82 parent.getRegionNameAsString());
83 this.server.getMetrics().incrementSplitFailureCount();
84 } else {
85 this.server.abort("Abort; we got an error after point-of-no-return");
86 }
87 } catch (RuntimeException ee) {
88 String msg = "Failed rollback of failed split of " +
89 parent.getRegionNameAsString() + " -- aborting server";
90
91 LOG.info(msg, ee);
92 this.server.abort(msg);
93 }
94 return;
95 }
96 LOG.info("Region split, META updated, and report to master. Parent="
97 + parent.getRegionInfo().getRegionNameAsString() + ", new regions: "
98 + st.getFirstDaughter().getRegionNameAsString() + ", "
99 + st.getSecondDaughter().getRegionNameAsString() + ". Split took "
100 + StringUtils.formatTimeDiff(System.currentTimeMillis(), startTime));
101 } catch (IOException ex) {
102 LOG.error("Split failed " + this, RemoteExceptionHandler
103 .checkIOException(ex));
104 this.server.getMetrics().incrementSplitFailureCount();
105 server.checkFileSystem();
106 }
107 }
108 }