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