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  import org.apache.hadoop.hbase.RemoteExceptionHandler;
24  
25  import java.io.IOException;
26  
27  /** Scanner for the <code>ROOT</code> HRegion. */
28  class RootScanner extends BaseScanner {
29    /**
30     * Constructor
31     * @param master
32     */
33    public RootScanner(HMaster master) {
34      super(master, true, master.getShutdownRequested());
35    }
36  
37    /**
38     * Don't retry if we get an error while scanning. Errors are most often
39     *
40     * caused by the server going away. Wait until next rescan interval when
41     * things should be back to normal.
42     * @return True if successfully scanned.
43     */
44    private boolean scanRoot() {
45      master.getRegionManager().waitForRootRegionLocation();
46      if (master.isClosed()) {
47        return false;
48      }
49  
50      try {
51        // Don't interrupt us while we're working
52        synchronized(scannerLock) {
53          if (master.getRegionManager().getRootRegionLocation() != null) {
54            scanRegion(new MetaRegion(master.getRegionManager().getRootRegionLocation(),
55              HRegionInfo.ROOT_REGIONINFO));
56          }
57        }
58      } catch (IOException e) {
59        e = RemoteExceptionHandler.checkIOException(e);
60        LOG.warn("Scan ROOT region", e);
61        // Make sure the file system is still available
62        master.checkFileSystem();
63      } catch (Exception e) {
64        // If for some reason we get some other kind of exception,
65        // at least log it rather than go out silently.
66        LOG.error("Unexpected exception", e);
67      }
68      return true;
69    }
70  
71    @Override
72    protected boolean initialScan() {
73      this.initialScanComplete = scanRoot();
74      return initialScanComplete;
75    }
76  
77    @Override
78    protected void maintenanceScan() {
79      scanRoot();
80    }
81  }