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