<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>For English only</strong>, other languages will not accept.</p>
<p dir="auto">Before report a bug, make sure you have:</p>
<ul dir="auto">
<li>Searched open and closed <a href="https://github.com/apache/incubator-shardingsphere/issues">GitHub issues</a>.</li>
<li>Read documentation: <a href="https://shardingsphere.apache.org/document/current/en/overview" rel="nofollow">ShardingSphere Doc</a>.</li>
</ul>
<p dir="auto">Please pay attention on issues you submitted, because we maybe need more details.<br>
If no response <strong>more than 7 days</strong> and we cannot reproduce it on current information, we will <strong>close it</strong>.</p>
<p dir="auto">Please answer these questions before submitting your issue. Thanks!</p>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<blockquote>
<p dir="auto">5.6.4-Sharding-Proxy 4.0.0<br>
Download From <code class="notranslate">https://www.apache.org/dyn/closer.cgi?path=incubator/shardingsphere/4.0.0/apache-shardingsphere-incubating-4.0.0-sharding-jdbc-bin.tar.gz</code></p>
</blockquote>
<h3 dir="auto">Which project did you use? Sharding-JDBC or Sharding-Proxy?</h3>
<blockquote>
<p dir="auto">Sharding-Proxy</p>
</blockquote>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">I use SQLAlchemy to do a <code class="notranslate">SELECT</code> action like <code class="notranslate">Model.query.limit(10).all()</code></p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">Here is the <code class="notranslate">stdout.log</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[INFO ] 16:12:02.712 [nioEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x2df725aa, L:/0.0.0.0:3307] READ: [id: 0xd7c30a2a, L:/127.0.0.1:3307 - R:/127.0.0.1:50186]
[INFO ] 16:12:02.724 [nioEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x2df725aa, L:/0.0.0.0:3307] READ COMPLETE
[WARN ] 16:12:02.937 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[1].
[WARN ] 16:12:03.141 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[2].
[WARN ] 16:12:03.346 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[3].
[WARN ] 16:12:03.550 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[4].
[WARN ] 16:12:03.751 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[5].
[ERROR] 16:12:03.751 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Cannot do switch, exceed maximum retry count:[5].
[ERROR] 16:12:03.751 [ShardingSphere-Command-0] o.a.s.s.f.c.CommandExecutorTask - Exception occur: 
org.apache.shardingsphere.core.exception.ShardingException: Failed to switch schema, please terminate current transaction.
	at org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection.setCurrentSchema(BackendConnection.java:116)
	at org.apache.shardingsphere.shardingproxy.backend.text.admin.BroadcastBackendHandler.execute(BroadcastBackendHandler.java:53)
	at org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:73)
	at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:92)
	at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)"><pre class="notranslate"><code class="notranslate">[INFO ] 16:12:02.712 [nioEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x2df725aa, L:/0.0.0.0:3307] READ: [id: 0xd7c30a2a, L:/127.0.0.1:3307 - R:/127.0.0.1:50186]
[INFO ] 16:12:02.724 [nioEventLoopGroup-2-1] i.n.handler.logging.LoggingHandler - [id: 0x2df725aa, L:/0.0.0.0:3307] READ COMPLETE
[WARN ] 16:12:02.937 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[1].
[WARN ] 16:12:03.141 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[2].
[WARN ] 16:12:03.346 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[3].
[WARN ] 16:12:03.550 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[4].
[WARN ] 16:12:03.751 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Current transaction have not terminated, retry count:[5].
[ERROR] 16:12:03.751 [ShardingSphere-Command-0] o.a.s.s.b.c.j.c.BackendConnection - Cannot do switch, exceed maximum retry count:[5].
[ERROR] 16:12:03.751 [ShardingSphere-Command-0] o.a.s.s.f.c.CommandExecutorTask - Exception occur: 
org.apache.shardingsphere.core.exception.ShardingException: Failed to switch schema, please terminate current transaction.
	at org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection.setCurrentSchema(BackendConnection.java:116)
	at org.apache.shardingsphere.shardingproxy.backend.text.admin.BroadcastBackendHandler.execute(BroadcastBackendHandler.java:53)
	at org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:73)
	at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:92)
	at org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:72)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
</code></pre></div>
<h3 dir="auto">Reason analyze (If you can)</h3>
<h3 dir="auto">Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.</h3>
<p dir="auto">I didn't see any SQL print. The logic SQL <code class="notranslate"> select * from t_order</code> execute successfully in Proxy shell.</p>
<p dir="auto">The <code class="notranslate">config-sharding.yaml</code></p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="schemaName: sharding_db

dataSources:
 ds_0:
   url: jdbc:mysql://127.0.0.1:33065/test_db_0
   username: root
   password: ****
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 30
 ds_1:
   url: jdbc:mysql://127.0.0.1:33065/test_db_1
   username: root
   password: ****
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 30
 ds_2:
   url: jdbc:mysql://127.0.0.1:33065/test_db_2
   username: root
   password: ****
   connectionTimeoutMilliseconds: 30000
   idleTimeoutMilliseconds: 60000
   maxLifetimeMilliseconds: 1800000
   maxPoolSize: 30

shardingRule:
 tables:
   t_order:
     actualDataNodes: ds_${0..2}.t_order_${0..2}
     tableStrategy:
       inline:
         shardingColumn: order_id
         algorithmExpression: t_order_${order_id % 3}"><pre class="notranslate"><span class="pl-ent">schemaName</span>: <span class="pl-s">sharding_db</span>

<span class="pl-ent">dataSources</span>:
 <span class="pl-ent">ds_0</span>:
   <span class="pl-ent">url</span>: <span class="pl-s">jdbc:mysql://127.0.0.1:33065/test_db_0</span>
   <span class="pl-ent">username</span>: <span class="pl-s">root</span>
   <span class="pl-ent">password</span>: <span class="pl-s">****</span>
   <span class="pl-ent">connectionTimeoutMilliseconds</span>: <span class="pl-c1">30000</span>
   <span class="pl-ent">idleTimeoutMilliseconds</span>: <span class="pl-c1">60000</span>
   <span class="pl-ent">maxLifetimeMilliseconds</span>: <span class="pl-c1">1800000</span>
   <span class="pl-ent">maxPoolSize</span>: <span class="pl-c1">30</span>
 <span class="pl-ent">ds_1</span>:
   <span class="pl-ent">url</span>: <span class="pl-s">jdbc:mysql://127.0.0.1:33065/test_db_1</span>
   <span class="pl-ent">username</span>: <span class="pl-s">root</span>
   <span class="pl-ent">password</span>: <span class="pl-s">****</span>
   <span class="pl-ent">connectionTimeoutMilliseconds</span>: <span class="pl-c1">30000</span>
   <span class="pl-ent">idleTimeoutMilliseconds</span>: <span class="pl-c1">60000</span>
   <span class="pl-ent">maxLifetimeMilliseconds</span>: <span class="pl-c1">1800000</span>
   <span class="pl-ent">maxPoolSize</span>: <span class="pl-c1">30</span>
 <span class="pl-ent">ds_2</span>:
   <span class="pl-ent">url</span>: <span class="pl-s">jdbc:mysql://127.0.0.1:33065/test_db_2</span>
   <span class="pl-ent">username</span>: <span class="pl-s">root</span>
   <span class="pl-ent">password</span>: <span class="pl-s">****</span>
   <span class="pl-ent">connectionTimeoutMilliseconds</span>: <span class="pl-c1">30000</span>
   <span class="pl-ent">idleTimeoutMilliseconds</span>: <span class="pl-c1">60000</span>
   <span class="pl-ent">maxLifetimeMilliseconds</span>: <span class="pl-c1">1800000</span>
   <span class="pl-ent">maxPoolSize</span>: <span class="pl-c1">30</span>

<span class="pl-ent">shardingRule</span>:
 <span class="pl-ent">tables</span>:
   <span class="pl-ent">t_order</span>:
     <span class="pl-ent">actualDataNodes</span>: <span class="pl-s">ds_${0..2}.t_order_${0..2}</span>
     <span class="pl-ent">tableStrategy</span>:
       <span class="pl-ent">inline</span>:
         <span class="pl-ent">shardingColumn</span>: <span class="pl-s">order_id</span>
         <span class="pl-ent">algorithmExpression</span>: <span class="pl-s">t_order_${order_id % 3}</span></pre></div>
<h3 dir="auto">Example codes for reproduce this issue (such as a github link).</h3>
<p dir="auto">The table:</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CREATE TABLE `t_order` (
  `order_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `status` varchar(50) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"><pre class="notranslate"><span class="pl-k">CREATE</span> <span class="pl-k">TABLE</span> `<span class="pl-en">t_order</span>` (
  <span class="pl-s"><span class="pl-pds">`</span>order_id<span class="pl-pds">`</span></span> <span class="pl-k">bigint</span>(<span class="pl-c1">20</span>) <span class="pl-k">NOT NULL</span> AUTO_INCREMENT,
  <span class="pl-s"><span class="pl-pds">`</span>user_id<span class="pl-pds">`</span></span> <span class="pl-k">int</span>(<span class="pl-c1">11</span>) <span class="pl-k">NOT NULL</span>,
  <span class="pl-s"><span class="pl-pds">`</span>status<span class="pl-pds">`</span></span> <span class="pl-k">varchar</span>(<span class="pl-c1">50</span>) COLLATE utf8_bin DEFAULT <span class="pl-k">NULL</span>,
  <span class="pl-k">PRIMARY KEY</span> (<span class="pl-s"><span class="pl-pds">`</span>order_id<span class="pl-pds">`</span></span>)
) ENGINE<span class="pl-k">=</span>InnoDB DEFAULT CHARSET<span class="pl-k">=</span>utf8 COLLATE<span class="pl-k">=</span>utf8_bin;</pre></div>
<p dir="auto">The  SQLAlchemy Model:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Order(db.Model):
    __tablename__ = 't_order'
    order_id = db.Column(db.BigInteger, primary_key=True)
    user_id = db.Column(db.Integer)
    status = db.Column(db.VARCHAR(50), server_default=&quot;&quot;)

    def __repr__(self):
        return '&lt;Order {id} {status}&gt;'.format(id=self.user_id, status=self.status)"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Order</span>(<span class="pl-s1">db</span>.<span class="pl-v">Model</span>):
    <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'t_order'</span>
    <span class="pl-s1">order_id</span> <span class="pl-c1">=</span> <span class="pl-s1">db</span>.<span class="pl-v">Column</span>(<span class="pl-s1">db</span>.<span class="pl-v">BigInteger</span>, <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
    <span class="pl-s1">user_id</span> <span class="pl-c1">=</span> <span class="pl-s1">db</span>.<span class="pl-v">Column</span>(<span class="pl-s1">db</span>.<span class="pl-v">Integer</span>)
    <span class="pl-s1">status</span> <span class="pl-c1">=</span> <span class="pl-s1">db</span>.<span class="pl-v">Column</span>(<span class="pl-s1">db</span>.<span class="pl-v">VARCHAR</span>(<span class="pl-c1">50</span>), <span class="pl-s1">server_default</span><span class="pl-c1">=</span><span class="pl-s">""</span>)

    <span class="pl-k">def</span> <span class="pl-en">__repr__</span>(<span class="pl-s1">self</span>):
        <span class="pl-k">return</span> <span class="pl-s">'&lt;Order {id} {status}&gt;'</span>.<span class="pl-en">format</span>(<span class="pl-s1">id</span><span class="pl-c1">=</span><span class="pl-s1">self</span>.<span class="pl-s1">user_id</span>, <span class="pl-s1">status</span><span class="pl-c1">=</span><span class="pl-s1">self</span>.<span class="pl-s1">status</span>)</pre></div>
<p dir="auto">The URI:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SQLALCHEMY_DATABASE_URI = 'mysql://root:root@127.0.0.1:3307/sharding_db'"><pre class="notranslate"><code class="notranslate">SQLALCHEMY_DATABASE_URI = 'mysql://root:root@127.0.0.1:3307/sharding_db'
</code></pre></div>
<p dir="auto">The Python package:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SQLAlchemy==1.3.12
mysqlclient==1.4.6
Flask_SQLAlchemy==2.4.0
Flask==1.1.1"><pre class="notranslate"><code class="notranslate">SQLAlchemy==1.3.12
mysqlclient==1.4.6
Flask_SQLAlchemy==2.4.0
Flask==1.1.1
</code></pre></div>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<p dir="auto">master batch</p>
<h3 dir="auto">Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?</h3>
<p dir="auto">ShardingSphere-Proxy</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">/metadata/schemaName/tables broadcast table metadata exist</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">/metadata/schemaName/tables broadcast table metadata lost</p>
<h3 dir="auto">Reason analyze (If you can)</h3>
<p dir="auto">It may be because Debug finds<br>
TableMetadataLoadRengine's LOAD method leads to the loss of the broadcast</p>
<h3 dir="auto">Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.</h3>
<p dir="auto">1、start ShardingSphere-proxy<br>
2、perform distsql<br>
3、Data loss found in ZK</p>