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 java.io.IOException; 021import java.util.List; 022import java.util.concurrent.Semaphore; 023import org.apache.hadoop.hbase.Server; 024import org.apache.hadoop.hbase.ServerName; 025import org.apache.hadoop.hbase.TableDescriptors; 026import org.apache.hadoop.hbase.TableName; 027import org.apache.hadoop.hbase.TableNotDisabledException; 028import org.apache.hadoop.hbase.TableNotFoundException; 029import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; 030import org.apache.hadoop.hbase.client.MasterSwitchType; 031import org.apache.hadoop.hbase.client.NormalizeTableFilterParams; 032import org.apache.hadoop.hbase.client.RegionInfo; 033import org.apache.hadoop.hbase.client.TableDescriptor; 034import org.apache.hadoop.hbase.executor.ExecutorService; 035import org.apache.hadoop.hbase.favored.FavoredNodesManager; 036import org.apache.hadoop.hbase.keymeta.KeyManagementService; 037import org.apache.hadoop.hbase.master.assignment.AssignmentManager; 038import org.apache.hadoop.hbase.master.hbck.HbckChore; 039import org.apache.hadoop.hbase.master.janitor.CatalogJanitor; 040import org.apache.hadoop.hbase.master.locking.LockManager; 041import org.apache.hadoop.hbase.master.normalizer.RegionNormalizerManager; 042import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 043import org.apache.hadoop.hbase.master.replication.ReplicationPeerManager; 044import org.apache.hadoop.hbase.master.replication.SyncReplicationReplayWALManager; 045import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; 046import org.apache.hadoop.hbase.master.zksyncer.MetaLocationSyncer; 047import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost; 048import org.apache.hadoop.hbase.procedure2.LockedResource; 049import org.apache.hadoop.hbase.procedure2.Procedure; 050import org.apache.hadoop.hbase.procedure2.ProcedureEvent; 051import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 052import org.apache.hadoop.hbase.quotas.MasterQuotaManager; 053import org.apache.hadoop.hbase.quotas.RpcThrottleStateStore; 054import org.apache.hadoop.hbase.replication.ReplicationException; 055import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; 056import org.apache.hadoop.hbase.replication.ReplicationPeerDescription; 057import org.apache.hadoop.hbase.replication.SyncReplicationState; 058import org.apache.hadoop.hbase.replication.master.ReplicationLogCleanerBarrier; 059import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager; 060import org.apache.hadoop.hbase.security.access.AccessChecker; 061import org.apache.hadoop.hbase.security.access.ZKPermissionWatcher; 062import org.apache.yetus.audience.InterfaceAudience; 063 064import org.apache.hbase.thirdparty.com.google.protobuf.Service; 065 066/** 067 * A curated subset of services provided by {@link HMaster}. For use internally only. Passed to 068 * Managers, Services and Chores so can pass less-than-a full-on HMaster at test-time. Be judicious 069 * adding API. Changes cause ripples through the code base. 070 */ 071@InterfaceAudience.Private 072public interface MasterServices extends Server, KeyManagementService { 073 /** Returns the underlying snapshot manager */ 074 SnapshotManager getSnapshotManager(); 075 076 /** Returns the underlying MasterProcedureManagerHost */ 077 MasterProcedureManagerHost getMasterProcedureManagerHost(); 078 079 /** Returns Master's instance of {@link ClusterSchema} */ 080 ClusterSchema getClusterSchema(); 081 082 /** Returns Master's instance of the {@link AssignmentManager} */ 083 AssignmentManager getAssignmentManager(); 084 085 /** Returns Master's filesystem {@link MasterFileSystem} utility class. */ 086 MasterFileSystem getMasterFileSystem(); 087 088 /** Returns Master's WALs {@link MasterWalManager} utility class. */ 089 MasterWalManager getMasterWalManager(); 090 091 /** Rotates the system key if changed, returns true if a new key was detected and rotated */ 092 boolean rotateSystemKeyIfChanged() throws IOException; 093 094 /** Returns Master's {@link ServerManager} instance. */ 095 ServerManager getServerManager(); 096 097 /** Returns Master's instance of {@link ExecutorService} */ 098 ExecutorService getExecutorService(); 099 100 /** Returns Master's instance of {@link TableStateManager} */ 101 TableStateManager getTableStateManager(); 102 103 /** Returns Master's instance of {@link MasterCoprocessorHost} */ 104 MasterCoprocessorHost getMasterCoprocessorHost(); 105 106 /** Returns Master's instance of {@link MasterQuotaManager} */ 107 MasterQuotaManager getMasterQuotaManager(); 108 109 /** Returns Master's instance of {@link RegionNormalizerManager} */ 110 RegionNormalizerManager getRegionNormalizerManager(); 111 112 /** Returns Master's instance of {@link CatalogJanitor} */ 113 CatalogJanitor getCatalogJanitor(); 114 115 /** Returns Master's instance of {@link HbckChore} */ 116 HbckChore getHbckChore(); 117 118 /** Returns Master's instance of {@link ProcedureExecutor} */ 119 ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor(); 120 121 /** Returns Tripped when Master has finished initialization. */ 122 public ProcedureEvent<?> getInitializedEvent(); 123 124 /** Returns Master's instance of {@link MetricsMaster} */ 125 MetricsMaster getMasterMetrics(); 126 127 /** 128 * Check table is modifiable; i.e. exists and is offline. 129 * @param tableName Name of table to check. 130 */ 131 // We actually throw the exceptions mentioned in the 132 void checkTableModifiable(final TableName tableName) 133 throws IOException, TableNotFoundException, TableNotDisabledException; 134 135 /** 136 * Create a table using the given table definition. 137 * @param desc The table definition 138 * @param splitKeys Starting row keys for the initial table regions. If null a single region is 139 * created. 140 */ 141 long createTable(final TableDescriptor desc, final byte[][] splitKeys, final long nonceGroup, 142 final long nonce) throws IOException; 143 144 /** 145 * Create a system table using the given table definition. 146 * @param tableDescriptor The system table definition a single region is created. 147 */ 148 long createSystemTable(final TableDescriptor tableDescriptor) throws IOException; 149 150 /** 151 * Delete a table 152 * @param tableName The table name 153 */ 154 long deleteTable(final TableName tableName, final long nonceGroup, final long nonce) 155 throws IOException; 156 157 /** 158 * Truncate a table 159 * @param tableName The table name 160 * @param preserveSplits True if the splits should be preserved 161 */ 162 public long truncateTable(final TableName tableName, final boolean preserveSplits, 163 final long nonceGroup, final long nonce) throws IOException; 164 165 /** 166 * Modify the descriptor of an existing table 167 * @param tableName The table name 168 * @param descriptor The updated table descriptor 169 */ 170 default long modifyTable(final TableName tableName, final TableDescriptor descriptor, 171 final long nonceGroup, final long nonce) throws IOException { 172 return modifyTable(tableName, descriptor, nonceGroup, nonce, true); 173 } 174 175 /** 176 * Modify the descriptor of an existing table 177 * @param tableName The table name 178 * @param descriptor The updated table descriptor 179 * @param reopenRegions Whether to reopen regions after modifying the table descriptor 180 */ 181 long modifyTable(final TableName tableName, final TableDescriptor descriptor, 182 final long nonceGroup, final long nonce, final boolean reopenRegions) throws IOException; 183 184 /** 185 * Modify the store file tracker of an existing table 186 */ 187 long modifyTableStoreFileTracker(final TableName tableName, final String dstSFT, 188 final long nonceGroup, final long nonce) throws IOException; 189 190 /** 191 * Enable an existing table 192 * @param tableName The table name 193 */ 194 long enableTable(final TableName tableName, final long nonceGroup, final long nonce) 195 throws IOException; 196 197 /** 198 * Disable an existing table 199 * @param tableName The table name 200 */ 201 long disableTable(final TableName tableName, final long nonceGroup, final long nonce) 202 throws IOException; 203 204 /** 205 * Add a new column to an existing table 206 * @param tableName The table name 207 * @param column The column definition 208 */ 209 long addColumn(final TableName tableName, final ColumnFamilyDescriptor column, 210 final long nonceGroup, final long nonce) throws IOException; 211 212 /** 213 * Modify the column descriptor of an existing column in an existing table 214 * @param tableName The table name 215 * @param descriptor The updated column definition 216 */ 217 long modifyColumn(final TableName tableName, final ColumnFamilyDescriptor descriptor, 218 final long nonceGroup, final long nonce) throws IOException; 219 220 /** 221 * Modify the store file tracker of an existing column in an existing table 222 */ 223 long modifyColumnStoreFileTracker(final TableName tableName, final byte[] family, 224 final String dstSFT, final long nonceGroup, final long nonce) throws IOException; 225 226 /** 227 * Delete a column from an existing table 228 * @param tableName The table name 229 * @param columnName The column name 230 */ 231 long deleteColumn(final TableName tableName, final byte[] columnName, final long nonceGroup, 232 final long nonce) throws IOException; 233 234 /** 235 * Merge regions in a table. 236 * @param regionsToMerge daughter regions to merge 237 * @param forcible whether to force to merge even two regions are not adjacent 238 * @param nonceGroup used to detect duplicate 239 * @param nonce used to detect duplicate 240 * @return procedure Id 241 */ 242 long mergeRegions(final RegionInfo[] regionsToMerge, final boolean forcible, 243 final long nonceGroup, final long nonce) throws IOException; 244 245 /** 246 * Split a region. 247 * @param regionInfo region to split 248 * @param splitRow split point 249 * @param nonceGroup used to detect duplicate 250 * @param nonce used to detect duplicate 251 * @return procedure Id 252 */ 253 long splitRegion(final RegionInfo regionInfo, final byte[] splitRow, final long nonceGroup, 254 final long nonce) throws IOException; 255 256 /** Returns Return table descriptors implementation. */ 257 TableDescriptors getTableDescriptors(); 258 259 /** 260 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint. 261 * <p/> 262 * Only a single instance may be registered for a given {@link Service} subclass (the instances 263 * are keyed on 264 * {@link org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}. 265 * After the first registration, subsequent calls with the same service name will fail with a 266 * return value of {@code false}. 267 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint 268 * @return {@code true} if the registration was successful, {@code false} otherwise 269 */ 270 boolean registerService(Service instance); 271 272 /** Returns true if master is the active one */ 273 boolean isActiveMaster(); 274 275 /** Returns timestamp in millis when this master became the active one. */ 276 long getMasterActiveTime(); 277 278 /** Returns true if master is initialized */ 279 boolean isInitialized(); 280 281 /** 282 * @return true if master is in maintanceMode 283 * @throws IOException if the inquiry failed due to an IO problem 284 */ 285 boolean isInMaintenanceMode(); 286 287 /** 288 * Checks master state before initiating action over region topology. 289 * @param action the name of the action under consideration, for logging. 290 * @return {@code true} when the caller should exit early, {@code false} otherwise. 291 */ 292 boolean skipRegionManagementAction(final String action); 293 294 /** 295 * Abort a procedure. 296 * @param procId ID of the procedure 297 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? 298 * @return true if aborted, false if procedure already completed or does not exist 299 */ 300 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) 301 throws IOException; 302 303 /** 304 * Get procedures 305 * @return procedure list 306 */ 307 public List<Procedure<?>> getProcedures() throws IOException; 308 309 /** 310 * Get locks 311 * @return lock list 312 */ 313 public List<LockedResource> getLocks() throws IOException; 314 315 /** 316 * Get list of table descriptors by namespace 317 * @param name namespace name 318 */ 319 public List<TableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException; 320 321 /** 322 * Get list of table names by namespace 323 * @param name namespace name 324 * @return table names 325 */ 326 public List<TableName> listTableNamesByNamespace(String name) throws IOException; 327 328 /** 329 * @param table the table for which last successful major compaction time is queried 330 * @return the timestamp of the last successful major compaction for the passed table, or 0 if no 331 * HFile resulting from a major compaction exists 332 */ 333 public long getLastMajorCompactionTimestamp(TableName table) throws IOException; 334 335 /** 336 * Returns the timestamp of the last successful major compaction for the passed region or 0 if no 337 * HFile resulting from a major compaction exists 338 */ 339 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException; 340 341 /** Returns load balancer */ 342 public LoadBalancer getLoadBalancer(); 343 344 boolean isSplitOrMergeEnabled(MasterSwitchType switchType); 345 346 /** Returns Favored Nodes Manager */ 347 public FavoredNodesManager getFavoredNodesManager(); 348 349 /** 350 * Add a new replication peer for replicating data to slave cluster 351 * @param peerId a short name that identifies the peer 352 * @param peerConfig configuration for the replication slave cluster 353 * @param enabled peer state, true if ENABLED and false if DISABLED 354 */ 355 long addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled) 356 throws ReplicationException, IOException; 357 358 /** 359 * Removes a peer and stops the replication 360 * @param peerId a short name that identifies the peer 361 */ 362 long removeReplicationPeer(String peerId) throws ReplicationException, IOException; 363 364 /** 365 * Restart the replication stream to the specified peer 366 * @param peerId a short name that identifies the peer 367 */ 368 long enableReplicationPeer(String peerId) throws ReplicationException, IOException; 369 370 /** 371 * Stop the replication stream to the specified peer 372 * @param peerId a short name that identifies the peer 373 */ 374 long disableReplicationPeer(String peerId) throws ReplicationException, IOException; 375 376 /** 377 * Returns the configured ReplicationPeerConfig for the specified peer 378 * @param peerId a short name that identifies the peer 379 * @return ReplicationPeerConfig for the peer 380 */ 381 ReplicationPeerConfig getReplicationPeerConfig(String peerId) 382 throws ReplicationException, IOException; 383 384 /** 385 * Returns the {@link ReplicationPeerManager}. 386 */ 387 ReplicationPeerManager getReplicationPeerManager(); 388 389 /** 390 * Returns the {@link ReplicationLogCleanerBarrier}. It will be used at multiple places so we put 391 * it in MasterServices directly. 392 */ 393 ReplicationLogCleanerBarrier getReplicationLogCleanerBarrier(); 394 395 /** 396 * Returns the SyncReplicationPeerLock. 397 */ 398 Semaphore getSyncReplicationPeerLock(); 399 400 /** 401 * Returns the {@link SyncReplicationReplayWALManager}. 402 */ 403 SyncReplicationReplayWALManager getSyncReplicationReplayWALManager(); 404 405 /** 406 * Update the peerConfig for the specified peer 407 * @param peerId a short name that identifies the peer 408 * @param peerConfig new config for the peer 409 */ 410 long updateReplicationPeerConfig(String peerId, ReplicationPeerConfig peerConfig) 411 throws ReplicationException, IOException; 412 413 /** 414 * Return a list of replication peers. 415 * @param regex The regular expression to match peer id 416 * @return a list of replication peers description 417 */ 418 List<ReplicationPeerDescription> listReplicationPeers(String regex) 419 throws ReplicationException, IOException; 420 421 /** 422 * Set current cluster state for a synchronous replication peer. 423 * @param peerId a short name that identifies the peer 424 * @param clusterState state of current cluster 425 */ 426 long transitReplicationPeerSyncReplicationState(String peerId, SyncReplicationState clusterState) 427 throws ReplicationException, IOException; 428 429 boolean replicationPeerModificationSwitch(boolean on) throws IOException; 430 431 boolean isReplicationPeerModificationEnabled(); 432 433 /** Returns {@link LockManager} to lock namespaces/tables/regions. */ 434 LockManager getLockManager(); 435 436 public String getRegionServerVersion(final ServerName sn); 437 438 /** 439 * Called when a new RegionServer is added to the cluster. Checks if new server has a newer 440 * version than any existing server and will move system tables there if so. 441 */ 442 public void checkIfShouldMoveSystemRegionAsync(); 443 444 String getClientIdAuditPrefix(); 445 446 /** Returns True if cluster is up; false if cluster is not up (we are shutting down). */ 447 boolean isClusterUp(); 448 449 /** Returns return null if current is zk-based WAL splitting */ 450 default SplitWALManager getSplitWALManager() { 451 return null; 452 } 453 454 /** Returns the {@link AccessChecker} */ 455 AccessChecker getAccessChecker(); 456 457 /** Returns the {@link ZKPermissionWatcher} */ 458 ZKPermissionWatcher getZKPermissionWatcher(); 459 460 /** 461 * Execute region plans with throttling 462 * @param plans to execute 463 * @return succeeded plans 464 */ 465 List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans); 466 467 /** 468 * Run the ReplicationBarrierChore. 469 */ 470 void runReplicationBarrierCleaner(); 471 472 /** Returns the {@link RSGroupInfoManager} */ 473 RSGroupInfoManager getRSGroupInfoManager(); 474 475 /** 476 * Queries the state of the {@code LoadBalancerStateStore}. If the balancer is not initialized, 477 * false is returned. 478 * @return The state of the load balancer, or false if the load balancer isn't defined. 479 */ 480 boolean isBalancerOn(); 481 482 /** 483 * Perform normalization of cluster. 484 * @param ntfp Selection criteria for identifying which tables to normalize. 485 * @param isHighPriority {@code true} when these requested tables should skip to the front of the 486 * queue. 487 * @return {@code true} when the request was submitted, {@code false} otherwise. 488 */ 489 boolean normalizeRegions(final NormalizeTableFilterParams ntfp, final boolean isHighPriority) 490 throws IOException; 491 492 /** 493 * Get the meta location syncer. 494 * <p/> 495 * We need to get this in MTP to tell the syncer the new meta replica count. 496 */ 497 MetaLocationSyncer getMetaLocationSyncer(); 498 499 /** 500 * Flush master local region 501 */ 502 void flushMasterStore() throws IOException; 503 504 /** 505 * Flush an existing table 506 * @param tableName The table name 507 * @param columnFamilies The column families to flush 508 * @param nonceGroup the nonce group 509 * @param nonce the nonce 510 * @return the flush procedure id 511 */ 512 long flushTable(final TableName tableName, final List<byte[]> columnFamilies, 513 final long nonceGroup, final long nonce) throws IOException; 514 515 /** 516 * Truncate region 517 * @param regionInfo region to be truncated 518 * @param nonceGroup the nonce group 519 * @param nonce the nonce 520 * @return procedure Id 521 */ 522 long truncateRegion(RegionInfo regionInfo, long nonceGroup, long nonce) throws IOException; 523 524 /** 525 * Roll WAL writer for all RegionServers 526 * @return procedure id 527 */ 528 long rollAllWALWriters(long nonceGroup, long nonce) throws IOException; 529 530 RpcThrottleStateStore getRpcThrottleStateStore(); 531}