Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'only_timeout_work' into new_version
- Loading branch information
Showing
6 changed files
with
111 additions
and
17 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/scala/com/twitter/querulous/ConnectionDestroying.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
package com.twitter.querulous.query | |||
|
|||
import java.sql.Connection | |||
import org.apache.commons.dbcp.{DelegatingConnection => DBCPConnection} | |||
import com.mysql.jdbc.{ConnectionImpl => MySQLConnection} | |||
|
|||
|
|||
// Emergency connection destruction toolkit | |||
|
|||
trait ConnectionDestroying { | |||
def destroyConnection(conn: Connection) { | |||
if ( !conn.isClosed ) | |||
conn match { | |||
case c: DBCPConnection => | |||
destroyDbcpWrappedConnection(c) | |||
case c: MySQLConnection => | |||
destroyMysqlConnection(c) | |||
case _ => error("Unsupported driver type, cannot reliably timeout.") | |||
} | |||
} | |||
|
|||
def destroyDbcpWrappedConnection(conn: DBCPConnection) { | |||
val inner = conn.getInnermostDelegate | |||
|
|||
if ( inner != null ) { | |||
destroyConnection(inner) | |||
} else { | |||
// this should never happen if we use our own ApachePoolingDatabase to get connections. | |||
error("Could not get access to the delegate connection. Make sure the dbcp connection pool allows access to underlying connections.") | |||
} | |||
|
|||
// "close" the wrapper so that it updates its internal bookkeeping, just do it | |||
try { conn.close } catch { case _ => } | |||
} | |||
|
|||
def destroyMysqlConnection(conn: MySQLConnection) { | |||
val abort = Class.forName("com.mysql.jdbc.ConnectionImpl").getDeclaredMethod("abortInternal") | |||
abort.setAccessible(true) | |||
|
|||
abort.invoke(conn) | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters