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