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.hbase.HRegionInfo;
25  import org.apache.hadoop.hbase.HTableDescriptor;
26  import org.apache.hadoop.hbase.Server;
27  import org.apache.hadoop.hbase.TableName;
28  import org.apache.hadoop.hbase.classification.InterfaceAudience;
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.MasterFileSystem;
33  import org.apache.hadoop.hbase.master.MasterServices;
34  import org.apache.hadoop.hbase.util.Bytes;
35  
36  /**
37   * Handles Deleting a column family from an existing table.
38   */
39  @InterfaceAudience.Private
40  public class TableDeleteFamilyHandler extends TableEventHandler {
41  
42    private byte [] familyName;
43  
44    public TableDeleteFamilyHandler(TableName tableName, byte [] familyName,
45        Server server, final MasterServices masterServices) throws IOException {
46      super(EventType.C_M_DELETE_FAMILY, tableName, server, masterServices);
47      this.familyName = familyName;
48    }
49  
50    @Override
51    protected void prepareWithTableLock() throws IOException {
52      super.prepareWithTableLock();
53      HTableDescriptor htd = getTableDescriptor();
54      this.familyName = hasColumnFamily(htd, familyName);
55    }
56  
57    @Override
58    protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
59      MasterCoprocessorHost cpHost = ((HMaster) this.server)
60          .getMasterCoprocessorHost();
61      if (cpHost != null) {
62        cpHost.preDeleteColumnHandler(this.tableName, this.familyName);
63      }
64      // Update table descriptor
65      this.masterServices.getMasterFileSystem().deleteColumn(tableName, familyName);
66      // Remove the column family from the file system
67      MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
68      for (HRegionInfo hri : hris) {
69        // Delete the family directory in FS for all the regions one by one
70        mfs.deleteFamilyFromFS(hri, familyName);
71      }
72      if (cpHost != null) {
73        cpHost.postDeleteColumnHandler(this.tableName, this.familyName);
74      }
75    }
76  
77    @Override
78    public String toString() {
79      String name = "UnknownServerName";
80      if(server != null && server.getServerName() != null) {
81        name = server.getServerName().toString();
82      }
83      String family = "UnknownFamily";
84      if(familyName != null) {
85        family = Bytes.toString(familyName);
86      }
87      return getClass().getSimpleName() + "-" + name + "-" + getSeqid() +
88          "-" + tableName + "-" + family;
89    }
90  }