Skip to content

Commit bf5b5fc

Browse files
maochongxinstuBirdFly
authored andcommitted
Bugfix/sql and conflict fixes (#69)
* add sql for multi-cf test; fix conflict error * fix buffered mutation family_violation check * Remove multi-family checks for buffered mutations * fix check family empty
1 parent 7bf29e8 commit bf5b5fc

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public Result get(final Get get) throws IOException {
512512
if (get.getFamilyMap().keySet() == null || get.getFamilyMap().keySet().isEmpty()) {
513513
// check nothing, use table group;
514514
} else {
515-
checkFamilyViolation(get.getFamilyMap().keySet());
515+
checkFamilyViolation(get.getFamilyMap().keySet(), false);
516516
}
517517

518518
ServerCallable<Result> serverCallable = new ServerCallable<Result>(configuration,
@@ -590,7 +590,7 @@ public ResultScanner getScanner(final Scan scan) throws IOException {
590590
if (scan.getFamilyMap().keySet().isEmpty()) {
591591
// check nothing, use table group;
592592
} else {
593-
checkFamilyViolation(scan.getFamilyMap().keySet());
593+
checkFamilyViolation(scan.getFamilyMap().keySet(), false);
594594
}
595595

596596
//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<Put> puts) throws IOException {
681681
int n = 0;
682682
for (Put put : puts) {
683683
validatePut(put);
684-
checkFamilyViolation(put.getFamilyMap().keySet());
684+
checkFamilyViolation(put.getFamilyMap().keySet(), true);
685685
writeBuffer.add(put);
686686
currentWriteBufferSize += put.heapSize();
687687

@@ -778,7 +778,7 @@ private void innerDelete(Delete delete) throws IOException {
778778
BatchOperationResult results = null;
779779

780780
try {
781-
checkFamilyViolation(delete.getFamilyMap().keySet());
781+
checkFamilyViolation(delete.getFamilyMap().keySet(), false);
782782
if (delete.getFamilyMap().isEmpty()) {
783783
// For a Delete operation without any qualifiers, we construct a DeleteFamily request.
784784
// The server then performs the operation on all column families.
@@ -801,7 +801,7 @@ private void innerDelete(Delete delete) throws IOException {
801801
} else {
802802
for (Map.Entry<byte[], List<KeyValue>> entry : delete.getFamilyMap().entrySet()) {
803803
BatchOperation batch = buildBatchOperation(
804-
getTargetTableName(tableNameString, Bytes.toString(entry.getKey())),
804+
getTargetTableName(tableNameString, Bytes.toString(entry.getKey()), configuration),
805805
entry.getValue(), false, null);
806806
results = batch.execute();
807807
}
@@ -830,7 +830,7 @@ private void innerDelete(Delete delete) throws IOException {
830830

831831
@Override
832832
public void delete(Delete delete) throws IOException {
833-
checkFamilyViolation(delete.getFamilyMap().keySet());
833+
checkFamilyViolation(delete.getFamilyMap().keySet(), false);
834834
innerDelete(delete);
835835
}
836836

@@ -1419,7 +1419,7 @@ private ObHTableFilter buildObHTableFilter(Filter filter, TimeRange timeRange, i
14191419
ObHTableFilter obHTableFilter = new ObHTableFilter();
14201420

14211421
if (filter != null) {
1422-
obHTableFilter.setFilterString(HBaseFilterUtils.toParseableString(filter).getBytes());
1422+
obHTableFilter.setFilterString(HBaseFilterUtils.toParseableString(filter));
14231423
}
14241424

14251425
if (timeRange != null) {
@@ -1459,7 +1459,7 @@ private ObHTableFilter buildObHTableFilter(String filterString, TimeRange timeRa
14591459
ObHTableFilter obHTableFilter = new ObHTableFilter();
14601460

14611461
if (filterString != null) {
1462-
obHTableFilter.setFilterString(filterString.getBytes());
1462+
obHTableFilter.setFilterString(filterString);
14631463
}
14641464

14651465
if (timeRange != null) {
@@ -1753,9 +1753,15 @@ private ObTableQueryAndMutateRequest buildObTableQueryAndMutateRequest(ObTableQu
17531753
return request;
17541754
}
17551755

1756-
public static void checkFamilyViolation(Collection<byte[]> families) {
1756+
public static void checkFamilyViolation(Collection<byte[]> families, boolean check_empty_family) {
1757+
if (check_empty_family && (families == null || families.isEmpty())) {
1758+
throw new FeatureNotSupportedException("family is empty");
1759+
}
1760+
17571761
for (byte[] family : families) {
1758-
if (isBlank(Bytes.toString(family))) {
1762+
if (family == null || family.length == 0) {
1763+
throw new IllegalArgumentException("family is empty");
1764+
} else if (isBlank(Bytes.toString(family))) {
17591765
throw new IllegalArgumentException("family is blank");
17601766
}
17611767
}
@@ -1765,7 +1771,7 @@ public static void checkFamilyViolation(Collection<byte[]> families) {
17651771
// This method is currently only used for append and increment operations.
17661772
// It restricts these two methods to use multi-column family operations.
17671773
// Note: After completing operations on multiple column families, they are deleted using the method described above.
1768-
private void checkFamilyViolationForOneFamily(Collection<byte[]> families) {
1774+
public static void checkFamilyViolationForOneFamily(Collection<byte[]> families) {
17691775
if (families == null || families.size() == 0) {
17701776
throw new FeatureNotSupportedException("family is empty.");
17711777
}
@@ -1774,7 +1780,9 @@ private void checkFamilyViolationForOneFamily(Collection<byte[]> families) {
17741780
throw new FeatureNotSupportedException("multi family is not supported yet.");
17751781
}
17761782
for (byte[] family : families) {
1777-
if (isBlank(Bytes.toString(family))) {
1783+
if (family == null || family.length == 0) {
1784+
throw new IllegalArgumentException("family is empty");
1785+
} else if (isBlank(Bytes.toString(family))) {
17781786
throw new IllegalArgumentException("family is blank");
17791787
}
17801788
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void mutate(List<? extends Mutation> mutations) throws IOException {
142142
// check if every mutation's family is the same
143143
// check if mutations are the same type
144144
for (Mutation m : mutations) {
145-
OHTable.checkFamilyViolation(m.getFamilyMap().keySet());
145+
OHTable.checkFamilyViolation(m.getFamilyMap().keySet(), true);
146146
validateInsUpAndDelete(m);
147147
Class<?> curType = m.getClass();
148148
// set the type of this BufferedMutator

src/test/java/unit_test_db.sql

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,29 @@ CREATE TABLE `test_t$family_with_local_index` (
162162
PRIMARY KEY (`K`, `Q`, `T`)
163163
);
164164

165-
CREATE TABLE `test$family'1` (
165+
166+
CREATE TABLEGROUP test_multi_cf SHARDING = 'ADAPTIVE';
167+
168+
CREATE TABLE `test_multi_cf$family_with_group1` (
166169
`K` varbinary(1024) NOT NULL,
167170
`Q` varbinary(256) NOT NULL,
168171
`T` bigint(20) NOT NULL,
169172
`V` varbinary(1024) DEFAULT NULL,
170-
PRIMARY KEY (`K`, `Q`, `T`)
171-
) TABLEGROUP = test;
173+
PRIMARY KEY (`K`, `Q`, `T`)
174+
) TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;
172175

173-
CREATE TABLE `test_t$family'1` (
176+
CREATE TABLE `test_multi_cf$family_with_group2` (
174177
`K` varbinary(1024) NOT NULL,
175178
`Q` varbinary(256) NOT NULL,
176179
`T` bigint(20) NOT NULL,
177180
`V` varbinary(1024) DEFAULT NULL,
178-
PRIMARY KEY (`K`, `Q`, `T`)
179-
) TABLEGROUP = test_t;
181+
PRIMARY KEY (`K`, `Q`, `T`)
182+
) TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;
180183

184+
CREATE TABLE `test_multi_cf$family_with_group3` (
185+
`K` varbinary(1024) NOT NULL,
186+
`Q` varbinary(256) NOT NULL,
187+
`T` bigint(20) NOT NULL,
188+
`V` varbinary(1024) DEFAULT NULL,
189+
PRIMARY KEY (`K`, `Q`, `T`)
190+
) TABLEGROUP = test_multi_cf PARTITION BY KEY(`K`) PARTITIONS 3;

0 commit comments

Comments
 (0)