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