1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.coprocessor.example;
20
21 import com.google.protobuf.RpcCallback;
22 import com.google.protobuf.RpcController;
23 import com.google.protobuf.Service;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.hbase.Coprocessor;
27 import org.apache.hadoop.hbase.CoprocessorEnvironment;
28 import org.apache.hadoop.hbase.coprocessor.CoprocessorException;
29 import org.apache.hadoop.hbase.coprocessor.CoprocessorService;
30 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
31 import org.apache.hadoop.hbase.protobuf.ResponseConverter;
32 import org.apache.hadoop.hbase.protobuf.generated.RefreshHFilesProtos;
33 import org.apache.hadoop.hbase.regionserver.Store;
34
35 import java.io.IOException;
36
37
38
39
40
41
42
43
44
45 public class RefreshHFilesEndpoint extends RefreshHFilesProtos.RefreshHFilesService
46 implements Coprocessor, CoprocessorService {
47 protected static final Log LOG = LogFactory.getLog(RefreshHFilesEndpoint.class);
48 private RegionCoprocessorEnvironment env;
49
50 public RefreshHFilesEndpoint() {
51 }
52
53 @Override
54 public Service getService() {
55 return this;
56 }
57
58 @Override
59 public void refreshHFiles(RpcController controller, RefreshHFilesProtos.RefreshHFilesRequest request,
60 RpcCallback<RefreshHFilesProtos.RefreshHFilesResponse> done) {
61 try {
62 for (Store store : env.getRegion().getStores()) {
63 LOG.debug("Refreshing HFiles for region: " + store.getRegionInfo().getRegionNameAsString() +
64 " and store: " + store.getColumnFamilyName() + "class:" + store.getClass());
65 store.refreshStoreFiles();
66 }
67 } catch (IOException ioe) {
68 LOG.error("Exception while trying to refresh store files: ", ioe);
69 ResponseConverter.setControllerException(controller, ioe);
70 }
71 done.run(RefreshHFilesProtos.RefreshHFilesResponse.getDefaultInstance());
72 }
73
74 @Override
75 public void start(CoprocessorEnvironment env) throws IOException {
76 if (env instanceof RegionCoprocessorEnvironment) {
77 this.env = (RegionCoprocessorEnvironment) env;
78 } else {
79 throw new CoprocessorException("Must be loaded on a table region!");
80 }
81 }
82
83 @Override
84 public void stop(CoprocessorEnvironment env) throws IOException {
85 }
86 }