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