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 import java.util.concurrent.Future;
24
25 import org.apache.hadoop.hbase.backup.BackupType;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.HColumnDescriptor;
28 import org.apache.hadoop.hbase.HRegionInfo;
29 import org.apache.hadoop.hbase.HTableDescriptor;
30 import org.apache.hadoop.hbase.NamespaceDescriptor;
31 import org.apache.hadoop.hbase.ProcedureInfo;
32 import org.apache.hadoop.hbase.Server;
33 import org.apache.hadoop.hbase.TableDescriptors;
34 import org.apache.hadoop.hbase.TableName;
35 import org.apache.hadoop.hbase.TableNotDisabledException;
36 import org.apache.hadoop.hbase.TableNotFoundException;
37 import org.apache.hadoop.hbase.TableStateManager;
38 import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
39 import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
40 import org.apache.hadoop.hbase.procedure.MasterProcedureManagerHost;
41 import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
42 import org.apache.hadoop.hbase.executor.ExecutorService;
43 import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
44 import org.apache.hadoop.hbase.util.Pair;
45
46 import com.google.protobuf.Service;
47
48 /**
49 * Services Master supplies
50 */
51 @InterfaceAudience.Private
52 public interface MasterServices extends Server {
53 /**
54 * @return the underlying snapshot manager
55 */
56 SnapshotManager getSnapshotManager();
57
58 /**
59 * @return the underlying MasterProcedureManagerHost
60 */
61 MasterProcedureManagerHost getMasterProcedureManagerHost();
62
63 /**
64 * @return Master's instance of the {@link AssignmentManager}
65 */
66 AssignmentManager getAssignmentManager();
67
68 /**
69 * @return Master's filesystem {@link MasterFileSystem} utility class.
70 */
71 MasterFileSystem getMasterFileSystem();
72
73 /**
74 * @return Master's {@link ServerManager} instance.
75 */
76 ServerManager getServerManager();
77
78 /**
79 * @return Master's instance of {@link ExecutorService}
80 */
81 ExecutorService getExecutorService();
82
83 /**
84 * @return Master's instance of {@link TableLockManager}
85 */
86 TableLockManager getTableLockManager();
87
88 /**
89 * @return Master's instance of {@link MasterCoprocessorHost}
90 */
91 MasterCoprocessorHost getMasterCoprocessorHost();
92
93 /**
94 * @return Master's instance of {@link MasterQuotaManager}
95 */
96 MasterQuotaManager getMasterQuotaManager();
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 * Check whether the procedure executor is enabled
116 */
117 boolean isMasterProcedureExecutorEnabled();
118
119 /**
120 * Create a table using the given table definition.
121 * @param desc The table definition
122 * @param splitKeys Starting row keys for the initial table regions. If null
123 * @param nonceGroup
124 * @param nonce
125 * a single region is created.
126 */
127 long createTable(
128 final HTableDescriptor desc,
129 final byte[][] splitKeys,
130 final long nonceGroup,
131 final long nonce) throws IOException;
132
133 /**
134 * Delete a table
135 * @param tableName The table name
136 * @param nonceGroup
137 * @param nonce
138 * @throws IOException
139 */
140 long deleteTable(
141 final TableName tableName,
142 final long nonceGroup,
143 final long nonce) throws IOException;
144
145 /**
146 * Truncate a table
147 * @param tableName The table name
148 * @param preserveSplits True if the splits should be preserved
149 * @param nonceGroup
150 * @param nonce
151 * @throws IOException
152 */
153 public void truncateTable(
154 final TableName tableName,
155 final boolean preserveSplits,
156 final long nonceGroup,
157 final long nonce) throws IOException;
158
159 /**
160 * Modify the descriptor of an existing table
161 * @param tableName The table name
162 * @param descriptor The updated table descriptor
163 * @param nonceGroup
164 * @param nonce
165 * @throws IOException
166 */
167 void modifyTable(
168 final TableName tableName,
169 final HTableDescriptor descriptor,
170 final long nonceGroup,
171 final long nonce)
172 throws IOException;
173
174 /**
175 * Full backup given list of tables
176 * @param type whether the backup is full or incremental
177 * @param tableList list of tables to backup
178 * @param targetRootDir root dir for saving the backup
179 * @param workers number of paralle workers. -1 - system defined
180 * @param bandwidth bandwidth per worker in MB per sec. -1 - unlimited
181 * @return pair of procedure Id and backupId
182 * @throws IOException
183 */
184 public Pair<Long, String> backupTables(
185 final BackupType type,
186 List<TableName> tableList,
187 final String targetRootDir,
188 final int workers,
189 final long bandwidth) throws IOException;
190
191 /**
192 * Enable an existing table
193 * @param tableName The table name
194 * @param nonceGroup
195 * @param nonce
196 * @throws IOException
197 */
198 long enableTable(
199 final TableName tableName,
200 final long nonceGroup,
201 final long nonce) throws IOException;
202
203 /**
204 * Disable an existing table
205 * @param tableName The table name
206 * @param nonceGroup
207 * @param nonce
208 * @throws IOException
209 */
210 long disableTable(
211 final TableName tableName,
212 final long nonceGroup,
213 final long nonce) throws IOException;
214
215
216 /**
217 * Add a new column to an existing table
218 * @param tableName The table name
219 * @param column The column definition
220 * @param nonceGroup
221 * @param nonce
222 * @throws IOException
223 */
224 void addColumn(
225 final TableName tableName,
226 final HColumnDescriptor column,
227 final long nonceGroup,
228 final long nonce)
229 throws IOException;
230
231 /**
232 * Modify the column descriptor of an existing column in an existing table
233 * @param tableName The table name
234 * @param descriptor The updated column definition
235 * @param nonceGroup
236 * @param nonce
237 * @throws IOException
238 */
239 void modifyColumn(
240 final TableName tableName,
241 final HColumnDescriptor descriptor,
242 final long nonceGroup,
243 final long nonce)
244 throws IOException;
245
246 /**
247 * Delete a column from an existing table
248 * @param tableName The table name
249 * @param columnName The column name
250 * @param nonceGroup
251 * @param nonce
252 * @throws IOException
253 */
254 void deleteColumn(
255 final TableName tableName,
256 final byte[] columnName,
257 final long nonceGroup,
258 final long nonce)
259 throws IOException;
260
261 /**
262 * @return Return table descriptors implementation.
263 */
264 TableDescriptors getTableDescriptors();
265
266 /**
267 * @return true if master enables ServerShutdownHandler;
268 */
269 boolean isServerShutdownHandlerEnabled();
270
271 /**
272 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint.
273 *
274 * <p>
275 * Only a single instance may be registered for a given {@link Service} subclass (the
276 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
277 * After the first registration, subsequent calls with the same service name will fail with
278 * a return value of {@code false}.
279 * </p>
280 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
281 * @return {@code true} if the registration was successful, {@code false}
282 * otherwise
283 */
284 boolean registerService(Service instance);
285
286 /**
287 * Merge two regions. The real implementation is on the regionserver, master
288 * just move the regions together and send MERGE RPC to regionserver
289 * @param region_a region to merge
290 * @param region_b region to merge
291 * @param forcible true if do a compulsory merge, otherwise we will only merge
292 * two adjacent regions
293 * @throws IOException
294 */
295 void dispatchMergingRegions(
296 final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible
297 ) throws IOException;
298
299 /**
300 * @return true if master is initialized
301 */
302 boolean isInitialized();
303
304 /**
305 * @return true if master is initialized with namespace ready
306 */
307 boolean isNamespaceManagerInitialized();
308
309 /**
310 * Create a new namespace
311 * @param descriptor descriptor which describes the new namespace
312 * @throws IOException
313 */
314 public void createNamespace(NamespaceDescriptor descriptor) throws IOException;
315
316 /**
317 * Modify an existing namespace
318 * @param descriptor descriptor which updates the existing namespace
319 * @throws IOException
320 */
321 public void modifyNamespace(NamespaceDescriptor descriptor) throws IOException;
322
323 /**
324 * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
325 * @param name namespace name
326 * @throws IOException
327 */
328 public void deleteNamespace(String name) throws IOException;
329
330 /**
331 * @return true if master is in maintanceMode
332 */
333 boolean isInMaintenanceMode();
334
335 /**
336 * Abort a procedure.
337 * @param procId ID of the procedure
338 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
339 * @return true if aborted, false if procedure already completed or does not exist
340 * @throws IOException
341 */
342 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
343 throws IOException;
344
345 /**
346 * List procedures
347 * @return procedure list
348 * @throws IOException
349 */
350 public List<ProcedureInfo> listProcedures() throws IOException;
351
352 /**
353 * Get a namespace descriptor by name
354 * @param name name of namespace descriptor
355 * @return A descriptor
356 * @throws IOException
357 */
358 public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException;
359
360 /**
361 * List available namespace descriptors
362 * @return A descriptor
363 * @throws IOException
364 */
365 public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException;
366
367 /**
368 * Get list of table descriptors by namespace
369 * @param name namespace name
370 * @return descriptors
371 * @throws IOException
372 */
373 public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException;
374
375 /**
376 * Get list of table names by namespace
377 * @param name namespace name
378 * @return table names
379 * @throws IOException
380 */
381 public List<TableName> listTableNamesByNamespace(String name) throws IOException;
382
383 /**
384 * @param table
385 * @return the timestamp of the last successful major compaction for the passed table,
386 * or 0 if no HFile resulting from a major compaction exists
387 * @throws IOException
388 */
389 public long getLastMajorCompactionTimestamp(TableName table) throws IOException;
390
391 /**
392 * @param regionName
393 * @return the timestamp of the last successful major compaction for the passed region
394 * or 0 if no HFile resulting from a major compaction exists
395 * @throws IOException
396 */
397 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException;
398
399 /**
400 * @return load balancer
401 */
402 public LoadBalancer getLoadBalancer();
403
404 public TableStateManager getTableStateManager();
405 }