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.regionserver.HRegion;
24
25 import java.io.IOException;
26
27 /**
28 * ProcessRegionClose is the way we do post-processing on a closed region. We
29 * only spawn one of these asynchronous tasks when the region needs to be
30 * either offlined or deleted. We used to create one of these tasks whenever
31 * a region was closed, but since closing a region that isn't being offlined
32 * or deleted doesn't actually require post processing, it's no longer
33 * necessary.
34 */
35 public class ProcessRegionClose extends ProcessRegionStatusChange {
36 protected final boolean offlineRegion;
37 protected final boolean reassignRegion;
38
39 /**
40 * @param master
41 * @param regionInfo Region to operate on
42 * @param offlineRegion if true, set the region to offline in meta
43 * @param reassignRegion if true, region is to be reassigned
44 */
45 public ProcessRegionClose(HMaster master, HRegionInfo regionInfo,
46 boolean offlineRegion, boolean reassignRegion) {
47
48 super(master, regionInfo);
49 this.offlineRegion = offlineRegion;
50 this.reassignRegion = reassignRegion;
51 }
52
53 @Override
54 public String toString() {
55 return "ProcessRegionClose of " + this.regionInfo.getRegionNameAsString() +
56 ", " + this.offlineRegion + ", reassign: " + this.reassignRegion;
57 }
58
59 @Override
60 protected boolean process() throws IOException {
61 if (!metaRegionAvailable()) {
62 // We can't proceed unless the meta region we are going to update
63 // is online. metaRegionAvailable() has put this operation on the
64 // delayedToDoQueue, so return true so the operation is not put
65 // back on the toDoQueue
66 return true;
67 }
68 Boolean result = null;
69 if (offlineRegion || reassignRegion) {
70 result =
71 new RetryableMetaOperation<Boolean>(getMetaRegion(), this.master) {
72 public Boolean call() throws IOException {
73
74
75 // We can't proceed unless the meta region we are going to update
76 // is online. metaRegionAvailable() will put this operation on the
77 // delayedToDoQueue, so return true so the operation is not put
78 // back on the toDoQueue
79
80 if (metaRegionAvailable()) {
81 if(offlineRegion) {
82 // offline the region in meta and then remove it from the
83 // set of regions in transition
84 HRegion.offlineRegionInMETA(server, metaRegionName,
85 regionInfo);
86 master.getRegionManager().removeRegion(regionInfo);
87 LOG.info("region closed: " + regionInfo.getRegionNameAsString());
88 } else {
89 // we are reassigning the region eventually, so set it unassigned
90 // and remove the server info
91 HRegion.cleanRegionInMETA(server, metaRegionName,
92 regionInfo);
93 master.getRegionManager().setUnassigned(regionInfo, false);
94 LOG.info("region set as unassigned: " + regionInfo.getRegionNameAsString());
95 }
96 }
97 return true;
98 }
99 }.doWithRetries();
100 result = result == null ? true : result;
101
102 } else {
103 LOG.info("Region was neither offlined, or asked to be reassigned, what gives: " +
104 regionInfo.getRegionNameAsString());
105 }
106
107 return result == null ? true : result;
108 }
109 }