Skip to content

Commit 49f04c4

Browse files
authored
support weak in old interface (#417)
1 parent 92b546b commit 49f04c4

File tree

3 files changed

+636
-18
lines changed

3 files changed

+636
-18
lines changed

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ private BatchOperationResult executeWithLSBatchOp() throws Exception {
355355
batchOps.setServerCanRetry(serverCanRetry);
356356
batchOps.setNeedTabletId(needTabletId);
357357
batchOps.setHbaseOpType(hbaseOpType);
358+
if (readConsistency != null) {
359+
isWeakRead = (readConsistency == ObReadConsistency.WEAK);
360+
} else {
361+
// 如果 BatchOperation 没有设置,使用 TableRoute 上的全局设置
362+
isWeakRead = obTableClient.getTableRoute().getReadConsistency() == ObReadConsistency.WEAK;
363+
}
364+
batchOps.setIsWeakRead(isWeakRead);
358365
for (Object operation : operations) {
359366
if (operation instanceof CheckAndInsUp) {
360367
checkAndInsUpCnt++;
@@ -383,23 +390,9 @@ private BatchOperationResult executeWithLSBatchOp() throws Exception {
383390
if (get.getRowKey() == null) {
384391
throw new IllegalArgumentException("RowKey is null in Get operation");
385392
}
386-
// BatchOperation 级别的 readConsistency 优先,忽略 Get 上的设置
387-
if (readConsistency != null) {
388-
isWeakRead = (readConsistency == ObReadConsistency.WEAK);
389-
} else {
390-
// 如果 BatchOperation 没有设置,使用 TableRoute 上的全局设置
391-
isWeakRead = obTableClient.getTableRoute().getReadConsistency() == ObReadConsistency.WEAK;
392-
}
393393
batchOps.addOperation(get);
394394
} else if (operation instanceof TableQuery) {
395395
TableQuery query = (TableQuery) operation;
396-
// BatchOperation 级别的 readConsistency 优先,忽略 TableQuery 上的设置
397-
if (readConsistency != null) {
398-
isWeakRead = (readConsistency == ObReadConsistency.WEAK);
399-
} else {
400-
// 如果 BatchOperation 没有设置,使用 TableRoute 上的全局设置
401-
isWeakRead = obTableClient.getTableRoute().getReadConsistency() == ObReadConsistency.WEAK;
402-
}
403396
batchOps.addOperation(query);
404397
} else if (operation instanceof QueryAndMutate) {
405398
QueryAndMutate qm = (QueryAndMutate) operation;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ public ObTableBatchOperationResult executeInternal() throws Exception {
590590
if (tableName == null || tableName.isEmpty()) {
591591
throw new IllegalArgumentException("table name is null");
592592
}
593+
if (batchOperation.isReadOnly()) {
594+
setIsWeakRead(obTableClient.getTableRoute().getReadConsistency() == ObReadConsistency.WEAK);
595+
}
596+
593597
long start = System.currentTimeMillis();
594598
List<ObTableOperation> operations = batchOperation.getTableOperations();
595599
ObTableOperationResult[] obTableOperationResults = returnOneResult ? new ObTableOperationResult[1]

0 commit comments

Comments
 (0)