001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.master; 020 021import java.io.IOException; 022import java.util.List; 023 024import org.apache.hadoop.hbase.HBaseIOException; 025import org.apache.hadoop.hbase.Server; 026import org.apache.hadoop.hbase.ServerName; 027import org.apache.hadoop.hbase.TableDescriptors; 028import org.apache.hadoop.hbase.TableName; 029import org.apache.hadoop.hbase.TableNotDisabledException; 030import org.apache.hadoop.hbase.TableNotFoundException; 031import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 032import org.apache.hadoop.hbase.client.MasterSwitchType; 033import org.apache.hadoop.hbase.client.RegionInfo; 034import org.apache.hadoop.hbase.client.TableDescriptor; 035import org.apache.hadoop.hbase.executor.ExecutorService; 036import org.apache.hadoop.hbase.favored.FavoredNodesManager; 037import org.apache.hadoop.hbase.master.assignment.AssignmentManager; 038import org.apache.hadoop.hbase.master.locking.LockManager; 039import org.apache.hadoop.hbase.master.normalizer.RegionNormalizer; 040import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 041import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; 042import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost; 043import org.apache.hadoop.hbase.procedure2.LockedResource; 044import org.apache.hadoop.hbase.procedure2.Procedure; 045import org.apache.hadoop.hbase.procedure2.ProcedureEvent; 046import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 047import org.apache.hadoop.hbase.quotas.MasterQuotaManager; 048import org.apache.hadoop.hbase.replication.ReplicationException; 049import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 050import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; 051import org.apache.yetus.audience.InterfaceAudience; 052 053import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; 054 055import com.google.protobuf.Service; 056 057/** 058 * A curated subset of services provided by {@link HMaster}. 059 * For use internally only. Passed to Managers, Services and Chores so can pass less-than-a 060 * full-on HMaster at test-time. Be judicious adding API. Changes cause ripples through 061 * the code base. 062 */ 063@InterfaceAudience.Private 064public interface MasterServices extends Server { 065 /** 066 * @return the underlying snapshot manager 067 */ 068 SnapshotManager getSnapshotManager(); 069 070 /** 071 * @return the underlying MasterProcedureManagerHost 072 */ 073 MasterProcedureManagerHost getMasterProcedureManagerHost(); 074 075 /** 076 * @return Master's instance of {@link ClusterSchema} 077 */ 078 ClusterSchema getClusterSchema(); 079 080 /** 081 * @return Master's instance of the {@link AssignmentManager} 082 */ 083 AssignmentManager getAssignmentManager(); 084 085 /** 086 * @return Master's filesystem {@link MasterFileSystem} utility class. 087 */ 088 MasterFileSystem getMasterFileSystem(); 089 090 /** 091 * @return Master's WALs {@link MasterWalManager} utility class. 092 */ 093 MasterWalManager getMasterWalManager(); 094 095 /** 096 * @return Master's {@link ServerManager} instance. 097 */ 098 ServerManager getServerManager(); 099 100 /** 101 * @return Master's instance of {@link ExecutorService} 102 */ 103 ExecutorService getExecutorService(); 104 105 /** 106 * @return Master's instance of {@link TableStateManager} 107 */ 108 TableStateManager getTableStateManager(); 109 110 /** 111 * @return Master's instance of {@link MasterCoprocessorHost} 112 */ 113 MasterCoprocessorHost getMasterCoprocessorHost(); 114 115 /** 116 * @return Master's instance of {@link MasterQuotaManager} 117 */ 118 MasterQuotaManager getMasterQuotaManager(); 119 120 /** 121 * @return Master's instance of {@link RegionNormalizer} 122 */ 123 RegionNormalizer getRegionNormalizer(); 124 125 /** 126 * @return Master's instance of {@link CatalogJanitor} 127 */ 128 CatalogJanitor getCatalogJanitor(); 129 130 /** 131 * @return Master's instance of {@link ProcedureExecutor} 132 */ 133 ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor(); 134 135 /** 136 * @return Tripped when Master has finished initialization. 137 */ 138 @VisibleForTesting 139 public ProcedureEvent getInitializedEvent(); 140 141 /** 142 * @return Master's instance of {@link MetricsMaster} 143 */ 144 MetricsMaster getMasterMetrics(); 145 146 /** 147 * Check table is modifiable; i.e. exists and is offline. 148 * @param tableName Name of table to check. 149 * @throws TableNotDisabledException 150 * @throws TableNotFoundException 151 * @throws IOException 152 */ 153 // We actually throw the exceptions mentioned in the 154 void checkTableModifiable(final TableName tableName) 155 throws IOException, TableNotFoundException, TableNotDisabledException; 156 157 /** 158 * Create a table using the given table definition. 159 * @param desc The table definition 160 * @param splitKeys Starting row keys for the initial table regions. If null 161 * @param nonceGroup 162 * @param nonce 163 * a single region is created. 164 */ 165 long createTable( 166 final TableDescriptor desc, 167 final byte[][] splitKeys, 168 final long nonceGroup, 169 final long nonce) throws IOException; 170 171 /** 172 * Create a system table using the given table definition. 173 * @param tableDescriptor The system table definition 174 * a single region is created. 175 */ 176 long createSystemTable(final TableDescriptor tableDescriptor) throws IOException; 177 178 /** 179 * Delete a table 180 * @param tableName The table name 181 * @param nonceGroup 182 * @param nonce 183 * @throws IOException 184 */ 185 long deleteTable( 186 final TableName tableName, 187 final long nonceGroup, 188 final long nonce) throws IOException; 189 190 /** 191 * Truncate a table 192 * @param tableName The table name 193 * @param preserveSplits True if the splits should be preserved 194 * @param nonceGroup 195 * @param nonce 196 * @throws IOException 197 */ 198 public long truncateTable( 199 final TableName tableName, 200 final boolean preserveSplits, 201 final long nonceGroup, 202 final long nonce) throws IOException; 203 204 /** 205 * Modify the descriptor of an existing table 206 * @param tableName The table name 207 * @param descriptor The updated table descriptor 208 * @param nonceGroup 209 * @param nonce 210 * @throws IOException 211 */ 212 long modifyTable( 213 final TableName tableName, 214 final TableDescriptor descriptor, 215 final long nonceGroup, 216 final long nonce) 217 throws IOException; 218 219 /** 220 * Enable an existing table 221 * @param tableName The table name 222 * @param nonceGroup 223 * @param nonce 224 * @throws IOException 225 */ 226 long enableTable( 227 final TableName tableName, 228 final long nonceGroup, 229 final long nonce) throws IOException; 230 231 /** 232 * Disable an existing table 233 * @param tableName The table name 234 * @param nonceGroup 235 * @param nonce 236 * @throws IOException 237 */ 238 long disableTable( 239 final TableName tableName, 240 final long nonceGroup, 241 final long nonce) throws IOException; 242 243 244 /** 245 * Add a new column to an existing table 246 * @param tableName The table name 247 * @param column The column definition 248 * @param nonceGroup 249 * @param nonce 250 * @throws IOException 251 */ 252 long addColumn( 253 final TableName tableName, 254 final ColumnFamilyDescriptor column, 255 final long nonceGroup, 256 final long nonce) 257 throws IOException; 258 259 /** 260 * Modify the column descriptor of an existing column in an existing table 261 * @param tableName The table name 262 * @param descriptor The updated column definition 263 * @param nonceGroup 264 * @param nonce 265 * @throws IOException 266 */ 267 long modifyColumn( 268 final TableName tableName, 269 final ColumnFamilyDescriptor descriptor, 270 final long nonceGroup, 271 final long nonce) 272 throws IOException; 273 274 /** 275 * Delete a column from an existing table 276 * @param tableName The table name 277 * @param columnName The column name 278 * @param nonceGroup 279 * @param nonce 280 * @throws IOException 281 */ 282 long deleteColumn( 283 final TableName tableName, 284 final byte[] columnName, 285 final long nonceGroup, 286 final long nonce) 287 throws IOException; 288 289 /** 290 * Merge regions in a table. 291 * @param regionsToMerge daughter regions to merge 292 * @param forcible whether to force to merge even two regions are not adjacent 293 * @param nonceGroup used to detect duplicate 294 * @param nonce used to detect duplicate 295 * @return procedure Id 296 * @throws IOException 297 */ 298 long mergeRegions( 299 final RegionInfo[] regionsToMerge, 300 final boolean forcible, 301 final long nonceGroup, 302 final long nonce) throws IOException; 303 304 /** 305 * Split a region. 306 * @param regionInfo region to split 307 * @param splitRow split point 308 * @param nonceGroup used to detect duplicate 309 * @param nonce used to detect duplicate 310 * @return procedure Id 311 * @throws IOException 312 */ 313 long splitRegion( 314 final RegionInfo regionInfo, 315 final byte [] splitRow, 316 final long nonceGroup, 317 final long nonce) throws IOException; 318 319 /** 320 * @return Return table descriptors implementation. 321 */ 322 TableDescriptors getTableDescriptors(); 323 324 /** 325 * @return true if master enables ServerShutdownHandler; 326 */ 327 boolean isServerCrashProcessingEnabled(); 328 329 /** 330 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint. 331 * 332 * <p> 333 * Only a single instance may be registered for a given {@link Service} subclass (the 334 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}. 335 * After the first registration, subsequent calls with the same service name will fail with 336 * a return value of {@code false}. 337 * </p> 338 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint 339 * @return {@code true} if the registration was successful, {@code false} 340 * otherwise 341 */ 342 boolean registerService(Service instance); 343 344 /** 345 * @return true if master is the active one 346 */ 347 boolean isActiveMaster(); 348 349 /** 350 * @return true if master is initialized 351 */ 352 boolean isInitialized(); 353 354 /** 355 * @return true if master is in maintanceMode 356 * @throws IOException if the inquiry failed due to an IO problem 357 */ 358 boolean isInMaintenanceMode() throws IOException; 359 360 /** 361 * Abort a procedure. 362 * @param procId ID of the procedure 363 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? 364 * @return true if aborted, false if procedure already completed or does not exist 365 * @throws IOException 366 */ 367 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) 368 throws IOException; 369 370 /** 371 * Get procedures 372 * @return procedure list 373 * @throws IOException 374 */ 375 public List<Procedure<?>> getProcedures() throws IOException; 376 377 /** 378 * Get locks 379 * @return lock list 380 * @throws IOException 381 */ 382 public List<LockedResource> getLocks() throws IOException; 383 384 /** 385 * Get list of table descriptors by namespace 386 * @param name namespace name 387 * @return descriptors 388 * @throws IOException 389 */ 390 public List<TableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException; 391 392 /** 393 * Get list of table names by namespace 394 * @param name namespace name 395 * @return table names 396 * @throws IOException 397 */ 398 public List<TableName> listTableNamesByNamespace(String name) throws IOException; 399 400 /** 401 * @param table the table for which last successful major compaction time is queried 402 * @return the timestamp of the last successful major compaction for the passed table, 403 * or 0 if no HFile resulting from a major compaction exists 404 * @throws IOException 405 */ 406 public long getLastMajorCompactionTimestamp(TableName table) throws IOException; 407 408 /** 409 * @param regionName 410 * @return the timestamp of the last successful major compaction for the passed region 411 * or 0 if no HFile resulting from a major compaction exists 412 * @throws IOException 413 */ 414 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException; 415 416 /** 417 * @return load balancer 418 */ 419 public LoadBalancer getLoadBalancer(); 420 421 boolean isSplitOrMergeEnabled(MasterSwitchType switchType); 422 423 /** 424 * @return Favored Nodes Manager 425 */ 426 public FavoredNodesManager getFavoredNodesManager(); 427 428 /** 429 * Add a new replication peer for replicating data to slave cluster 430 * @param peerId a short name that identifies the peer 431 * @param peerConfig configuration for the replication slave cluster 432 * @param enabled peer state, true if ENABLED and false if DISABLED 433 */ 434 void addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled) 435 throws ReplicationException, IOException; 436 437 /** 438 * Removes a peer and stops the replication 439 * @param peerId a short name that identifies the peer 440 */ 441 void removeReplicationPeer(String peerId) throws ReplicationException, IOException; 442 443 /** 444 * Restart the replication stream to the specified peer 445 * @param peerId a short name that identifies the peer 446 */ 447 void enableReplicationPeer(String peerId) throws ReplicationException, IOException; 448 449 /** 450 * Stop the replication stream to the specified peer 451 * @param peerId a short name that identifies the peer 452 */ 453 void disableReplicationPeer(String peerId) throws ReplicationException, IOException; 454 455 /** 456 * Returns the configured ReplicationPeerConfig for the specified peer 457 * @param peerId a short name that identifies the peer 458 * @return ReplicationPeerConfig for the peer 459 */ 460 ReplicationPeerConfig getReplicationPeerConfig(String peerId) throws ReplicationException, 461 IOException; 462 463 /** 464 * Update the peerConfig for the specified peer 465 * @param peerId a short name that identifies the peer 466 * @param peerConfig new config for the peer 467 */ 468 void updateReplicationPeerConfig(String peerId, ReplicationPeerConfig peerConfig) 469 throws ReplicationException, IOException; 470 471 /** 472 * Return a list of replication peers. 473 * @param regex The regular expression to match peer id 474 * @return a list of replication peers description 475 */ 476 List<ReplicationPeerDescription> listReplicationPeers(String regex) throws ReplicationException, 477 IOException; 478 479 /** 480 * @return {@link LockManager} to lock namespaces/tables/regions. 481 */ 482 LockManager getLockManager(); 483 484 public String getRegionServerVersion(final ServerName sn); 485 486 /** 487 * Called when a new RegionServer is added to the cluster. 488 * Checks if new server has a newer version than any existing server and will move system tables 489 * there if so. 490 */ 491 public void checkIfShouldMoveSystemRegionAsync(); 492 493 /** 494 * Recover meta table. Will result in no-op is meta is already initialized. Any code that has 495 * access to master and requires to access meta during process initialization can call this 496 * method to make sure meta is initialized. 497 */ 498 boolean recoverMeta() throws IOException; 499 500 String getClientIdAuditPrefix(); 501 502 /** 503 * @return True if cluster is up; false if cluster is not up (we are shutting down). 504 */ 505 boolean isClusterUp(); 506}