Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 22, 2024
1 parent f983d93 commit e769a72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions go/transactions/transaction_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,9 @@ func (m *txSignatureMap) MarshalJSON() ([]byte, error) {
signatures = append(signatures, bucket...)
}

sort.Slice(signatures, func(i, j int) bool {
return signatures[i].Count > signatures[j].Count
})

return json.Marshal(signatures)
}
24 changes: 15 additions & 9 deletions go/transactions/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ func (s *state) parse(q string) sqlparser.Statement {

func (s *state) startProducing(loader data.IteratorLoader, defaultAutocommit bool, ch chan<- []sqlparser.Statement) {
connections := map[int]*Connection{}

getConn := func(id int) *Connection {
connection, ok := connections[id]
if !ok {
connection = &Connection{Autocommit: defaultAutocommit}
connections[id] = connection
}
return connection
}
_ = data.ForeachSQLQuery(loader, func(query data.Query) error {
stmt := s.parse(query.Query)
if stmt == nil {
Expand All @@ -98,21 +105,20 @@ func (s *state) startProducing(loader data.IteratorLoader, defaultAutocommit boo
case *sqlparser.Begin:
case *sqlparser.Commit:
// Commit seen, so we can yield the queries in the transaction
connection := connections[query.ConnectionID]
connection := getConn(query.ConnectionID)
if connection.Transaction == nil {
return nil
}
ch <- connection.Transaction
connection.Transaction = nil
case *sqlparser.Set:
connection := connections[query.ConnectionID]
connection.Autocommit = getAutocommitStatus(stmt, connection.Autocommit)
conn := getConn(query.ConnectionID)
conn.Autocommit = getAutocommitStatus(stmt, defaultAutocommit)
default:
if !sqlparser.IsDMLStatement(stmt) {
return nil
}
connection, ok := connections[query.ConnectionID]
if !ok {
connection = &Connection{Autocommit: defaultAutocommit}
connections[query.ConnectionID] = connection
}
connection := getConn(query.ConnectionID)
if connection.Autocommit {
ch <- []sqlparser.Statement{stmt}
} else {
Expand Down

0 comments on commit e769a72

Please sign in to comment.