@@ -572,4 +572,119 @@ private void batchInsert(int rows, String tablegroup) throws Exception {
572
572
Object [] results = new Object [batchLsit .size ()];
573
573
table .batch (batchLsit , results );
574
574
}
575
+
576
+ @ Test
577
+ public void testAdminEnDisableTable () throws Exception {
578
+ java .sql .Connection conn = ObHTableTestUtil .getConnection ();
579
+ Statement st = conn .createStatement ();
580
+ st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
581
+ "\n " +
582
+ "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
583
+ " `K` varbinary(1024) NOT NULL,\n " +
584
+ " `Q` varbinary(256) NOT NULL,\n " +
585
+ " `T` bigint(20) NOT NULL,\n " +
586
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
587
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
588
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
589
+ "\n " +
590
+ "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\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 = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
597
+ "\n " +
598
+ "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\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 = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
605
+ "\n " +
606
+ "CREATE DATABASE IF NOT EXISTS `n1`;\n " +
607
+ "use `n1`;\n " +
608
+ "CREATE TABLEGROUP IF NOT EXISTS `n1:test` SHARDING = 'ADAPTIVE';\n " +
609
+ "CREATE TABLE IF NOT EXISTS `n1:test$family_group` (\n " +
610
+ " `K` varbinary(1024) NOT NULL,\n " +
611
+ " `Q` varbinary(256) NOT NULL,\n " +
612
+ " `T` bigint(20) NOT NULL,\n " +
613
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
614
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
615
+ ") TABLEGROUP = `n1:test`;" +
616
+ "\n " +
617
+ "CREATE TABLE IF NOT EXISTS `n1:test$family1` (\n " +
618
+ " `K` varbinary(1024) NOT NULL,\n " +
619
+ " `Q` varbinary(256) NOT NULL,\n " +
620
+ " `T` bigint(20) NOT NULL,\n " +
621
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
622
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
623
+ ") TABLEGROUP = `n1:test`;" );
624
+ Configuration conf = ObHTableTestUtil .newConfiguration ();
625
+ Connection connection = ConnectionFactory .createConnection (conf );
626
+ Admin admin = connection .getAdmin ();
627
+ admin .disableTable (TableName .valueOf ("test_multi_cf" ));
628
+ assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test" )));
629
+ assertTrue (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
630
+ // disable a non-existed table
631
+ IOException thrown = assertThrows (IOException .class ,
632
+ () -> {
633
+ admin .disableTable (TableName .valueOf ("tablegroup_not_exists" ));
634
+ });
635
+ assertTrue (thrown .getCause () instanceof ObTableException );
636
+ Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
637
+
638
+ // write an enabled table, should succeed
639
+ batchInsert (10 , "test_multi_ch" );
640
+ // disable a disabled table
641
+ thrown = assertThrows (IOException .class ,
642
+ () -> {
643
+ admin .disableTable (TableName .valueOf ("test_multi_cf" ));
644
+ });
645
+ assertTrue (thrown .getCause () instanceof ObTableException );
646
+ Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_DISABLED .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
647
+
648
+ // write an enabled table, should fail
649
+ batchInsert (10 , "test_multi_ch" );
650
+ enDisableRead (10 , "test_multi_ch" );
651
+
652
+ // enable a disabled table
653
+ admin .enableTable (TableName .valueOf ("test_multi_cf" ));
654
+
655
+ // write an enabled table, should succeed
656
+ batchInsert (10 , "test_multi_ch" );
657
+ enDisableRead (10 , "test_multi_ch" );
658
+
659
+ // enable an enabled table
660
+ thrown = assertThrows (IOException .class ,
661
+ () -> {
662
+ admin .disableTable (TableName .valueOf ("n1" , "test" );
663
+ });
664
+ assertTrue (thrown .getCause () instanceof ObTableException );
665
+ Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_ENABLED .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
666
+
667
+ admin .deleteTable (TableName .valueOf ("n1" , "test" ));
668
+ admin .deleteTable (TableName .valueOf ("test_multi_cf" ));
669
+ assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test" )));
670
+ assertFalse (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
671
+ }
672
+
673
+ private void enDisableRead (int rows , String tablegroup ) throws Exception {
674
+ Configuration conf = ObHTableTestUtil .newConfiguration ();
675
+ Connection connection = ConnectionFactory .createConnection (conf );
676
+ Table table = connection .getTable (TableName .valueOf (tablegroup ));
677
+ List <Row > batchLsit = new LinkedList <>();
678
+ for (int i = 0 ; i < rows ; ++i ) {
679
+ Get get = new Get (toBytes ("Key" + i ));
680
+ batchLsit .add (get );
681
+ if (i % 100 == 0 ) { // 100 rows one batch to avoid OB_TIMEOUT
682
+ Object [] results = new Object [batchLsit .size ()];
683
+ table .batch (batchLsit , results );
684
+ batchLsit .clear ();
685
+ }
686
+ }
687
+ Object [] results = new Object [batchLsit .size ()];
688
+ table .batch (batchLsit , results );
689
+ }
575
690
}
0 commit comments