-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
Codecov Report
@@ 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 |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SunRunAway PTAL again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done.
/run-all-tests |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!done.
executor/infoschema_reader.go
Outdated
c.tableRows = tableRows | ||
c.colLength = colLength | ||
c.modifyTime = time.Now() | ||
c.loading = true |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
What problem does this PR solve?
fix #15226 , fix #15222
What is changed and how it works?
Check List
Tests