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.fs.Path;
25  import org.apache.hadoop.hbase.HRegionInfo;
26  import org.apache.hadoop.hbase.RemoteExceptionHandler;
27  import org.apache.hadoop.hbase.TableNotDisabledException;
28  import org.apache.hadoop.hbase.ipc.HRegionInterface;
29  import org.apache.hadoop.hbase.regionserver.HRegion;
30  import org.apache.hadoop.hbase.util.Bytes;
31  
32  import java.io.IOException;
33  
34  /**
35   * Instantiated to delete a table. Table must be offline.
36   */
37  class TableDelete extends TableOperation {
38    private final Log LOG = LogFactory.getLog(this.getClass());
39  
40    TableDelete(final HMaster master, final byte [] tableName) throws IOException {
41      super(master, tableName);
42    }
43  
44    @Override
45    protected void processScanItem(String serverName,
46        final HRegionInfo info) throws IOException {
47      if (isEnabled(info)) {
48        LOG.debug("Region still enabled: " + info.toString());
49        throw new TableNotDisabledException(tableName);
50      }
51    }
52  
53    @Override
54    protected void postProcessMeta(MetaRegion m, HRegionInterface server)
55    throws IOException {
56      for (HRegionInfo i: unservedRegions) {
57        if (!Bytes.equals(this.tableName, i.getTableDesc().getName())) {
58          // Don't delete regions that are not from our table.
59          continue;
60        }
61        // Delete the region
62        try {
63          HRegion.removeRegionFromMETA(server, m.getRegionName(), i.getRegionName());
64          HRegion.deleteRegion(this.master.getFileSystem(),
65            this.master.getRootDir(), i);
66  
67        } catch (IOException e) {
68          LOG.error("failed to delete region " + Bytes.toString(i.getRegionName()),
69            RemoteExceptionHandler.checkIOException(e));
70        }
71      }
72  
73      // delete the table's folder from fs.
74      this.master.getFileSystem().delete(new Path(this.master.getRootDir(),
75        Bytes.toString(this.tableName)), true);
76    }
77  }