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 timestamp in millis when this master became the active one. */ 271 long getMasterActiveTime(); 272 273 /** Returns true if master is initialized */ 274 boolean isInitialized(); 275 276 /** 277 * @return true if master is in maintanceMode 278 * @throws IOException if the inquiry failed due to an IO problem 279 */ 280 boolean isInMaintenanceMode(); 281 282 /** 283 * Checks master state before initiating action over region topology. 284 * @param action the name of the action under consideration, for logging. 285 * @return {@code true} when the caller should exit early, {@code false} otherwise. 286 */ 287 boolean skipRegionManagementAction(final String action); 288 289 /** 290 * Abort a procedure. 291 * @param procId ID of the procedure 292 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted? 293 * @return true if aborted, false if procedure already completed or does not exist 294 */ 295 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning) 296 throws IOException; 297 298 /** 299 * Get procedures 300 * @return procedure list 301 */ 302 public List<Procedure<?>> getProcedures() throws IOException; 303 304 /** 305 * Get locks 306 * @return lock list 307 */ 308 public List<LockedResource> getLocks() throws IOException; 309 310 /** 311 * Get list of table descriptors by namespace 312 * @param name namespace name 313 */ 314 public List<TableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException; 315 316 /** 317 * Get list of table names by namespace 318 * @param name namespace name 319 * @return table names 320 */ 321 public List<TableName> listTableNamesByNamespace(String name) throws IOException; 322 323 /** 324 * @param table the table for which last successful major compaction time is queried 325 * @return the timestamp of the last successful major compaction for the passed table, or 0 if no 326 * HFile resulting from a major compaction exists 327 */ 328 public long getLastMajorCompactionTimestamp(TableName table) throws IOException; 329 330 /** 331 * Returns the timestamp of the last successful major compaction for the passed region or 0 if no 332 * HFile resulting from a major compaction exists 333 */ 334 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException; 335 336 /** Returns load balancer */ 337 public LoadBalancer getLoadBalancer(); 338 339 boolean isSplitOrMergeEnabled(MasterSwitchType switchType); 340 341 /** Returns Favored Nodes Manager */ 342 public FavoredNodesManager getFavoredNodesManager(); 343 344 /** 345 * Add a new replication peer for replicating data to slave cluster 346 * @param peerId a short name that identifies the peer 347 * @param peerConfig configuration for the replication slave cluster 348 * @param enabled peer state, true if ENABLED and false if DISABLED 349 */ 350 long addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled) 351 throws ReplicationException, IOException; 352 353 /** 354 * Removes a peer and stops the replication 355 * @param peerId a short name that identifies the peer 356 */ 357 long removeReplicationPeer(String peerId) throws ReplicationException, IOException; 358 359 /** 360 * Restart the replication stream to the specified peer 361 * @param peerId a short name that identifies the peer 362 */ 363 long enableReplicationPeer(String peerId) throws ReplicationException, IOException; 364 365 /** 366 * Stop the replication stream to the specified peer 367 * @param peerId a short name that identifies the peer 368 */ 369 long disableReplicationPeer(String peerId) throws ReplicationException, IOException; 370 371 /** 372 * Returns the configured ReplicationPeerConfig for the specified peer 373 * @param peerId a short name that identifies the peer 374 * @return ReplicationPeerConfig for the peer 375 */ 376 ReplicationPeerConfig getReplicationPeerConfig(String peerId) 377 throws ReplicationException, IOException; 378 379 /** 380 * Returns the {@link ReplicationPeerManager}. 381 */ 382 ReplicationPeerManager getReplicationPeerManager(); 383 384 /** 385 * Returns the {@link ReplicationLogCleanerBarrier}. It will be used at multiple places so we put 386 * it in MasterServices directly. 387 */ 388 ReplicationLogCleanerBarrier getReplicationLogCleanerBarrier(); 389 390 /** 391 * Returns the SyncReplicationPeerLock. 392 */ 393 Semaphore getSyncReplicationPeerLock(); 394 395 /** 396 * Returns the {@link SyncReplicationReplayWALManager}. 397 */ 398 SyncReplicationReplayWALManager getSyncReplicationReplayWALManager(); 399 400 /** 401 * Update the peerConfig for the specified peer 402 * @param peerId a short name that identifies the peer 403 * @param peerConfig new config for the peer 404 */ 405 long updateReplicationPeerConfig(String peerId, ReplicationPeerConfig peerConfig) 406 throws ReplicationException, IOException; 407 408 /** 409 * Return a list of replication peers. 410 * @param regex The regular expression to match peer id 411 * @return a list of replication peers description 412 */ 413 List<ReplicationPeerDescription> listReplicationPeers(String regex) 414 throws ReplicationException, IOException; 415 416 /** 417 * Set current cluster state for a synchronous replication peer. 418 * @param peerId a short name that identifies the peer 419 * @param clusterState state of current cluster 420 */ 421 long transitReplicationPeerSyncReplicationState(String peerId, SyncReplicationState clusterState) 422 throws ReplicationException, IOException; 423 424 boolean replicationPeerModificationSwitch(boolean on) throws IOException; 425 426 boolean isReplicationPeerModificationEnabled(); 427 428 /** Returns {@link LockManager} to lock namespaces/tables/regions. */ 429 LockManager getLockManager(); 430 431 public String getRegionServerVersion(final ServerName sn); 432 433 /** 434 * Called when a new RegionServer is added to the cluster. Checks if new server has a newer 435 * version than any existing server and will move system tables there if so. 436 */ 437 public void checkIfShouldMoveSystemRegionAsync(); 438 439 String getClientIdAuditPrefix(); 440 441 /** Returns True if cluster is up; false if cluster is not up (we are shutting down). */ 442 boolean isClusterUp(); 443 444 /** Returns return null if current is zk-based WAL splitting */ 445 default SplitWALManager getSplitWALManager() { 446 return null; 447 } 448 449 /** Returns the {@link AccessChecker} */ 450 AccessChecker getAccessChecker(); 451 452 /** Returns the {@link ZKPermissionWatcher} */ 453 ZKPermissionWatcher getZKPermissionWatcher(); 454 455 /** 456 * Execute region plans with throttling 457 * @param plans to execute 458 * @return succeeded plans 459 */ 460 List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans); 461 462 /** 463 * Run the ReplicationBarrierChore. 464 */ 465 void runReplicationBarrierCleaner(); 466 467 /** Returns the {@link RSGroupInfoManager} */ 468 RSGroupInfoManager getRSGroupInfoManager(); 469 470 /** 471 * Queries the state of the {@code LoadBalancerStateStore}. If the balancer is not initialized, 472 * false is returned. 473 * @return The state of the load balancer, or false if the load balancer isn't defined. 474 */ 475 boolean isBalancerOn(); 476 477 /** 478 * Perform normalization of cluster. 479 * @param ntfp Selection criteria for identifying which tables to normalize. 480 * @param isHighPriority {@code true} when these requested tables should skip to the front of the 481 * queue. 482 * @return {@code true} when the request was submitted, {@code false} otherwise. 483 */ 484 boolean normalizeRegions(final NormalizeTableFilterParams ntfp, final boolean isHighPriority) 485 throws IOException; 486 487 /** 488 * Get the meta location syncer. 489 * <p/> 490 * We need to get this in MTP to tell the syncer the new meta replica count. 491 */ 492 MetaLocationSyncer getMetaLocationSyncer(); 493 494 /** 495 * Flush master local region 496 */ 497 void flushMasterStore() throws IOException; 498 499 /** 500 * Flush an existing table 501 * @param tableName The table name 502 * @param columnFamilies The column families to flush 503 * @param nonceGroup the nonce group 504 * @param nonce the nonce 505 * @return the flush procedure id 506 */ 507 long flushTable(final TableName tableName, final List<byte[]> columnFamilies, 508 final long nonceGroup, final long nonce) throws IOException; 509 510 /** 511 * Truncate region 512 * @param regionInfo region to be truncated 513 * @param nonceGroup the nonce group 514 * @param nonce the nonce 515 * @return procedure Id 516 */ 517 long truncateRegion(RegionInfo regionInfo, long nonceGroup, long nonce) throws IOException; 518}