1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.hbase.coordination; 19 20 import org.apache.hadoop.hbase.classification.InterfaceAudience; 21 import org.apache.hadoop.hbase.HRegionInfo; 22 import org.apache.hadoop.hbase.ServerName; 23 import org.apache.hadoop.hbase.master.AssignmentManager; 24 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos; 25 import org.apache.hadoop.hbase.regionserver.HRegion; 26 import org.apache.hadoop.hbase.regionserver.RegionServerServices; 27 28 import java.io.IOException; 29 30 /** 31 * Cocoordination operations for opening regions. 32 */ 33 @InterfaceAudience.Private 34 public interface OpenRegionCoordination { 35 36 //--------------------- 37 // RS-side operations 38 //--------------------- 39 /** 40 * Tries to move regions to OPENED state. 41 * 42 * @param r Region we're working on. 43 * @param ord details about region opening task 44 * @return whether transition was successful or not 45 * @throws java.io.IOException 46 */ 47 boolean transitionToOpened(HRegion r, OpenRegionDetails ord) throws IOException; 48 49 /** 50 * Transitions region from offline to opening state. 51 * @param regionInfo region we're working on. 52 * @param ord details about opening task. 53 * @return true if successful, false otherwise 54 */ 55 boolean transitionFromOfflineToOpening(HRegionInfo regionInfo, 56 OpenRegionDetails ord); 57 58 /** 59 * Heartbeats to prevent timeouts. 60 * 61 * @param ord details about opening task. 62 * @param regionInfo region we're working on. 63 * @param rsServices instance of RegionServerrServices 64 * @param context used for logging purposes only 65 * @return true if successful heartbeat, false otherwise. 66 */ 67 boolean tickleOpening(OpenRegionDetails ord, HRegionInfo regionInfo, 68 RegionServerServices rsServices, String context); 69 70 /** 71 * Tries transition region from offline to failed open. 72 * @param rsServices instance of RegionServerServices 73 * @param hri region we're working on 74 * @param ord details about region opening task 75 * @return true if successful, false otherwise 76 */ 77 boolean tryTransitionFromOfflineToFailedOpen(RegionServerServices rsServices, 78 HRegionInfo hri, OpenRegionDetails ord); 79 80 /** 81 * Tries transition from Opening to Failed open. 82 * @param hri region we're working on 83 * @param ord details about region opening task 84 * @return true if successfu. false otherwise. 85 */ 86 boolean tryTransitionFromOpeningToFailedOpen(HRegionInfo hri, OpenRegionDetails ord); 87 88 /** 89 * Construct OpenRegionDetails instance from part of protobuf request. 90 * @return instance of OpenRegionDetails. 91 */ 92 OpenRegionDetails parseFromProtoRequest(AdminProtos.OpenRegionRequest.RegionOpenInfo 93 regionOpenInfo); 94 95 /** 96 * Get details object with params for case when we're opening on 97 * regionserver side with all "default" properties. 98 */ 99 OpenRegionDetails getDetailsForNonCoordinatedOpening(); 100 101 //------------------------- 102 // HMaster-side operations 103 //------------------------- 104 105 /** 106 * Commits opening operation on HM side (steps required for "commit" 107 * are determined by coordination implementation). 108 * @return true if committed successfully, false otherwise. 109 */ 110 public boolean commitOpenOnMasterSide(AssignmentManager assignmentManager, 111 HRegionInfo regionInfo, 112 OpenRegionDetails ord); 113 114 /** 115 * Interface for region opening tasks. Used to carry implementation details in 116 * encapsulated way through Handlers to the coordination API. 117 */ 118 static interface OpenRegionDetails { 119 /** 120 * Sets server name on which opening operation is running. 121 */ 122 void setServerName(ServerName serverName); 123 124 /** 125 * @return server name on which opening op is running. 126 */ 127 ServerName getServerName(); 128 } 129 }