remove mutex from sql tx

Summary: We were releasing tx lock before consuming rows data which could place the connection in a bad state. Instead of changing lock placement we chose to remove it as mutations were changed to being serial which is expected when working with transactions.

Reviewed By: a8m

Differential Revision: D16449629

fbshipit-source-id: 9f2e7435036f35c407f0640e3dd1071a17b3c368
This commit is contained in:
Alex Snast
2019-07-23 20:12:21 -07:00
committed by Facebook Github Bot
parent 1e47de5300
commit ff6403b4ae
8 changed files with 62 additions and 79 deletions

View File

@@ -4,7 +4,6 @@ package ent
import (
"context"
"sync"
"fbc/ent/dialect"
"fbc/ent/entc/integration/plugin/ent/migrate"
@@ -46,13 +45,10 @@ func (tx *Tx) Client() *Client {
// applies a query, for example: Boring.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that this driver is safe for concurrent usage, however, it executes only one query
// at the time.
// Note that txDriver is not goroutine safe.
type txDriver struct {
// the driver we started the transaction from.
drv dialect.Driver
// protects the tx below from concurrent execution.
mu sync.Mutex
// tx is the underlying transaction.
tx dialect.Tx
}
@@ -86,15 +82,11 @@ func (*txDriver) Rollback() error { return nil }
// Exec calls tx.Exec.
func (tx *txDriver) Exec(ctx context.Context, query string, args interface{}, v interface{}) error {
tx.mu.Lock()
defer tx.mu.Unlock()
return tx.tx.Exec(ctx, query, args, v)
}
// Query calls tx.Query.
func (tx *txDriver) Query(ctx context.Context, query string, args interface{}, v interface{}) error {
tx.mu.Lock()
defer tx.mu.Unlock()
return tx.tx.Query(ctx, query, args, v)
}