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.HColumnDescriptor;
26  import org.apache.hadoop.hbase.HRegionInfo;
27  import org.apache.hadoop.hbase.HTableDescriptor;
28  import org.apache.hadoop.hbase.Server;
29  import org.apache.hadoop.hbase.executor.EventType;
30  import org.apache.hadoop.hbase.master.HMaster;
31  import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
32  import org.apache.hadoop.hbase.master.MasterServices;
33  
34  /**
35   * Handles adding a new family to an existing table.
36   */
37  @InterfaceAudience.Private
38  public class TableModifyFamilyHandler extends TableEventHandler {
39    private final HColumnDescriptor familyDesc;
40  
41    public TableModifyFamilyHandler(byte[] tableName,
42        HColumnDescriptor familyDesc, Server server,
43        final MasterServices masterServices) {
44      super(EventType.C_M_MODIFY_FAMILY, tableName, server, masterServices);
45      this.familyDesc = familyDesc;
46    }
47  
48    @Override
49    protected void prepareWithTableLock() throws IOException {
50      super.prepareWithTableLock();
51      HTableDescriptor htd = getTableDescriptor();
52      hasColumnFamily(htd, familyDesc.getName());
53    }
54  
55    @Override
56    protected void handleTableOperation(List<HRegionInfo> regions) throws IOException {
57      MasterCoprocessorHost cpHost = ((HMaster) this.server)
58          .getCoprocessorHost();
59      if (cpHost != null) {
60        cpHost.preModifyColumnHandler(this.tableName, this.familyDesc);
61      }
62      // Update table descriptor
63      this.masterServices.getMasterFileSystem().modifyColumn(tableName, familyDesc);
64      if (cpHost != null) {
65        cpHost.postModifyColumnHandler(this.tableName, this.familyDesc);
66      }
67    }
68  
69    @Override
70    public String toString() {
71      String name = "UnknownServerName";
72      if(server != null && server.getServerName() != null) {
73        name = server.getServerName().toString();
74      }
75      String family = "UnknownFamily";
76      if(familyDesc != null) {
77        family = familyDesc.getNameAsString();
78      }
79      return getClass().getSimpleName() + "-" + name + "-" + getSeqid() + "-" + tableNameStr + "-" + family;
80    }
81  
82  }