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.master; 20 21 import java.io.IOException; 22 import java.util.List; 23 24 import org.apache.hadoop.hbase.classification.InterfaceAudience; 25 import org.apache.hadoop.hbase.HColumnDescriptor; 26 import org.apache.hadoop.hbase.HRegionInfo; 27 import org.apache.hadoop.hbase.HTableDescriptor; 28 import org.apache.hadoop.hbase.NamespaceDescriptor; 29 import org.apache.hadoop.hbase.ProcedureInfo; 30 import org.apache.hadoop.hbase.Server; 31 import org.apache.hadoop.hbase.TableDescriptors; 32 import org.apache.hadoop.hbase.TableName; 33 import org.apache.hadoop.hbase.TableNotDisabledException; 34 import org.apache.hadoop.hbase.TableNotFoundException; 35 import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 36 import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 37 import org.apache.hadoop.hbase.executor.ExecutorService; 38 import org.apache.hadoop.hbase.quotas.MasterQuotaManager; 39 40 import com.google.protobuf.Service; 41 42 /** 43 * Services Master supplies 44 */ 45 @InterfaceAudience.Private 46 public interface MasterServices extends Server { 47 /** 48 * @return Master's instance of the {@link AssignmentManager} 49 */ 50 AssignmentManager getAssignmentManager(); 51 52 /** 53 * @return Master's filesystem {@link MasterFileSystem} utility class. 54 */ 55 MasterFileSystem getMasterFileSystem(); 56 57 /** 58 * @return Master's {@link ServerManager} instance. 59 */ 60 ServerManager getServerManager(); 61 62 /** 63 * @return Master's instance of {@link ExecutorService} 64 */ 65 ExecutorService getExecutorService(); 66 67 /** 68 * @return Master's instance of {@link TableLockManager} 69 */ 70 TableLockManager getTableLockManager(); 71 72 /** 73 * @return Master's instance of {@link MasterCoprocessorHost} 74 */ 75 MasterCoprocessorHost getMasterCoprocessorHost(); 76 77 /** 78 * @return Master's instance of {@link MasterQuotaManager} 79 */ 80 MasterQuotaManager getMasterQuotaManager(); 81 82 /** 83 * @return Master's instance of {@link ProcedureExecutor} 84 */ 85 ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor(); 86 87 /** 88 * Check table is modifiable; i.e. exists and is offline. 89 * @param tableName Name of table to check. 90 * @throws TableNotDisabledException 91 * @throws TableNotFoundException 92 * @throws IOException 93 */ 94 // We actually throw the exceptions mentioned in the 95 void checkTableModifiable(final TableName tableName) 96 throws IOException, TableNotFoundException, TableNotDisabledException; 97 98 /** 99 * Check whether the procedure executor is enabled 100 */ 101 boolean isMasterProcedureExecutorEnabled(); 102 103 /** 104 * Create a table using the given table definition. 105 * @param desc The table definition 106 * @param splitKeys Starting row keys for the initial table regions. If null 107 * @param nonceGroup 108 * @param nonce 109 * a single region is created. 110 */ 111 long createTable( 112 final HTableDescriptor desc, 113 final byte[][] splitKeys, 114 final long nonceGroup, 115 final long nonce) throws IOException; 116 117 /** 118 * Delete a table 119 * @param tableName The table name 120 * @param nonceGroup 121 * @param nonce 122 * @throws IOException 123 */ 124 long deleteTable( 125 final TableName tableName, 126 final long nonceGroup, 127 final long nonce) throws IOException; 128 129 /** 130 * Truncate a table 131 * @param tableName The table name 132 * @param preserveSplits True if the splits should be preserved 133 * @param nonceGroup 134 * @param nonce 135 * @throws IOException 136 */ 137 public void truncateTable( 138 final TableName tableName, 139 final boolean preserveSplits, 140 final long nonceGroup, 141 final long nonce) throws IOException; 142 143 /** 144 * Modify the descriptor of an existing table 145 * @param tableName The table name 146 * @param descriptor The updated table descriptor 147 * @param nonceGroup 148 * @param nonce 149 * @throws IOException 150 */ 151 void modifyTable( 152 final TableName tableName, 153 final HTableDescriptor descriptor, 154 final long nonceGroup, 155 final long nonce) 156 throws IOException; 157 158 /** 159 * Enable an existing table 160 * @param tableName The table name 161 * @param nonceGroup 162 * @param nonce 163 * @throws IOException 164 */ 165 long enableTable( 166 final TableName tableName, 167 final long nonceGroup, 168 final long nonce) throws IOException; 169 170 /** 171 * Disable an existing table 172 * @param tableName The table name 173 * @param nonceGroup 174 * @param nonce 175 * @throws IOException 176 */ 177 long disableTable( 178 final TableName tableName, 179 final long nonceGroup, 180 final long nonce) throws IOException; 181 182 183 /** 184 * Add a new column to an existing table 185 * @param tableName The table name 186 * @param column The column definition 187 * @param nonceGroup 188 * @param nonce 189 * @throws IOException 190 */ 191 void addColumn( 192 final TableName tableName, 193 final HColumnDescriptor column, 194 final long nonceGroup, 195 final long nonce) 196 throws IOException; 197 198 /** 199 * Modify the column descriptor of an existing column in an existing table 200 * @param tableName The table name 201 * @param descriptor The updated column definition 202 * @param nonceGroup 203 * @param nonce 204 * @throws IOException 205 */ 206 void modifyColumn( 207 final TableName tableName, 208 final HColumnDescriptor descriptor, 209 final long nonceGroup, 210 final long nonce) 211 throws IOException; 212 213 /** 214 * Delete a column from an existing table 215 * @param tableName The table name 216 * @param columnName The column name 217 * @param nonceGroup 218 * @param nonce 219 * @throws IOException 220 */ 221 void deleteColumn( 222 final TableName tableName, 223 final byte[] columnName, 224 final long nonceGroup, 225 final long nonce) 226 throws IOException; 227 228 /** 229 * @return Return table descriptors implementation. 230 */ 231 TableDescriptors getTableDescriptors(); 232 233 /** 234 * @return true if master enables ServerShutdownHandler; 235 */ 236 boolean isServerShutdownHandlerEnabled(); 237 238 /** 239 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint. 240 * 241 * <p> 242 * Only a single instance may be registered for a given {@link Service} subclass (the 243 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}. 244 * After the first registration, subsequent calls with the same service name will fail with 245 * a return value of {@code false}. 246 * </p> 247 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint 248 * @return {@code true} if the registration was successful, {@code false} 249 * otherwise 250 */ 251 boolean registerService(Service instance); 252 253 /** 254 * Merge two regions. The real implementation is on the regionserver, master 255 * just move the regions together and send MERGE RPC to regionserver 256 * @param region_a region to merge 257 * @param region_b region to merge 258 * @param forcible true if do a compulsory merge, otherwise we will only merge 259 * two adjacent regions 260 * @throws IOException 261 */ 262 void dispatchMergingRegions( 263 final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible 264 ) throws IOException; 265 266 /** 267 * @return true if master is initialized 268 */ 269 boolean isInitialized(); 270 271 /** 272 * Create a new namespace 273 * @param descriptor descriptor which describes the new namespace 274 * @throws IOException 275 */ 276 public void createNamespace(NamespaceDescriptor descriptor) throws IOException; 277 278 /** 279 * Modify an existing namespace 280 * @param descriptor descriptor which updates the existing namespace 281 * @throws IOException 282 */ 283 public void modifyNamespace(NamespaceDescriptor descriptor) throws IOException; 284 285 /** 286 * Delete an existing namespace. Only empty namespaces (no tables) can be removed. 287 * @param name namespace name 288 * @throws IOException 289 */ 290 public void deleteNamespace(String name) throws IOException; 291 292 /** 293 * Abort a procedure. 294 * @param procId ID of the procedure 295 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? 296 * @return true if aborted, false if procedure already completed or does not exist 297 * @throws IOException 298 */ 299 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) 300 throws IOException; 301 302 /** 303 * List procedures 304 * @return procedure list 305 * @throws IOException 306 */ 307 public List<ProcedureInfo> listProcedures() throws IOException; 308 309 /** 310 * Get a namespace descriptor by name 311 * @param name name of namespace descriptor 312 * @return A descriptor 313 * @throws IOException 314 */ 315 public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException; 316 317 /** 318 * List available namespace descriptors 319 * @return A descriptor 320 * @throws IOException 321 */ 322 public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException; 323 324 /** 325 * Get list of table descriptors by namespace 326 * @param name namespace name 327 * @return descriptors 328 * @throws IOException 329 */ 330 public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException; 331 332 /** 333 * Get list of table names by namespace 334 * @param name namespace name 335 * @return table names 336 * @throws IOException 337 */ 338 public List<TableName> listTableNamesByNamespace(String name) throws IOException; 339 340 /** 341 * @param table 342 * @return the timestamp of the last successful major compaction for the passed table, 343 * or 0 if no HFile resulting from a major compaction exists 344 * @throws IOException 345 */ 346 public long getLastMajorCompactionTimestamp(TableName table) throws IOException; 347 348 /** 349 * @param regionName 350 * @return the timestamp of the last successful major compaction for the passed region 351 * or 0 if no HFile resulting from a major compaction exists 352 * @throws IOException 353 */ 354 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException; 355 }