Skip to content

Commit

Permalink
fix dead lock in multi DB when using batchUpdate(#31038)
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Jason committed May 20, 2024
1 parent 12144de commit e316f4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

/**
* Abstract execution prepare engine.
Expand Down Expand Up @@ -80,7 +80,7 @@ private List<List<ExecutionUnit>> group(final List<ExecutionUnit> sqlUnits) {
protected abstract List<ExecutionGroup<T>> group(String dataSourceName, int connectionOffset, List<List<ExecutionUnit>> executionUnitGroups, ConnectionMode connectionMode) throws SQLException;

private Map<String, List<ExecutionUnit>> aggregateExecutionUnitGroups(final Collection<ExecutionUnit> executionUnits) {
Map<String, List<ExecutionUnit>> result = new LinkedHashMap<>(executionUnits.size(), 1F);
Map<String, List<ExecutionUnit>> result = new TreeMap<>();
for (ExecutionUnit each : executionUnits) {
result.computeIfAbsent(each.getDataSourceName(), unused -> new LinkedList<>()).add(each);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public void processSuccess() throws SQLException {
final Collection<Long> orderIds = insertData();
Collection<Order> orders = orderRepository.selectAll();
assertThat(orders.stream().map(Order::getOrderType).collect(Collectors.toList()),
equalTo(Arrays.asList(1, 1, 1, 1, 1, 0, 0, 0, 0, 0)));
equalTo(Arrays.asList(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)));
assertThat(orders.stream().map(Order::getUserId).collect(Collectors.toList()),
equalTo(new ArrayList<>(Arrays.asList(1, 3, 5, 7, 9, 2, 4, 6, 8, 10))));
equalTo(new ArrayList<>(Arrays.asList(2, 4, 6, 8, 10, 1, 3, 5, 7, 9))));
assertThat(orders.stream().map(Order::getAddressId).collect(Collectors.toList()),
equalTo(new ArrayList<>(Arrays.asList(1L, 3L, 5L, 7L, 9L, 2L, 4L, 6L, 8L, 10L))));
equalTo(new ArrayList<>(Arrays.asList(2L, 4L, 6L, 8L, 10L, 1L, 3L, 5L, 7L, 9L))));
assertThat(orders.stream().map(Order::getStatus).collect(Collectors.toList()),
equalTo(IntStream.range(1, 11).mapToObj(i -> "INSERT_TEST").collect(Collectors.toList())));
Collection<OrderItem> orderItems = orderItemRepository.selectAll();
assertThat(orderItems.stream().map(OrderItem::getUserId).collect(Collectors.toList()),
equalTo(new ArrayList<>(Arrays.asList(1, 3, 5, 7, 9, 2, 4, 6, 8, 10))));
equalTo(new ArrayList<>(Arrays.asList(2, 4, 6, 8, 10, 1, 3, 5, 7, 9))));
assertThat(orderItems.stream().map(OrderItem::getPhone).collect(Collectors.toList()),
equalTo(IntStream.range(1, 11).mapToObj(i -> "13800000001").collect(Collectors.toList())));
assertThat(orderItems.stream().map(OrderItem::getStatus).collect(Collectors.toList()),
Expand Down

0 comments on commit e316f4a

Please sign in to comment.