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

executor: fix the data race on TestDataForTableStatsField and TestPartitionsTable #15260

Merged
merged 14 commits into from
Mar 10, 2020
Merged

Conversation

reafans
Copy link
Contributor

@reafans reafans commented Mar 10, 2020

What problem does this PR solve?

fix #15226 , fix #15222

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test

@reafans reafans requested a review from a team as a code owner March 10, 2020 08:16
@ghost ghost requested review from qw4990 and SunRunAway and removed request for a team March 10, 2020 08:16
@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

Merging #15260 into master will decrease coverage by 0.0705%.
The diff coverage is 75%.

@@               Coverage Diff                @@
##             master     #15260        +/-   ##
================================================
- Coverage   80.4203%   80.3498%   -0.0706%     
================================================
  Files           503        503                
  Lines        133087     132925       -162     
================================================
- Hits         107029     106805       -224     
- Misses        17670      17717        +47     
- Partials       8388       8403        +15

@github-actions github-actions bot added the sig/execution SIG execution label Mar 10, 2020
@reafans reafans added the type/bugfix This PR fixes a bug. label Mar 10, 2020
Copy link
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -201,7 +198,7 @@ func (c *statsCache) setLoading(loading bool) {

func (c *statsCache) get(ctx sessionctx.Context) (map[int64]uint64, map[tableHistID]uint64, error) {
c.mu.Lock()
if time.Since(c.modifyTime) < TableStatsCacheExpiry || c.loading {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we accept this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

@SunRunAway PTAL again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, done.

@reafans
Copy link
Contributor Author

reafans commented Mar 10, 2020

/run-all-tests

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

tableRows, colLength := c.tableRows, c.colLength
c.mu.Unlock()
return tableRows, colLength, nil
}
c.loading = true
c.mu.Unlock()

tableRows, err := getRowCountAllTable(ctx)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

if this err happens, it will deadlock.
Prefer to use defer in this situation.

c.mu.Lock()
defer c.mu.Unlock()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great!

Copy link
Contributor

Choose a reason for hiding this comment

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

For best performance, we can use sync.RWMutex here.

// fast path
c.mu.RLock()
if time.Since(c.modifyTime) < TableStatsCacheExpiry {
    tableRows, colLength := c.tableRows, c.colLength
    c.mu.RUnlock()
    return tableRows, colLength, nil
}
c.mu.RUnlock()


c.mu.Lock()
defer c.mu.Unlock()
if time.Since(c.modifyTime) < TableStatsCacheExpiry {
    return c.tableRows, c.colLength, nil
}
// slow path: fetch from remote

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great!done.

c.tableRows = tableRows
c.colLength = colLength
c.modifyTime = time.Now()
c.loading = true
Copy link
Contributor

Choose a reason for hiding this comment

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

I donot think c.loading is useful anymore. Since the entire get function is locked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

LGTM

@SunRunAway SunRunAway added the status/can-merge Indicates a PR has been approved by a committer. label Mar 10, 2020
@SunRunAway SunRunAway added the status/LGT2 Indicates that a PR has LGTM 2. label Mar 10, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 10, 2020

/run-all-tests

@sre-bot sre-bot merged commit 12fa28f into pingcap:master Mar 10, 2020
@reafans reafans deleted the fix_CI branch March 11, 2020 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

data race detected in TestPartitionsTable unit test TestDataForTableStatsField fails
5 participants