View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.master;
20  
21  import java.io.IOException;
22  import java.util.List;
23  import java.util.concurrent.Future;
24  
25  import org.apache.hadoop.hbase.backup.BackupType;
26  import org.apache.hadoop.hbase.ServerName;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.hbase.HColumnDescriptor;
29  import org.apache.hadoop.hbase.HRegionInfo;
30  import org.apache.hadoop.hbase.HTableDescriptor;
31  import org.apache.hadoop.hbase.NamespaceDescriptor;
32  import org.apache.hadoop.hbase.ProcedureInfo;
33  import org.apache.hadoop.hbase.Server;
34  import org.apache.hadoop.hbase.TableDescriptors;
35  import org.apache.hadoop.hbase.TableName;
36  import org.apache.hadoop.hbase.TableNotDisabledException;
37  import org.apache.hadoop.hbase.TableNotFoundException;
38  import org.apache.hadoop.hbase.TableStateManager;
39  import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
40  import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
41  import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost;
42  import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
43  import org.apache.hadoop.hbase.executor.ExecutorService;
44  import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
45  import org.apache.hadoop.hbase.util.Pair;
46  
47  import com.google.protobuf.Service;
48  
49  /**
50   * Services Master supplies
51   */
52  @InterfaceAudience.Private
53  public interface MasterServices extends Server {
54    /**
55     * @return the underlying snapshot manager
56     */
57    SnapshotManager getSnapshotManager();
58  
59    /**
60     * @return the underlying MasterProcedureManagerHost
61     */
62    MasterProcedureManagerHost getMasterProcedureManagerHost();
63  
64    /**
65     * @return Master's instance of the {@link AssignmentManager}
66     */
67    AssignmentManager getAssignmentManager();
68  
69    /**
70     * @return Master's filesystem {@link MasterFileSystem} utility class.
71     */
72    MasterFileSystem getMasterFileSystem();
73  
74    /**
75     * @return Master's {@link ServerManager} instance.
76     */
77    ServerManager getServerManager();
78  
79    /**
80     * @return Master's instance of {@link ExecutorService}
81     */
82    ExecutorService getExecutorService();
83  
84    /**
85     * @return Master's instance of {@link TableLockManager}
86     */
87    TableLockManager getTableLockManager();
88  
89    /**
90     * @return Master's instance of {@link MasterCoprocessorHost}
91     */
92    MasterCoprocessorHost getMasterCoprocessorHost();
93  
94    /**
95     * @return Master's instance of {@link MasterQuotaManager}
96     */
97    MasterQuotaManager getMasterQuotaManager();
98  
99    /**
100    * @return Master's instance of {@link ProcedureExecutor}
101    */
102   ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor();
103 
104   /**
105    * Check table is modifiable; i.e. exists and is offline.
106    * @param tableName Name of table to check.
107    * @throws TableNotDisabledException
108    * @throws TableNotFoundException
109    * @throws IOException
110    */
111   // We actually throw the exceptions mentioned in the
112   void checkTableModifiable(final TableName tableName)
113       throws IOException, TableNotFoundException, TableNotDisabledException;
114 
115   /**
116    * Check whether the procedure executor is enabled
117    */
118   boolean isMasterProcedureExecutorEnabled();
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
124    * @param nonceGroup
125    * @param nonce
126    *     a single region is created.
127    */
128   long createTable(
129       final HTableDescriptor desc,
130       final byte[][] splitKeys,
131       final long nonceGroup,
132       final long nonce) throws IOException;
133 
134   /**
135    * Delete a table
136    * @param tableName The table name
137    * @param nonceGroup
138    * @param nonce
139    * @throws IOException
140    */
141   long deleteTable(
142       final TableName tableName,
143       final long nonceGroup,
144       final long nonce) throws IOException;
145 
146   /**
147    * Truncate a table
148    * @param tableName The table name
149    * @param preserveSplits True if the splits should be preserved
150    * @param nonceGroup
151    * @param nonce
152    * @throws IOException
153    */
154   public void truncateTable(
155       final TableName tableName,
156       final boolean preserveSplits,
157       final long nonceGroup,
158       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    * @param nonceGroup
165    * @param nonce
166    * @throws IOException
167    */
168   void modifyTable(
169       final TableName tableName,
170       final HTableDescriptor descriptor,
171       final long nonceGroup,
172       final long nonce)
173       throws IOException;
174 
175   /**
176    * Full backup given list of tables
177    * @param type whether the backup is full or incremental
178    * @param tableList list of tables to backup
179    * @param targetRootDir root dir for saving the backup
180    * @param workers number of paralle workers. -1 - system defined
181    * @param bandwidth bandwidth per worker in MB per sec. -1 - unlimited
182    * @return pair of procedure Id and backupId
183    * @throws IOException
184    */
185   public Pair<Long, String> backupTables(
186       final BackupType type,
187       List<TableName> tableList,
188       final String targetRootDir,
189       final int workers,
190       final long bandwidth) throws IOException;
191 
192   /**
193    * Enable an existing table
194    * @param tableName The table name
195    * @param nonceGroup
196    * @param nonce
197    * @throws IOException
198    */
199   long enableTable(
200       final TableName tableName,
201       final long nonceGroup,
202       final long nonce) throws IOException;
203 
204   /**
205    * Disable an existing table
206    * @param tableName The table name
207    * @param nonceGroup
208    * @param nonce
209    * @throws IOException
210    */
211   long disableTable(
212       final TableName tableName,
213       final long nonceGroup,
214       final long nonce) throws IOException;
215 
216 
217   /**
218    * Add a new column to an existing table
219    * @param tableName The table name
220    * @param column The column definition
221    * @param nonceGroup
222    * @param nonce
223    * @throws IOException
224    */
225   void addColumn(
226       final TableName tableName,
227       final HColumnDescriptor column,
228       final long nonceGroup,
229       final long nonce)
230       throws IOException;
231 
232   /**
233    * Modify the column descriptor of an existing column in an existing table
234    * @param tableName The table name
235    * @param descriptor The updated column definition
236    * @param nonceGroup
237    * @param nonce
238    * @throws IOException
239    */
240   void modifyColumn(
241       final TableName tableName,
242       final HColumnDescriptor descriptor,
243       final long nonceGroup,
244       final long nonce)
245       throws IOException;
246 
247   /**
248    * Delete a column from an existing table
249    * @param tableName The table name
250    * @param columnName The column name
251    * @param nonceGroup
252    * @param nonce
253    * @throws IOException
254    */
255   void deleteColumn(
256       final TableName tableName,
257       final byte[] columnName,
258       final long nonceGroup,
259       final long nonce)
260       throws IOException;
261 
262   /**
263    * @return Return table descriptors implementation.
264    */
265   TableDescriptors getTableDescriptors();
266 
267   /**
268    * @return true if master enables ServerShutdownHandler;
269    */
270   boolean isServerShutdownHandlerEnabled();
271 
272   /**
273    * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint.
274    *
275    * <p>
276    * Only a single instance may be registered for a given {@link Service} subclass (the
277    * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
278    * After the first registration, subsequent calls with the same service name will fail with
279    * a return value of {@code false}.
280    * </p>
281    * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
282    * @return {@code true} if the registration was successful, {@code false}
283    * otherwise
284    */
285   boolean registerService(Service instance);
286 
287   /**
288    * Merge two regions. The real implementation is on the regionserver, master
289    * just move the regions together and send MERGE RPC to regionserver
290    * @param region_a region to merge
291    * @param region_b region to merge
292    * @param forcible true if do a compulsory merge, otherwise we will only merge
293    *          two adjacent regions
294    * @throws IOException
295    */
296   void dispatchMergingRegions(
297     final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible
298   ) throws IOException;
299 
300   /**
301    * @return true if master is initialized
302    */
303   boolean isInitialized();
304 
305   /**
306    * @return true if master is initialized with namespace ready
307    */
308   boolean isNamespaceManagerInitialized();
309 
310   /**
311    * Create a new namespace
312    * @param descriptor descriptor which describes the new namespace
313    * @throws IOException
314    */
315   public void createNamespace(NamespaceDescriptor descriptor) throws IOException;
316 
317   /**
318    * Modify an existing namespace
319    * @param descriptor descriptor which updates the existing namespace
320    * @throws IOException
321    */
322   public void modifyNamespace(NamespaceDescriptor descriptor) throws IOException;
323 
324   /**
325    * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
326    * @param name namespace name
327    * @throws IOException
328    */
329   public void deleteNamespace(String name) throws IOException;
330 
331   /**
332    * @return true if master is in maintanceMode
333    */
334   boolean isInMaintenanceMode();
335 
336   /**
337    * Abort a procedure.
338    * @param procId ID of the procedure
339    * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
340    * @return true if aborted, false if procedure already completed or does not exist
341    * @throws IOException
342    */
343   public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
344       throws IOException;
345 
346   /**
347    * List procedures
348    * @return procedure list
349    * @throws IOException
350    */
351   public List<ProcedureInfo> listProcedures() throws IOException;
352 
353   /**
354    * Get a namespace descriptor by name
355    * @param name name of namespace descriptor
356    * @return A descriptor
357    * @throws IOException
358    */
359   public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException;
360 
361   /**
362    * List available namespace descriptors
363    * @return A descriptor
364    * @throws IOException
365    */
366   public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException;
367 
368   /**
369    * Get list of table descriptors by namespace
370    * @param name namespace name
371    * @return descriptors
372    * @throws IOException
373    */
374   public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException;
375 
376   /**
377    * Get list of table names by namespace
378    * @param name namespace name
379    * @return table names
380    * @throws IOException
381    */
382   public List<TableName> listTableNamesByNamespace(String name) throws IOException;
383 
384   /**
385    * @param table
386    * @return the timestamp of the last successful major compaction for the passed table,
387    * or 0 if no HFile resulting from a major compaction exists
388    * @throws IOException
389    */
390   public long getLastMajorCompactionTimestamp(TableName table) throws IOException;
391 
392   /**
393    * @param regionName
394    * @return the timestamp of the last successful major compaction for the passed region
395    * or 0 if no HFile resulting from a major compaction exists
396    * @throws IOException
397    */
398   public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException;
399 
400   /**
401    * @return load balancer
402    */
403   public LoadBalancer getLoadBalancer();
404 
405   public TableStateManager getTableStateManager();
406 
407   public String getRegionServerVersion(final ServerName sn);
408 
409   public void checkIfShouldMoveSystemRegionAsync();
410 }