Record queries executed during transaction for better diagnostics

This commit is contained in:
Sugu Sougoumarane 2013-02-21 10:04:44 -08:00
Родитель 36ebb8a889
Коммит 806e757605
2 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -5,13 +5,14 @@
package tabletserver
import (
"fmt"
"sync/atomic"
"time"
"code.google.com/p/vitess/go/pools"
"code.google.com/p/vitess/go/relog"
"code.google.com/p/vitess/go/stats"
"code.google.com/p/vitess/go/timer"
"fmt"
"sync/atomic"
"time"
)
/* Function naming convention:
@ -65,7 +66,7 @@ func (self *ActiveTxPool) WaitForEmpty() {
func (self *ActiveTxPool) TransactionKiller() {
for _, v := range self.pool.GetTimedout(time.Duration(self.Timeout())) {
conn := v.(*TxConnection)
relog.Info("killing transaction %d", conn.transactionId)
relog.Info("killing transaction %d: %#v", conn.transactionId, conn.queries)
killStats.Add("Transactions", 1)
conn.Close()
conn.discard()
@ -137,6 +138,7 @@ type TxConnection struct {
inUse bool
startTime time.Time
dirtyTables map[string]DirtyKeys
queries []string
}
func newTxConnection(conn PoolConnection, transactionId int64, pool *ActiveTxPool) *TxConnection {
@ -146,6 +148,7 @@ func newTxConnection(conn PoolConnection, transactionId int64, pool *ActiveTxPoo
pool: pool,
startTime: time.Now(),
dirtyTables: make(map[string]DirtyKeys),
queries: make([]string, 0, 8),
}
}
@ -166,6 +169,10 @@ func (self *TxConnection) Recycle() {
}
}
func (self *TxConnection) RecordQuery(query string) {
self.queries = append(self.queries, query)
}
func (self *TxConnection) discard() {
self.pool.pool.Unregister(self.transactionId)
self.PoolConnection.Recycle()

Просмотреть файл

@ -223,6 +223,7 @@ func (qe *QueryEngine) Execute(logStats *sqlQueryStats, query *proto.Query) (rep
// Need upfront connection for DMLs and transactions
conn := qe.activeTxPool.Get(query.TransactionId)
defer conn.Recycle()
conn.RecordQuery(plan.FullQuery.Query)
var invalidator CacheInvalidator
if plan.TableInfo != nil && plan.TableInfo.CacheType != 0 {
invalidator = conn.DirtyKeys(plan.TableName)