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

[3.4] clientv3/mvcc: fixed DATA RACE #14279

Merged
merged 1 commit into from
Jul 26, 2022
Merged

Conversation

SimFG
Copy link
Contributor

@SimFG SimFG commented Jul 26, 2022

clientv3/mvcc: fixed DATA RACE between mvcc.(*store).setupMetricsReporter and mvcc.(*store).restore
issue: #14270

By comparing the code on the main branch, it is found that the main branch does not have this problem. But there is a small problem on the main branch, the code is as follows:

{
s.revMu.Lock()
s.currentRev = <-revc
// keys in the range [compacted revision -N, compaction] might all be deleted due to compaction.
// the correct revision should be set to compaction revision in the case, not the largest revision
// we have seen.
if s.currentRev < s.compactMainRev {
s.currentRev = s.compactMainRev
}
s.revMu.Unlock()
}
if scheduledCompact <= s.compactMainRev {
scheduledCompact = 0
}

L362: s.compactMainRev
I think this needs a read lock. However, I think this simple modification like this pull request is more appropriate.

{
		s.revMu.Lock()
		s.currentRev = <-revc

		// keys in the range [compacted revision -N, compaction] might all be deleted due to compaction.
		// the correct revision should be set to compaction revision in the case, not the largest revision
		// we have seen.
		if s.currentRev < s.compactMainRev {
			s.currentRev = s.compactMainRev
		}

		if scheduledCompact <= s.compactMainRev {
			scheduledCompact = 0
		}
		s.revMu.Unlock()
	}

Signed-off-by: SimFG 1142838399@qq.com

…csReporter and mvcc.(*store).restore

Signed-off-by: SimFG <1142838399@qq.com>
@SimFG
Copy link
Contributor Author

SimFG commented Jul 26, 2022

cc @ahrtr

@@ -35,7 +35,7 @@ require (
github.com/soheilhy/cmux v0.1.4
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.1
github.com/stretchr/testify v1.3.0 // indirect
Copy link
Member

Choose a reason for hiding this comment

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

Did you manually make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's GoLand editor.

@ahrtr ahrtr mentioned this pull request Jul 26, 2022
25 tasks
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thank you @SimFG

@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2022

Codecov Report

❗ No coverage uploaded for pull request base (release-3.4@2c778ee). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head a3b410c differs from pull request most recent head 04e5e55. Consider uploading reports for the commit 04e5e55 to get more accurate results

@@              Coverage Diff               @@
##             release-3.4   #14279   +/-   ##
==============================================
  Coverage               ?   75.50%           
==============================================
  Files                  ?      456           
  Lines                  ?    37037           
  Branches               ?        0           
==============================================
  Hits                   ?    27965           
  Misses                 ?     7331           
  Partials               ?     1741           
Flag Coverage Δ
all 75.50% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants