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.master.handler;
21
22 import java.io.IOException;
23 import java.util.List;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.hbase.HRegionInfo;
28 import org.apache.hadoop.hbase.Server;
29 import org.apache.hadoop.hbase.catalog.MetaReader;
30 import org.apache.hadoop.hbase.executor.EventHandler;
31 import org.apache.hadoop.hbase.master.MasterServices;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.apache.zookeeper.KeeperException;
34
35
36
37
38
39
40
41
42 public abstract class TableEventHandler extends EventHandler {
43 private static final Log LOG = LogFactory.getLog(TableEventHandler.class);
44 protected final MasterServices masterServices;
45 protected final byte [] tableName;
46 protected final String tableNameStr;
47
48 public TableEventHandler(EventType eventType, byte [] tableName, Server server,
49 MasterServices masterServices)
50 throws IOException {
51 super(server, eventType);
52 this.masterServices = masterServices;
53 this.tableName = tableName;
54 this.masterServices.checkTableModifiable(tableName);
55 this.tableNameStr = Bytes.toString(this.tableName);
56 }
57
58 @Override
59 public void process() {
60 try {
61 LOG.info("Handling table operation " + eventType + " on table " +
62 Bytes.toString(tableName));
63 List<HRegionInfo> hris =
64 MetaReader.getTableRegions(this.server.getCatalogTracker(),
65 tableName);
66 handleTableOperation(hris);
67 } catch (IOException e) {
68 LOG.error("Error manipulating table " + Bytes.toString(tableName), e);
69 } catch (KeeperException e) {
70 LOG.error("Error manipulating table " + Bytes.toString(tableName), e);
71 }
72 }
73
74 protected abstract void handleTableOperation(List<HRegionInfo> regions)
75 throws IOException, KeeperException;
76 }