From 56b852d05cc85ed2c88b9ac2d4fa3b7fbe548c5c Mon Sep 17 00:00:00 2001 From: maochongxin Date: Wed, 18 Sep 2024 12:08:05 +0800 Subject: [PATCH 1/4] add sql for multi-cf test; fix conflict error --- .../com/alipay/oceanbase/hbase/OHTable.java | 6 ++--- src/test/java/unit_test_db.sql | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java index 71361b32..0f7d26e6 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java +++ b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java @@ -801,7 +801,7 @@ private void innerDelete(Delete delete) throws IOException { } else { for (Map.Entry> entry : delete.getFamilyMap().entrySet()) { BatchOperation batch = buildBatchOperation( - getTargetTableName(tableNameString, Bytes.toString(entry.getKey())), + getTargetTableName(tableNameString, Bytes.toString(entry.getKey()), configuration), entry.getValue(), false, null); results = batch.execute(); } @@ -1419,7 +1419,7 @@ private ObHTableFilter buildObHTableFilter(Filter filter, TimeRange timeRange, i ObHTableFilter obHTableFilter = new ObHTableFilter(); if (filter != null) { - obHTableFilter.setFilterString(HBaseFilterUtils.toParseableString(filter).getBytes()); + obHTableFilter.setFilterString(HBaseFilterUtils.toParseableString(filter)); } if (timeRange != null) { @@ -1459,7 +1459,7 @@ private ObHTableFilter buildObHTableFilter(String filterString, TimeRange timeRa ObHTableFilter obHTableFilter = new ObHTableFilter(); if (filterString != null) { - obHTableFilter.setFilterString(filterString.getBytes()); + obHTableFilter.setFilterString(filterString); } if (timeRange != null) { diff --git a/src/test/java/unit_test_db.sql b/src/test/java/unit_test_db.sql index 97c8ab13..f838a705 100644 --- a/src/test/java/unit_test_db.sql +++ b/src/test/java/unit_test_db.sql @@ -161,3 +161,30 @@ CREATE TABLE `test_t$family_with_local_index` ( key `idx1`(T) local, PRIMARY KEY (`K`, `Q`, `T`) ); + + +CREATE TABLEGROUP test_multi_cf SHARDING = 'ADAPTIVE'; + +CREATE TABLE `test_multi_cf$family_with_group1` ( + `K` varbinary(1024) NOT NULL, + `Q` varbinary(256) NOT NULL, + `T` bigint(20) NOT NULL, + `V` varbinary(1024) DEFAULT NULL, + PRIMARY KEY (`K`, `Q`, `T`) +) TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3; + +CREATE TABLE `test_multi_cf$family_with_group2` ( + `K` varbinary(1024) NOT NULL, + `Q` varbinary(256) NOT NULL, + `T` bigint(20) NOT NULL, + `V` varbinary(1024) DEFAULT NULL, + PRIMARY KEY (`K`, `Q`, `T`) +) TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3; + +CREATE TABLE `test_multi_cf$family_with_group3` ( + `K` varbinary(1024) NOT NULL, + `Q` varbinary(256) NOT NULL, + `T` bigint(20) NOT NULL, + `V` varbinary(1024) DEFAULT NULL, + PRIMARY KEY (`K`, `Q`, `T`) +) TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3; From b012b9101ac9c36d6429414c9f53187221d2559f Mon Sep 17 00:00:00 2001 From: maochongxin Date: Wed, 18 Sep 2024 15:45:34 +0800 Subject: [PATCH 2/4] fix buffered mutation family_violation check --- src/main/java/com/alipay/oceanbase/hbase/OHTable.java | 2 +- .../com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java index 0f7d26e6..2b1ea289 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java +++ b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java @@ -1765,7 +1765,7 @@ public static void checkFamilyViolation(Collection families) { // This method is currently only used for append and increment operations. // It restricts these two methods to use multi-column family operations. // Note: After completing operations on multiple column families, they are deleted using the method described above. - private void checkFamilyViolationForOneFamily(Collection families) { + public static void checkFamilyViolationForOneFamily(Collection families) { if (families == null || families.size() == 0) { throw new FeatureNotSupportedException("family is empty."); } diff --git a/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java b/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java index e9dbb7d9..2dc7483e 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java +++ b/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java @@ -142,7 +142,7 @@ public void mutate(List mutations) throws IOException { // check if every mutation's family is the same // check if mutations are the same type for (Mutation m : mutations) { - OHTable.checkFamilyViolation(m.getFamilyMap().keySet()); + OHTable.checkFamilyViolationForOneFamily(m.getFamilyMap().keySet()); validateInsUpAndDelete(m); Class curType = m.getClass(); // set the type of this BufferedMutator From 039c4002878422d2baf5afc63118a13eba4fa76d Mon Sep 17 00:00:00 2001 From: maochongxin Date: Wed, 18 Sep 2024 19:27:34 +0800 Subject: [PATCH 3/4] Remove multi-family checks for buffered mutations --- .../com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java b/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java index 2dc7483e..e9dbb7d9 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java +++ b/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java @@ -142,7 +142,7 @@ public void mutate(List mutations) throws IOException { // check if every mutation's family is the same // check if mutations are the same type for (Mutation m : mutations) { - OHTable.checkFamilyViolationForOneFamily(m.getFamilyMap().keySet()); + OHTable.checkFamilyViolation(m.getFamilyMap().keySet()); validateInsUpAndDelete(m); Class curType = m.getClass(); // set the type of this BufferedMutator From ddcd202d0b6b7a6c416cc56f3694d2a230facffe Mon Sep 17 00:00:00 2001 From: maochongxin Date: Wed, 18 Sep 2024 20:39:51 +0800 Subject: [PATCH 4/4] fix check family empty --- .../com/alipay/oceanbase/hbase/OHTable.java | 24 ++++++++++++------- .../hbase/util/OHBufferedMutatorImpl.java | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java index 2b1ea289..85a8f26f 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/OHTable.java +++ b/src/main/java/com/alipay/oceanbase/hbase/OHTable.java @@ -512,7 +512,7 @@ public Result get(final Get get) throws IOException { if (get.getFamilyMap().keySet() == null || get.getFamilyMap().keySet().isEmpty()) { // check nothing, use table group; } else { - checkFamilyViolation(get.getFamilyMap().keySet()); + checkFamilyViolation(get.getFamilyMap().keySet(), false); } ServerCallable serverCallable = new ServerCallable(configuration, @@ -590,7 +590,7 @@ public ResultScanner getScanner(final Scan scan) throws IOException { if (scan.getFamilyMap().keySet().isEmpty()) { // check nothing, use table group; } else { - checkFamilyViolation(scan.getFamilyMap().keySet()); + checkFamilyViolation(scan.getFamilyMap().keySet(), false); } //be careful about the packet size ,may the packet exceed the max result size ,leading to error @@ -681,7 +681,7 @@ private void doPut(List puts) throws IOException { int n = 0; for (Put put : puts) { validatePut(put); - checkFamilyViolation(put.getFamilyMap().keySet()); + checkFamilyViolation(put.getFamilyMap().keySet(), true); writeBuffer.add(put); currentWriteBufferSize += put.heapSize(); @@ -778,7 +778,7 @@ private void innerDelete(Delete delete) throws IOException { BatchOperationResult results = null; try { - checkFamilyViolation(delete.getFamilyMap().keySet()); + checkFamilyViolation(delete.getFamilyMap().keySet(), false); if (delete.getFamilyMap().isEmpty()) { // For a Delete operation without any qualifiers, we construct a DeleteFamily request. // The server then performs the operation on all column families. @@ -830,7 +830,7 @@ private void innerDelete(Delete delete) throws IOException { @Override public void delete(Delete delete) throws IOException { - checkFamilyViolation(delete.getFamilyMap().keySet()); + checkFamilyViolation(delete.getFamilyMap().keySet(), false); innerDelete(delete); } @@ -1753,9 +1753,15 @@ private ObTableQueryAndMutateRequest buildObTableQueryAndMutateRequest(ObTableQu return request; } - public static void checkFamilyViolation(Collection families) { + public static void checkFamilyViolation(Collection families, boolean check_empty_family) { + if (check_empty_family && (families == null || families.isEmpty())) { + throw new FeatureNotSupportedException("family is empty"); + } + for (byte[] family : families) { - if (isBlank(Bytes.toString(family))) { + if (family == null || family.length == 0) { + throw new IllegalArgumentException("family is empty"); + } else if (isBlank(Bytes.toString(family))) { throw new IllegalArgumentException("family is blank"); } } @@ -1774,7 +1780,9 @@ public static void checkFamilyViolationForOneFamily(Collection families) throw new FeatureNotSupportedException("multi family is not supported yet."); } for (byte[] family : families) { - if (isBlank(Bytes.toString(family))) { + if (family == null || family.length == 0) { + throw new IllegalArgumentException("family is empty"); + } else if (isBlank(Bytes.toString(family))) { throw new IllegalArgumentException("family is blank"); } } diff --git a/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java b/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java index e9dbb7d9..004720d4 100644 --- a/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java +++ b/src/main/java/com/alipay/oceanbase/hbase/util/OHBufferedMutatorImpl.java @@ -142,7 +142,7 @@ public void mutate(List mutations) throws IOException { // check if every mutation's family is the same // check if mutations are the same type for (Mutation m : mutations) { - OHTable.checkFamilyViolation(m.getFamilyMap().keySet()); + OHTable.checkFamilyViolation(m.getFamilyMap().keySet(), true); validateInsUpAndDelete(m); Class curType = m.getClass(); // set the type of this BufferedMutator