View Javadoc

1   /**
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.master;
21  
22  import org.apache.hadoop.hbase.HColumnDescriptor;
23  import org.apache.hadoop.hbase.HRegionInfo;
24  import org.apache.hadoop.hbase.ipc.HRegionInterface;
25  import org.apache.hadoop.hbase.util.Bytes;
26  
27  import java.io.IOException;
28  
29  /** Instantiated to modify an existing column family on a table */
30  class ModifyColumn extends ColumnOperation {
31    private final HColumnDescriptor descriptor;
32    private final byte [] columnName;
33  
34    ModifyColumn(final HMaster master, final byte [] tableName,
35      final byte [] columnName, HColumnDescriptor descriptor)
36    throws IOException {
37      super(master, tableName);
38      this.descriptor = descriptor;
39      this.columnName = columnName;
40    }
41  
42    @Override
43    protected void postProcessMeta(MetaRegion m, HRegionInterface server)
44    throws IOException {
45      for (HRegionInfo i: unservedRegions) {
46        if (i.getTableDesc().hasFamily(columnName)) {
47          i.getTableDesc().addFamily(descriptor);
48          updateRegionInfo(server, m.getRegionName(), i);
49        } else { // otherwise, we have an error.
50          throw new InvalidColumnNameException("Column family '" +
51            Bytes.toString(columnName) +
52            "' doesn't exist, so cannot be modified.");
53        }
54      }
55    }
56  }