qixiaobo commented on issue #1496: Read write splitter for `Select ... for 
update` should route to master data node
URL: 
https://github.com/apache/incubator-shardingsphere/issues/1496#issuecomment-542760093
 
 
   ```java
   public final class MasterSlaveRouter {
       
       private final MasterSlaveRule masterSlaveRule;
       
       private final SQLParseEngine parseEngine;
       
       private final boolean showSQL;
       
       /**
        * Route Master slave.
        *
        * @param sql SQL
        * @param useCache use cache or not
        * @return data source names
        */
       // TODO for multiple masters may return more than one data source
       public Collection<String> route(final String sql, final boolean 
useCache) {
           Collection<String> result = route(parseEngine.parse(sql, useCache));
           if (showSQL) {
               SQLLogger.logSQL(sql, result);
           }
           return result;
       }
       
       private Collection<String> route(final SQLStatement sqlStatement) {
           if (isMasterRoute(sqlStatement)) {
               MasterVisitedManager.setMasterVisited();
               return 
Collections.singletonList(masterSlaveRule.getMasterDataSourceName());
           }
           return 
Collections.singletonList(masterSlaveRule.getLoadBalanceAlgorithm().getDataSource(
                   masterSlaveRule.getName(), 
masterSlaveRule.getMasterDataSourceName(), new 
ArrayList<>(masterSlaveRule.getSlaveDataSourceNames())));
       }
       
       private boolean isMasterRoute(final SQLStatement sqlStatement) {
           return !(sqlStatement instanceof SelectStatement) || 
MasterVisitedManager.isMasterVisited() || HintManager.isMasterRouteOnly();
       }
   ```
   You should use hintManager

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to