@@ -268,6 +268,121 @@ public void testGetStartEndKeysOHTablePoolLoadNon() throws Exception {
268
268
Assert .assertEquals (0 , startEndKeys .getSecond ()[0 ].length );
269
269
}
270
270
271
+ @ Test
272
+ public void testAdminEnDisableTable () throws Exception {
273
+ java .sql .Connection conn = ObHTableTestUtil .getConnection ();
274
+ Statement st = conn .createStatement ();
275
+ st .execute ("CREATE TABLEGROUP IF NOT EXISTS test_multi_cf SHARDING = 'ADAPTIVE';\n " +
276
+ "\n " +
277
+ "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group1` (\n " +
278
+ " `K` varbinary(1024) NOT NULL,\n " +
279
+ " `Q` varbinary(256) NOT NULL,\n " +
280
+ " `T` bigint(20) NOT NULL,\n " +
281
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
282
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
283
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
284
+ "\n " +
285
+ "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group2` (\n " +
286
+ " `K` varbinary(1024) NOT NULL,\n " +
287
+ " `Q` varbinary(256) NOT NULL,\n " +
288
+ " `T` bigint(20) NOT NULL,\n " +
289
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
290
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
291
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
292
+ "\n " +
293
+ "CREATE TABLE IF NOT EXISTS `test_multi_cf$family_with_group3` (\n " +
294
+ " `K` varbinary(1024) NOT NULL,\n " +
295
+ " `Q` varbinary(256) NOT NULL,\n " +
296
+ " `T` bigint(20) NOT NULL,\n " +
297
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
298
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
299
+ ") TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;\n " +
300
+ "\n " +
301
+ "CREATE DATABASE IF NOT EXISTS `n1`;\n " +
302
+ "use `n1`;\n " +
303
+ "CREATE TABLEGROUP IF NOT EXISTS `n1:test` SHARDING = 'ADAPTIVE';\n " +
304
+ "CREATE TABLE IF NOT EXISTS `n1:test$family_group` (\n " +
305
+ " `K` varbinary(1024) NOT NULL,\n " +
306
+ " `Q` varbinary(256) NOT NULL,\n " +
307
+ " `T` bigint(20) NOT NULL,\n " +
308
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
309
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
310
+ ") TABLEGROUP = `n1:test`;" +
311
+ "\n " +
312
+ "CREATE TABLE IF NOT EXISTS `n1:test$family1` (\n " +
313
+ " `K` varbinary(1024) NOT NULL,\n " +
314
+ " `Q` varbinary(256) NOT NULL,\n " +
315
+ " `T` bigint(20) NOT NULL,\n " +
316
+ " `V` varbinary(1024) DEFAULT NULL,\n " +
317
+ " PRIMARY KEY (`K`, `Q`, `T`)\n " +
318
+ ") TABLEGROUP = `n1:test`;" );
319
+ Configuration conf = ObHTableTestUtil .newConfiguration ();
320
+ Connection connection = ConnectionFactory .createConnection (conf );
321
+ Admin admin = connection .getAdmin ();
322
+ admin .disableTable (TableName .valueOf ("test_multi_cf" ));
323
+ assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test" )));
324
+ assertTrue (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
325
+ // disable a non-existed table
326
+ IOException thrown = assertThrows (IOException .class ,
327
+ () -> {
328
+ admin .disableTable (TableName .valueOf ("tablegroup_not_exists" ));
329
+ });
330
+ assertTrue (thrown .getCause () instanceof ObTableException );
331
+ Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
332
+
333
+ // write an enabled table, should succeed
334
+ batchInsert (10 , "test_multi_ch" );
335
+ // disable a disabled table
336
+ thrown = assertThrows (IOException .class ,
337
+ () -> {
338
+ admin .disableTable (TableName .valueOf ("test_multi_cf" ));
339
+ });
340
+ assertTrue (thrown .getCause () instanceof ObTableException );
341
+ Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_DISABLED .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
342
+
343
+ // write an enabled table, should fail
344
+ batchInsert (10 , "test_multi_ch" );
345
+ enDisableRead (10 , "test_multi_ch" );
346
+
347
+ // enable a disabled table
348
+ admin .enableTable (TableName .valueOf ("test_multi_cf" ));
349
+
350
+ // write an enabled table, should succeed
351
+ batchInsert (10 , "test_multi_ch" );
352
+ enDisableRead (10 , "test_multi_ch" );
353
+
354
+ // enable an enabled table
355
+ thrown = assertThrows (IOException .class ,
356
+ () -> {
357
+ admin .disableTable (TableName .valueOf ("n1" , "test" );
358
+ });
359
+ assertTrue (thrown .getCause () instanceof ObTableException );
360
+ Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_ENABLED .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
361
+
362
+ admin .deleteTable (TableName .valueOf ("n1" , "test" ));
363
+ admin .deleteTable (TableName .valueOf ("test_multi_cf" ));
364
+ assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test" )));
365
+ assertFalse (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
366
+ }
367
+
368
+ private void enDisableRead (int rows , String tablegroup ) throws Exception {
369
+ Configuration conf = ObHTableTestUtil .newConfiguration ();
370
+ Connection connection = ConnectionFactory .createConnection (conf );
371
+ Table table = connection .getTable (TableName .valueOf (tablegroup ));
372
+ List <Row > batchLsit = new LinkedList <>();
373
+ for (int i = 0 ; i < rows ; ++i ) {
374
+ Get get = new Get (toBytes ("Key" + i ));
375
+ batchLsit .add (get );
376
+ if (i % 100 == 0 ) { // 100 rows one batch to avoid OB_TIMEOUT
377
+ Object [] results = new Object [batchLsit .size ()];
378
+ table .batch (batchLsit , results );
379
+ batchLsit .clear ();
380
+ }
381
+ }
382
+ Object [] results = new Object [batchLsit .size ()];
383
+ table .batch (batchLsit , results );
384
+ }
385
+
271
386
@ Test
272
387
public void testAdminGetRegionMetrics () throws Exception {
273
388
java .sql .Connection conn = ObHTableTestUtil .getConnection ();
0 commit comments