From b732ffc5f2be30d1550e669eec1c450ef7bd656b Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Mon, 14 Mar 2022 23:24:35 +0800 Subject: [PATCH] fix race condition --- pkg/snapshot/file/publisher.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/snapshot/file/publisher.go b/pkg/snapshot/file/publisher.go index fcb5255..b1e09c0 100644 --- a/pkg/snapshot/file/publisher.go +++ b/pkg/snapshot/file/publisher.go @@ -147,14 +147,13 @@ func (p *publisher) txDir(index uint32) string { } func (p *publisher) BeginTx() (snapt.Tx, error) { - index := atomic.LoadUint32(&p.txCounter) + index := atomic.AddUint32(&p.txCounter, 1) - 1 dir := p.txDir(index) writers, err := makeFileWriters(dir, perNodeTables) if err != nil { return nil, err } - atomic.AddUint32(&p.txCounter, 1) return fileTx{writers}, nil }