question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to switch schema, please terminate current transaction.

See original GitHub issue

Bug Report

Which version of ShardingSphere did you use?

4.1.0

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-Proxy

Steps to reproduce the behavior

My project developed by Django wants to connect mysql proxy, errors are always reported when initializing the connection, but after the initialization is complete, it can continue to work fine.

I used wireshark to grab the data package that initialized the connection process(the login process is omitted):

SET AUTOCOMMIT = 0
SELECT @@SQL_AUTO_IS_NULL
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED

get error response: 2Unknown exception: [Failed to switch schema, please terminate current transaction.]

the content of config-sharding.yaml:

schemaName: sharding_db

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
    username: root
    password: admin
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
  ds_1:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
    username: root
    password: admin
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50

shardingRule:
  tables:
    t_order:
      actualDataNodes: ds_${0..1}.t_order_${0..1}
      tableStrategy:
        inline:
          shardingColumn: order_id
          algorithmExpression: t_order_${order_id % 2}
      keyGenerator:
        type: SNOWFLAKE
        column: order_id
    t_order_item:
      actualDataNodes: ds_${0..1}.t_order_item_${0..1}
      tableStrategy:
        inline:
          shardingColumn: order_id
          algorithmExpression: t_order_item_${order_id % 2}
      keyGenerator:
        type: SNOWFLAKE
        column: order_item_id
  bindingTables:
    - t_order,t_order_item
  defaultDatabaseStrategy:
    inline:
      shardingColumn: user_id
      algorithmExpression: ds_${user_id % 2}
  defaultTableStrategy:
    none:

Example codes for reproduce this issue (such as a github link).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:30 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
hongfulicommented, May 12, 2020

Will the issue be resolved in the 5 milestone or 4.1.x version? I hope to solve it as soon as possible because I need it urgently 😃

0reactions
jingshanglucommented, Mar 17, 2022

It maybe fixed by #14983 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to switch schema, please terminate current transaction.
yunqian-c9 commented on issue #12759: URL: https://github.com/apache/shardingsphere/issues/12759#issuecomment-939736120
Read more >
current transaction is aborted, commands ignored until end of ...
ROLLBACK − To rollback the changes. so i use the END TRANSACTION to end the error TRANSACTION, code like this: for key_of_attribute, command...
Read more >
Solution to "current transaction is aborted" error for Po...
> SELECT * FROM T1; ==>ERROR: current transaction is aborted, commands ignored until end of transaction block> The SELECT and subsequent ...
Read more >
ALTER SESSION SET CURRENT_SCHEMA - Ask TOM
However, it fails when trying to use a variable in place of the schema name. Any ideas? EXEC SQL ALTER SESSION SET CURRENT_SCHEM=:DB-SCHEMA...
Read more >
CREATE SCHEMA - Amazon Redshift - AWS Documentation
Defines a new schema for the current database. ... make no changes and return a message that the schema exists, rather than terminating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found