1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.master.handler;
20
21 import java.io.IOException;
22 import java.util.List;
23 import java.util.Set;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.HRegionInfo;
29 import org.apache.hadoop.hbase.HTableDescriptor;
30 import org.apache.hadoop.hbase.Server;
31 import org.apache.hadoop.hbase.executor.EventType;
32 import org.apache.hadoop.hbase.master.HMaster;
33 import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
34 import org.apache.hadoop.hbase.master.MasterFileSystem;
35 import org.apache.hadoop.hbase.master.MasterServices;
36 import org.apache.hadoop.hbase.util.Bytes;
37
38 @InterfaceAudience.Private
39 public class ModifyTableHandler extends TableEventHandler {
40 private static final Log LOG = LogFactory.getLog(ModifyTableHandler.class);
41
42 private final HTableDescriptor htd;
43
44 public ModifyTableHandler(final byte [] tableName,
45 final HTableDescriptor htd, final Server server,
46 final MasterServices masterServices) {
47 super(EventType.C_M_MODIFY_TABLE, tableName, server, masterServices);
48
49 this.htd = htd;
50 }
51
52 @Override
53 protected void prepareWithTableLock() throws IOException {
54 super.prepareWithTableLock();
55
56 getTableDescriptor();
57 }
58
59 @Override
60 protected void handleTableOperation(List<HRegionInfo> hris)
61 throws IOException {
62 MasterCoprocessorHost cpHost = ((HMaster) this.server).getCoprocessorHost();
63 if (cpHost != null) {
64 cpHost.preModifyTableHandler(this.tableName, this.htd);
65 }
66
67 HTableDescriptor oldHtd = getTableDescriptor();
68 this.masterServices.getTableDescriptors().add(this.htd);
69 deleteFamilyFromFS(hris, oldHtd.getFamiliesKeys());
70 if (cpHost != null) {
71 cpHost.postModifyTableHandler(this.tableName, this.htd);
72 }
73 }
74
75
76
77
78 private void deleteFamilyFromFS(final List<HRegionInfo> hris, final Set<byte[]> oldFamilies) {
79 try {
80 Set<byte[]> newFamilies = this.htd.getFamiliesKeys();
81 MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
82 for (byte[] familyName: oldFamilies) {
83 if (!newFamilies.contains(familyName)) {
84 LOG.debug("Removing family=" + Bytes.toString(familyName) +
85 " from table=" + this.tableName);
86 for (HRegionInfo hri: hris) {
87
88 mfs.deleteFamilyFromFS(hri, familyName);
89 }
90 }
91 }
92 } catch (IOException e) {
93 LOG.warn("Unable to remove on-disk directories for the removed families", e);
94 }
95 }
96
97 @Override
98 public String toString() {
99 String name = "UnknownServerName";
100 if(server != null && server.getServerName() != null) {
101 name = server.getServerName().toString();
102 }
103 return getClass().getSimpleName() + "-" + name + "-" + getSeqid() + "-" +
104 tableNameStr;
105 }
106 }