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 .*;
@@ -388,31 +389,49 @@ public void testAdminGetRegionMetrics() throws Exception {
388
389
java .sql .Connection conn = ObHTableTestUtil .getConnection ();
389
390
Statement st = conn .createStatement ();
390
391
st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
391
- "\n " +
392
392
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
393
393
" `K` varbinary(1024) NOT NULL,\n " +
394
394
" `Q` varbinary(256) NOT NULL,\n " +
395
395
" `T` bigint(20) NOT NULL,\n " +
396
396
" `V` varbinary(1024) DEFAULT NULL,\n " +
397
397
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
398
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
399
- "\n " +
398
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
400
399
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\n " +
401
400
" `K` varbinary(1024) NOT NULL,\n " +
402
401
" `Q` varbinary(256) NOT NULL,\n " +
403
402
" `T` bigint(20) NOT NULL,\n " +
404
403
" `V` varbinary(1024) DEFAULT NULL,\n " +
405
404
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
406
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
407
- "\n " +
405
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
408
406
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\n " +
409
407
" `K` varbinary(1024) NOT NULL,\n " +
410
408
" `Q` varbinary(256) NOT NULL,\n " +
411
409
" `T` bigint(20) NOT NULL,\n " +
412
410
" `V` varbinary(1024) DEFAULT NULL,\n " +
413
411
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
414
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
415
- "\n " +
412
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
413
+ "CREATE TABLEGROUP IF NOT EXISTS test_no_part SHARDING = 'ADAPTIVE';\n " +
414
+ "CREATE TABLE IF NOT EXISTS `test_no_part$family_with_group1` (\n " +
415
+ " `K` varbinary(1024) NOT NULL,\n " +
416
+ " `Q` varbinary(256) NOT NULL,\n " +
417
+ " `T` bigint(20) NOT NULL,\n " +
418
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
419
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
420
+ ") TABLEGROUP = test_no_part;\n " +
421
+ "CREATE TABLE IF NOT EXISTS `test_no_part$family_with_group2` (\n " +
422
+ " `K` varbinary(1024) NOT NULL,\n " +
423
+ " `Q` varbinary(256) NOT NULL,\n " +
424
+ " `T` bigint(20) NOT NULL,\n " +
425
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
426
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
427
+ ") TABLEGROUP = test_no_part;\n " +
428
+ "CREATE TABLE IF NOT EXISTS `test_no_part$family_with_group3` (\n " +
429
+ " `K` varbinary(1024) NOT NULL,\n " +
430
+ " `Q` varbinary(256) NOT NULL,\n " +
431
+ " `T` bigint(20) NOT NULL,\n " +
432
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
433
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
434
+ ") TABLEGROUP = test_no_part;\n " +
416
435
"CREATE DATABASE IF NOT EXISTS `n1`;\n " +
417
436
"use `n1`;\n " +
418
437
"CREATE TABLEGROUP IF NOT EXISTS `n1:test_multi_cf` SHARDING = 'ADAPTIVE';\n " +
@@ -444,25 +463,30 @@ public void testAdminGetRegionMetrics() throws Exception {
444
463
Configuration conf = ObHTableTestUtil .newConfiguration ();
445
464
Connection connection = ConnectionFactory .createConnection (conf );
446
465
Admin admin = connection .getAdmin ();
466
+ // test tablegroup not existed
447
467
IOException thrown = assertThrows (IOException .class ,
448
468
() -> {
449
469
admin .getRegionMetrics (null , TableName .valueOf ("tablegroup_not_exists" ));
450
470
});
451
471
Assert .assertTrue (thrown .getCause () instanceof ObTableException );
452
472
Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
473
+
474
+ // test use serverName without tableName to get region metrics
453
475
assertThrows (FeatureNotSupportedException .class ,
454
476
() -> {
455
477
admin .getRegionMetrics (ServerName .valueOf ("localhost,1,1" ));
456
478
});
457
- // insert 300 thousand of rows in each table under tablegroup test_multi_cf
479
+
480
+ // test single-thread getRegionMetrics after writing
458
481
batchInsert (100000 , tablegroup1 );
459
- List <RegionMetrics > metrics = admin .getRegionMetrics (null , TableName .valueOf (tablegroup1 ));
460
- for (RegionMetrics regionMetrics : metrics ) {
461
- System .out .println ("region name: " + regionMetrics .getNameAsString ()
462
- + ", storeFileSize: " + regionMetrics .getStoreFileSize ()
463
- + ", memFileSize: " + regionMetrics .getMemStoreSize ());
464
- }
465
- // concurrently read while writing 150 thousand of rows to 2 tablegroups
482
+ // test ServerName is any string
483
+ long start = System .currentTimeMillis ();
484
+ List <RegionMetrics > metrics = admin .getRegionMetrics (ServerName .valueOf ("localhost,1,1" ), TableName .valueOf (tablegroup1 ));
485
+ long cost = System .currentTimeMillis () - start ;
486
+ System .out .println ("get region metrics time usage: " + cost + "ms, tablegroup: " + tablegroup1 );
487
+ assertEquals (30 , metrics .size ());
488
+
489
+ // test getRegionMetrics concurrently reading while writing
466
490
ExecutorService executorService = Executors .newFixedThreadPool (10 );
467
491
CountDownLatch latch = new CountDownLatch (100 );
468
492
List <Exception > exceptionCatcher = new ArrayList <>();
@@ -474,21 +498,42 @@ public void testAdminGetRegionMetrics() throws Exception {
474
498
List <RegionMetrics > regionMetrics = null ;
475
499
// test get regionMetrics from different namespaces
476
500
if (taskId % 3 != 0 ) {
501
+ long thrStart = System .currentTimeMillis ();
477
502
regionMetrics = admin .getRegionMetrics (null , TableName .valueOf (tablegroup1 ));
503
+ long thrCost = System .currentTimeMillis () - thrStart ;
504
+ System .out .println ("task: " + taskId + ", get region metrics time usage: " + thrCost + "ms, tablegroup: " + tablegroup1 );
505
+ if (regionMetrics .size () != 30 ) {
506
+ throw new ObTableGetException (
507
+ "the number of region metrics does not match the number of tablets, the number of region metrics: " + regionMetrics .size ());
508
+ }
478
509
} else {
510
+ long thrStart = System .currentTimeMillis ();
479
511
regionMetrics = admin .getRegionMetrics (null , TableName .valueOf (tablegroup2 ));
480
- }
481
- for ( RegionMetrics m : regionMetrics ) {
482
- System . out . println ( "task: " + taskId + ", tablegroup: " + (( OHRegionMetrics ) m ). getTablegroup ()
483
- + ", region name: " + m . getNameAsString ()
484
- + ", storeFileSize : " + m . getStoreFileSize ()
485
- + ", memFileSize: " + m . getMemStoreSize ());
512
+ long thrCost = System . currentTimeMillis () - thrStart ;
513
+ System . out . println ( "task: " + taskId + ", get region metrics time usage: " + thrCost + "ms, tablegroup: " + tablegroup1 );
514
+ if ( regionMetrics . size () != 9 ) {
515
+ throw new ObTableGetException (
516
+ "the number of region metrics does not match the number of tablets, the number of region metrics : " + regionMetrics . size ());
517
+ }
486
518
}
487
519
} else {
488
- if (taskId % 8 == 0 ) {
489
- batchInsert (1000 , tablegroup2 );
490
- } else {
491
- batchInsert (1000 , tablegroup1 );
520
+ try {
521
+ if (taskId % 8 == 0 ) {
522
+ batchInsert (1000 , tablegroup2 );
523
+ } else {
524
+ batchInsert (1000 , tablegroup1 );
525
+ }
526
+ } catch (Exception e ) {
527
+ Exception originalCause = e ;
528
+ while (originalCause .getCause () != null && originalCause .getCause () instanceof ObTableException ) {
529
+ originalCause = (Exception ) originalCause .getCause ();
530
+ }
531
+ if (originalCause instanceof ObTableException && ((ObTableException ) originalCause ).getErrorCode () == ResultCodes .OB_TIMEOUT .errorCode ) {
532
+ // ignore
533
+ System .out .println ("taskId: " + taskId + " OB_TIMEOUT" );
534
+ } else {
535
+ throw e ;
536
+ }
492
537
}
493
538
System .out .println ("task: " + taskId + ", batchInsert" );
494
539
}
@@ -508,72 +553,76 @@ public void testAdminGetRegionMetrics() throws Exception {
508
553
}
509
554
executorService .shutdownNow ();
510
555
Assert .assertTrue (exceptionCatcher .isEmpty ());
556
+
557
+ // test getRegionMetrics from non-partitioned table
558
+ String non_part_tablegroup = "test_no_part" ;
559
+ batchInsert (10000 , non_part_tablegroup );
560
+ start = System .currentTimeMillis ();
561
+ metrics = admin .getRegionMetrics (null , TableName .valueOf (non_part_tablegroup ));
562
+ cost = System .currentTimeMillis () - start ;
563
+ System .out .println ("get region metrics time usage: " + cost + "ms, tablegroup: " + non_part_tablegroup );
564
+ assertEquals (3 , metrics .size ());
511
565
}
512
566
513
567
@ Test
514
568
public void testAdminDeleteTable () throws Exception {
515
569
java .sql .Connection conn = ObHTableTestUtil .getConnection ();
516
570
Statement st = conn .createStatement ();
517
571
st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
518
- "\n " +
519
572
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
520
573
" `K` varbinary(1024) NOT NULL,\n " +
521
574
" `Q` varbinary(256) NOT NULL,\n " +
522
575
" `T` bigint(20) NOT NULL,\n " +
523
576
" `V` varbinary(1024) DEFAULT NULL,\n " +
524
577
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
525
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
526
- "\n " +
578
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
527
579
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\n " +
528
580
" `K` varbinary(1024) NOT NULL,\n " +
529
581
" `Q` varbinary(256) NOT NULL,\n " +
530
582
" `T` bigint(20) NOT NULL,\n " +
531
583
" `V` varbinary(1024) DEFAULT NULL,\n " +
532
584
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
533
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
534
- "\n " +
585
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
535
586
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\n " +
536
587
" `K` varbinary(1024) NOT NULL,\n " +
537
588
" `Q` varbinary(256) NOT NULL,\n " +
538
589
" `T` bigint(20) NOT NULL,\n " +
539
590
" `V` varbinary(1024) DEFAULT NULL,\n " +
540
591
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
541
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
542
- "\n " +
592
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
543
593
"CREATE DATABASE IF NOT EXISTS `n1`;\n " +
544
594
"use `n1`;\n " +
545
- "CREATE TABLEGROUP IF NOT EXISTS `n1:test` SHARDING = 'ADAPTIVE';\n " +
546
- "CREATE TABLE IF NOT EXISTS `n1:test$family_group` (\n " +
547
- " `K` varbinary(1024) NOT NULL,\n " +
548
- " `Q` varbinary(256) NOT NULL,\n " +
549
- " `T` bigint(20) NOT NULL,\n " +
550
- " `V` varbinary(1024) DEFAULT NULL,\n " +
551
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
552
- ") TABLEGROUP = `n1:test`;" +
553
- "\n " +
554
- "CREATE TABLE IF NOT EXISTS `n1:test$family1` (\n " +
555
- " `K` varbinary(1024) NOT NULL,\n " +
556
- " `Q` varbinary(256) NOT NULL,\n " +
557
- " `T` bigint(20) NOT NULL,\n " +
558
- " `V` varbinary(1024) DEFAULT NULL,\n " +
559
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
560
- ") TABLEGROUP = `n1:test`;" );
595
+ "CREATE TABLEGROUP IF NOT EXISTS `n1:test_multi_cf` SHARDING = 'ADAPTIVE';\n " +
596
+ "CREATE TABLE IF NOT EXISTS `n1:test_multi_cf$family_with_group1` (\n " +
597
+ " `K` varbinary(1024) NOT NULL,\n " +
598
+ " `Q` varbinary(256) NOT NULL,\n " +
599
+ " `T` bigint(20) NOT NULL,\n " +
600
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
601
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
602
+ ") TABLEGROUP = `n1:test_multi_cf` PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
603
+ "CREATE TABLE IF NOT EXISTS `n1:test_multi_cf$family_with_group2` (\n " +
604
+ " `K` varbinary(1024) NOT NULL,\n " +
605
+ " `Q` varbinary(256) NOT NULL,\n " +
606
+ " `T` bigint(20) NOT NULL,\n " +
607
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
608
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
609
+ ") TABLEGROUP = `n1:test_multi_cf` PARTITION BY KEY(`K`) PARTITIONS 3;" );
561
610
st .close ();
562
611
conn .close ();
563
612
Configuration conf = ObHTableTestUtil .newConfiguration ();
564
613
Connection connection = ConnectionFactory .createConnection (conf );
565
614
Admin admin = connection .getAdmin ();
566
- assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test " )));
615
+ assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test_multi_cf " )));
567
616
assertTrue (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
568
617
IOException thrown = assertThrows (IOException .class ,
569
618
() -> {
570
619
admin .deleteTable (TableName .valueOf ("tablegroup_not_exists" ));
571
620
});
572
621
Assert .assertTrue (thrown .getCause () instanceof ObTableException );
573
622
Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
574
- admin .deleteTable (TableName .valueOf ("n1" , "test " ));
623
+ admin .deleteTable (TableName .valueOf ("n1" , "test_multi_cf " ));
575
624
admin .deleteTable (TableName .valueOf ("test_multi_cf" ));
576
- assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test " )));
625
+ assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test_multi_cf " )));
577
626
assertFalse (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
578
627
}
579
628
@@ -582,49 +631,16 @@ public void testAdminTableExists() throws Exception {
582
631
java .sql .Connection conn = ObHTableTestUtil .getConnection ();
583
632
Statement st = conn .createStatement ();
584
633
st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
585
- "\n " +
586
634
"CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
587
635
" `K` varbinary(1024) NOT NULL,\n " +
588
636
" `Q` varbinary(256) NOT NULL,\n " +
589
637
" `T` bigint(20) NOT NULL,\n " +
590
638
" `V` varbinary(1024) DEFAULT NULL,\n " +
591
639
" PRIMARY KEY (`K`, `Q`, `T`)\n " +
592
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
593
- "\n " +
594
- "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\n " +
595
- " `K` varbinary(1024) NOT NULL,\n " +
596
- " `Q` varbinary(256) NOT NULL,\n " +
597
- " `T` bigint(20) NOT NULL,\n " +
598
- " `V` varbinary(1024) DEFAULT NULL,\n " +
599
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
600
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
601
- "\n " +
602
- "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\n " +
603
- " `K` varbinary(1024) NOT NULL,\n " +
604
- " `Q` varbinary(256) NOT NULL,\n " +
605
- " `T` bigint(20) NOT NULL,\n " +
606
- " `V` varbinary(1024) DEFAULT NULL,\n " +
607
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
608
- ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
609
- "\n " +
640
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 10;\n " +
610
641
"CREATE DATABASE IF NOT EXISTS `n1`;\n " +
611
642
"use `n1`;\n " +
612
- "CREATE TABLEGROUP IF NOT EXISTS `n1:test` SHARDING = 'ADAPTIVE';\n " +
613
- "CREATE TABLE IF NOT EXISTS `n1:test$family_group` (\n " +
614
- " `K` varbinary(1024) NOT NULL,\n " +
615
- " `Q` varbinary(256) NOT NULL,\n " +
616
- " `T` bigint(20) NOT NULL,\n " +
617
- " `V` varbinary(1024) DEFAULT NULL,\n " +
618
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
619
- ") TABLEGROUP = `n1:test`;" +
620
- "\n " +
621
- "CREATE TABLE IF NOT EXISTS `n1:test$family1` (\n " +
622
- " `K` varbinary(1024) NOT NULL,\n " +
623
- " `Q` varbinary(256) NOT NULL,\n " +
624
- " `T` bigint(20) NOT NULL,\n " +
625
- " `V` varbinary(1024) DEFAULT NULL,\n " +
626
- " PRIMARY KEY (`K`, `Q`, `T`)\n " +
627
- ") TABLEGROUP = `n1:test`;" );
643
+ "CREATE TABLEGROUP IF NOT EXISTS `n1:test_multi_cf` SHARDING = 'ADAPTIVE';" );
628
644
st .close ();
629
645
conn .close ();
630
646
Configuration conf = ObHTableTestUtil .newConfiguration ();
@@ -636,8 +652,8 @@ public void testAdminTableExists() throws Exception {
636
652
TableName .valueOf ("random_string$" );
637
653
});
638
654
Assert .assertFalse (admin .tableExists (TableName .valueOf ("tablegroup_not_exists" )));
655
+ Assert .assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test_multi_cf" )));
639
656
Assert .assertTrue (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
640
- Assert .assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test" )));
641
657
}
642
658
643
659
private void batchInsert (int rows , String tablegroup ) throws Exception {
0 commit comments