Skip to content

Commit bf72ef4

Browse files
authored
Merge pull request #257 from oceanbase/lsop_index_bugfix
Lsop index bugfix
2 parents 0b273b0 + d99cd3f commit bf72ef4

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -342,35 +342,32 @@ private Object[] calculateRowKey(ObTableSingleOp operation) {
342342
return rowKey;
343343
}
344344

345-
private List<ObTableSingleOp> extractOperations(Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperationsMap) {
346-
List<ObTableSingleOp> operations = new ArrayList<>();
345+
private List<ObPair<Integer, ObTableSingleOp>> extractOperations(Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperationsMap) {
346+
List<ObPair<Integer, ObTableSingleOp>> operationsWithIndex = new ArrayList<>();
347347
for (ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>> pair : tabletOperationsMap.values()) {
348-
for (ObPair<Integer, ObTableSingleOp> operationWithIndex : pair.getRight()) {
349-
operations.add(operationWithIndex.getRight());
350-
}
348+
operationsWithIndex.addAll(pair.getRight());
351349
}
352-
return operations;
350+
return operationsWithIndex;
353351
}
354352

355-
public Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>>> prepareOperations(List<ObTableSingleOp> operations) throws Exception {
356-
Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>>> lsOperationsMap = new HashMap<>();
353+
public Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>>> prepareOperations(List<ObPair<Integer, ObTableSingleOp>> operationsWithIndex) throws Exception {
354+
Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>>> lsOperationsMap = new HashMap<>();
357355

358356
if (obTableClient.isOdpMode()) {
359357
Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperationsMap = new HashMap<>();
360358
ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>> obTableOperations =
361359
new ObPair<>(new ObTableParam(obTableClient.getOdpTable()),
362360
new ArrayList<ObPair<Integer, ObTableSingleOp>>());
363-
for (int i = 0; i < operations.size(); i++) {
364-
ObTableSingleOp operation = operations.get(i);
365-
obTableOperations.getRight().add(new ObPair<Integer, ObTableSingleOp>(i, operation));
361+
for (int i = 0; i < operationsWithIndex.size(); i++) {
362+
obTableOperations.getRight().add(operationsWithIndex.get(i));
366363
}
367364
tabletOperationsMap.put(INVALID_TABLET_ID, obTableOperations);
368365
lsOperationsMap.put(INVALID_LS_ID, tabletOperationsMap);
369366
return lsOperationsMap;
370367
}
371368

372-
for (int i = 0; i < operations.size(); i++) {
373-
ObTableSingleOp operation = operations.get(i);
369+
for (int i = 0; i < operationsWithIndex.size(); i++) {
370+
ObTableSingleOp operation = operationsWithIndex.get(i).getRight();
374371
Object[] rowKey = calculateRowKey(operation);
375372

376373
String real_tableName = tableName;
@@ -382,22 +379,26 @@ public Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSing
382379
long lsId = tableObPair.getRight().getLsId();
383380

384381
Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperations
385-
= lsOperationsMap.computeIfAbsent(lsId, k -> new HashMap<>());
382+
= lsOperationsMap.computeIfAbsent(lsId, k -> new HashMap<>());
386383
// if ls id not exists
387384

388385
ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>> singleOperations =
389-
tabletOperations.computeIfAbsent(tableObPair.getLeft(), k -> new ObPair<>(tableObPair.getRight(), new ArrayList<>()));
386+
tabletOperations.computeIfAbsent(tableObPair.getLeft(), k -> new ObPair<>(tableObPair.getRight(), new ArrayList<>()));
390387
// if tablet id not exists
391-
singleOperations.getRight().add(new ObPair<>(i, operation));
388+
singleOperations.getRight().add(operationsWithIndex.get(i));
392389
}
393390

394391
return lsOperationsMap;
395392
}
396393

397394
public Map<Long, Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>>> partitionPrepare()
398-
throws Exception {
395+
throws Exception {
399396
List<ObTableSingleOp> operations = getSingleOperations();
400-
return prepareOperations(operations);
397+
List<ObPair<Integer, ObTableSingleOp>> operationsWithIndex = new LinkedList<>();
398+
for (int i = 0; i < operations.size(); i++) {
399+
operationsWithIndex.add(new ObPair<>(i, operations.get(i)));
400+
}
401+
return prepareOperations(operationsWithIndex);
401402
}
402403

403404
/*
@@ -661,7 +662,7 @@ private void executeWithRetries(
661662
retryCount++;
662663
errCode = ((ObTableNeedFetchAllException)e).getErrorCode();
663664
errMsg = e.getMessage();
664-
List<ObTableSingleOp> failedOperations = extractOperations(currentEntry.getValue());
665+
List<ObPair<Integer, ObTableSingleOp>> failedOperations = extractOperations(currentEntry.getValue());
665666
currentPartitions = prepareOperations(failedOperations);
666667
allPartitionsSuccess = false;
667668
break;

0 commit comments

Comments
 (0)