fix race condition

This commit is contained in:
Roy Crihfield 2022-03-14 23:24:35 +08:00
parent 2481d0a28d
commit b732ffc5f2

View File

@ -147,14 +147,13 @@ func (p *publisher) txDir(index uint32) string {
} }
func (p *publisher) BeginTx() (snapt.Tx, error) { func (p *publisher) BeginTx() (snapt.Tx, error) {
index := atomic.LoadUint32(&p.txCounter) index := atomic.AddUint32(&p.txCounter, 1) - 1
dir := p.txDir(index) dir := p.txDir(index)
writers, err := makeFileWriters(dir, perNodeTables) writers, err := makeFileWriters(dir, perNodeTables)
if err != nil { if err != nil {
return nil, err return nil, err
} }
atomic.AddUint32(&p.txCounter, 1)
return fileTx{writers}, nil return fileTx{writers}, nil
} }