Skip to content

Commit cd97228

Browse files
committed
Use provided dataSourceNames instead of usedDataSourceNames.
Ensure return logic datasource name.
1 parent a75a02a commit cd97228

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.TablelessInstanceBroadcastRouteEngine;
2929
import org.apache.shardingsphere.infra.route.engine.tableless.type.ignore.TablelessIgnoreRouteEngine;
3030
import org.apache.shardingsphere.infra.route.engine.tableless.type.unicast.TablelessDataSourceUnicastRouteEngine;
31-
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
3231
import org.apache.shardingsphere.infra.session.query.QueryContext;
3332
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
3433
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.AlterResourceGroupStatement;
@@ -82,7 +81,7 @@ public static TablelessRouteEngine newInstance(final QueryContext queryContext,
8281
return getDDLRouteEngine(queryContext.getSqlStatementContext(), database);
8382
}
8483
if (sqlStatement instanceof DMLStatement) {
85-
return getDMLRouteEngine(queryContext.getSqlStatementContext(), queryContext.getConnectionContext());
84+
return getDMLRouteEngine(queryContext.getSqlStatementContext());
8685
}
8786
return new TablelessIgnoreRouteEngine();
8887
}
@@ -135,9 +134,9 @@ private static TablelessRouteEngine getCursorRouteEngine(final SQLStatementConte
135134
return new TablelessIgnoreRouteEngine();
136135
}
137136

138-
private static TablelessRouteEngine getDMLRouteEngine(final SQLStatementContext sqlStatementContext, final ConnectionContext connectionContext) {
137+
private static TablelessRouteEngine getDMLRouteEngine(final SQLStatementContext sqlStatementContext) {
139138
if (sqlStatementContext instanceof SelectStatementContext) {
140-
return new TablelessDataSourceUnicastRouteEngine(connectionContext);
139+
return new TablelessDataSourceUnicastRouteEngine();
141140
}
142141
return new TablelessIgnoreRouteEngine();
143142
}

infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/unicast/TablelessDataSourceUnicastRouteEngine.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
@RequiredArgsConstructor
3737
public final class TablelessDataSourceUnicastRouteEngine implements TablelessRouteEngine {
3838

39-
private final ConnectionContext connectionContext;
40-
4139
@Override
4240
public RouteContext route(final RuleMetaData globalRuleMetaData, final Collection<String> aggregatedDataSources) {
4341
RouteContext result = new RouteContext();
@@ -51,7 +49,6 @@ private RouteMapper getDataSourceRouteMapper(final Collection<String> dataSource
5149
}
5250

5351
private String getRandomDataSourceName(final Collection<String> dataSourceNames) {
54-
Collection<String> usedDataSourceNames = connectionContext.getUsedDataSourceNames().isEmpty() ? dataSourceNames : connectionContext.getUsedDataSourceNames();
55-
return new ArrayList<>(usedDataSourceNames).get(ThreadLocalRandom.current().nextInt(usedDataSourceNames.size()));
52+
return new ArrayList<>(dataSourceNames).get(ThreadLocalRandom.current().nextInt(dataSourceNames.size()));
5653
}
5754
}

infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/type/unicast/TablelessDataSourceUnicastRouteEngineTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ class TablelessDataSourceUnicastRouteEngineTest {
3939

4040
@Test
4141
void assertRouteWithoutUsedDataSourceNames() {
42-
ConnectionContext connectionContext = new ConnectionContext(Collections::emptyList);
4342
Collection<String> aggregatedDataSources = Arrays.asList("foo_ds_1", "foo_ds_2");
44-
RouteContext actual = new TablelessDataSourceUnicastRouteEngine(connectionContext).route(mock(RuleMetaData.class), aggregatedDataSources);
43+
RouteContext actual = new TablelessDataSourceUnicastRouteEngine().route(mock(RuleMetaData.class), aggregatedDataSources);
4544
assertThat(actual.getRouteUnits().size(), is(1));
4645
RouteUnit routeUnit = actual.getRouteUnits().iterator().next();
4746
assertTrue(aggregatedDataSources.contains(routeUnit.getDataSourceMapper().getLogicName()));
@@ -51,9 +50,8 @@ void assertRouteWithoutUsedDataSourceNames() {
5150

5251
@Test
5352
void assertRouteWithUsedDataSourceNames() {
54-
ConnectionContext connectionContext = new ConnectionContext(() -> Collections.singleton("foo_ds_1"));
5553
Collection<String> aggregatedDataSources = Arrays.asList("foo_ds_1", "foo_ds_2");
56-
RouteContext actual = new TablelessDataSourceUnicastRouteEngine(connectionContext).route(mock(RuleMetaData.class), aggregatedDataSources);
54+
RouteContext actual = new TablelessDataSourceUnicastRouteEngine().route(mock(RuleMetaData.class), aggregatedDataSources);
5755
assertThat(actual.getRouteUnits().size(), is(1));
5856
RouteUnit routeUnit = actual.getRouteUnits().iterator().next();
5957
assertThat(routeUnit.getDataSourceMapper().getLogicName(), is("foo_ds_1"));

0 commit comments

Comments
 (0)