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