Fix issue #167 - Concurrent write/write of in-flight shard map (#168)

This commit is contained in:
Guy A Molinari 2024-12-07 13:54:45 -06:00 committed by GitHub
parent 9b6b643efb
commit baf8258298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -313,32 +313,22 @@ func isShardClosed(nextShardIterator, currentShardIterator *string) bool {
} }
type shards struct { type shards struct {
*sync.RWMutex shardsInProcess sync.Map
shardsInProcess map[string]struct{}
} }
func newShardsInProcess() *shards { func newShardsInProcess() *shards {
return &shards{ return &shards{}
RWMutex: &sync.RWMutex{},
shardsInProcess: make(map[string]struct{}),
}
} }
func (s *shards) addShard(shardId string) { func (s *shards) addShard(shardId string) {
s.Lock() s.shardsInProcess.Store(shardId, struct{}{})
defer s.Unlock()
s.shardsInProcess[shardId] = struct{}{}
} }
func (s *shards) doesShardExist(shardId string) bool { func (s *shards) doesShardExist(shardId string) bool {
s.RLock() _, ok := s.shardsInProcess.Load(shardId)
defer s.RUnlock()
_, ok := s.shardsInProcess[shardId]
return ok return ok
} }
func (s *shards) deleteShard(shardId string) { func (s *shards) deleteShard(shardId string) {
s.Lock() s.shardsInProcess.Delete(shardId)
defer s.Unlock()
delete(s.shardsInProcess, shardId)
} }