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.backup.master;
20  
21  import java.io.IOException;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.hadoop.hbase.HConstants;
26  import org.apache.hadoop.hbase.HTableDescriptor;
27  import org.apache.hadoop.hbase.TableExistsException;
28  import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
29  import org.apache.hadoop.hbase.coprocessor.BaseMasterAndRegionObserver;
30  import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
31  import org.apache.hadoop.hbase.coprocessor.ObserverContext;
32  import org.apache.hadoop.hbase.master.MasterServices;
33  
34  /**
35   * The current implementation checks if the backup system table 
36   * (hbase:backup) exists on HBasae Master startup and if it does not -
37   * it creates it. We need to make sure that backup system table is  
38   * created under HBase user with ADMIN privileges
39   */
40  public class BackupController extends BaseMasterAndRegionObserver {
41    private static final Log LOG = LogFactory.getLog(BackupController.class.getName());
42  
43    @Override
44    public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx)
45        throws IOException {
46      // Need to create the new system table for backups (if does not exist)
47      MasterServices master = ctx.getEnvironment().getMasterServices();
48      HTableDescriptor backupHTD = BackupSystemTable.getSystemTableDescriptor();
49      try{
50        master.createTable(backupHTD, null, HConstants.NO_NONCE, HConstants.NO_NONCE);
51        LOG.info("Created "+ BackupSystemTable.getTableNameAsString()+" table");
52      } catch(TableExistsException e) {
53        LOG.info("Table "+ BackupSystemTable.getTableNameAsString() +" already exists");
54      } 
55    }
56  }