001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master; 019 020import com.google.protobuf.Service; 021 022import java.io.IOException; 023import java.util.List; 024import org.apache.hadoop.hbase.Server; 025import org.apache.hadoop.hbase.ServerName; 026import org.apache.hadoop.hbase.TableDescriptors; 027import org.apache.hadoop.hbase.TableName; 028import org.apache.hadoop.hbase.TableNotDisabledException; 029import org.apache.hadoop.hbase.TableNotFoundException; 030import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 031import org.apache.hadoop.hbase.client.MasterSwitchType; 032import org.apache.hadoop.hbase.client.NormalizeTableFilterParams; 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.janitor.CatalogJanitor; 039import org.apache.hadoop.hbase.master.locking.LockManager; 040import org.apache.hadoop.hbase.master.normalizer.RegionNormalizerManager; 041import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 042import org.apache.hadoop.hbase.master.replication.ReplicationPeerManager; 043import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; 044import org.apache.hadoop.hbase.master.zksyncer.MetaLocationSyncer; 045import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost; 046import org.apache.hadoop.hbase.procedure2.LockedResource; 047import org.apache.hadoop.hbase.procedure2.Procedure; 048import org.apache.hadoop.hbase.procedure2.ProcedureEvent; 049import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 050import org.apache.hadoop.hbase.quotas.MasterQuotaManager; 051import org.apache.hadoop.hbase.replication.ReplicationException; 052import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 053import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; 054import org.apache.hadoop.hbase.security.access.AccessChecker; 055import org.apache.hadoop.hbase.security.access.ZKPermissionWatcher; 056import org.apache.yetus.audience.InterfaceAudience; 057 058/** 059 * A curated subset of services provided by {@link HMaster}. 060 * For use internally only. Passed to Managers, Services and Chores so can pass less-than-a 061 * full-on HMaster at test-time. Be judicious adding API. Changes cause ripples through 062 * the code base. 063 */ 064@InterfaceAudience.Private 065public interface MasterServices extends Server { 066 /** 067 * @return the underlying snapshot manager 068 */ 069 SnapshotManager getSnapshotManager(); 070 071 /** 072 * @return the underlying MasterProcedureManagerHost 073 */ 074 MasterProcedureManagerHost getMasterProcedureManagerHost(); 075 076 /** 077 * @return Master's instance of {@link ClusterSchema} 078 */ 079 ClusterSchema getClusterSchema(); 080 081 /** 082 * @return Master's instance of the {@link AssignmentManager} 083 */ 084 AssignmentManager getAssignmentManager(); 085 086 /** 087 * @return Master's filesystem {@link MasterFileSystem} utility class. 088 */ 089 MasterFileSystem getMasterFileSystem(); 090 091 /** 092 * @return Master's WALs {@link MasterWalManager} utility class. 093 */ 094 MasterWalManager getMasterWalManager(); 095 096 /** 097 * @return Master's {@link ServerManager} instance. 098 */ 099 ServerManager getServerManager(); 100 101 /** 102 * @return Master's instance of {@link ExecutorService} 103 */ 104 ExecutorService getExecutorService(); 105 106 /** 107 * @return Master's instance of {@link TableStateManager} 108 */ 109 TableStateManager getTableStateManager(); 110 111 /** 112 * @return Master's instance of {@link MasterCoprocessorHost} 113 */ 114 MasterCoprocessorHost getMasterCoprocessorHost(); 115 116 /** 117 * @return Master's instance of {@link MasterQuotaManager} 118 */ 119 MasterQuotaManager getMasterQuotaManager(); 120 121 /** 122 * @return Master's instance of {@link RegionNormalizerManager} 123 */ 124 RegionNormalizerManager getRegionNormalizerManager(); 125 126 /** 127 * @return Master's instance of {@link CatalogJanitor} 128 */ 129 CatalogJanitor getCatalogJanitor(); 130 131 /** 132 * @return Master's instance of {@link ProcedureExecutor} 133 */ 134 ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor(); 135 136 /** 137 * @return Tripped when Master has finished initialization. 138 */ 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 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint. 326 * <p/> 327 * Only a single instance may be registered for a given {@link Service} subclass (the instances 328 * are keyed on 329 * {@link org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}. 330 * After the first registration, subsequent calls with the same service name will fail with a 331 * return value of {@code false}. 332 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint 333 * @return {@code true} if the registration was successful, {@code false} otherwise 334 */ 335 boolean registerService(Service instance); 336 337 /** 338 * @return true if master is the active one 339 */ 340 boolean isActiveMaster(); 341 342 /** 343 * @return true if master is initialized 344 */ 345 boolean isInitialized(); 346 347 /** 348 * @return true if master is in maintanceMode 349 * @throws IOException if the inquiry failed due to an IO problem 350 */ 351 boolean isInMaintenanceMode(); 352 353 /** 354 * Checks master state before initiating action over region topology. 355 * @param action the name of the action under consideration, for logging. 356 * @return {@code true} when the caller should exit early, {@code false} otherwise. 357 */ 358 boolean skipRegionManagementAction(final String action); 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 long 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 long 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 long 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 long 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 * Returns the {@link ReplicationPeerManager}. 465 */ 466 ReplicationPeerManager getReplicationPeerManager(); 467 468 /** 469 * Update the peerConfig for the specified peer 470 * @param peerId a short name that identifies the peer 471 * @param peerConfig new config for the peer 472 */ 473 long updateReplicationPeerConfig(String peerId, ReplicationPeerConfig peerConfig) 474 throws ReplicationException, IOException; 475 476 /** 477 * Return a list of replication peers. 478 * @param regex The regular expression to match peer id 479 * @return a list of replication peers description 480 */ 481 List<ReplicationPeerDescription> listReplicationPeers(String regex) throws ReplicationException, 482 IOException; 483 484 /** 485 * @return {@link LockManager} to lock namespaces/tables/regions. 486 */ 487 LockManager getLockManager(); 488 489 public String getRegionServerVersion(final ServerName sn); 490 491 /** 492 * Called when a new RegionServer is added to the cluster. 493 * Checks if new server has a newer version than any existing server and will move system tables 494 * there if so. 495 */ 496 public void checkIfShouldMoveSystemRegionAsync(); 497 498 String getClientIdAuditPrefix(); 499 500 /** 501 * @return True if cluster is up; false if cluster is not up (we are shutting down). 502 */ 503 boolean isClusterUp(); 504 505 /** 506 * @return return null if current is zk-based WAL splitting 507 */ 508 default SplitWALManager getSplitWALManager(){ 509 return null; 510 } 511 512 /** 513 * @return the {@link AccessChecker} 514 */ 515 AccessChecker getAccessChecker(); 516 517 /** 518 * @return the {@link ZKPermissionWatcher} 519 */ 520 ZKPermissionWatcher getZKPermissionWatcher(); 521 522 /** 523 * Execute region plans with throttling 524 * @param plans to execute 525 * @return succeeded plans 526 */ 527 List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans); 528 529 /** 530 * Run the ReplicationBarrierChore. 531 */ 532 void runReplicationBarrierCleaner(); 533 534 /** 535 * Perform normalization of cluster. 536 * @param ntfp Selection criteria for identifying which tables to normalize. 537 * @param isHighPriority {@code true} when these requested tables should skip to the front of 538 * the queue. 539 * @return {@code true} when the request was submitted, {@code false} otherwise. 540 */ 541 boolean normalizeRegions( 542 final NormalizeTableFilterParams ntfp, final boolean isHighPriority) throws IOException; 543 544 /** 545 * Get the meta location syncer. 546 * <p/> 547 * We need to get this in MTP to tell the syncer the new meta replica count. 548 */ 549 MetaLocationSyncer getMetaLocationSyncer(); 550}