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