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.client;
20
21 import java.io.Closeable;
22 import java.io.IOException;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.concurrent.Future;
26 import java.util.regex.Pattern;
27
28 import org.apache.hadoop.conf.Configuration;
29 import org.apache.hadoop.hbase.Abortable;
30 import org.apache.hadoop.hbase.ClusterStatus;
31 import org.apache.hadoop.hbase.HColumnDescriptor;
32 import org.apache.hadoop.hbase.HRegionInfo;
33 import org.apache.hadoop.hbase.HTableDescriptor;
34 import org.apache.hadoop.hbase.NamespaceDescriptor;
35 import org.apache.hadoop.hbase.ProcedureInfo;
36 import org.apache.hadoop.hbase.ServerName;
37 import org.apache.hadoop.hbase.TableExistsException;
38 import org.apache.hadoop.hbase.TableName;
39 import org.apache.hadoop.hbase.TableNotFoundException;
40 import org.apache.hadoop.hbase.backup.BackupRequest;
41 import org.apache.hadoop.hbase.backup.BackupType;
42 import org.apache.hadoop.hbase.classification.InterfaceAudience;
43 import org.apache.hadoop.hbase.classification.InterfaceStability;
44 import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
45 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos;
46 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
47 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos;
48 import org.apache.hadoop.hbase.quotas.QuotaFilter;
49 import org.apache.hadoop.hbase.quotas.QuotaRetriever;
50 import org.apache.hadoop.hbase.quotas.QuotaSettings;
51 import org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException;
52 import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
53 import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
54 import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
55 import org.apache.hadoop.hbase.snapshot.UnknownSnapshotException;
56 import org.apache.hadoop.hbase.util.Pair;
57
58 /**
59 * The administrative API for HBase. Obtain an instance from an {@link Connection#getAdmin()} and
60 * call {@link #close()} afterwards.
61 * <p>Admin can be used to create, drop, list, enable and disable tables, add and drop table
62 * column families and other administrative operations.
63 *
64 * @see ConnectionFactory
65 * @see Connection
66 * @see Table
67 * @since 0.99.0
68 */
69 @InterfaceAudience.Public
70 @InterfaceStability.Evolving
71 public interface Admin extends Abortable, Closeable {
72 int getOperationTimeout();
73
74 @Override
75 void abort(String why, Throwable e);
76
77 @Override
78 boolean isAborted();
79
80 /**
81 * @return Connection used by this object.
82 */
83 Connection getConnection();
84
85 /**
86 * @param tableName Table to check.
87 * @return True if table exists already.
88 * @throws IOException
89 */
90 boolean tableExists(final TableName tableName) throws IOException;
91
92 /**
93 * List all the userspace tables.
94 *
95 * @return - returns an array of HTableDescriptors
96 * @throws IOException if a remote or network exception occurs
97 */
98 HTableDescriptor[] listTables() throws IOException;
99
100 /**
101 * List all the userspace tables matching the given pattern.
102 *
103 * @param pattern The compiled regular expression to match against
104 * @return - returns an array of HTableDescriptors
105 * @throws IOException if a remote or network exception occurs
106 * @see #listTables()
107 */
108 HTableDescriptor[] listTables(Pattern pattern) throws IOException;
109
110 /**
111 * List all the userspace tables matching the given regular expression.
112 *
113 * @param regex The regular expression to match against
114 * @return - returns an array of HTableDescriptors
115 * @throws IOException if a remote or network exception occurs
116 * @see #listTables(java.util.regex.Pattern)
117 */
118 HTableDescriptor[] listTables(String regex) throws IOException;
119
120 /**
121 * List all the tables matching the given pattern.
122 *
123 * @param pattern The compiled regular expression to match against
124 * @param includeSysTables False to match only against userspace tables
125 * @return - returns an array of HTableDescriptors
126 * @throws IOException if a remote or network exception occurs
127 * @see #listTables()
128 */
129 HTableDescriptor[] listTables(Pattern pattern, boolean includeSysTables)
130 throws IOException;
131
132 /**
133 * List all the tables matching the given pattern.
134 *
135 * @param regex The regular expression to match against
136 * @param includeSysTables False to match only against userspace tables
137 * @return - returns an array of HTableDescriptors
138 * @throws IOException if a remote or network exception occurs
139 * @see #listTables(java.util.regex.Pattern, boolean)
140 */
141 HTableDescriptor[] listTables(String regex, boolean includeSysTables)
142 throws IOException;
143
144 /**
145 * List all of the names of userspace tables.
146 *
147 * @return TableName[] table names
148 * @throws IOException if a remote or network exception occurs
149 */
150 TableName[] listTableNames() throws IOException;
151
152 /**
153 * List all of the names of userspace tables.
154 * @param pattern The regular expression to match against
155 * @return TableName[] table names
156 * @throws IOException if a remote or network exception occurs
157 */
158 TableName[] listTableNames(Pattern pattern) throws IOException;
159
160 /**
161 * List all of the names of userspace tables.
162 * @param regex The regular expression to match against
163 * @return TableName[] table names
164 * @throws IOException if a remote or network exception occurs
165 */
166 TableName[] listTableNames(String regex) throws IOException;
167
168 /**
169 * List all of the names of userspace tables.
170 * @param pattern The regular expression to match against
171 * @param includeSysTables False to match only against userspace tables
172 * @return TableName[] table names
173 * @throws IOException if a remote or network exception occurs
174 */
175 TableName[] listTableNames(final Pattern pattern, final boolean includeSysTables)
176 throws IOException;
177
178 /**
179 * List all of the names of userspace tables.
180 * @param regex The regular expression to match against
181 * @param includeSysTables False to match only against userspace tables
182 * @return TableName[] table names
183 * @throws IOException if a remote or network exception occurs
184 */
185 TableName[] listTableNames(final String regex, final boolean includeSysTables)
186 throws IOException;
187
188 /**
189 * Method for getting the tableDescriptor
190 *
191 * @param tableName as a {@link TableName}
192 * @return the tableDescriptor
193 * @throws org.apache.hadoop.hbase.TableNotFoundException
194 * @throws IOException if a remote or network exception occurs
195 */
196 HTableDescriptor getTableDescriptor(final TableName tableName)
197 throws TableNotFoundException, IOException;
198
199 /**
200 * Creates a new table. Synchronous operation.
201 *
202 * @param desc table descriptor for table
203 * @throws IllegalArgumentException if the table name is reserved
204 * @throws MasterNotRunningException if master is not running
205 * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
206 * threads, the table may have been created between test-for-existence and attempt-at-creation).
207 * @throws IOException if a remote or network exception occurs
208 */
209 void createTable(HTableDescriptor desc) throws IOException;
210
211 /**
212 * Creates a new table with the specified number of regions. The start key specified will become
213 * the end key of the first region of the table, and the end key specified will become the start
214 * key of the last region of the table (the first region has a null start key and the last region
215 * has a null end key). BigInteger math will be used to divide the key range specified into enough
216 * segments to make the required number of total regions. Synchronous operation.
217 *
218 * @param desc table descriptor for table
219 * @param startKey beginning of key range
220 * @param endKey end of key range
221 * @param numRegions the total number of regions to create
222 * @throws IllegalArgumentException if the table name is reserved
223 * @throws MasterNotRunningException if master is not running
224 * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
225 * threads, the table may have been created between test-for-existence and attempt-at-creation).
226 * @throws IOException
227 */
228 void createTable(HTableDescriptor desc, byte[] startKey, byte[] endKey, int numRegions)
229 throws IOException;
230
231 /**
232 * Creates a new table with an initial set of empty regions defined by the specified split keys.
233 * The total number of regions created will be the number of split keys plus one. Synchronous
234 * operation. Note : Avoid passing empty split key.
235 *
236 * @param desc table descriptor for table
237 * @param splitKeys array of split keys for the initial regions of the table
238 * @throws IllegalArgumentException if the table name is reserved, if the split keys are repeated
239 * and if the split key has empty byte array.
240 * @throws MasterNotRunningException if master is not running
241 * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
242 * threads, the table may have been created between test-for-existence and attempt-at-creation).
243 * @throws IOException
244 */
245 void createTable(final HTableDescriptor desc, byte[][] splitKeys) throws IOException;
246
247 /**
248 * Creates a new table but does not block and wait for it to come online. Asynchronous operation.
249 * To check if the table exists, use {@link #isTableAvailable} -- it is not safe to create an
250 * HTable instance to this table before it is available. Note : Avoid passing empty split key.
251 *
252 * @param desc table descriptor for table
253 * @throws IllegalArgumentException Bad table name, if the split keys are repeated and if the
254 * split key has empty byte array.
255 * @throws MasterNotRunningException if master is not running
256 * @throws org.apache.hadoop.hbase.TableExistsException if table already exists (If concurrent
257 * threads, the table may have been created between test-for-existence and attempt-at-creation).
258 * @throws IOException
259 */
260 void createTableAsync(final HTableDescriptor desc, final byte[][] splitKeys) throws IOException;
261
262 /**
263 * Deletes a table. Synchronous operation.
264 *
265 * @param tableName name of table to delete
266 * @throws IOException if a remote or network exception occurs
267 */
268 void deleteTable(final TableName tableName) throws IOException;
269
270 /**
271 * Deletes tables matching the passed in pattern and wait on completion. Warning: Use this method
272 * carefully, there is no prompting and the effect is immediate. Consider using {@link
273 * #listTables(java.lang.String)} and {@link #deleteTable(org.apache.hadoop.hbase.TableName)}
274 *
275 * @param regex The regular expression to match table names against
276 * @return Table descriptors for tables that couldn't be deleted
277 * @throws IOException
278 * @see #deleteTables(java.util.regex.Pattern)
279 * @see #deleteTable(org.apache.hadoop.hbase.TableName)
280 */
281 HTableDescriptor[] deleteTables(String regex) throws IOException;
282
283 /**
284 * Delete tables matching the passed in pattern and wait on completion. Warning: Use this method
285 * carefully, there is no prompting and the effect is immediate. Consider using {@link
286 * #listTables(java.util.regex.Pattern) } and
287 * {@link #deleteTable(org.apache.hadoop.hbase.TableName)}
288 *
289 * @param pattern The pattern to match table names against
290 * @return Table descriptors for tables that couldn't be deleted
291 * @throws IOException
292 */
293 HTableDescriptor[] deleteTables(Pattern pattern) throws IOException;
294
295 /**
296 * Truncate a table.
297 * Synchronous operation.
298 *
299 * @param tableName name of table to truncate
300 * @param preserveSplits True if the splits should be preserved
301 * @throws IOException if a remote or network exception occurs
302 */
303 public void truncateTable(final TableName tableName, final boolean preserveSplits)
304 throws IOException;
305
306 /**
307 * Enable a table. May timeout. Use {@link #enableTableAsync(org.apache.hadoop.hbase.TableName)}
308 * and {@link #isTableEnabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in
309 * disabled state for it to be enabled.
310 *
311 * @param tableName name of the table
312 * @throws IOException if a remote or network exception occurs There could be couple types of
313 * IOException TableNotFoundException means the table doesn't exist. TableNotDisabledException
314 * means the table isn't in disabled state.
315 * @see #isTableEnabled(org.apache.hadoop.hbase.TableName)
316 * @see #disableTable(org.apache.hadoop.hbase.TableName)
317 * @see #enableTableAsync(org.apache.hadoop.hbase.TableName)
318 */
319 void enableTable(final TableName tableName) throws IOException;
320
321 /**
322 * Brings a table on-line (enables it). Method returns immediately though enable of table may
323 * take some time to complete, especially if the table is large (All regions are opened as part of
324 * enabling process). Check {@link #isTableEnabled(org.apache.hadoop.hbase.TableName)} to learn
325 * when table is fully online. If table is taking too long to online, check server logs.
326 *
327 * @param tableName
328 * @throws IOException
329 * @since 0.90.0
330 */
331 void enableTableAsync(final TableName tableName) throws IOException;
332
333 /**
334 * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method
335 * carefully, there is no prompting and the effect is immediate. Consider using {@link
336 * #listTables(java.lang.String)} and {@link #enableTable(org.apache.hadoop.hbase.TableName)}
337 *
338 * @param regex The regular expression to match table names against
339 * @throws IOException
340 * @see #enableTables(java.util.regex.Pattern)
341 * @see #enableTable(org.apache.hadoop.hbase.TableName)
342 */
343 HTableDescriptor[] enableTables(String regex) throws IOException;
344
345 /**
346 * Enable tables matching the passed in pattern and wait on completion. Warning: Use this method
347 * carefully, there is no prompting and the effect is immediate. Consider using {@link
348 * #listTables(java.util.regex.Pattern) } and
349 * {@link #enableTable(org.apache.hadoop.hbase.TableName)}
350 *
351 * @param pattern The pattern to match table names against
352 * @throws IOException
353 */
354 HTableDescriptor[] enableTables(Pattern pattern) throws IOException;
355
356 /**
357 * Starts the disable of a table. If it is being served, the master will tell the servers to stop
358 * serving it. This method returns immediately. The disable of a table can take some time if the
359 * table is large (all regions are closed as part of table disable operation). Call {@link
360 * #isTableDisabled(org.apache.hadoop.hbase.TableName)} to check for when disable completes. If
361 * table is taking too long to online, check server logs.
362 *
363 * @param tableName name of table
364 * @throws IOException if a remote or network exception occurs
365 * @see #isTableDisabled(org.apache.hadoop.hbase.TableName)
366 * @see #isTableEnabled(org.apache.hadoop.hbase.TableName)
367 * @since 0.90.0
368 */
369 void disableTableAsync(final TableName tableName) throws IOException;
370
371 /**
372 * Disable table and wait on completion. May timeout eventually. Use {@link
373 * #disableTableAsync(org.apache.hadoop.hbase.TableName)} and
374 * {@link #isTableDisabled(org.apache.hadoop.hbase.TableName)} instead. The table has to be in
375 * enabled state for it to be disabled.
376 *
377 * @param tableName
378 * @throws IOException There could be couple types of IOException TableNotFoundException means the
379 * table doesn't exist. TableNotEnabledException means the table isn't in enabled state.
380 */
381 void disableTable(final TableName tableName) throws IOException;
382
383 /**
384 * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method
385 * carefully, there is no prompting and the effect is immediate. Consider using {@link
386 * #listTables(java.lang.String)} and {@link #disableTable(org.apache.hadoop.hbase.TableName)}
387 *
388 * @param regex The regular expression to match table names against
389 * @return Table descriptors for tables that couldn't be disabled
390 * @throws IOException
391 * @see #disableTables(java.util.regex.Pattern)
392 * @see #disableTable(org.apache.hadoop.hbase.TableName)
393 */
394 HTableDescriptor[] disableTables(String regex) throws IOException;
395
396 /**
397 * Disable tables matching the passed in pattern and wait on completion. Warning: Use this method
398 * carefully, there is no prompting and the effect is immediate. Consider using {@link
399 * #listTables(java.util.regex.Pattern) } and
400 * {@link #disableTable(org.apache.hadoop.hbase.TableName)}
401 *
402 * @param pattern The pattern to match table names against
403 * @return Table descriptors for tables that couldn't be disabled
404 * @throws IOException
405 */
406 HTableDescriptor[] disableTables(Pattern pattern) throws IOException;
407
408 /**
409 * @param tableName name of table to check
410 * @return true if table is on-line
411 * @throws IOException if a remote or network exception occurs
412 */
413 boolean isTableEnabled(TableName tableName) throws IOException;
414
415 /**
416 * @param tableName name of table to check
417 * @return true if table is off-line
418 * @throws IOException if a remote or network exception occurs
419 */
420 boolean isTableDisabled(TableName tableName) throws IOException;
421
422 /**
423 * @param tableName name of table to check
424 * @return true if all regions of the table are available
425 * @throws IOException if a remote or network exception occurs
426 */
427 boolean isTableAvailable(TableName tableName) throws IOException;
428
429 /**
430 * Use this api to check if the table has been created with the specified number of splitkeys
431 * which was used while creating the given table. Note : If this api is used after a table's
432 * region gets splitted, the api may return false.
433 *
434 * @param tableName name of table to check
435 * @param splitKeys keys to check if the table has been created with all split keys
436 * @throws IOException if a remote or network excpetion occurs
437 */
438 boolean isTableAvailable(TableName tableName, byte[][] splitKeys) throws IOException;
439
440 /**
441 * Get the status of alter command - indicates how many regions have received the updated schema
442 * Asynchronous operation.
443 *
444 * @param tableName TableName instance
445 * @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are
446 * yet to be updated Pair.getSecond() is the total number of regions of the table
447 * @throws IOException if a remote or network exception occurs
448 */
449 Pair<Integer, Integer> getAlterStatus(final TableName tableName) throws IOException;
450
451 /**
452 * Get the status of alter command - indicates how many regions have received the updated schema
453 * Asynchronous operation.
454 *
455 * @param tableName name of the table to get the status of
456 * @return Pair indicating the number of regions updated Pair.getFirst() is the regions that are
457 * yet to be updated Pair.getSecond() is the total number of regions of the table
458 * @throws IOException if a remote or network exception occurs
459 */
460 Pair<Integer, Integer> getAlterStatus(final byte[] tableName) throws IOException;
461
462 /**
463 * Add a column to an existing table. Asynchronous operation.
464 *
465 * @param tableName name of the table to add column to
466 * @param column column descriptor of column to be added
467 * @throws IOException if a remote or network exception occurs
468 */
469 void addColumn(final TableName tableName, final HColumnDescriptor column) throws IOException;
470
471 /**
472 * Delete a column from a table. Asynchronous operation.
473 *
474 * @param tableName name of table
475 * @param columnName name of column to be deleted
476 * @throws IOException if a remote or network exception occurs
477 */
478 void deleteColumn(final TableName tableName, final byte[] columnName) throws IOException;
479
480 /**
481 * Modify an existing column family on a table. Asynchronous operation.
482 *
483 * @param tableName name of table
484 * @param descriptor new column descriptor to use
485 * @throws IOException if a remote or network exception occurs
486 */
487 void modifyColumn(final TableName tableName, final HColumnDescriptor descriptor)
488 throws IOException;
489
490 /**
491 * Close a region. For expert-admins. Runs close on the regionserver. The master will not be
492 * informed of the close.
493 *
494 * @param regionname region name to close
495 * @param serverName If supplied, we'll use this location rather than the one currently in
496 * <code>hbase:meta</code>
497 * @throws IOException if a remote or network exception occurs
498 */
499 void closeRegion(final String regionname, final String serverName) throws IOException;
500
501 /**
502 * Close a region. For expert-admins Runs close on the regionserver. The master will not be
503 * informed of the close.
504 *
505 * @param regionname region name to close
506 * @param serverName The servername of the regionserver. If passed null we will use servername
507 * found in the hbase:meta table. A server name is made of host, port and startcode. Here is an
508 * example: <code> host187.example.com,60020,1289493121758</code>
509 * @throws IOException if a remote or network exception occurs
510 */
511 void closeRegion(final byte[] regionname, final String serverName) throws IOException;
512
513 /**
514 * For expert-admins. Runs close on the regionserver. Closes a region based on the encoded region
515 * name. The region server name is mandatory. If the servername is provided then based on the
516 * online regions in the specified regionserver the specified region will be closed. The master
517 * will not be informed of the close. Note that the regionname is the encoded regionname.
518 *
519 * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
520 * suffix: e.g. if regionname is
521 * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
522 * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
523 * @param serverName The servername of the regionserver. A server name is made of host, port and
524 * startcode. This is mandatory. Here is an example:
525 * <code> host187.example.com,60020,1289493121758</code>
526 * @return true if the region was closed, false if not.
527 * @throws IOException if a remote or network exception occurs
528 */
529 boolean closeRegionWithEncodedRegionName(final String encodedRegionName, final String serverName)
530 throws IOException;
531
532 /**
533 * Close a region. For expert-admins Runs close on the regionserver. The master will not be
534 * informed of the close.
535 *
536 * @param sn
537 * @param hri
538 * @throws IOException
539 */
540 void closeRegion(final ServerName sn, final HRegionInfo hri) throws IOException;
541
542 /**
543 * Get all the online regions on a region server.
544 */
545 List<HRegionInfo> getOnlineRegions(final ServerName sn) throws IOException;
546
547 /**
548 * Flush a table. Synchronous operation.
549 *
550 * @param tableName table to flush
551 * @throws IOException if a remote or network exception occurs
552 */
553 void flush(final TableName tableName) throws IOException;
554
555 /**
556 * Flush an individual region. Synchronous operation.
557 *
558 * @param regionName region to flush
559 * @throws IOException if a remote or network exception occurs
560 */
561 void flushRegion(final byte[] regionName) throws IOException;
562
563 /**
564 * Compact a table. Asynchronous operation.
565 *
566 * @param tableName table to compact
567 * @throws IOException if a remote or network exception occurs
568 */
569 void compact(final TableName tableName) throws IOException;
570
571 /**
572 * Compact an individual region. Asynchronous operation.
573 *
574 * @param regionName region to compact
575 * @throws IOException if a remote or network exception occurs
576 */
577 void compactRegion(final byte[] regionName) throws IOException;
578
579 /**
580 * Compact a column family within a table. Asynchronous operation.
581 *
582 * @param tableName table to compact
583 * @param columnFamily column family within a table
584 * @throws IOException if a remote or network exception occurs
585 */
586 void compact(final TableName tableName, final byte[] columnFamily)
587 throws IOException;
588
589 /**
590 * Compact a column family within a region. Asynchronous operation.
591 *
592 * @param regionName region to compact
593 * @param columnFamily column family within a region
594 * @throws IOException if a remote or network exception occurs
595 */
596 void compactRegion(final byte[] regionName, final byte[] columnFamily)
597 throws IOException;
598
599 /**
600 * Major compact a table. Asynchronous operation.
601 *
602 * @param tableName table to major compact
603 * @throws IOException if a remote or network exception occurs
604 */
605 void majorCompact(TableName tableName) throws IOException;
606
607 /**
608 * Major compact a table or an individual region. Asynchronous operation.
609 *
610 * @param regionName region to major compact
611 * @throws IOException if a remote or network exception occurs
612 */
613 void majorCompactRegion(final byte[] regionName) throws IOException;
614
615 /**
616 * Major compact a column family within a table. Asynchronous operation.
617 *
618 * @param tableName table to major compact
619 * @param columnFamily column family within a table
620 * @throws IOException if a remote or network exception occurs
621 */
622 void majorCompact(TableName tableName, final byte[] columnFamily)
623 throws IOException;
624
625 /**
626 * Major compact a column family within region. Asynchronous operation.
627 *
628 * @param regionName egion to major compact
629 * @param columnFamily column family within a region
630 * @throws IOException if a remote or network exception occurs
631 */
632 void majorCompactRegion(final byte[] regionName, final byte[] columnFamily)
633 throws IOException;
634
635 /**
636 * Compact all regions on the region server
637 * @param sn the region server name
638 * @param major if it's major compaction
639 * @throws IOException
640 * @throws InterruptedException
641 */
642 public void compactRegionServer(final ServerName sn, boolean major)
643 throws IOException, InterruptedException;
644
645 /**
646 * Move the region <code>r</code> to <code>dest</code>.
647 *
648 * @param encodedRegionName The encoded region name; i.e. the hash that makes up the region name
649 * suffix: e.g. if regionname is
650 * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
651 * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
652 * @param destServerName The servername of the destination regionserver. If passed the empty byte
653 * array we'll assign to a random server. A server name is made of host, port and startcode.
654 * Here is an example: <code> host187.example.com,60020,1289493121758</code>
655 * @throws UnknownRegionException Thrown if we can't find a region named
656 * <code>encodedRegionName</code>
657 */
658 void move(final byte[] encodedRegionName, final byte[] destServerName)
659 throws IOException;
660
661 /**
662 * @param regionName Region name to assign.
663 */
664 void assign(final byte[] regionName)
665 throws IOException;
666
667 /**
668 * Unassign a region from current hosting regionserver. Region will then be assigned to a
669 * regionserver chosen at random. Region could be reassigned back to the same server. Use {@link
670 * #move(byte[], byte[])} if you want to control the region movement.
671 *
672 * @param regionName Region to unassign. Will clear any existing RegionPlan if one found.
673 * @param force If true, force unassign (Will remove region from regions-in-transition too if
674 * present. If results in double assignment use hbck -fix to resolve. To be used by experts).
675 */
676 void unassign(final byte[] regionName, final boolean force)
677 throws IOException;
678
679 /**
680 * Offline specified region from master's in-memory state. It will not attempt to reassign the
681 * region as in unassign. This API can be used when a region not served by any region server and
682 * still online as per Master's in memory state. If this API is incorrectly used on active region
683 * then master will loose track of that region. This is a special method that should be used by
684 * experts or hbck.
685 *
686 * @param regionName Region to offline.
687 * @throws IOException
688 */
689 void offline(final byte[] regionName) throws IOException;
690
691 /**
692 * Turn the load balancer on or off.
693 *
694 * @param synchronous If true, it waits until current balance() call, if outstanding, to return.
695 * @return Previous balancer value
696 */
697 boolean setBalancerRunning(final boolean on, final boolean synchronous)
698 throws IOException;
699
700 /**
701 * Invoke the balancer. Will run the balancer and if regions to move, it will go ahead and do the
702 * reassignments. Can NOT run for various reasons. Check logs.
703 *
704 * @return True if balancer ran, false otherwise.
705 */
706 boolean balancer() throws IOException;
707
708 /**
709 * Invoke the balancer. Will run the balancer and if regions to move, it will
710 * go ahead and do the reassignments. If there is region in transition, force parameter of true
711 * would still run balancer. Can *not* run for other reasons. Check
712 * logs.
713 * @param force whether we should force balance even if there is region in transition
714 * @return True if balancer ran, false otherwise.
715 */
716 boolean balancer(boolean force) throws IOException;
717
718 /**
719 * Query the current state of the balancer
720 *
721 * @return true if the balancer is enabled, false otherwise.
722 */
723 boolean isBalancerEnabled() throws IOException;
724
725 /**
726 * Invoke region normalizer. Can NOT run for various reasons. Check logs.
727 *
728 * @return True if region normalizer ran, false otherwise.
729 */
730 boolean normalize() throws IOException;
731
732 /**
733 * Query the current state of the region normalizer
734 *
735 * @return true if region normalizer is enabled, false otherwise.
736 */
737 boolean isNormalizerEnabled() throws IOException;
738
739 /**
740 * Turn region normalizer on or off.
741 *
742 * @return Previous normalizer value
743 */
744 boolean setNormalizerRunning(final boolean on)
745 throws IOException;
746
747 /**
748 * Enable/Disable the catalog janitor
749 *
750 * @param enable if true enables the catalog janitor
751 * @return the previous state
752 */
753 boolean enableCatalogJanitor(boolean enable) throws IOException;
754
755 /**
756 * Ask for a scan of the catalog table
757 *
758 * @return the number of entries cleaned
759 */
760 int runCatalogScan() throws IOException;
761
762 /**
763 * Query on the catalog janitor state (Enabled/Disabled?)
764 *
765 */
766 boolean isCatalogJanitorEnabled() throws IOException;
767
768 /**
769 * Merge two regions. Asynchronous operation.
770 *
771 * @param encodedNameOfRegionA encoded name of region a
772 * @param encodedNameOfRegionB encoded name of region b
773 * @param forcible true if do a compulsory merge, otherwise we will only merge two adjacent
774 * regions
775 * @throws IOException
776 */
777 void mergeRegions(final byte[] encodedNameOfRegionA, final byte[] encodedNameOfRegionB,
778 final boolean forcible) throws IOException;
779
780 /**
781 * Split a table. Asynchronous operation.
782 *
783 * @param tableName table to split
784 * @throws IOException if a remote or network exception occurs
785 */
786 void split(final TableName tableName) throws IOException;
787
788 /**
789 * Split an individual region. Asynchronous operation.
790 *
791 * @param regionName region to split
792 * @throws IOException if a remote or network exception occurs
793 */
794 void splitRegion(final byte[] regionName) throws IOException;
795
796 /**
797 * Split a table. Asynchronous operation.
798 *
799 * @param tableName table to split
800 * @param splitPoint the explicit position to split on
801 * @throws IOException if a remote or network exception occurs
802 */
803 void split(final TableName tableName, final byte[] splitPoint)
804 throws IOException;
805
806 /**
807 * Split an individual region. Asynchronous operation.
808 *
809 * @param regionName region to split
810 * @param splitPoint the explicit position to split on
811 * @throws IOException if a remote or network exception occurs
812 */
813 void splitRegion(final byte[] regionName, final byte[] splitPoint)
814 throws IOException;
815
816
817 /**
818 * Modify an existing table, more IRB friendly version. Asynchronous operation. This means that
819 * it may be a while before your schema change is updated across all of the table.
820 *
821 * @param tableName name of table.
822 * @param htd modified description of the table
823 * @throws IOException if a remote or network exception occurs
824 */
825 void modifyTable(final TableName tableName, final HTableDescriptor htd)
826 throws IOException;
827
828 /**
829 * Shuts down the HBase cluster
830 *
831 * @throws IOException if a remote or network exception occurs
832 */
833 void shutdown() throws IOException;
834
835 /**
836 * Shuts down the current HBase master only. Does not shutdown the cluster.
837 *
838 * @throws IOException if a remote or network exception occurs
839 * @see #shutdown()
840 */
841 void stopMaster() throws IOException;
842
843 /**
844 * Stop the designated regionserver
845 *
846 * @param hostnamePort Hostname and port delimited by a <code>:</code> as in
847 * <code>example.org:1234</code>
848 * @throws IOException if a remote or network exception occurs
849 */
850 void stopRegionServer(final String hostnamePort) throws IOException;
851
852 /**
853 * @return cluster status
854 * @throws IOException if a remote or network exception occurs
855 */
856 ClusterStatus getClusterStatus() throws IOException;
857
858 /**
859 * @return Configuration used by the instance.
860 */
861 Configuration getConfiguration();
862
863 /**
864 * Create a new namespace
865 *
866 * @param descriptor descriptor which describes the new namespace
867 * @throws IOException
868 */
869 void createNamespace(final NamespaceDescriptor descriptor)
870 throws IOException;
871
872 /**
873 * Modify an existing namespace
874 *
875 * @param descriptor descriptor which describes the new namespace
876 * @throws IOException
877 */
878 void modifyNamespace(final NamespaceDescriptor descriptor)
879 throws IOException;
880
881 /**
882 * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
883 *
884 * @param name namespace name
885 * @throws IOException
886 */
887 void deleteNamespace(final String name) throws IOException;
888
889 /**
890 * Get a namespace descriptor by name
891 *
892 * @param name name of namespace descriptor
893 * @return A descriptor
894 * @throws IOException
895 */
896 NamespaceDescriptor getNamespaceDescriptor(final String name)
897 throws IOException;
898
899 /**
900 * List available namespace descriptors
901 *
902 * @return List of descriptors
903 * @throws IOException
904 */
905 NamespaceDescriptor[] listNamespaceDescriptors()
906 throws IOException;
907
908 /**
909 * Get list of table descriptors by namespace
910 *
911 * @param name namespace name
912 * @return A descriptor
913 * @throws IOException
914 */
915 HTableDescriptor[] listTableDescriptorsByNamespace(final String name)
916 throws IOException;
917
918 /**
919 * Get list of table names by namespace
920 *
921 * @param name namespace name
922 * @return The list of table names in the namespace
923 * @throws IOException
924 */
925 TableName[] listTableNamesByNamespace(final String name)
926 throws IOException;
927
928 /**
929 * Get the regions of a given table.
930 *
931 * @param tableName the name of the table
932 * @return List of {@link HRegionInfo}.
933 * @throws IOException
934 */
935 List<HRegionInfo> getTableRegions(final TableName tableName)
936 throws IOException;
937
938 @Override
939 void close() throws IOException;
940
941 /**
942 * Get tableDescriptors
943 *
944 * @param tableNames List of table names
945 * @return HTD[] the tableDescriptor
946 * @throws IOException if a remote or network exception occurs
947 */
948 HTableDescriptor[] getTableDescriptorsByTableName(List<TableName> tableNames)
949 throws IOException;
950
951 /**
952 * Get tableDescriptors
953 *
954 * @param names List of table names
955 * @return HTD[] the tableDescriptor
956 * @throws IOException if a remote or network exception occurs
957 */
958 HTableDescriptor[] getTableDescriptors(List<String> names)
959 throws IOException;
960
961 /**
962 * abort a procedure
963 * @param procId ID of the procedure to abort
964 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
965 * @return true if aborted, false if procedure already completed or does not exist
966 * @throws IOException
967 */
968 boolean abortProcedure(
969 final long procId,
970 final boolean mayInterruptIfRunning) throws IOException;
971
972 /**
973 * List procedures
974 * @return procedure list
975 * @throws IOException
976 */
977 ProcedureInfo[] listProcedures() throws IOException;
978
979 /**
980 * Abort a procedure but does not block and wait for it be completely removed.
981 * You can use Future.get(long, TimeUnit) to wait on the operation to complete.
982 * It may throw ExecutionException if there was an error while executing the operation
983 * or TimeoutException in case the wait timeout was not long enough to allow the
984 * operation to complete.
985 *
986 * @param procId ID of the procedure to abort
987 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
988 * @return true if aborted, false if procedure already completed or does not exist
989 * @throws IOException
990 */
991 Future<Boolean> abortProcedureAsync(
992 final long procId,
993 final boolean mayInterruptIfRunning) throws IOException;
994
995 /**
996 * Roll the log writer. I.e. for filesystem based write ahead logs, start writing to a new file.
997 *
998 * Note that the actual rolling of the log writer is asynchronous and may not be complete when
999 * this method returns. As a side effect of this call, the named region server may schedule
1000 * store flushes at the request of the wal.
1001 *
1002 * @param serverName The servername of the regionserver.
1003 * @throws IOException if a remote or network exception occurs
1004 * @throws org.apache.hadoop.hbase.regionserver.wal.FailedLogCloseException
1005 */
1006 void rollWALWriter(ServerName serverName) throws IOException, FailedLogCloseException;
1007
1008 /**
1009 * Helper delegage to getClusterStatus().getMasterCoprocessors().
1010 * @return an array of master coprocessors
1011 * @see org.apache.hadoop.hbase.ClusterStatus#getMasterCoprocessors()
1012 */
1013 String[] getMasterCoprocessors() throws IOException;
1014
1015 /**
1016 * Get the current compaction state of a table. It could be in a major compaction, a minor
1017 * compaction, both, or none.
1018 *
1019 * @param tableName table to examine
1020 * @return the current compaction state
1021 * @throws IOException if a remote or network exception occurs
1022 */
1023 AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState(final TableName tableName)
1024 throws IOException;
1025
1026 /**
1027 * Get the current compaction state of region. It could be in a major compaction, a minor
1028 * compaction, both, or none.
1029 *
1030 * @param regionName region to examine
1031 * @return the current compaction state
1032 * @throws IOException if a remote or network exception occurs
1033 */
1034 AdminProtos.GetRegionInfoResponse.CompactionState getCompactionStateForRegion(
1035 final byte[] regionName) throws IOException;
1036
1037 /**
1038 * Get the timestamp of the last major compaction for the passed table
1039 *
1040 * The timestamp of the oldest HFile resulting from a major compaction of that table,
1041 * or 0 if no such HFile could be found.
1042 *
1043 * @param tableName table to examine
1044 * @return the last major compaction timestamp or 0
1045 * @throws IOException if a remote or network exception occurs
1046 */
1047 long getLastMajorCompactionTimestamp(final TableName tableName)
1048 throws IOException;
1049
1050 /**
1051 * Get the timestamp of the last major compaction for the passed region.
1052 *
1053 * The timestamp of the oldest HFile resulting from a major compaction of that region,
1054 * or 0 if no such HFile could be found.
1055 *
1056 * @param regionName region to examine
1057 * @return the last major compaction timestamp or 0
1058 * @throws IOException if a remote or network exception occurs
1059 */
1060 long getLastMajorCompactionTimestampForRegion(final byte[] regionName)
1061 throws IOException;
1062
1063 /**
1064 * Take a snapshot for the given table. If the table is enabled, a FLUSH-type snapshot will be
1065 * taken. If the table is disabled, an offline snapshot is taken. Snapshots are considered unique
1066 * based on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even
1067 * a different type or with different parameters) will fail with a {@link
1068 * org.apache.hadoop.hbase.snapshot.SnapshotCreationException} indicating the duplicate naming.
1069 * Snapshot names follow the same naming constraints as tables in HBase. See {@link
1070 * org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
1071 *
1072 * @param snapshotName name of the snapshot to be created
1073 * @param tableName name of the table for which snapshot is created
1074 * @throws IOException if a remote or network exception occurs
1075 * @throws org.apache.hadoop.hbase.snapshot.SnapshotCreationException if snapshot creation failed
1076 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1077 */
1078 void snapshot(final String snapshotName, final TableName tableName)
1079 throws IOException, SnapshotCreationException, IllegalArgumentException;
1080
1081 /**
1082 * public void snapshot(final String snapshotName, Create a timestamp consistent snapshot for the
1083 * given table. final byte[] tableName) throws IOException, Snapshots are considered unique based
1084 * on <b>the name of the snapshot</b>. Attempts to take a snapshot with the same name (even a
1085 * different type or with different parameters) will fail with a {@link SnapshotCreationException}
1086 * indicating the duplicate naming. Snapshot names follow the same naming constraints as tables in
1087 * HBase.
1088 *
1089 * @param snapshotName name of the snapshot to be created
1090 * @param tableName name of the table for which snapshot is created
1091 * @throws IOException if a remote or network exception occurs
1092 * @throws SnapshotCreationException if snapshot creation failed
1093 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1094 */
1095 void snapshot(final byte[] snapshotName, final TableName tableName)
1096 throws IOException, SnapshotCreationException, IllegalArgumentException;
1097
1098 /**
1099 * Create typed snapshot of the table. Snapshots are considered unique based on <b>the name of the
1100 * snapshot</b>. Attempts to take a snapshot with the same name (even a different type or with
1101 * different parameters) will fail with a {@link SnapshotCreationException} indicating the
1102 * duplicate naming. Snapshot names follow the same naming constraints as tables in HBase. See
1103 * {@link org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}.
1104 *
1105 * @param snapshotName name to give the snapshot on the filesystem. Must be unique from all other
1106 * snapshots stored on the cluster
1107 * @param tableName name of the table to snapshot
1108 * @param type type of snapshot to take
1109 * @throws IOException we fail to reach the master
1110 * @throws SnapshotCreationException if snapshot creation failed
1111 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1112 */
1113 void snapshot(final String snapshotName,
1114 final TableName tableName,
1115 HBaseProtos.SnapshotDescription.Type type) throws IOException, SnapshotCreationException,
1116 IllegalArgumentException;
1117
1118 /**
1119 * Take a snapshot and wait for the server to complete that snapshot (blocking). Only a single
1120 * snapshot should be taken at a time for an instance of HBase, or results may be undefined (you
1121 * can tell multiple HBase clusters to snapshot at the same time, but only one at a time for a
1122 * single cluster). Snapshots are considered unique based on <b>the name of the snapshot</b>.
1123 * Attempts to take a snapshot with the same name (even a different type or with different
1124 * parameters) will fail with a {@link SnapshotCreationException} indicating the duplicate naming.
1125 * Snapshot names follow the same naming constraints as tables in HBase. See {@link
1126 * org.apache.hadoop.hbase.TableName#isLegalFullyQualifiedTableName(byte[])}. You should probably
1127 * use {@link #snapshot(String, org.apache.hadoop.hbase.TableName)} or
1128 * {@link #snapshot(byte[], org.apache.hadoop.hbase.TableName)} unless you are sure about the type
1129 * of snapshot that you want to take.
1130 *
1131 * @param snapshot snapshot to take
1132 * @throws IOException or we lose contact with the master.
1133 * @throws SnapshotCreationException if snapshot failed to be taken
1134 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1135 */
1136 void snapshot(HBaseProtos.SnapshotDescription snapshot)
1137 throws IOException, SnapshotCreationException, IllegalArgumentException;
1138
1139 /**
1140 * Take a snapshot without waiting for the server to complete that snapshot (asynchronous) Only a
1141 * single snapshot should be taken at a time, or results may be undefined.
1142 *
1143 * @param snapshot snapshot to take
1144 * @return response from the server indicating the max time to wait for the snapshot
1145 * @throws IOException if the snapshot did not succeed or we lose contact with the master.
1146 * @throws SnapshotCreationException if snapshot creation failed
1147 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
1148 */
1149 MasterProtos.SnapshotResponse takeSnapshotAsync(HBaseProtos.SnapshotDescription snapshot)
1150 throws IOException, SnapshotCreationException;
1151
1152 /**
1153 * Check the current state of the passed snapshot. There are three possible states: <ol>
1154 * <li>running - returns <tt>false</tt></li> <li>finished - returns <tt>true</tt></li>
1155 * <li>finished with error - throws the exception that caused the snapshot to fail</li> </ol> The
1156 * cluster only knows about the most recent snapshot. Therefore, if another snapshot has been
1157 * run/started since the snapshot your are checking, you will recieve an {@link
1158 * org.apache.hadoop.hbase.snapshot.UnknownSnapshotException}.
1159 *
1160 * @param snapshot description of the snapshot to check
1161 * @return <tt>true</tt> if the snapshot is completed, <tt>false</tt> if the snapshot is still
1162 * running
1163 * @throws IOException if we have a network issue
1164 * @throws org.apache.hadoop.hbase.snapshot.HBaseSnapshotException if the snapshot failed
1165 * @throws org.apache.hadoop.hbase.snapshot.UnknownSnapshotException if the requested snapshot is
1166 * unknown
1167 */
1168 boolean isSnapshotFinished(final HBaseProtos.SnapshotDescription snapshot)
1169 throws IOException, HBaseSnapshotException, UnknownSnapshotException;
1170
1171 /**
1172 * Restore the specified snapshot on the original table. (The table must be disabled) If the
1173 * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a
1174 * snapshot of the current table is taken before executing the restore operation. In case of
1175 * restore failure, the failsafe snapshot will be restored. If the restore completes without
1176 * problem the failsafe snapshot is deleted.
1177 *
1178 * @param snapshotName name of the snapshot to restore
1179 * @throws IOException if a remote or network exception occurs
1180 * @throws org.apache.hadoop.hbase.snapshot.RestoreSnapshotException if snapshot failed to be
1181 * restored
1182 * @throws IllegalArgumentException if the restore request is formatted incorrectly
1183 */
1184 void restoreSnapshot(final byte[] snapshotName) throws IOException, RestoreSnapshotException;
1185
1186 /**
1187 * Restore the specified snapshot on the original table. (The table must be disabled) If the
1188 * "hbase.snapshot.restore.take.failsafe.snapshot" configuration property is set to true, a
1189 * snapshot of the current table is taken before executing the restore operation. In case of
1190 * restore failure, the failsafe snapshot will be restored. If the restore completes without
1191 * problem the failsafe snapshot is deleted.
1192 *
1193 * @param snapshotName name of the snapshot to restore
1194 * @throws IOException if a remote or network exception occurs
1195 * @throws RestoreSnapshotException if snapshot failed to be restored
1196 * @throws IllegalArgumentException if the restore request is formatted incorrectly
1197 */
1198 void restoreSnapshot(final String snapshotName) throws IOException, RestoreSnapshotException;
1199
1200 /**
1201 * Restore the specified snapshot on the original table. (The table must be disabled) If
1202 * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
1203 * executing the restore operation. In case of restore failure, the failsafe snapshot will be
1204 * restored. If the restore completes without problem the failsafe snapshot is deleted. The
1205 * failsafe snapshot name is configurable by using the property
1206 * "hbase.snapshot.restore.failsafe.name".
1207 *
1208 * @param snapshotName name of the snapshot to restore
1209 * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
1210 * @throws IOException if a remote or network exception occurs
1211 * @throws RestoreSnapshotException if snapshot failed to be restored
1212 * @throws IllegalArgumentException if the restore request is formatted incorrectly
1213 */
1214 void restoreSnapshot(final byte[] snapshotName, final boolean takeFailSafeSnapshot)
1215 throws IOException, RestoreSnapshotException;
1216
1217 /**
1218 * Restore the specified snapshot on the original table. (The table must be disabled) If
1219 * 'takeFailSafeSnapshot' is set to true, a snapshot of the current table is taken before
1220 * executing the restore operation. In case of restore failure, the failsafe snapshot will be
1221 * restored. If the restore completes without problem the failsafe snapshot is deleted. The
1222 * failsafe snapshot name is configurable by using the property
1223 * "hbase.snapshot.restore.failsafe.name".
1224 *
1225 * @param snapshotName name of the snapshot to restore
1226 * @param takeFailSafeSnapshot true if the failsafe snapshot should be taken
1227 * @throws IOException if a remote or network exception occurs
1228 * @throws RestoreSnapshotException if snapshot failed to be restored
1229 * @throws IllegalArgumentException if the restore request is formatted incorrectly
1230 */
1231 void restoreSnapshot(final String snapshotName, boolean takeFailSafeSnapshot)
1232 throws IOException, RestoreSnapshotException;
1233
1234 /**
1235 * Create a new table by cloning the snapshot content.
1236 *
1237 * @param snapshotName name of the snapshot to be cloned
1238 * @param tableName name of the table where the snapshot will be restored
1239 * @throws IOException if a remote or network exception occurs
1240 * @throws TableExistsException if table to be created already exists
1241 * @throws RestoreSnapshotException if snapshot failed to be cloned
1242 * @throws IllegalArgumentException if the specified table has not a valid name
1243 */
1244 void cloneSnapshot(final byte[] snapshotName, final TableName tableName)
1245 throws IOException, TableExistsException, RestoreSnapshotException;
1246
1247 /**
1248 * Create a new table by cloning the snapshot content.
1249 *
1250 * @param snapshotName name of the snapshot to be cloned
1251 * @param tableName name of the table where the snapshot will be restored
1252 * @throws IOException if a remote or network exception occurs
1253 * @throws TableExistsException if table to be created already exists
1254 * @throws RestoreSnapshotException if snapshot failed to be cloned
1255 * @throws IllegalArgumentException if the specified table has not a valid name
1256 */
1257 void cloneSnapshot(final String snapshotName, final TableName tableName)
1258 throws IOException, TableExistsException, RestoreSnapshotException;
1259
1260 /**
1261 * Execute a distributed procedure on a cluster.
1262 *
1263 * @param signature A distributed procedure is uniquely identified by its signature (default the
1264 * root ZK node name of the procedure).
1265 * @param instance The instance name of the procedure. For some procedures, this parameter is
1266 * optional.
1267 * @param props Property/Value pairs of properties passing to the procedure
1268 * @throws IOException
1269 */
1270 void execProcedure(String signature, String instance, Map<String, String> props)
1271 throws IOException;
1272
1273 /**
1274 * Execute a distributed procedure on a cluster.
1275 *
1276 * @param signature A distributed procedure is uniquely identified by its signature (default the
1277 * root ZK node name of the procedure).
1278 * @param instance The instance name of the procedure. For some procedures, this parameter is
1279 * optional.
1280 * @param props Property/Value pairs of properties passing to the procedure
1281 * @return data returned after procedure execution. null if no return data.
1282 * @throws IOException
1283 */
1284 byte[] execProcedureWithRet(String signature, String instance, Map<String, String> props)
1285 throws IOException;
1286
1287 /**
1288 * Check the current state of the specified procedure. There are three possible states: <ol>
1289 * <li>running - returns <tt>false</tt></li> <li>finished - returns <tt>true</tt></li>
1290 * <li>finished with error - throws the exception that caused the procedure to fail</li> </ol>
1291 *
1292 * @param signature The signature that uniquely identifies a procedure
1293 * @param instance The instance name of the procedure
1294 * @param props Property/Value pairs of properties passing to the procedure
1295 * @return true if the specified procedure is finished successfully, false if it is still running
1296 * @throws IOException if the specified procedure finished with error
1297 */
1298 boolean isProcedureFinished(String signature, String instance, Map<String, String> props)
1299 throws IOException;
1300
1301 /**
1302 * List completed snapshots.
1303 *
1304 * @return a list of snapshot descriptors for completed snapshots
1305 * @throws IOException if a network error occurs
1306 */
1307 List<HBaseProtos.SnapshotDescription> listSnapshots() throws IOException;
1308
1309 /**
1310 * List all the completed snapshots matching the given regular expression.
1311 *
1312 * @param regex The regular expression to match against
1313 * @return - returns a List of SnapshotDescription
1314 * @throws IOException if a remote or network exception occurs
1315 */
1316 List<HBaseProtos.SnapshotDescription> listSnapshots(String regex) throws IOException;
1317
1318 /**
1319 * List all the completed snapshots matching the given pattern.
1320 *
1321 * @param pattern The compiled regular expression to match against
1322 * @return - returns a List of SnapshotDescription
1323 * @throws IOException if a remote or network exception occurs
1324 */
1325 List<HBaseProtos.SnapshotDescription> listSnapshots(Pattern pattern) throws IOException;
1326
1327 /**
1328 * Delete an existing snapshot.
1329 *
1330 * @param snapshotName name of the snapshot
1331 * @throws IOException if a remote or network exception occurs
1332 */
1333 void deleteSnapshot(final byte[] snapshotName) throws IOException;
1334
1335 /**
1336 * Delete an existing snapshot.
1337 *
1338 * @param snapshotName name of the snapshot
1339 * @throws IOException if a remote or network exception occurs
1340 */
1341 void deleteSnapshot(final String snapshotName) throws IOException;
1342
1343 /**
1344 * Delete existing snapshots whose names match the pattern passed.
1345 *
1346 * @param regex The regular expression to match against
1347 * @throws IOException if a remote or network exception occurs
1348 */
1349 void deleteSnapshots(final String regex) throws IOException;
1350
1351 /**
1352 * Delete existing snapshots whose names match the pattern passed.
1353 *
1354 * @param pattern pattern for names of the snapshot to match
1355 * @throws IOException if a remote or network exception occurs
1356 */
1357 void deleteSnapshots(final Pattern pattern) throws IOException;
1358
1359 /**
1360 * Apply the new quota settings.
1361 * @param quota the quota settings
1362 * @throws IOException if a remote or network exception occurs
1363 */
1364 void setQuota(final QuotaSettings quota) throws IOException;
1365
1366 /**
1367 * Return a QuotaRetriever to list the quotas based on the filter.
1368 * @param filter the quota settings filter
1369 * @return the quota retriever
1370 * @throws IOException if a remote or network exception occurs
1371 */
1372 QuotaRetriever getQuotaRetriever(final QuotaFilter filter) throws IOException;
1373
1374 /**
1375 * Creates and returns a {@link com.google.protobuf.RpcChannel} instance connected to the active
1376 * master. <p> The obtained {@link com.google.protobuf.RpcChannel} instance can be used to access
1377 * a published coprocessor {@link com.google.protobuf.Service} using standard protobuf service
1378 * invocations: </p> <div style="background-color: #cccccc; padding: 2px">
1379 * <blockquote><pre>
1380 * CoprocessorRpcChannel channel = myAdmin.coprocessorService();
1381 * MyService.BlockingInterface service = MyService.newBlockingStub(channel);
1382 * MyCallRequest request = MyCallRequest.newBuilder()
1383 * ...
1384 * .build();
1385 * MyCallResponse response = service.myCall(null, request);
1386 * </pre></blockquote></div>
1387 *
1388 * @return A MasterCoprocessorRpcChannel instance
1389 */
1390 CoprocessorRpcChannel coprocessorService();
1391
1392
1393 /**
1394 * Creates and returns a {@link com.google.protobuf.RpcChannel} instance
1395 * connected to the passed region server.
1396 *
1397 * <p>
1398 * The obtained {@link com.google.protobuf.RpcChannel} instance can be used to access a published
1399 * coprocessor {@link com.google.protobuf.Service} using standard protobuf service invocations:
1400 * </p>
1401 *
1402 * <div style="background-color: #cccccc; padding: 2px">
1403 * <blockquote><pre>
1404 * CoprocessorRpcChannel channel = myAdmin.coprocessorService(serverName);
1405 * MyService.BlockingInterface service = MyService.newBlockingStub(channel);
1406 * MyCallRequest request = MyCallRequest.newBuilder()
1407 * ...
1408 * .build();
1409 * MyCallResponse response = service.myCall(null, request);
1410 * </pre></blockquote></div>
1411 *
1412 * @param sn the server name to which the endpoint call is made
1413 * @return A RegionServerCoprocessorRpcChannel instance
1414 */
1415 CoprocessorRpcChannel coprocessorService(ServerName sn);
1416
1417
1418 /**
1419 * Update the configuration and trigger an online config change
1420 * on the regionserver
1421 * @param server : The server whose config needs to be updated.
1422 * @throws IOException
1423 */
1424 void updateConfiguration(ServerName server) throws IOException;
1425
1426
1427 /**
1428 * Update the configuration and trigger an online config change
1429 * on all the regionservers
1430 * @throws IOException
1431 */
1432 void updateConfiguration() throws IOException;
1433
1434 /**
1435 * Get the info port of the current master if one is available.
1436 * @return master info port
1437 * @throws IOException
1438 */
1439 public int getMasterInfoPort() throws IOException;
1440
1441 /**
1442 * Compact a table. Asynchronous operation.
1443 *
1444 * @param tableName table to compact
1445 * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1446 * @throws IOException
1447 * @throws InterruptedException
1448 */
1449 void compact(final TableName tableName, CompactType compactType)
1450 throws IOException, InterruptedException;
1451
1452 /**
1453 * Compact a column family within a table. Asynchronous operation.
1454 *
1455 * @param tableName table to compact
1456 * @param columnFamily column family within a table
1457 * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1458 * @throws IOException if not a mob column family or if a remote or network exception occurs
1459 * @throws InterruptedException
1460 */
1461 void compact(final TableName tableName, final byte[] columnFamily, CompactType compactType)
1462 throws IOException, InterruptedException;
1463
1464 /**
1465 * Major compact a table. Asynchronous operation.
1466 *
1467 * @param tableName table to compact
1468 * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1469 * @throws IOException
1470 * @throws InterruptedException
1471 */
1472 void majorCompact(final TableName tableName, CompactType compactType) throws IOException,
1473 InterruptedException;
1474
1475 /**
1476 * Major compact a column family within a table. Asynchronous operation.
1477 *
1478 * @param tableName table to compact
1479 * @param columnFamily column family within a table
1480 * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1481 * @throws IOException if not a mob column family or if a remote or network exception occurs
1482 * @throws InterruptedException
1483 */
1484 void majorCompact(final TableName tableName, final byte[] columnFamily, CompactType compactType)
1485 throws IOException, InterruptedException;
1486
1487 /**
1488 * Get the current compaction state of a table. It could be in a compaction, or none.
1489 *
1490 * @param tableName table to examine
1491 * @param compactType {@link org.apache.hadoop.hbase.client.Admin.CompactType}
1492 * @return the current compaction state
1493 * @throws IOException if a remote or network exception occurs
1494 */
1495 AdminProtos.GetRegionInfoResponse.CompactionState getCompactionState(final TableName tableName,
1496 CompactType compactType) throws IOException;
1497
1498 /**
1499 * Get Backup Admin interface
1500 * @return backup admin object
1501 * @throws IOException exception
1502 */
1503 BackupAdmin getBackupAdmin() throws IOException;
1504
1505 /**
1506 * Currently, there are only two compact types:
1507 * {@code NORMAL} means do store files compaction;
1508 * {@code MOB} means do mob files compaction.
1509 * */
1510
1511 @InterfaceAudience.Public
1512 @InterfaceStability.Unstable
1513 public enum CompactType {
1514
1515 NORMAL (0),
1516 MOB (1);
1517
1518 CompactType(int value) {}
1519 }
1520
1521 /**
1522 * Turn the Split or Merge switches on or off.
1523 *
1524 * @param enabled enabled or not
1525 * @param synchronous If true, it waits until current split() call, if outstanding, to return.
1526 * @param switchTypes switchType list {@link MasterSwitchType}
1527 * @return Previous switch value array
1528 */
1529 boolean[] setSplitOrMergeEnabled(final boolean enabled, final boolean synchronous,
1530 final MasterSwitchType... switchTypes) throws IOException;
1531
1532 /**
1533 * Query the current state of the switch
1534 *
1535 * @return true if the switch is enabled, false otherwise.
1536 */
1537 boolean isSplitOrMergeEnabled(final MasterSwitchType switchType) throws IOException;
1538
1539 @InterfaceAudience.Public
1540 @InterfaceStability.Evolving
1541 public enum MasterSwitchType {
1542 SPLIT,
1543 MERGE
1544 }
1545
1546 }