Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add locking around partitionIDToState map accesses #1239

Merged
merged 4 commits into from
Dec 6, 2018

Conversation

vprithvi
Copy link
Contributor

@vprithvi vprithvi commented Dec 5, 2018

Signed-off-by: Prithvi Raj [email protected]

Which problem is this PR solving?

  • Prevents concurrent access of partitionIDToState map

Short description of the changes

  • Add locks around partitionIDToState to prevent concurrent access

c.partitionMapLock.Lock()
wg := &c.partitionIDToState[pc.Partition()].wg
c.partitionMapLock.Unlock()
wg.Add(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a great pattern - the Add() should be happening before this goroutine is started, otherwise the caller (or Close()) might have already called Wait() and exited. You can do Add(2) after creating the state

c.partitionIDToState[pc.Partition()] = &consumerState{partitionConsumer: pc}
c.partitionIDToState[pc.Partition()].Add(2)

@codecov
Copy link

codecov bot commented Dec 6, 2018

Codecov Report

Merging #1239 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1239   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         159     159           
  Lines        7136    7145    +9     
======================================
+ Hits         7136    7145    +9
Impacted Files Coverage Δ
cmd/ingester/app/consumer/consumer.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6237e2f...812b46c. Read the comment docs.

@yurishkuro yurishkuro merged commit 7b18bd9 into master Dec 6, 2018
@ghost ghost removed the review label Dec 6, 2018
@vprithvi vprithvi deleted the fix-concurrent-rw branch December 6, 2018 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants