protect counter race condition

This commit is contained in:
Harlow Ward 2019-04-08 19:34:47 -07:00
parent dbab92f317
commit d176afa7ec

View file

@ -321,8 +321,12 @@ func (fc *fakeCheckpoint) Get(streamName, shardID string) (string, error) {
// implementation of counter // implementation of counter
type fakeCounter struct { type fakeCounter struct {
counter int64 counter int64
mu sync.Mutex
} }
func (fc *fakeCounter) Add(streamName string, count int64) { func (fc *fakeCounter) Add(streamName string, count int64) {
fc.mu.Lock()
defer fc.mu.Unlock()
fc.counter += count fc.counter += count
} }