snower / TorMySQL

The highest performance asynchronous MySQL driver by PyMySQL
MIT License
308 stars 63 forks source link

Helpers return a dead connection ? #22

Closed keysona closed 7 years ago

keysona commented 7 years ago

I run a select statement, and result is None. But in database, it exist.

this is my log:

[P898 I 170925 16:55:08 /user-server/torcore/database/table.py:29 execute()] SQL time_cost: 0.008
    sql: SELECT * FROM client_user WHERE removed = %s AND uid = %s ORDER BY created_at DESC, updated_at DESC
    params: [False, '1000057']
[P898 I 170925 16:55:08 /user-server/torcore/database/table.py:29 execute()] SQL time_cost: 0.004
    sql: SELECT * FROM client_user WHERE removed = %s AND uid = %s ORDER BY created_at DESC, updated_at DESC
    params: [False, '1000057']

And first query return a user, second return a None.

I think may be this connection is dead ?

snower commented 7 years ago

If the connection is dead, the execute will raise a exception,instead of returning a None. Can you show detailed code?

snower commented 7 years ago

You output the Exception, then what is the Exception? Through this can know the specific problem.

keysona commented 7 years ago

There is no exception output...

I use execute_transaction to insert/update data, use execute to query.

And I met a incredible scence: query return a last result, but I had change the data...no cache...finally, I restart the program, the query return correct result...

snower commented 7 years ago

PyMysql autocommit acquiescence is Fasle, so query must also commit to query the latest data. helpers do not commit, i will fix this.

snower commented 7 years ago

You can default to autocommit set to True, you can use the normal.

keysona commented 7 years ago

Thx !

I have set autocommit to true .

And I will spend 3 days to test!

    @staticmethod
    def get_database_pool():
        if not TableBase._pool:
            hostname, port, username, password, dbname = options.mysql_string.split(":")
            get_logger().info("connect mysql(%s) by pool", options.mysql_string)
            _pool = ConnectionPool(
                max_connections=60,
                idle_seconds=7200,
                wait_connection_timeout=3,
                host=hostname,
                port=int(port),
                user=username,
                passwd=password,
                db=dbname,
                charset="utf8",
                cursorclass=DictCursor,
                autocommit=True
            )
            TableBase._pool = _pool
        return TableBase._pool
snower commented 7 years ago

Already fixed! You can reinstall lastest version. thanks.