1818package org .apache .hadoop .hbase .snapshot ;
1919
2020import static org .junit .Assert .assertEquals ;
21- import static org .junit .Assert .assertTrue ;
2221import static org .junit .Assert .fail ;
2322
2423import java .io .IOException ;
2726import java .util .HashMap ;
2827import java .util .List ;
2928import java .util .Map ;
30- import java .util .concurrent .CountDownLatch ;
3129
3230import org .apache .commons .logging .Log ;
3331import org .apache .commons .logging .LogFactory ;
6563@ Category (LargeTests .class )
6664public class TestFlushSnapshotFromClient {
6765 private static final Log LOG = LogFactory .getLog (TestFlushSnapshotFromClient .class );
68- private static final HBaseTestingUtility UTIL = new HBaseTestingUtility ();
66+ protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility ();
6967 private static final int NUM_RS = 2 ;
7068 private static final byte [] TEST_FAM = Bytes .toBytes ("fam" );
7169 private static final TableName TABLE_NAME = TableName .valueOf ("test" );
@@ -86,7 +84,7 @@ public static void setupCluster() throws Exception {
8684 UTIL .startMiniCluster (NUM_RS );
8785 }
8886
89- private static void setupConf (Configuration conf ) {
87+ protected static void setupConf (Configuration conf ) {
9088 // disable the ui
9189 conf .setInt ("hbase.regionsever.info.port" , -1 );
9290 // change the flush size to a small amount, regulating number of store files
@@ -400,111 +398,6 @@ public void testFlushCreateListDestroy() throws Exception {
400398 snapshotName , rootDir , fs , true );
401399 }
402400
403- /**
404- * Demonstrate that we reject snapshot requests if there is a snapshot already running on the
405- * same table currently running and that concurrent snapshots on different tables can both
406- * succeed concurretly.
407- */
408- @ Test (timeout =300000 )
409- public void testConcurrentSnapshottingAttempts () throws IOException , InterruptedException {
410- final TableName TABLE2_NAME = TableName .valueOf (TABLE_NAME + "2" );
411-
412- int ssNum = 20 ;
413- Admin admin = UTIL .getHBaseAdmin ();
414- // make sure we don't fail on listing snapshots
415- SnapshotTestingUtils .assertNoSnapshots (admin );
416- // create second testing table
417- SnapshotTestingUtils .createTable (UTIL , TABLE2_NAME , TEST_FAM );
418- // load the table so we have some data
419- SnapshotTestingUtils .loadData (UTIL , TABLE_NAME , DEFAULT_NUM_ROWS , TEST_FAM );
420- SnapshotTestingUtils .loadData (UTIL , TABLE2_NAME , DEFAULT_NUM_ROWS , TEST_FAM );
421-
422- final CountDownLatch toBeSubmitted = new CountDownLatch (ssNum );
423- // We'll have one of these per thread
424- class SSRunnable implements Runnable {
425- SnapshotDescription ss ;
426- SSRunnable (SnapshotDescription ss ) {
427- this .ss = ss ;
428- }
429-
430- @ Override
431- public void run () {
432- try {
433- Admin admin = UTIL .getHBaseAdmin ();
434- LOG .info ("Submitting snapshot request: " + ClientSnapshotDescriptionUtils .toString (ss ));
435- admin .takeSnapshotAsync (ss );
436- } catch (Exception e ) {
437- LOG .info ("Exception during snapshot request: " + ClientSnapshotDescriptionUtils .toString (
438- ss )
439- + ". This is ok, we expect some" , e );
440- }
441- LOG .info ("Submitted snapshot request: " + ClientSnapshotDescriptionUtils .toString (ss ));
442- toBeSubmitted .countDown ();
443- }
444- };
445-
446- // build descriptions
447- SnapshotDescription [] descs = new SnapshotDescription [ssNum ];
448- for (int i = 0 ; i < ssNum ; i ++) {
449- SnapshotDescription .Builder builder = SnapshotDescription .newBuilder ();
450- builder .setTable (((i % 2 ) == 0 ? TABLE_NAME : TABLE2_NAME ).getNameAsString ());
451- builder .setName ("ss" +i );
452- builder .setType (SnapshotDescription .Type .FLUSH );
453- descs [i ] = builder .build ();
454- }
455-
456- // kick each off its own thread
457- for (int i =0 ; i < ssNum ; i ++) {
458- new Thread (new SSRunnable (descs [i ])).start ();
459- }
460-
461- // wait until all have been submitted
462- toBeSubmitted .await ();
463-
464- // loop until all are done.
465- while (true ) {
466- int doneCount = 0 ;
467- for (SnapshotDescription ss : descs ) {
468- try {
469- if (admin .isSnapshotFinished (ss )) {
470- doneCount ++;
471- }
472- } catch (Exception e ) {
473- LOG .warn ("Got an exception when checking for snapshot " + ss .getName (), e );
474- doneCount ++;
475- }
476- }
477- if (doneCount == descs .length ) {
478- break ;
479- }
480- Thread .sleep (100 );
481- }
482-
483- // dump for debugging
484- UTIL .getHBaseCluster ().getMaster ().getMasterFileSystem ().logFileSystemState (LOG );
485-
486- List <SnapshotDescription > taken = admin .listSnapshots ();
487- int takenSize = taken .size ();
488- LOG .info ("Taken " + takenSize + " snapshots: " + taken );
489- assertTrue ("We expect at least 1 request to be rejected because of we concurrently" +
490- " issued many requests" , takenSize < ssNum && takenSize > 0 );
491-
492- // Verify that there's at least one snapshot per table
493- int t1SnapshotsCount = 0 ;
494- int t2SnapshotsCount = 0 ;
495- for (SnapshotDescription ss : taken ) {
496- if (TableName .valueOf (ss .getTable ()).equals (TABLE_NAME )) {
497- t1SnapshotsCount ++;
498- } else if (TableName .valueOf (ss .getTable ()).equals (TABLE2_NAME )) {
499- t2SnapshotsCount ++;
500- }
501- }
502- assertTrue ("We expect at least 1 snapshot of table1 " , t1SnapshotsCount > 0 );
503- assertTrue ("We expect at least 1 snapshot of table2 " , t2SnapshotsCount > 0 );
504-
505- UTIL .deleteTable (TABLE2_NAME );
506- }
507-
508401 private void waitRegionsAfterMerge (final long numRegionsAfterMerge )
509402 throws IOException , InterruptedException {
510403 Admin admin = UTIL .getHBaseAdmin ();
0 commit comments