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.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.hbase.HConstants;
25  import org.apache.hadoop.hbase.HRegionInfo;
26  import org.apache.hadoop.hbase.HTableDescriptor;
27  import org.apache.hadoop.hbase.TableNotDisabledException;
28  import org.apache.hadoop.hbase.client.Put;
29  import org.apache.hadoop.hbase.ipc.HRegionInterface;
30  import org.apache.hadoop.hbase.util.Bytes;
31  import org.apache.hadoop.hbase.util.Writables;
32  
33  import java.io.IOException;
34  
35  /** Instantiated to modify table descriptor metadata */
36  class ModifyTableMeta extends TableOperation {
37  
38    private static Log LOG = LogFactory.getLog(ModifyTableMeta.class);
39  
40    private HTableDescriptor desc;
41  
42    ModifyTableMeta(final HMaster master, final byte [] tableName,
43      HTableDescriptor desc)
44    throws IOException {
45      super(master, tableName);
46      this.desc = desc;
47      LOG.debug("modifying " + Bytes.toString(tableName) + ": " +
48          desc.toString());
49    }
50  
51    protected void updateRegionInfo(HRegionInterface server, byte [] regionName,
52      HRegionInfo i)
53    throws IOException {
54      Put put = new Put(i.getRegionName());
55      put.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, Writables.getBytes(i));
56      server.put(regionName, put);
57      LOG.debug("updated HTableDescriptor for region " + i.getRegionNameAsString());
58    }
59  
60    @Override
61    protected void processScanItem(String serverName,
62        final HRegionInfo info) throws IOException {
63      if (isEnabled(info)) {
64        throw new TableNotDisabledException(Bytes.toString(tableName));
65      }
66    }
67  
68    @Override
69    protected void postProcessMeta(MetaRegion m, HRegionInterface server)
70    throws IOException {
71      for (HRegionInfo i: unservedRegions) {
72        i.setTableDesc(desc);
73        updateRegionInfo(server, m.getRegionName(), i);
74      }
75      // kick off a meta scan right away
76      master.getRegionManager().metaScannerThread.triggerNow();
77    }
78  }