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

Commit 6f2de86

Browse files
committed
sql/index/pilosa: correctly guard mapping transactions
Signed-off-by: Miguel Molina <[email protected]>
1 parent 540d256 commit 6f2de86

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

sql/index/pilosa/mapping.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import (
2020
type mapping struct {
2121
path string
2222

23-
mut sync.RWMutex
24-
txmut sync.RWMutex
25-
db *bolt.DB
23+
mut sync.RWMutex
24+
db *bolt.DB
2625

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

131130
func (m *mapping) transaction(writable bool, f func(*bolt.Tx) error) error {
131+
m.clientMut.Lock()
132+
defer m.clientMut.Unlock()
133+
132134
var tx *bolt.Tx
133135
var err error
134136
if m.create {
135-
m.clientMut.Lock()
136137
if m.tx == nil {
137138
m.tx, err = m.db.Begin(true)
138139
if err != nil {
139-
m.clientMut.Unlock()
140140
return err
141141
}
142142
}
143143

144-
m.clientMut.Unlock()
145-
146144
tx = m.tx
147145
} else {
148146
tx, err = m.db.Begin(writable)
@@ -151,15 +149,8 @@ func (m *mapping) transaction(writable bool, f func(*bolt.Tx) error) error {
151149
}
152150
}
153151

154-
m.txmut.Lock()
155152
err = f(tx)
156-
m.txmut.Unlock()
157-
158-
m.clientMut.Lock()
159-
create := m.create
160-
m.clientMut.Unlock()
161-
162-
if create {
153+
if m.create {
163154
return err
164155
}
165156

0 commit comments

Comments
 (0)