22
22
import com .alipay .oceanbase .hbase .exception .FeatureNotSupportedException ;
23
23
import com .alipay .oceanbase .hbase .util .ResultSetPrinter ;
24
24
import com .alipay .oceanbase .rpc .exception .ObTableException ;
25
+ import com .alipay .oceanbase .rpc .exception .ObTableGetException ;
25
26
import com .alipay .oceanbase .rpc .protocol .payload .ResultCodes ;
26
27
import org .apache .hadoop .conf .Configuration ;
27
28
import org .apache .hadoop .hbase .*;
@@ -432,31 +433,49 @@ public void testAdminGetRegionMetrics() throws Exception {
432
433
java .sql .Connection conn = ObHTableTestUtil .getConnection ();
433
434
Statement st = conn .createStatement ();
434
435
st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
435
- "\n " +
436
436
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
437
437
" `K` varbinary(1024) NOT NULL,\n " +
438
438
" `Q` varbinary(256) NOT NULL,\n " +
439
439
" `T` bigint(20) NOT NULL,\n " +
440
440
" `V` varbinary(1024) DEFAULT NULL,\n " +
441
441
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
442
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
443
- "\n " +
442
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
444
443
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\n " +
445
444
" `K` varbinary(1024) NOT NULL,\n " +
446
445
" `Q` varbinary(256) NOT NULL,\n " +
447
446
" `T` bigint(20) NOT NULL,\n " +
448
447
" `V` varbinary(1024) DEFAULT NULL,\n " +
449
448
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
450
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
451
- "\n " +
449
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
452
450
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\n " +
453
451
" `K` varbinary(1024) NOT NULL,\n " +
454
452
" `Q` varbinary(256) NOT NULL,\n " +
455
453
" `T` bigint(20) NOT NULL,\n " +
456
454
" `V` varbinary(1024) DEFAULT NULL,\n " +
457
455
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
458
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
459
- "\n " +
456
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
457
+ "CREATE TABLEGROUP IF NOT EXISTS test_no_part SHARDING = 'ADAPTIVE';\n " +
458
+ "CREATE TABLE IF NOT EXISTS `test_no_part$family_with_group1` (\n " +
459
+ " `K` varbinary(1024) NOT NULL,\n " +
460
+ " `Q` varbinary(256) NOT NULL,\n " +
461
+ " `T` bigint(20) NOT NULL,\n " +
462
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
463
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
464
+ ") TABLEGROUP = test_no_part;\n " +
465
+ "CREATE TABLE IF NOT EXISTS `test_no_part$family_with_group2` (\n " +
466
+ " `K` varbinary(1024) NOT NULL,\n " +
467
+ " `Q` varbinary(256) NOT NULL,\n " +
468
+ " `T` bigint(20) NOT NULL,\n " +
469
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
470
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
471
+ ") TABLEGROUP = test_no_part;\n " +
472
+ "CREATE TABLE IF NOT EXISTS `test_no_part$family_with_group3` (\n " +
473
+ " `K` varbinary(1024) NOT NULL,\n " +
474
+ " `Q` varbinary(256) NOT NULL,\n " +
475
+ " `T` bigint(20) NOT NULL,\n " +
476
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
477
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
478
+ ") TABLEGROUP = test_no_part;\n " +
460
479
"CREATE DATABASE IF NOT EXISTS `n1`;\n " +
461
480
"use `n1`;\n " +
462
481
"CREATE TABLEGROUP IF NOT EXISTS `n1:test_multi_cf` SHARDING = 'ADAPTIVE';\n " +
@@ -488,25 +507,30 @@ public void testAdminGetRegionMetrics() throws Exception {
488
507
Configuration conf = ObHTableTestUtil .newConfiguration ();
489
508
Connection connection = ConnectionFactory .createConnection (conf );
490
509
Admin admin = connection .getAdmin ();
510
+ // test tablegroup not existed
491
511
IOException thrown = assertThrows (IOException .class ,
492
512
() -> {
493
513
admin .getRegionMetrics (null , TableName .valueOf ("tablegroup_not_exists" ));
494
514
});
495
515
Assert .assertTrue (thrown .getCause () instanceof ObTableException );
496
516
Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
517
+
518
+ // test use serverName without tableName to get region metrics
497
519
assertThrows (FeatureNotSupportedException .class ,
498
520
() -> {
499
521
admin .getRegionMetrics (ServerName .valueOf ("localhost,1,1" ));
500
522
});
501
- // insert 300 thousand of rows in each table under tablegroup test_multi_cf
523
+
524
+ // test single-thread getRegionMetrics after writing
502
525
batchInsert (100000 , tablegroup1 );
503
- List <RegionMetrics > metrics = admin .getRegionMetrics (null , TableName .valueOf (tablegroup1 ));
504
- for (RegionMetrics regionMetrics : metrics ) {
505
- System .out .println ("region name: " + regionMetrics .getNameAsString ()
506
- + ", storeFileSize: " + regionMetrics .getStoreFileSize ()
507
- + ", memFileSize: " + regionMetrics .getMemStoreSize ());
508
- }
509
- // concurrently read while writing 150 thousand of rows to 2 tablegroups
526
+ // test ServerName is any string
527
+ long start = System .currentTimeMillis ();
528
+ List <RegionMetrics > metrics = admin .getRegionMetrics (ServerName .valueOf ("localhost,1,1" ), TableName .valueOf (tablegroup1 ));
529
+ long cost = System .currentTimeMillis () - start ;
530
+ System .out .println ("get region metrics time usage: " + cost + "ms, tablegroup: " + tablegroup1 );
531
+ assertEquals (30 , metrics .size ());
532
+
533
+ // test getRegionMetrics concurrently reading while writing
510
534
ExecutorService executorService = Executors .newFixedThreadPool (10 );
511
535
CountDownLatch latch = new CountDownLatch (100 );
512
536
List <Exception > exceptionCatcher = new ArrayList <>();
@@ -518,21 +542,42 @@ public void testAdminGetRegionMetrics() throws Exception {
518
542
List <RegionMetrics > regionMetrics = null ;
519
543
// test get regionMetrics from different namespaces
520
544
if (taskId % 3 != 0 ) {
545
+ long thrStart = System .currentTimeMillis ();
521
546
regionMetrics = admin .getRegionMetrics (null , TableName .valueOf (tablegroup1 ));
547
+ long thrCost = System .currentTimeMillis () - thrStart ;
548
+ System .out .println ("task: " + taskId + ", get region metrics time usage: " + thrCost + "ms, tablegroup: " + tablegroup1 );
549
+ if (regionMetrics .size () != 30 ) {
550
+ throw new ObTableGetException (
551
+ "the number of region metrics does not match the number of tablets, the number of region metrics: " + regionMetrics .size ());
552
+ }
522
553
} else {
554
+ long thrStart = System .currentTimeMillis ();
523
555
regionMetrics = admin .getRegionMetrics (null , TableName .valueOf (tablegroup2 ));
524
- }
525
- for ( RegionMetrics m : regionMetrics ) {
526
- System . out . println ( "task: " + taskId + ", tablegroup: " + (( OHRegionMetrics ) m ). getTablegroup ()
527
- + ", region name: " + m . getNameAsString ()
528
- + ", storeFileSize : " + m . getStoreFileSize ()
529
- + ", memFileSize: " + m . getMemStoreSize ());
556
+ long thrCost = System . currentTimeMillis () - thrStart ;
557
+ System . out . println ( "task: " + taskId + ", get region metrics time usage: " + thrCost + "ms, tablegroup: " + tablegroup1 );
558
+ if ( regionMetrics . size () != 9 ) {
559
+ throw new ObTableGetException (
560
+ "the number of region metrics does not match the number of tablets, the number of region metrics : " + regionMetrics . size ());
561
+ }
530
562
}
531
563
} else {
532
- if (taskId % 8 == 0 ) {
533
- batchInsert (1000 , tablegroup2 );
534
- } else {
535
- batchInsert (1000 , tablegroup1 );
564
+ try {
565
+ if (taskId % 8 == 0 ) {
566
+ batchInsert (1000 , tablegroup2 );
567
+ } else {
568
+ batchInsert (1000 , tablegroup1 );
569
+ }
570
+ } catch (Exception e ) {
571
+ Exception originalCause = e ;
572
+ while (originalCause .getCause () != null && originalCause .getCause () instanceof ObTableException ) {
573
+ originalCause = (Exception ) originalCause .getCause ();
574
+ }
575
+ if (originalCause instanceof ObTableException && ((ObTableException ) originalCause ).getErrorCode () == ResultCodes .OB_TIMEOUT .errorCode ) {
576
+ // ignore
577
+ System .out .println ("taskId: " + taskId + " OB_TIMEOUT" );
578
+ } else {
579
+ throw e ;
580
+ }
536
581
}
537
582
System .out .println ("task: " + taskId + ", batchInsert" );
538
583
}
@@ -552,72 +597,76 @@ public void testAdminGetRegionMetrics() throws Exception {
552
597
}
553
598
executorService .shutdownNow ();
554
599
Assert .assertTrue (exceptionCatcher .isEmpty ());
600
+
601
+ // test getRegionMetrics from non-partitioned table
602
+ String non_part_tablegroup = "test_no_part" ;
603
+ batchInsert (10000 , non_part_tablegroup );
604
+ start = System .currentTimeMillis ();
605
+ metrics = admin .getRegionMetrics (null , TableName .valueOf (non_part_tablegroup ));
606
+ cost = System .currentTimeMillis () - start ;
607
+ System .out .println ("get region metrics time usage: " + cost + "ms, tablegroup: " + non_part_tablegroup );
608
+ assertEquals (3 , metrics .size ());
555
609
}
556
610
557
611
@ Test
558
612
public void testAdminDeleteTable () throws Exception {
559
613
java .sql .Connection conn = ObHTableTestUtil .getConnection ();
560
614
Statement st = conn .createStatement ();
561
615
st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
562
- "\n " +
563
616
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
564
617
" `K` varbinary(1024) NOT NULL,\n " +
565
618
" `Q` varbinary(256) NOT NULL,\n " +
566
619
" `T` bigint(20) NOT NULL,\n " +
567
620
" `V` varbinary(1024) DEFAULT NULL,\n " +
568
621
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
569
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
570
- "\n " +
622
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
571
623
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\n " +
572
624
" `K` varbinary(1024) NOT NULL,\n " +
573
625
" `Q` varbinary(256) NOT NULL,\n " +
574
626
" `T` bigint(20) NOT NULL,\n " +
575
627
" `V` varbinary(1024) DEFAULT NULL,\n " +
576
628
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
577
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
578
- "\n " +
629
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
579
630
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\n " +
580
631
" `K` varbinary(1024) NOT NULL,\n " +
581
632
" `Q` varbinary(256) NOT NULL,\n " +
582
633
" `T` bigint(20) NOT NULL,\n " +
583
634
" `V` varbinary(1024) DEFAULT NULL,\n " +
584
635
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
585
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
586
- "\n " +
636
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
587
637
"CREATE DATABASE IF NOT EXISTS `n1`;\n " +
588
638
"use `n1`;\n " +
589
- "CREATE TABLEGROUP IF NOT EXISTS `n1:test` SHARDING = 'ADAPTIVE';\n " +
590
- "CREATE TABLE IF NOT EXISTS `n1:test$family_group` (\n " +
591
- " `K` varbinary(1024) NOT NULL,\n " +
592
- " `Q` varbinary(256) NOT NULL,\n " +
593
- " `T` bigint(20) NOT NULL,\n " +
594
- " `V` varbinary(1024) DEFAULT NULL,\n " +
595
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
596
- ") TABLEGROUP = `n1:test`;" +
597
- "\n " +
598
- "CREATE TABLE IF NOT EXISTS `n1:test$family1` (\n " +
599
- " `K` varbinary(1024) NOT NULL,\n " +
600
- " `Q` varbinary(256) NOT NULL,\n " +
601
- " `T` bigint(20) NOT NULL,\n " +
602
- " `V` varbinary(1024) DEFAULT NULL,\n " +
603
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
604
- ") TABLEGROUP = `n1:test`;" );
639
+ "CREATE TABLEGROUP IF NOT EXISTS `n1:test_multi_cf` SHARDING = 'ADAPTIVE';\n " +
640
+ "CREATE TABLE IF NOT EXISTS `n1:test_multi_cf$family_with_group1` (\n " +
641
+ " `K` varbinary(1024) NOT NULL,\n " +
642
+ " `Q` varbinary(256) NOT NULL,\n " +
643
+ " `T` bigint(20) NOT NULL,\n " +
644
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
645
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
646
+ ") TABLEGROUP = `n1:test_multi_cf` PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
647
+ "CREATE TABLE IF NOT EXISTS `n1:test_multi_cf$family_with_group2` (\n " +
648
+ " `K` varbinary(1024) NOT NULL,\n " +
649
+ " `Q` varbinary(256) NOT NULL,\n " +
650
+ " `T` bigint(20) NOT NULL,\n " +
651
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
652
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
653
+ ") TABLEGROUP = `n1:test_multi_cf` PARTITION BY KEY(`K`) PARTITIONS 3;" );
605
654
st .close ();
606
655
conn .close ();
607
656
Configuration conf = ObHTableTestUtil .newConfiguration ();
608
657
Connection connection = ConnectionFactory .createConnection (conf );
609
658
Admin admin = connection .getAdmin ();
610
- assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test " )));
659
+ assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test_multi_cf " )));
611
660
assertTrue (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
612
661
IOException thrown = assertThrows (IOException .class ,
613
662
() -> {
614
663
admin .deleteTable (TableName .valueOf ("tablegroup_not_exists" ));
615
664
});
616
665
Assert .assertTrue (thrown .getCause () instanceof ObTableException );
617
666
Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
618
- admin .deleteTable (TableName .valueOf ("n1" , "test " ));
667
+ admin .deleteTable (TableName .valueOf ("n1" , "test_multi_cf " ));
619
668
admin .deleteTable (TableName .valueOf ("test_multi_cf" ));
620
- assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test " )));
669
+ assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test_multi_cf " )));
621
670
assertFalse (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
622
671
}
623
672
@@ -626,49 +675,16 @@ public void testAdminTableExists() throws Exception {
626
675
java .sql .Connection conn = ObHTableTestUtil .getConnection ();
627
676
Statement st = conn .createStatement ();
628
677
st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
629
- "\n " +
630
678
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
631
679
" `K` varbinary(1024) NOT NULL,\n " +
632
680
" `Q` varbinary(256) NOT NULL,\n " +
633
681
" `T` bigint(20) NOT NULL,\n " +
634
682
" `V` varbinary(1024) DEFAULT NULL,\n " +
635
683
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
636
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
637
- "\n " +
638
- "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\n " +
639
- " `K` varbinary(1024) NOT NULL,\n " +
640
- " `Q` varbinary(256) NOT NULL,\n " +
641
- " `T` bigint(20) NOT NULL,\n " +
642
- " `V` varbinary(1024) DEFAULT NULL,\n " +
643
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
644
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
645
- "\n " +
646
- "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\n " +
647
- " `K` varbinary(1024) NOT NULL,\n " +
648
- " `Q` varbinary(256) NOT NULL,\n " +
649
- " `T` bigint(20) NOT NULL,\n " +
650
- " `V` varbinary(1024) DEFAULT NULL,\n " +
651
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
652
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
653
- "\n " +
684
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
654
685
"CREATE DATABASE IF NOT EXISTS `n1`;\n " +
655
686
"use `n1`;\n " +
656
- "CREATE TABLEGROUP IF NOT EXISTS `n1:test` SHARDING = 'ADAPTIVE';\n " +
657
- "CREATE TABLE IF NOT EXISTS `n1:test$family_group` (\n " +
658
- " `K` varbinary(1024) NOT NULL,\n " +
659
- " `Q` varbinary(256) NOT NULL,\n " +
660
- " `T` bigint(20) NOT NULL,\n " +
661
- " `V` varbinary(1024) DEFAULT NULL,\n " +
662
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
663
- ") TABLEGROUP = `n1:test`;" +
664
- "\n " +
665
- "CREATE TABLE IF NOT EXISTS `n1:test$family1` (\n " +
666
- " `K` varbinary(1024) NOT NULL,\n " +
667
- " `Q` varbinary(256) NOT NULL,\n " +
668
- " `T` bigint(20) NOT NULL,\n " +
669
- " `V` varbinary(1024) DEFAULT NULL,\n " +
670
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
671
- ") TABLEGROUP = `n1:test`;" );
687
+ "CREATE TABLEGROUP IF NOT EXISTS `n1:test_multi_cf` SHARDING = 'ADAPTIVE';" );
672
688
st .close ();
673
689
conn .close ();
674
690
Configuration conf = ObHTableTestUtil .newConfiguration ();
@@ -680,8 +696,8 @@ public void testAdminTableExists() throws Exception {
680
696
TableName .valueOf ("random_string$" );
681
697
});
682
698
Assert .assertFalse (admin .tableExists (TableName .valueOf ("tablegroup_not_exists" )));
699
+ Assert .assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test_multi_cf" )));
683
700
Assert .assertTrue (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
684
- Assert .assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test" )));
685
701
}
686
702
687
703
private void batchInsert (int rows , String tablegroup ) throws Exception {
0 commit comments