You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/10/11 07:23:24 UTC
[GitHub] [incubator-shardingsphere] wgy8283335 opened a new issue #3226:
There is a question in ShardingMasterSlaveRouter.route()?
wgy8283335 opened a new issue #3226: There is a question in ShardingMasterSlaveRouter.route()?
URL: https://github.com/apache/incubator-shardingsphere/issues/3226
## There is a question in ShardingMasterSlaveRouter.route()?
org.apache.shardingsphere.core.route.router.masterslave.ShardingMasterSlaveRouter
```
private void route(final MasterSlaveRule masterSlaveRule, final SQLRouteResult sqlRouteResult) {
Collection<RoutingUnit> toBeRemoved = new LinkedList<>();
Collection<RoutingUnit> toBeAdded = new LinkedList<>();
for (RoutingUnit each : sqlRouteResult.getRoutingResult().getRoutingUnits()) {
if (!masterSlaveRule.getName().equalsIgnoreCase(each.getDataSourceName())) {
continue;
}
toBeRemoved.add(each);
String actualDataSourceName;
if (isMasterRoute(sqlRouteResult.getSqlStatementContext().getSqlStatement())) {
MasterVisitedManager.setMasterVisited();
actualDataSourceName = masterSlaveRule.getMasterDataSourceName();
} else {
actualDataSourceName = masterSlaveRule.getLoadBalanceAlgorithm().getDataSource(
masterSlaveRule.getName(), masterSlaveRule.getMasterDataSourceName(), new ArrayList<>(masterSlaveRule.getSlaveDataSourceNames()));
}
toBeAdded.add(createNewRoutingUnit(actualDataSourceName, each));
}
sqlRouteResult.getRoutingResult().getRoutingUnits().removeAll(toBeRemoved);
sqlRouteResult.getRoutingResult().getRoutingUnits().addAll(toBeAdded);
}
```
```
private boolean isMasterRoute(final SQLStatement sqlStatement) {
return !(sqlStatement instanceof SelectStatement) || MasterVisitedManager.isMasterVisited() || HintManager.isMasterRouteOnly();
}
```
My concern is these lines
```
if (isMasterRoute(sqlRouteResult.getSqlStatementContext().getSqlStatement())) {
MasterVisitedManager.setMasterVisited();
actualDataSourceName = masterSlaveRule.getMasterDataSourceName();
}
```
`MasterVisitedManager.isMasterVisited()` in ` isMasterRoute()` in `if` sentence.
If the result is true.
Then `MasterVisitedManager.setMasterVisited();` will set the value again, value is also true.
If the result is false.
Then `MasterVisitedManager.setMasterVisited();` will not be executed, value is also false.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services