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