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