1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.client;
20
21 import java.io.IOException;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController;
29 import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
30 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
31 import org.apache.hadoop.hbase.protobuf.RequestConverter;
32 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.FlushRegionRequest;
33 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.FlushRegionResponse;
34 import org.apache.hadoop.hbase.util.Bytes;
35 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
36
37 import com.google.protobuf.ServiceException;
38
39
40
41
42 @InterfaceAudience.Private
43 public class FlushRegionCallable extends RegionAdminServiceCallable<FlushRegionResponse> {
44
45 private static final Log LOG = LogFactory.getLog(FlushRegionCallable.class);
46
47 private final byte[] regionName;
48 private final boolean writeFlushWalMarker;
49 private boolean reload;
50
51 public FlushRegionCallable(ClusterConnection connection,
52 RpcControllerFactory rpcControllerFactory, TableName tableName, byte[] regionName,
53 byte[] regionStartKey, boolean writeFlushWalMarker) {
54 super(connection, rpcControllerFactory, tableName, regionStartKey);
55 this.regionName = regionName;
56 this.writeFlushWalMarker = writeFlushWalMarker;
57 }
58
59 public FlushRegionCallable(ClusterConnection connection,
60 RpcControllerFactory rpcControllerFactory, HRegionInfo regionInfo,
61 boolean writeFlushWalMarker) {
62 this(connection, rpcControllerFactory, regionInfo.getTable(), regionInfo.getRegionName(),
63 regionInfo.getStartKey(), writeFlushWalMarker);
64 }
65
66 @Override
67 public FlushRegionResponse call(int callTimeout) throws Exception {
68 return flushRegion();
69 }
70
71 @Override
72 public void prepare(boolean reload) throws IOException {
73 super.prepare(reload);
74 this.reload = reload;
75 }
76
77 private FlushRegionResponse flushRegion() throws IOException {
78
79
80 if (!Bytes.equals(location.getRegionInfo().getRegionName(), regionName)) {
81 if (!reload) {
82 throw new IOException("Cached location seems to be different than requested region.");
83 }
84 LOG.info("Skipping flush region, because the located region "
85 + Bytes.toStringBinary(location.getRegionInfo().getRegionName()) + " is different than "
86 + " requested region " + Bytes.toStringBinary(regionName));
87 return FlushRegionResponse.newBuilder()
88 .setLastFlushTime(EnvironmentEdgeManager.currentTime())
89 .setFlushed(false)
90 .setWroteFlushWalMarker(false)
91 .build();
92 }
93
94 FlushRegionRequest request =
95 RequestConverter.buildFlushRegionRequest(regionName, writeFlushWalMarker);
96
97 try {
98 PayloadCarryingRpcController controller = rpcControllerFactory.newController();
99 controller.setPriority(tableName);
100 return stub.flushRegion(controller, request);
101 } catch (ServiceException se) {
102 throw ProtobufUtil.getRemoteException(se);
103 }
104 }
105 }