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