本文整理匯總了Golang中github.com/youtube/vitess/go/vt/dbconnpool.PoolConnection.ID方法的典型用法代碼示例。如果您正苦於以下問題:Golang PoolConnection.ID方法的具體用法?Golang PoolConnection.ID怎麽用?Golang PoolConnection.ID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/youtube/vitess/go/vt/dbconnpool.PoolConnection
的用法示例。
在下文中一共展示了PoolConnection.ID方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: executeFetchContext
// executeFetchContext calls ExecuteFetch() on the given connection,
// while respecting Context deadline and cancellation.
func (mysqld *Mysqld) executeFetchContext(ctx context.Context, conn dbconnpool.PoolConnection, query string, maxrows int, wantfields bool) (*sqltypes.Result, error) {
// Fast fail if context is done.
select {
case <-ctx.Done():
return nil, ctx.Err()
default:
}
// Execute asynchronously so we can select on both it and the context.
var qr *sqltypes.Result
var executeErr error
done := make(chan struct{})
go func() {
defer close(done)
qr, executeErr = conn.ExecuteFetch(query, maxrows, wantfields)
}()
// Wait for either the query or the context to be done.
select {
case <-done:
return qr, executeErr
case <-ctx.Done():
// If both are done already, we may end up here anyway because select
// chooses among multiple ready channels pseudorandomly.
// Check the done channel and prefer that one if it's ready.
select {
case <-done:
return qr, executeErr
default:
}
// The context expired or was cancelled.
// Try to kill the connection to effectively cancel the ExecuteFetch().
connID := conn.ID()
log.Infof("Mysqld.executeFetchContext(): killing connID %v due to timeout of query: %v", connID, query)
if killErr := mysqld.killConnection(connID); killErr != nil {
// Log it, but go ahead and wait for the query anyway.
log.Warningf("Mysqld.executeFetchContext(): failed to kill connID %v: %v", connID, killErr)
}
// Wait for the conn.ExecuteFetch() call to return.
<-done
// Close the connection. Upon Recycle() it will be thrown out.
conn.Close()
// ExecuteFetch() may have succeeded before we tried to kill it.
// If ExecuteFetch() had returned because we cancelled it,
// then executeErr would be an error like "MySQL has gone away".
if executeErr == nil {
return qr, executeErr
}
return nil, ctx.Err()
}
}