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  
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.HColumnDescriptor;
26  import org.apache.hadoop.hbase.HRegionInfo;
27  import org.apache.hadoop.hbase.HTableDescriptor;
28  import org.apache.hadoop.hbase.NamespaceDescriptor;
29  import org.apache.hadoop.hbase.ProcedureInfo;
30  import org.apache.hadoop.hbase.Server;
31  import org.apache.hadoop.hbase.TableDescriptors;
32  import org.apache.hadoop.hbase.TableName;
33  import org.apache.hadoop.hbase.TableNotDisabledException;
34  import org.apache.hadoop.hbase.TableNotFoundException;
35  import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
36  import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
37  import org.apache.hadoop.hbase.executor.ExecutorService;
38  import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
39  
40  import com.google.protobuf.Service;
41  
42  /**
43   * Services Master supplies
44   */
45  @InterfaceAudience.Private
46  public interface MasterServices extends Server {
47    /**
48     * @return Master's instance of the {@link AssignmentManager}
49     */
50    AssignmentManager getAssignmentManager();
51  
52    /**
53     * @return Master's filesystem {@link MasterFileSystem} utility class.
54     */
55    MasterFileSystem getMasterFileSystem();
56  
57    /**
58     * @return Master's {@link ServerManager} instance.
59     */
60    ServerManager getServerManager();
61  
62    /**
63     * @return Master's instance of {@link ExecutorService}
64     */
65    ExecutorService getExecutorService();
66  
67    /**
68     * @return Master's instance of {@link TableLockManager}
69     */
70    TableLockManager getTableLockManager();
71  
72    /**
73     * @return Master's instance of {@link TableStateManager}
74     */
75    TableStateManager getTableStateManager();
76  
77    /**
78     * @return Master's instance of {@link MasterCoprocessorHost}
79     */
80    MasterCoprocessorHost getMasterCoprocessorHost();
81  
82    /**
83     * @return Master's instance of {@link TableNamespaceManager}
84     */
85    TableNamespaceManager getTableNamespaceManager();
86  
87    /**
88     * @return Master's instance of {@link MasterQuotaManager}
89     */
90    MasterQuotaManager getMasterQuotaManager();
91  
92    /**
93     * @return Master's instance of {@link ProcedureExecutor}
94     */
95    ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor();
96  
97    /**
98     * Check table is modifiable; i.e. exists and is offline.
99     * @param tableName Name of table to check.
100    * @throws TableNotDisabledException
101    * @throws TableNotFoundException
102    * @throws IOException
103    */
104   // We actually throw the exceptions mentioned in the
105   void checkTableModifiable(final TableName tableName)
106       throws IOException, TableNotFoundException, TableNotDisabledException;
107 
108   /**
109    * Create a table using the given table definition.
110    * @param desc The table definition
111    * @param splitKeys Starting row keys for the initial table regions.  If null
112    * @param nonceGroup
113    * @param nonce
114    *     a single region is created.
115    */
116   long createTable(
117       final HTableDescriptor desc,
118       final byte[][] splitKeys,
119       final long nonceGroup,
120       final long nonce) throws IOException;
121 
122   /**
123    * Delete a table
124    * @param tableName The table name
125    * @param nonceGroup
126    * @param nonce
127    * @throws IOException
128    */
129   long deleteTable(
130       final TableName tableName,
131       final long nonceGroup,
132       final long nonce) throws IOException;
133 
134   /**
135    * Truncate a table
136    * @param tableName The table name
137    * @param preserveSplits True if the splits should be preserved
138    * @param nonceGroup
139    * @param nonce
140    * @throws IOException
141    */
142   public long truncateTable(
143       final TableName tableName,
144       final boolean preserveSplits,
145       final long nonceGroup,
146       final long nonce) throws IOException;
147 
148   /**
149    * Modify the descriptor of an existing table
150    * @param tableName The table name
151    * @param descriptor The updated table descriptor
152    * @param nonceGroup
153    * @param nonce
154    * @throws IOException
155    */
156   long modifyTable(
157       final TableName tableName,
158       final HTableDescriptor descriptor,
159       final long nonceGroup,
160       final long nonce)
161       throws IOException;
162 
163   /**
164    * Enable an existing table
165    * @param tableName The table name
166    * @param nonceGroup
167    * @param nonce
168    * @throws IOException
169    */
170   long enableTable(
171       final TableName tableName,
172       final long nonceGroup,
173       final long nonce) throws IOException;
174 
175   /**
176    * Disable an existing table
177    * @param tableName The table name
178    * @param nonceGroup
179    * @param nonce
180    * @throws IOException
181    */
182   long disableTable(
183       final TableName tableName,
184       final long nonceGroup,
185       final long nonce) throws IOException;
186 
187 
188   /**
189    * Add a new column to an existing table
190    * @param tableName The table name
191    * @param column The column definition
192    * @param nonceGroup
193    * @param nonce
194    * @throws IOException
195    */
196   long addColumn(
197       final TableName tableName,
198       final HColumnDescriptor column,
199       final long nonceGroup,
200       final long nonce)
201       throws IOException;
202 
203   /**
204    * Modify the column descriptor of an existing column in an existing table
205    * @param tableName The table name
206    * @param descriptor The updated column definition
207    * @param nonceGroup
208    * @param nonce
209    * @throws IOException
210    */
211   long modifyColumn(
212       final TableName tableName,
213       final HColumnDescriptor descriptor,
214       final long nonceGroup,
215       final long nonce)
216       throws IOException;
217 
218   /**
219    * Delete a column from an existing table
220    * @param tableName The table name
221    * @param columnName The column name
222    * @param nonceGroup
223    * @param nonce
224    * @throws IOException
225    */
226   long deleteColumn(
227       final TableName tableName,
228       final byte[] columnName,
229       final long nonceGroup,
230       final long nonce)
231       throws IOException;
232 
233   /**
234    * @return Return table descriptors implementation.
235    */
236   TableDescriptors getTableDescriptors();
237 
238   /**
239    * @return true if master enables ServerShutdownHandler;
240    */
241   boolean isServerCrashProcessingEnabled();
242 
243   /**
244    * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint.
245    *
246    * <p>
247    * Only a single instance may be registered for a given {@link Service} subclass (the
248    * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
249    * After the first registration, subsequent calls with the same service name will fail with
250    * a return value of {@code false}.
251    * </p>
252    * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
253    * @return {@code true} if the registration was successful, {@code false}
254    * otherwise
255    */
256   boolean registerService(Service instance);
257 
258   /**
259    * Merge two regions. The real implementation is on the regionserver, master
260    * just move the regions together and send MERGE RPC to regionserver
261    * @param region_a region to merge
262    * @param region_b region to merge
263    * @param forcible true if do a compulsory merge, otherwise we will only merge
264    *          two adjacent regions
265    * @throws IOException
266    */
267   void dispatchMergingRegions(
268     final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible
269   ) throws IOException;
270 
271   /**
272    * @return true if master is initialized
273    */
274   boolean isInitialized();
275 
276   /**
277    * Create a new namespace
278    * @param descriptor descriptor which describes the new namespace
279    * @param nonceGroup
280    * @param nonce
281    * @throws IOException
282    */
283   public void createNamespace(
284       final NamespaceDescriptor descriptor,
285       final long nonceGroup,
286       final long nonce) throws IOException;
287 
288   /**
289    * Create a new namespace synchronously.
290    * @param descriptor descriptor which describes the new namespace
291    * @param nonceGroup
292    * @param nonce
293    * @throws IOException
294    */
295   public void createNamespaceSync(
296       final NamespaceDescriptor descriptor,
297       final long nonceGroup,
298       final long nonce) throws IOException;
299 
300   /**
301    * Modify an existing namespace
302    * @param descriptor descriptor which updates the existing namespace
303    * @param nonceGroup
304    * @param nonce
305    * @throws IOException
306    */
307   public void modifyNamespace(
308       final NamespaceDescriptor descriptor,
309       final long nonceGroup,
310       final long nonce) throws IOException;
311 
312   /**
313    * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
314    * @param name namespace name
315    * @param nonceGroup
316    * @param nonce
317    * @throws IOException
318    */
319   public void deleteNamespace(
320       final String name,
321       final long nonceGroup,
322       final long nonce) throws IOException;
323 
324   /**
325    * Abort a procedure.
326    * @param procId ID of the procedure
327    * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
328    * @return true if aborted, false if procedure already completed or does not exist
329    * @throws IOException 
330    */
331   public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
332       throws IOException;
333 
334   /**
335    * Get a namespace descriptor by name
336    * @param name name of namespace descriptor
337    * @return A descriptor
338    * @throws IOException
339    */
340   public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException;
341 
342   /**
343    * List available namespace descriptors
344    * @return A descriptor
345    * @throws IOException
346    */
347   public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException;
348 
349   /**
350    * List procedures
351    * @return procedure list
352    * @throws IOException
353    */
354   public List<ProcedureInfo> listProcedures() throws IOException;
355 
356   /**
357    * Get list of table descriptors by namespace
358    * @param name namespace name
359    * @return descriptors
360    * @throws IOException
361    */
362   public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException;
363 
364   /**
365    * Get list of table names by namespace
366    * @param name namespace name
367    * @return table names
368    * @throws IOException
369    */
370   public List<TableName> listTableNamesByNamespace(String name) throws IOException;
371 
372   /**
373    * @param table
374    * @return the timestamp of the last successful major compaction for the passed table,
375    * or 0 if no HFile resulting from a major compaction exists
376    * @throws IOException
377    */
378   public long getLastMajorCompactionTimestamp(TableName table) throws IOException;
379 
380   /**
381    * @param regionName
382    * @return the timestamp of the last successful major compaction for the passed region
383    * or 0 if no HFile resulting from a major compaction exists
384    * @throws IOException
385    */
386   public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException;
387 }