Coder Social home page Coder Social logo

Comments (2)

trowski avatar trowski commented on July 2, 2024

Hi @LouisTSpi!

Graceful closing of the connection requires sending a command to the server, which as you noticed needs to go into the queue. Cancelling a MySQL query requires issuing another query on a different connection, KILL QUERY process_id. Unfortunately we don't have an API exposed for this, and one would not be trivial to design or implement. I'm considering adding support in v3, but it's certainly not something that will be added to v2.

The other option is to abruptly close the socket connection, but this will leave the table in a metadata lock state again.

I suspect the table is being left in a lock state because the close operation is not being allowed to complete before the script is terminated. Instead of using Amp\Promise\wait(), wrap everything into Amp\Loop::run() to ensure any further tasks are executed before the script ends.

I'd recommend upgrading to v3 if you're able. The API is much cleaner and the use of fibers would have avoided the close issue, as the fiber will suspend until the connection closes.

from mysql.

LouisTSpi avatar LouisTSpi commented on July 2, 2024

Hello @trowski,

Thank you for your reply.

I think I was not clear enough about the metadata lock state, let me rephrase to try and clear things up.
My practical case arises when the table on one server is already in a metadata lock state (due to reasons independent from my app or amphp/mysql) when I issue the queries using amphp/mysql. It is not the queries made with amphp/mysql that render the table in the lock state, so I'm not expecting amphp/mysql to change the lock state of the table.

For example the situation would be:

  • there are 2 db servers (server1 and server2)
  • On server2, the table the query is selecting from is already in a "Waiting for table metadata lock" state
  • while server2 table is in this lock state, the app uses amphp/mysql as in the example above to query both servers in parallel
  • server1 promise resolves with its results
  • server2 does not respond in time due to the lock: its timeout promise fails and execution for this server goes through the catch and finally statements
  • $db->close() is called for connection to server2 but does not actually close the connection
  • php returns the results of server1 and execution stops.
  • the query issued on server2 stays in MySQL's processlist until the table metadata lock is released, even long after php execution stops

The other option is to abruptly close the socket connection, but this will leave the table in a metadata lock state again.
I suspect the table is being left in a lock state because the close operation is not being allowed to complete before the script is terminated.

I'll try force closing the socket. As said above, since the table was already in the lock state before issuing the queries, it does not really matter if the table is left in the lock state afterwards. What matters is that the connection is closed, so that mysql can accept new connections to answer other queries (not all queries use the locked table).

I'd recommend upgrading to v3 if you're able. The API is much cleaner and the use of fibers would have avoided the close issue, as the fiber will suspend until the connection closes.

I've tested an implementation using v3 beta but I get the same result. I'm considering migrating the production app once amphp/sql, amphp/sql-common and amphp/mysql are stable. As far as I can tell they are still in beta.

from mysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.