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