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