View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master.handler;
20  
21  import java.io.IOException;
22  import java.util.List;
23  
24  import org.apache.hadoop.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.HRegionInfo;
26  import org.apache.hadoop.hbase.HTableDescriptor;
27  import org.apache.hadoop.hbase.Server;
28  import org.apache.hadoop.hbase.executor.EventType;
29  import org.apache.hadoop.hbase.master.HMaster;
30  import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
31  import org.apache.hadoop.hbase.master.MasterServices;
32  
33  @InterfaceAudience.Private
34  public class ModifyTableHandler extends TableEventHandler {
35    private final HTableDescriptor htd;
36  
37    public ModifyTableHandler(final byte [] tableName,
38        final HTableDescriptor htd, final Server server,
39        final MasterServices masterServices) {
40      super(EventType.C_M_MODIFY_TABLE, tableName, server, masterServices);
41      // This is the new schema we are going to write out as this modification.
42      this.htd = htd;
43    }
44  
45    @Override
46    protected void prepareWithTableLock() throws IOException {
47      super.prepareWithTableLock();
48      // Check table exists.
49      getTableDescriptor();
50    }
51  
52    @Override
53    protected void handleTableOperation(List<HRegionInfo> hris)
54    throws IOException {
55      MasterCoprocessorHost cpHost = ((HMaster) this.server)
56          .getCoprocessorHost();
57      if (cpHost != null) {
58        cpHost.preModifyTableHandler(this.tableName, this.htd);
59      }
60      // Update descriptor
61      this.masterServices.getTableDescriptors().add(this.htd);
62      if (cpHost != null) {
63        cpHost.postModifyTableHandler(this.tableName, this.htd);
64      }
65    }
66  
67    @Override
68    public String toString() {
69      String name = "UnknownServerName";
70      if(server != null && server.getServerName() != null) {
71        name = server.getServerName().toString();
72      }
73      return getClass().getSimpleName() + "-" + name + "-" + getSeqid() + "-" +
74        tableNameStr;
75    }
76  }