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 * Create a table using the given table definition. 100 * @param desc The table definition 101 * @param splitKeys Starting row keys for the initial table regions. If null 102 * @param nonceGroup 103 * @param nonce 104 * a single region is created. 105 */ 106 long createTable( 107 final HTableDescriptor desc, 108 final byte[][] splitKeys, 109 final long nonceGroup, 110 final long nonce) throws IOException; 111 112 /** 113 * Delete a table 114 * @param tableName The table name 115 * @param nonceGroup 116 * @param nonce 117 * @throws IOException 118 */ 119 long deleteTable( 120 final TableName tableName, 121 final long nonceGroup, 122 final long nonce) throws IOException; 123 124 /** 125 * Truncate a table 126 * @param tableName The table name 127 * @param preserveSplits True if the splits should be preserved 128 * @param nonceGroup 129 * @param nonce 130 * @throws IOException 131 */ 132 public void truncateTable( 133 final TableName tableName, 134 final boolean preserveSplits, 135 final long nonceGroup, 136 final long nonce) throws IOException; 137 138 /** 139 * Modify the descriptor of an existing table 140 * @param tableName The table name 141 * @param descriptor The updated table descriptor 142 * @param nonceGroup 143 * @param nonce 144 * @throws IOException 145 */ 146 void modifyTable( 147 final TableName tableName, 148 final HTableDescriptor descriptor, 149 final long nonceGroup, 150 final long nonce) 151 throws IOException; 152 153 /** 154 * Enable an existing table 155 * @param tableName The table name 156 * @param nonceGroup 157 * @param nonce 158 * @throws IOException 159 */ 160 long enableTable( 161 final TableName tableName, 162 final long nonceGroup, 163 final long nonce) throws IOException; 164 165 /** 166 * Disable an existing table 167 * @param tableName The table name 168 * @param nonceGroup 169 * @param nonce 170 * @throws IOException 171 */ 172 long disableTable( 173 final TableName tableName, 174 final long nonceGroup, 175 final long nonce) throws IOException; 176 177 178 /** 179 * Add a new column to an existing table 180 * @param tableName The table name 181 * @param column The column definition 182 * @param nonceGroup 183 * @param nonce 184 * @throws IOException 185 */ 186 void addColumn( 187 final TableName tableName, 188 final HColumnDescriptor column, 189 final long nonceGroup, 190 final long nonce) 191 throws IOException; 192 193 /** 194 * Modify the column descriptor of an existing column in an existing table 195 * @param tableName The table name 196 * @param descriptor The updated column definition 197 * @param nonceGroup 198 * @param nonce 199 * @throws IOException 200 */ 201 void modifyColumn( 202 final TableName tableName, 203 final HColumnDescriptor descriptor, 204 final long nonceGroup, 205 final long nonce) 206 throws IOException; 207 208 /** 209 * Delete a column from an existing table 210 * @param tableName The table name 211 * @param columnName The column name 212 * @param nonceGroup 213 * @param nonce 214 * @throws IOException 215 */ 216 void deleteColumn( 217 final TableName tableName, 218 final byte[] columnName, 219 final long nonceGroup, 220 final long nonce) 221 throws IOException; 222 223 /** 224 * @return Return table descriptors implementation. 225 */ 226 TableDescriptors getTableDescriptors(); 227 228 /** 229 * @return true if master enables ServerShutdownHandler; 230 */ 231 boolean isServerCrashProcessingEnabled(); 232 233 /** 234 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint. 235 * 236 * <p> 237 * Only a single instance may be registered for a given {@link Service} subclass (the 238 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}. 239 * After the first registration, subsequent calls with the same service name will fail with 240 * a return value of {@code false}. 241 * </p> 242 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint 243 * @return {@code true} if the registration was successful, {@code false} 244 * otherwise 245 */ 246 boolean registerService(Service instance); 247 248 /** 249 * Merge two regions. The real implementation is on the regionserver, master 250 * just move the regions together and send MERGE RPC to regionserver 251 * @param region_a region to merge 252 * @param region_b region to merge 253 * @param forcible true if do a compulsory merge, otherwise we will only merge 254 * two adjacent regions 255 * @throws IOException 256 */ 257 void dispatchMergingRegions( 258 final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible 259 ) throws IOException; 260 261 /** 262 * @return true if master is initialized 263 */ 264 boolean isInitialized(); 265 266 /** 267 * Create a new namespace 268 * @param descriptor descriptor which describes the new namespace 269 * @throws IOException 270 */ 271 public void createNamespace(NamespaceDescriptor descriptor) throws IOException; 272 273 /** 274 * Modify an existing namespace 275 * @param descriptor descriptor which updates the existing namespace 276 * @throws IOException 277 */ 278 public void modifyNamespace(NamespaceDescriptor descriptor) throws IOException; 279 280 /** 281 * Delete an existing namespace. Only empty namespaces (no tables) can be removed. 282 * @param name namespace name 283 * @throws IOException 284 */ 285 public void deleteNamespace(String name) throws IOException; 286 287 /** 288 * Abort a procedure. 289 * @param procId ID of the procedure 290 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? 291 * @return true if aborted, false if procedure already completed or does not exist 292 * @throws IOException 293 */ 294 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) 295 throws IOException; 296 297 /** 298 * List procedures 299 * @return procedure list 300 * @throws IOException 301 */ 302 public List<ProcedureInfo> listProcedures() throws IOException; 303 304 /** 305 * Get a namespace descriptor by name 306 * @param name name of namespace descriptor 307 * @return A descriptor 308 * @throws IOException 309 */ 310 public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException; 311 312 /** 313 * List available namespace descriptors 314 * @return A descriptor 315 * @throws IOException 316 */ 317 public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException; 318 319 /** 320 * Get list of table descriptors by namespace 321 * @param name namespace name 322 * @return descriptors 323 * @throws IOException 324 */ 325 public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException; 326 327 /** 328 * Get list of table names by namespace 329 * @param name namespace name 330 * @return table names 331 * @throws IOException 332 */ 333 public List<TableName> listTableNamesByNamespace(String name) throws IOException; 334 335 /** 336 * @param table 337 * @return the timestamp of the last successful major compaction for the passed table, 338 * or 0 if no HFile resulting from a major compaction exists 339 * @throws IOException 340 */ 341 public long getLastMajorCompactionTimestamp(TableName table) throws IOException; 342 343 /** 344 * @param regionName 345 * @return the timestamp of the last successful major compaction for the passed region 346 * or 0 if no HFile resulting from a major compaction exists 347 * @throws IOException 348 */ 349 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException; 350 }