vendor: Mega update all dependencies
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
56
vendor/github.com/cznic/ql/ql.go
generated
vendored
56
vendor/github.com/cznic/ql/ql.go
generated
vendored
@@ -771,16 +771,17 @@ func cols2meta(f []*col) (s string) {
|
||||
// DB represent the database capable of executing QL statements.
|
||||
type DB struct {
|
||||
cc *TCtx // Current transaction context
|
||||
exprCache map[string]expression
|
||||
exprCacheMu sync.Mutex
|
||||
hasIndex2 int // 0: nope, 1: in progress, 2: yes.
|
||||
isMem bool
|
||||
mu sync.Mutex
|
||||
queue []chan struct{}
|
||||
root *root
|
||||
rw bool // DB FSM
|
||||
rwmu sync.RWMutex
|
||||
store storage
|
||||
tnl int // Transaction nesting level
|
||||
exprCache map[string]expression
|
||||
exprCacheMu sync.Mutex
|
||||
hasIndex2 int // 0: nope, 1: in progress, 2: yes.
|
||||
}
|
||||
|
||||
var selIndex2Expr = MustCompile("select Expr from __Index2_Expr where Index2_ID == $1")
|
||||
@@ -1086,7 +1087,7 @@ func mustCompile(src string) List {
|
||||
return list
|
||||
}
|
||||
|
||||
// Execute executes statements in a list while substituting QL paramaters from
|
||||
// Execute executes statements in a list while substituting QL parameters from
|
||||
// arg.
|
||||
//
|
||||
// The resulting []Recordset corresponds to the SELECT FROM statements in the
|
||||
@@ -1214,6 +1215,15 @@ func (db *DB) Execute(ctx *TCtx, l List, arg ...interface{}) (rs []Recordset, in
|
||||
return
|
||||
}
|
||||
|
||||
func (db *DB) muUnlock() {
|
||||
if n := len(db.queue); n != 0 {
|
||||
db.queue[0] <- struct{}{}
|
||||
copy(db.queue, db.queue[1:])
|
||||
db.queue = db.queue[:n-1]
|
||||
}
|
||||
db.mu.Unlock()
|
||||
}
|
||||
|
||||
func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tnlb int, err error) {
|
||||
db.mu.Lock()
|
||||
tnla = db.tnl
|
||||
@@ -1222,7 +1232,7 @@ func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tn
|
||||
case false:
|
||||
switch s.(type) {
|
||||
case beginTransactionStmt:
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
if pc == nil {
|
||||
return nil, tnla, tnlb, errors.New("BEGIN TRANSACTION: cannot start a transaction in nil TransactionCtx")
|
||||
}
|
||||
@@ -1239,19 +1249,19 @@ func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tn
|
||||
db.rw = true
|
||||
return
|
||||
case commitStmt:
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
return nil, tnla, tnlb, errCommitNotInTransaction
|
||||
case rollbackStmt:
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
return nil, tnla, tnlb, errRollbackNotInTransaction
|
||||
default:
|
||||
if s.isUpdating() {
|
||||
db.mu.Unlock()
|
||||
db.muUnlock()
|
||||
return nil, tnla, tnlb, fmt.Errorf("attempt to update the DB outside of a transaction")
|
||||
}
|
||||
|
||||
db.rwmu.RLock() // can safely grab before Unlock
|
||||
db.mu.Unlock()
|
||||
db.muUnlock()
|
||||
defer db.rwmu.RUnlock()
|
||||
rs, err = s.exec(&execCtx{db, arg}) // R/O tctx
|
||||
return rs, tnla, tnlb, err
|
||||
@@ -1259,7 +1269,7 @@ func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tn
|
||||
default: // case true:
|
||||
switch s.(type) {
|
||||
case beginTransactionStmt:
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
|
||||
if pc == nil {
|
||||
return nil, tnla, tnlb, errBeginTransNoCtx
|
||||
@@ -1267,12 +1277,16 @@ func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tn
|
||||
|
||||
if pc != db.cc {
|
||||
for db.rw {
|
||||
db.mu.Unlock() // Transaction isolation
|
||||
ch := make(chan struct{}, 1)
|
||||
db.queue = append(db.queue, ch)
|
||||
db.mu.Unlock()
|
||||
<-ch
|
||||
db.mu.Lock()
|
||||
}
|
||||
|
||||
db.rw = true
|
||||
db.rwmu.Lock()
|
||||
|
||||
}
|
||||
|
||||
if err = db.store.BeginTransaction(); err != nil {
|
||||
@@ -1285,7 +1299,7 @@ func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tn
|
||||
tnlb = db.tnl
|
||||
return
|
||||
case commitStmt:
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
if pc != db.cc {
|
||||
return nil, tnla, tnlb, fmt.Errorf("invalid passed transaction context")
|
||||
}
|
||||
@@ -1303,7 +1317,7 @@ func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tn
|
||||
db.rwmu.Unlock()
|
||||
return
|
||||
case rollbackStmt:
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
defer func() { pc.LastInsertID = db.root.lastInsertID }()
|
||||
if pc != db.cc {
|
||||
return nil, tnla, tnlb, fmt.Errorf("invalid passed transaction context")
|
||||
@@ -1324,18 +1338,18 @@ func (db *DB) run1(pc *TCtx, s stmt, arg ...interface{}) (rs Recordset, tnla, tn
|
||||
default:
|
||||
if pc == nil {
|
||||
if s.isUpdating() {
|
||||
db.mu.Unlock()
|
||||
db.muUnlock()
|
||||
return nil, tnla, tnlb, fmt.Errorf("attempt to update the DB outside of a transaction")
|
||||
}
|
||||
|
||||
db.mu.Unlock() // must Unlock before RLock
|
||||
db.muUnlock() // must Unlock before RLock
|
||||
db.rwmu.RLock()
|
||||
defer db.rwmu.RUnlock()
|
||||
rs, err = s.exec(&execCtx{db, arg})
|
||||
return rs, tnla, tnlb, err
|
||||
}
|
||||
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
defer func() { pc.LastInsertID = db.root.lastInsertID }()
|
||||
if pc != db.cc {
|
||||
return nil, tnla, tnlb, fmt.Errorf("invalid passed transaction context")
|
||||
@@ -1361,7 +1375,7 @@ func (db *DB) Flush() (err error) {
|
||||
// Close will close the DB. Successful Close is idempotent.
|
||||
func (db *DB) Close() error {
|
||||
db.mu.Lock()
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
if db.store == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -1380,17 +1394,17 @@ func (db *DB) do(r recordset, f func(data []interface{}) (bool, error)) (err err
|
||||
switch db.rw {
|
||||
case false:
|
||||
db.rwmu.RLock() // can safely grab before Unlock
|
||||
db.mu.Unlock()
|
||||
db.muUnlock()
|
||||
defer db.rwmu.RUnlock()
|
||||
default: // case true:
|
||||
if r.tx == nil {
|
||||
db.mu.Unlock() // must Unlock before RLock
|
||||
db.muUnlock() // must Unlock before RLock
|
||||
db.rwmu.RLock()
|
||||
defer db.rwmu.RUnlock()
|
||||
break
|
||||
}
|
||||
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
if r.tx != db.cc {
|
||||
return fmt.Errorf("invalid passed transaction context")
|
||||
}
|
||||
@@ -1569,7 +1583,7 @@ func (db *DB) info() (r *DbInfo, err error) {
|
||||
// to obtain the result.
|
||||
func (db *DB) Info() (r *DbInfo, err error) {
|
||||
db.mu.Lock()
|
||||
defer db.mu.Unlock()
|
||||
defer db.muUnlock()
|
||||
return db.info()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user