Skip to content

Commit de9d2e6

Browse files
authored
fix returnOneResult is not support in ob 421 (#174)
1 parent 286573c commit de9d2e6

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

src/main/java/com/alipay/oceanbase/rpc/ObClusterTableBatchOps.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.alipay.oceanbase.rpc;
1919

20+
import com.alipay.oceanbase.rpc.exception.FeatureNotSupportedException;
2021
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.*;
2122
import com.alipay.oceanbase.rpc.table.AbstractTableBatchOps;
2223
import com.alipay.oceanbase.rpc.table.ObTableClientBatchOpsImpl;
@@ -190,7 +191,10 @@ void preCheck() {
190191
throw new IllegalArgumentException("operations is empty");
191192
}
192193
ObTableOperationType lastType = operations.get(0).getOperationType();
193-
if (returnOneResult
194+
if (returnOneResult && !ObGlobal.isReturnOneResultSupport()) {
195+
throw new FeatureNotSupportedException(
196+
"returnOneResult is not supported in this Observer version [" + ObGlobal.obVsnString() +"]");
197+
} else if (returnOneResult
194198
&& !(this.tableBatchOps.getObTableBatchOperation().isSameType() && (lastType == ObTableOperationType.INSERT
195199
|| lastType == ObTableOperationType.PUT
196200
|| lastType == ObTableOperationType.REPLACE || lastType == ObTableOperationType.DEL))) {

src/main/java/com/alipay/oceanbase/rpc/ObGlobal.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,17 @@ public static boolean isLsOpSupport() {
8585
return OB_VERSION >= OB_VERSION_4_2_3_0 && OB_VERSION < OB_VERSION_4_3_0_0;
8686
}
8787

88+
public static boolean isReturnOneResultSupport() {
89+
return OB_VERSION >= OB_VERSION_4_2_3_0 && OB_VERSION < OB_VERSION_4_3_0_0 || OB_VERSION >= OB_VERSION_4_3_4_0;
90+
}
91+
8892
public static final long OB_VERSION_4_2_1_0 = calcVersion(4, (short) 2, (byte) 1, (byte) 0);
8993

9094
public static final long OB_VERSION_4_2_3_0 = calcVersion(4, (short) 2, (byte) 3, (byte) 0);
9195

9296
public static final long OB_VERSION_4_3_0_0 = calcVersion(4, (short) 3, (byte) 0, (byte) 0);
9397

98+
public static final long OB_VERSION_4_3_4_0 = calcVersion(4, (short) 3, (byte) 4, (byte) 0);
99+
94100
public static long OB_VERSION = calcVersion(0, (short) 0, (byte) 0, (byte) 0);
95101
}

src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.alipay.oceanbase.rpc.ObTableClient;
2121
import com.alipay.oceanbase.rpc.checkandmutate.CheckAndInsUp;
22+
import com.alipay.oceanbase.rpc.exception.FeatureNotSupportedException;
2223
import com.alipay.oceanbase.rpc.exception.ObTableException;
2324
import com.alipay.oceanbase.rpc.mutation.result.BatchOperationResult;
2425
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
@@ -157,7 +158,10 @@ public BatchOperation setReturnOneResult(boolean returnOneResult) {
157158

158159
@SuppressWarnings("unchecked")
159160
public BatchOperationResult execute() throws Exception {
160-
if (returnOneResult
161+
if (returnOneResult && !ObGlobal.isReturnOneResultSupport()) {
162+
throw new FeatureNotSupportedException(
163+
"returnOneResult is not supported in this Observer version [" + ObGlobal.obVsnString() +"]");
164+
} else if (returnOneResult
161165
&& !(isSameType && (lastType == ObTableOperationType.INSERT
162166
|| lastType == ObTableOperationType.PUT
163167
|| lastType == ObTableOperationType.REPLACE || lastType == ObTableOperationType.DEL))) {

src/test/java/com/alipay/oceanbase/rpc/ObAtomicBatchOperationTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
2828
import com.alipay.oceanbase.rpc.table.api.TableBatchOps;
2929
import com.alipay.oceanbase.rpc.util.ObTableClientTestUtil;
30-
import org.junit.After;
31-
import org.junit.Assert;
32-
import org.junit.Before;
33-
import org.junit.Test;
30+
import org.junit.*;
3431

3532
import java.util.ArrayList;
3633
import java.util.List;
@@ -212,7 +209,9 @@ public void testBatchOperation() {
212209
}
213210

214211
@Test
212+
215213
public void testReturnOneRes() {
214+
Assume.assumeTrue("Skipping returnOneResult when ob version not support", ObGlobal.isReturnOneResultSupport());
216215
TableBatchOps batchOps = obTableClient.batch("test_varchar_table");
217216
// no atomic ReturnOneRes batch operation
218217
try {
@@ -298,6 +297,7 @@ public void testReturnOneRes() {
298297

299298
@Test
300299
public void testReturnOneResPartition() throws Exception {
300+
Assume.assumeTrue("Skiping returnOneResult when ob version not support", ObGlobal.isReturnOneResultSupport());
301301
BatchOperation batchOperation = obTableClient.batchOperation("test_mutation");
302302
Object values[][] = { { 1L, "c2_val", "c3_val", 100L }, { 200L, "c2_val", "c3_val", 100L },
303303
{ 401L, "c2_val", "c3_val", 100L }, { 2000L, "c2_val", "c3_val", 100L },
@@ -328,6 +328,7 @@ public void testReturnOneResPartition() throws Exception {
328328

329329
@Test
330330
public void testBatchGet() throws Exception {
331+
Assume.assumeTrue("Skipping returnOneResult when ob version not support", ObGlobal.isReturnOneResultSupport());
331332
try {
332333
{
333334
// insert

src/test/java/com/alipay/oceanbase/rpc/ObTableLsBatchTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.alipay.oceanbase.rpc.util.ObTableClientTestUtil;
2626
import com.alipay.oceanbase.rpc.util.TimeUtils;
2727
import org.junit.Assert;
28+
import org.junit.Assume;
2829
import org.junit.Before;
2930
import org.junit.Test;
3031

@@ -309,6 +310,7 @@ public void testGetAllObjType() throws Exception {
309310

310311
@Test
311312
public void testBatchInsert() throws Exception {
313+
Assume.assumeTrue("Skipping returnOneResult when ob version not support", ObGlobal.isReturnOneResultSupport());
312314
BatchOperation batchOperation = client.batchOperation(TABLE_NAME);
313315
Object values[][] = { { 1L, "c2_val", "c3_val", 100L }, { 400L, "c2_val", "c3_val", 100L },
314316
{ 401L, "c2_val", "c3_val", 100L }, { 1000L, "c2_val", "c3_val", 100L },
@@ -396,6 +398,7 @@ public void testBatchAppend() throws Exception {
396398

397399
@Test
398400
public void testBatchDel() throws Exception {
401+
Assume.assumeTrue("Skipping returnOneResult when ob version not support", ObGlobal.isReturnOneResultSupport());
399402
Object values[][] = { { 1L, "c2_val", "c3_val", 100L }, { 400L, "c2_val", "c3_val", 100L },
400403
{ 401L, "c2_val", "c3_val", 100L }, { 1000L, "c2_val", "c3_val", 100L },
401404
{ 1001L, "c2_val", "c3_val", 100L }, { 1002L, "c2_val", "c3_val", 100L }, };
@@ -496,6 +499,7 @@ public void testBatchIncrement() throws Exception {
496499

497500
@Test
498501
public void testBatchReplace() throws Exception {
502+
Assume.assumeTrue("Skipping returnOneResult when ob version not support", ObGlobal.isReturnOneResultSupport());
499503
Object values[][] = { { 1L, "c2_val", "c3_val", 100L }, { 400L, "c2_val", "c3_val", 100L },
500504
{ 401L, "c2_val", "c3_val", 100L }, { 1000L, "c2_val", "c3_val", 100L },
501505
{ 1001L, "c2_val", "c3_val", 100L }, { 1002L, "c2_val", "c3_val", 100L }, };
@@ -712,6 +716,7 @@ public void testHybridBatch() throws Exception {
712716

713717
@Test
714718
public void testPut() throws Exception {
719+
Assume.assumeTrue("Skipping returnOneResult when ob version not support", ObGlobal.isReturnOneResultSupport());
715720
// put operation should set binlog_row_image minimal
716721
Connection connection = ObTableClientTestUtil.getConnection();
717722
Statement statement = connection.createStatement();

0 commit comments

Comments
 (0)