Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dead lock in multi DB when using batchUpdate(#31038) #31118

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -63,16 +63,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 All @@ -98,16 +98,16 @@ public void processSuccessInClickHouse() throws SQLException {
assertThat(orderIds, notNullValue());
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