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.handler;
21  
22  import java.io.IOException;
23  import java.util.List;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.hadoop.hbase.HRegionInfo;
28  import org.apache.hadoop.hbase.Server;
29  import org.apache.hadoop.hbase.catalog.MetaEditor;
30  import org.apache.hadoop.hbase.master.AssignmentManager;
31  import org.apache.hadoop.hbase.master.MasterServices;
32  import org.apache.hadoop.hbase.util.Bytes;
33  import org.apache.hadoop.hbase.util.Threads;
34  import org.apache.zookeeper.KeeperException;
35  
36  public class DeleteTableHandler extends TableEventHandler {
37    private static final Log LOG = LogFactory.getLog(DeleteTableHandler.class);
38  
39    public DeleteTableHandler(byte [] tableName, Server server,
40        final MasterServices masterServices)
41    throws IOException {
42      super(EventType.C_M_DELETE_TABLE, tableName, server, masterServices);
43    }
44  
45    @Override
46    protected void handleTableOperation(List<HRegionInfo> regions)
47    throws IOException, KeeperException {
48      AssignmentManager am = this.masterServices.getAssignmentManager();
49      long waitTime = server.getConfiguration().
50        getLong("hbase.master.wait.on.region", 5 * 60 * 1000);
51      for (HRegionInfo region : regions) {
52        long done = System.currentTimeMillis() + waitTime;
53        while (System.currentTimeMillis() < done) {
54          AssignmentManager.RegionState rs = am.isRegionInTransition(region);
55          if (rs == null) break;
56          Threads.sleep(waitingTimeForEvents);
57          LOG.debug("Waiting on  region to clear regions in transition; " + rs);
58        }
59        if (am.isRegionInTransition(region) != null) {
60          throw new IOException("Waited hbase.master.wait.on.region (" +
61            waitTime + "ms) for region to leave region " +
62            region.getRegionNameAsString() + " in transitions");
63        }
64        LOG.debug("Deleting region " + region.getRegionNameAsString() +
65          " from META and FS");
66        // Remove region from META
67        MetaEditor.deleteRegion(this.server.getCatalogTracker(), region);
68        // Delete region from FS
69        this.masterServices.getMasterFileSystem().deleteRegion(region);
70      }
71      // Delete table from FS
72      this.masterServices.getMasterFileSystem().deleteTable(tableName);
73  
74      // If entry for this table in zk, and up in AssignmentManager, remove it.
75      // Call to undisableTable does this. TODO: Make a more formal purge table.
76      am.getZKTable().setEnabledTable(Bytes.toString(tableName));
77    }
78  }