Bug #6509 statement.cancel() not implemented
Submitted: 8 Nov 2004 20:29 Modified: 11 Nov 2009 2:35
Reporter: Quartz 12h Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / J Severity:S4 (Feature request)
Version:3.1.4b OS:
Assigned to: CPU Architecture:Any

[8 Nov 2004 20:29] Quartz 12h
Description:
In the "Un-implemented Functionality" section of connector/j web page it is not mentionning that statement.cancel() is not implemented, although it really isn't implemented.

According to the source code, cancel() perform nothing at all, claiming that cancel has no meaning on sychronous driver:

 * Cancel can be used by one thread to cancel a statement that is being
 * executed by another thread.  However this driver is synchronous, so
 * this really has no meaning - we define it as a no-op (i.e. you can't
 * cancel, but there is no error if you try.)

Correct us if we are wrong, but that's the whole point: concurrent connections are running on separate sockets and threads. Granted those threads called a synchronous API, the goal is having another being able to kick out the threads blocked and waiting for answers.

Taking the mysqlcc, it is possible to 'kill a process', effectively destroying the connection. I tried to workaround with a thread that closes the connection and, although it kicks out the client-side thread that was waiting, the server continues to process the statement.

How to repeat:
create a slow query, like select count(*) on a large table.
one that takes >5 seconds.

on another thread:

-try to cancel() the running statement after 1 second (no effect)

-try to close connection (thread returns but looks at server process list: still running) (that why the query has to last long enough for you to look at process list)

Suggested fix:
implements cancel.

hint:

-cancel could be implemented by opening an admin connection or whatever it takes to reach the capabilities that mysqlcc used. Granted it whould be hell slow, that is still better than nothing.

-have the server look every few seconds at connections socket to detect orphan processes and cancel/roolback when it happens. (a connection.close() or statement .close() would then suffice for client code to implement cancel)
[16 Nov 2004 4:35] Mark Matthews
Query cancel functionality is in the server roadmap. When that is complete, all clients will support it as well.
[16 Nov 2004 4:37] Mark Matthews
The issue with your proposed implementations is that they leave the connection in an undefined state. That is not part of the 'contract' for Statement.cancel().

Given how the MySQL protocol currently works, there is no way to _correctly_ implement this feature. However, since it is planned that the server will have a 'real' cancel feature, we are going to wait until that is implemented before we expend engineering effort to develop partially-functional features.