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.HRegionInfo;
23  
24  /**
25   * Abstract class that performs common operations for
26   * @see ProcessRegionClose and @see ProcessRegionOpen
27   */
28  abstract class ProcessRegionStatusChange extends RegionServerOperation {
29    protected final boolean isMetaTable;
30    protected final HRegionInfo regionInfo;
31    @SuppressWarnings({"FieldCanBeLocal"})
32    private volatile MetaRegion metaRegion = null;
33    protected volatile byte[] metaRegionName = null;
34  
35    /**
36     * @param master the master
37     * @param regionInfo region info
38     */
39    public ProcessRegionStatusChange(HMaster master, HRegionInfo regionInfo) {
40      super(master);
41      this.regionInfo = regionInfo;
42      this.isMetaTable = regionInfo.isMetaTable();
43    }
44  
45    protected boolean metaRegionAvailable() {
46      boolean available = true;
47      if (isMetaTable) {
48        // This operation is for the meta table
49        if (!rootAvailable()) {
50          requeue();
51          // But we can't proceed unless the root region is available
52          available = false;
53        }
54      } else {
55        if (!master.getRegionManager().isInitialRootScanComplete() ||
56            !metaTableAvailable()) {
57          // The root region has not been scanned or the meta table is not
58          // available so we can't proceed.
59          // Put the operation on the delayedToDoQueue
60          requeue();
61          available = false;
62        }
63      }
64      return available;
65    }
66  
67    protected MetaRegion getMetaRegion() {
68      if (isMetaTable) {
69        this.metaRegionName = HRegionInfo.ROOT_REGIONINFO.getRegionName();
70        this.metaRegion = new MetaRegion(master.getRegionManager().getRootRegionLocation(),
71            HRegionInfo.ROOT_REGIONINFO);
72      } else {
73        this.metaRegion =
74          master.getRegionManager().getFirstMetaRegionForRegion(regionInfo);
75        if (this.metaRegion != null) {
76          this.metaRegionName = this.metaRegion.getRegionName();
77        }
78      }
79      return this.metaRegion;
80    }
81    
82    public HRegionInfo getRegionInfo() {
83      return regionInfo;
84    }
85  }