Skip to content

Commit 693bbb6

Browse files
maochongxinZhou-jw
authored andcommitted
add hash-like partition case for region locator
1 parent f53721c commit 693bbb6

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

src/main/java/com/alipay/oceanbase/hbase/util/OHTableDescriptorExecutor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.apache.hadoop.hbase.HColumnDescriptor;
1111
import org.apache.hadoop.hbase.HTableDescriptor;
1212
import org.apache.hadoop.hbase.TableName;
13-
import sun.font.SunFontManager;
1413

1514
import java.io.IOException;
1615
import java.util.HashMap;

src/test/java/com/alipay/oceanbase/hbase/OHConnectionTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.hadoop.conf.Configuration;
2323
import org.apache.hadoop.hbase.Cell;
2424
import org.apache.hadoop.hbase.CellUtil;
25+
import org.apache.hadoop.hbase.HConstants;
2526
import org.apache.hadoop.hbase.TableName;
2627
import org.apache.hadoop.hbase.client.*;
2728
import org.apache.hadoop.hbase.util.Bytes;
@@ -30,6 +31,7 @@
3031

3132
import java.io.IOException;
3233
import java.util.ArrayList;
34+
import java.util.Arrays;
3335
import java.util.List;
3436
import java.util.Optional;
3537
import java.util.concurrent.*;
@@ -990,6 +992,21 @@ public void testRangePartitionWithRegionLocator() throws Exception {
990992
});
991993
}
992994
}
995+
@Test
996+
public void testKeyPartitionWithRegionLocator() throws IOException {
997+
final String tableNameStr = "test_multi_cf";
998+
final TableName tableName = TableName.valueOf(tableNameStr);
999+
final Configuration conf = ObHTableTestUtil.newConfiguration();
1000+
connection = ConnectionFactory.createConnection(conf);
1001+
hTable = connection.getTable(tableName);
1002+
RegionLocator locator = connection.getRegionLocator(tableName);
1003+
byte[][] startKeys = locator.getStartKeys();
1004+
byte[][] endKeys = locator.getEndKeys();
1005+
Assert.assertEquals("Should have 1 region", 1, startKeys.length);
1006+
Assert.assertEquals("Should have 1 region", 1, endKeys.length);
1007+
Assert.assertEquals(startKeys[0], endKeys[0]);
1008+
Assert.assertEquals(startKeys[0], HConstants.EMPTY_BYTE_ARRAY);
1009+
}
9931010

9941011
@Test
9951012
public void testBufferedMutatorPeriodicFlush() throws Exception {

src/test/java/com/alipay/oceanbase/hbase/OHTableAdminInterfaceTest.java

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,121 @@ public void testGetStartEndKeysOHTablePoolLoadNon() throws Exception {
268268
Assert.assertEquals(0, startEndKeys.getSecond()[0].length);
269269
}
270270

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+
271386
@Test
272387
public void testAdminGetRegionMetrics() throws Exception {
273388
java.sql.Connection conn = ObHTableTestUtil.getConnection();

0 commit comments

Comments
 (0)