Skip to content

Commit 9fc0583

Browse files
authored
resolve some bugs caused by mismatched operation types (#258)
1 parent 2162067 commit 9fc0583

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ private BatchOperationResult executeWithNormalBatchOp() throws Exception {
268268
query.getSelectColumns().toArray((new String[0])));
269269
} else if (operation instanceof Get) {
270270
Get get = (Get) operation;
271+
if (get.getRowKey() == null) {
272+
throw new IllegalArgumentException("RowKey is null in Get operation");
273+
}
271274
batchOps.get(get.getRowKey().getValues(), get.getSelectColumns());
272275
} else {
273276
throw new ObTableException("unknown operation " + operation);
@@ -314,6 +317,9 @@ private BatchOperationResult executeWithLSBatchOp() throws Exception {
314317
}
315318
} else if (operation instanceof Get) {
316319
Get get = (Get) operation;
320+
if (get.getRowKey() == null) {
321+
throw new IllegalArgumentException("RowKey is null in Get operation");
322+
}
317323
batchOps.addOperation(get);
318324
} else if (operation instanceof TableQuery) {
319325
TableQuery query = (TableQuery) operation;

src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,22 @@ public List<Object> execute() throws Exception {
315315
*/
316316
public List<Object> executeWithResult() throws Exception {
317317
List<Object> results = new ArrayList<Object>(batchOperation.size());
318-
for (ObTableSingleOpResult result : executeInternal()) {
318+
ObTableSingleOpResult[] singleResults = executeInternal();
319+
for (int i = 0; i < singleResults.length; i++) {
320+
ObTableSingleOpResult result = singleResults[i];
321+
// Sometimes the server does not set the operation type,so we use request operation type
322+
ObTableOperationType opType = batchOperation.get(i).getSingleOpType();
319323
int errCode = result.getHeader().getErrno();
320324
if (errCode == ResultCodes.OB_SUCCESS.errorCode) {
321-
if (result.getOperationType() == ObTableOperationType.GET) {
325+
if (opType == ObTableOperationType.GET) {
322326
results.add(new GetResult(result));
323327
} else {
324328
results.add(new MutationResult(result));
325329
}
326330
} else {
327331
results.add(ExceptionUtil.convertToObTableException(result.getExecuteHost(),
328-
result.getExecutePort(), result.getSequence(), result.getUniqueId(), errCode,
329-
result.getHeader().getErrMsg()));
332+
result.getExecutePort(), result.getSequence(), result.getUniqueId(), errCode,
333+
result.getHeader().getErrMsg()));
330334
}
331335
}
332336
return results;

0 commit comments

Comments
 (0)