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    * Create a system table using the given table definition.
151    * @param hTableDescriptor The system table definition
152    *     a single region is created.
153    */
154   long createSystemTable(final HTableDescriptor hTableDescriptor) throws IOException;
155
156   /**
157    * Delete a table
158    * @param tableName The table name
159    * @param nonceGroup
160    * @param nonce
161    * @throws IOException
162    */
163   long deleteTable(
164       final TableName tableName,
165       final long nonceGroup,
166       final long nonce) throws IOException;
167
168   /**
169    * Truncate a table
170    * @param tableName The table name
171    * @param preserveSplits True if the splits should be preserved
172    * @param nonceGroup
173    * @param nonce
174    * @throws IOException
175    */
176   public long truncateTable(
177       final TableName tableName,
178       final boolean preserveSplits,
179       final long nonceGroup,
180       final long nonce) throws IOException;
181
182   /**
183    * Modify the descriptor of an existing table
184    * @param tableName The table name
185    * @param descriptor The updated table descriptor
186    * @param nonceGroup
187    * @param nonce
188    * @throws IOException
189    */
190   long modifyTable(
191       final TableName tableName,
192       final HTableDescriptor descriptor,
193       final long nonceGroup,
194       final long nonce)
195       throws IOException;
196
197   /**
198    * Enable an existing table
199    * @param tableName The table name
200    * @param nonceGroup
201    * @param nonce
202    * @throws IOException
203    */
204   long enableTable(
205       final TableName tableName,
206       final long nonceGroup,
207       final long nonce) throws IOException;
208
209   /**
210    * Disable an existing table
211    * @param tableName The table name
212    * @param nonceGroup
213    * @param nonce
214    * @throws IOException
215    */
216   long disableTable(
217       final TableName tableName,
218       final long nonceGroup,
219       final long nonce) throws IOException;
220
221
222   /**
223    * Add a new column to an existing table
224    * @param tableName The table name
225    * @param column The column definition
226    * @param nonceGroup
227    * @param nonce
228    * @throws IOException
229    */
230   long addColumn(
231       final TableName tableName,
232       final HColumnDescriptor column,
233       final long nonceGroup,
234       final long nonce)
235       throws IOException;
236
237   /**
238    * Modify the column descriptor of an existing column in an existing table
239    * @param tableName The table name
240    * @param descriptor The updated column definition
241    * @param nonceGroup
242    * @param nonce
243    * @throws IOException
244    */
245   long modifyColumn(
246       final TableName tableName,
247       final HColumnDescriptor descriptor,
248       final long nonceGroup,
249       final long nonce)
250       throws IOException;
251
252   /**
253    * Delete a column from an existing table
254    * @param tableName The table name
255    * @param columnName The column name
256    * @param nonceGroup
257    * @param nonce
258    * @throws IOException
259    */
260   long deleteColumn(
261       final TableName tableName,
262       final byte[] columnName,
263       final long nonceGroup,
264       final long nonce)
265       throws IOException;
266
267   /**
268    * @return Return table descriptors implementation.
269    */
270   TableDescriptors getTableDescriptors();
271
272   /**
273    * @return true if master enables ServerShutdownHandler;
274    */
275   boolean isServerCrashProcessingEnabled();
276
277   /**
278    * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint.
279    *
280    * <p>
281    * Only a single instance may be registered for a given {@link Service} subclass (the
282    * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
283    * After the first registration, subsequent calls with the same service name will fail with
284    * a return value of {@code false}.
285    * </p>
286    * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
287    * @return {@code true} if the registration was successful, {@code false}
288    * otherwise
289    */
290   boolean registerService(Service instance);
291
292   /**
293    * Merge two regions. The real implementation is on the regionserver, master
294    * just move the regions together and send MERGE RPC to regionserver
295    * @param region_a region to merge
296    * @param region_b region to merge
297    * @param forcible true if do a compulsory merge, otherwise we will only merge
298    *          two adjacent regions
299    * @return procedure Id
300    * @throws IOException
301    */
302   long dispatchMergingRegions(
303     final HRegionInfo region_a,
304     final HRegionInfo region_b,
305     final boolean forcible,
306     final long nonceGroup,
307     final long nonce) throws IOException;
308
309   /**
310    * @return true if master is the active one
311    */
312   boolean isActiveMaster();
313
314   /**
315    * @return true if master is initialized
316    */
317   boolean isInitialized();
318
319   /**
320    * @return true if master is in maintanceMode
321    */
322   boolean isInMaintenanceMode();
323
324   /**
325    * Abort a procedure.
326    * @param procId ID of the procedure
327    * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
328    * @return true if aborted, false if procedure already completed or does not exist
329    * @throws IOException
330    */
331   public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
332       throws IOException;
333
334   /**
335    * List procedures
336    * @return procedure list
337    * @throws IOException
338    */
339   public List<ProcedureInfo> listProcedures() throws IOException;
340
341   /**
342    * Get list of table descriptors by namespace
343    * @param name namespace name
344    * @return descriptors
345    * @throws IOException
346    */
347   public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException;
348
349   /**
350    * Get list of table names by namespace
351    * @param name namespace name
352    * @return table names
353    * @throws IOException
354    */
355   public List<TableName> listTableNamesByNamespace(String name) throws IOException;
356
357   /**
358    * @param table the table for which last successful major compaction time is queried
359    * @return the timestamp of the last successful major compaction for the passed table,
360    * or 0 if no HFile resulting from a major compaction exists
361    * @throws IOException
362    */
363   public long getLastMajorCompactionTimestamp(TableName table) throws IOException;
364
365   /**
366    * @param regionName
367    * @return the timestamp of the last successful major compaction for the passed region
368    * or 0 if no HFile resulting from a major compaction exists
369    * @throws IOException
370    */
371   public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException;
372
373   /**
374    * @return load balancer
375    */
376   public LoadBalancer getLoadBalancer();
377 }