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/11/25 08:48:12 UTC

[GitHub] [incubator-shardingsphere] vioao opened a new issue #3592: MasterSlaveRouter does not work well in some occasion

vioao opened a new issue #3592: MasterSlaveRouter does not work well in some occasion
URL: https://github.com/apache/incubator-shardingsphere/issues/3592
 
 
   ## Question
   I see the source code, and find that the MASTER_VISITED will be clear when the connection is closed. 
   And then, a read SQL that after write SQL in the same thread will be route to the slave.
   Is that right? However, I need it to be routed to the master.
   ```java
   public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOperationConnection {
       @Override
       public final void close() throws SQLException {
           closed = true;
           HintManagerHolder.clear();
           MasterVisitedManager.clear();
           TransactionTypeHolder.clear();
           int connectionSize = cachedConnections.size();
           try {
               forceExecuteTemplateForClose.execute(cachedConnections.entries(), new ForceExecuteCallback<Map.Entry<String, Connection>>() {
           
                   @Override
                   public void execute(final Entry<String, Connection> cachedConnections) throws SQLException {
                       cachedConnections.getValue().close();
                   }
               });
           } finally {
               cachedConnections.clear();
               rootInvokeHook.finish(connectionSize);
           }
       }
   }
   
   public final class MasterVisitedManager {
       
       private static final ThreadLocal<Boolean> MASTER_VISITED = new ThreadLocal<Boolean>() {
           
           @Override
           protected Boolean initialValue() {
               return false;
           }
       };
       
       /**
        * Adjust master data source visited in current thread.
        * 
        * @return master data source visited or not in current thread
        */
       public static boolean isMasterVisited() {
           return MASTER_VISITED.get();
       }
       
       /**
        * Set master data source visited in current thread.
        */
       public static void setMasterVisited() {
           MASTER_VISITED.set(true);
       }
       
       /**
        * Clear master data source visited.
        */
       public static void clear() {
           MASTER_VISITED.remove();
       }
   }
   ```

----------------------------------------------------------------
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