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