Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
sql/index/pilosa: correctly guard mapping transactions
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
  • Loading branch information
erizocosmico committed Apr 2, 2019
1 parent 540d256 commit 6f2de86
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions sql/index/pilosa/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import (
type mapping struct {
path string

mut sync.RWMutex
txmut sync.RWMutex
db *bolt.DB
mut sync.RWMutex
db *bolt.DB

// in create mode there's only one transaction closed explicitly by
// commit function
Expand Down Expand Up @@ -129,20 +128,19 @@ func (m *mapping) rollback() error {
}

func (m *mapping) transaction(writable bool, f func(*bolt.Tx) error) error {
m.clientMut.Lock()
defer m.clientMut.Unlock()

var tx *bolt.Tx
var err error
if m.create {
m.clientMut.Lock()
if m.tx == nil {
m.tx, err = m.db.Begin(true)
if err != nil {
m.clientMut.Unlock()
return err
}
}

m.clientMut.Unlock()

tx = m.tx
} else {
tx, err = m.db.Begin(writable)
Expand All @@ -151,15 +149,8 @@ func (m *mapping) transaction(writable bool, f func(*bolt.Tx) error) error {
}
}

m.txmut.Lock()
err = f(tx)
m.txmut.Unlock()

m.clientMut.Lock()
create := m.create
m.clientMut.Unlock()

if create {
if m.create {
return err
}

Expand Down

0 comments on commit 6f2de86

Please sign in to comment.