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