Skip to content

store/tikv: Avoid sending to channel everywhere in runGCJob#11032

Merged
MyonKeminta merged 9 commits into
pingcap:masterfrom
MyonKeminta:misono/polish-gc-code
Jul 17, 2019
Merged

store/tikv: Avoid sending to channel everywhere in runGCJob#11032
MyonKeminta merged 9 commits into
pingcap:masterfrom
MyonKeminta:misono/polish-gc-code

Conversation

@MyonKeminta
Copy link
Copy Markdown
Contributor

Signed-off-by: MyonKeminta MyonKeminta@users.noreply.github.com

What problem does this PR solve?

The code in GCWorker doesn't looks good. I'm trying to refine it.

What is changed and how it works?

This refinement includes two points:

  • w.gcIsRunning seems should be set to false when the main loop receives from w.done. So other assignment of w.gcIsRunning is not useful.
  • runGCJob is not in the main loop but a separated goroutine. When it finishes, it should send a signal to w.done. However there are many returns in runGCJob. There's a risk that someone changes the code, added a return but forgot to send the signal. It seems to be ok to put it in a defer clause, however there's another risk that a := is used in a inner scope, causing the error sent to w.done is not the actual error. So I returned the error from the function and send the error outside the function.

Check List

Tests

  • Unit test
  • Integration test

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
@MyonKeminta
Copy link
Copy Markdown
Contributor Author

MyonKeminta commented Jul 2, 2019

@disksing @zhangjinpeng1987 PTAL.

if err != nil {
metrics.GCJobFailureCounter.WithLabelValues("prepare").Inc()
}
w.gcIsRunning = false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think removing it will cause gcIsRunning cannot flip to false any more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If i'm right, here w.gcIsRunning must be false because of the check at L227. The only situation of changing it to false is at L179, and w.done is sent at L262. Please double check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh, you are right. I made a mistake.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does other routine may change the w.gcIsRunning?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No

@MyonKeminta
Copy link
Copy Markdown
Contributor Author

/run-all-tests

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 2, 2019

Codecov Report

Merging #11032 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11032   +/-   ##
===========================================
  Coverage   81.7314%   81.7314%           
===========================================
  Files           423        423           
  Lines         92038      92038           
===========================================
  Hits          75224      75224           
  Misses        11514      11514           
  Partials       5300       5300

@MyonKeminta
Copy link
Copy Markdown
Contributor Author

/run-unit-test

disksing
disksing previously approved these changes Jul 2, 2019
zhangjinpeng87
zhangjinpeng87 previously approved these changes Jul 3, 2019
Copy link
Copy Markdown
Contributor

@zhangjinpeng87 zhangjinpeng87 left a comment

Choose a reason for hiding this comment

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

LGTM

@MyonKeminta
Copy link
Copy Markdown
Contributor Author

@disksing Let's merge this PR later. I found that the existing tests are not sufficient to ensure this PR's correctness and I'll add some more tests in another PR.

MyonKeminta and others added 2 commits July 16, 2019 17:50
@MyonKeminta MyonKeminta dismissed stale reviews from zhangjinpeng87 and disksing via 6842992 July 16, 2019 10:42
@MyonKeminta
Copy link
Copy Markdown
Contributor Author

/run-all-tests

@MyonKeminta
Copy link
Copy Markdown
Contributor Author

/run-all-tests
@disksing @zhangjinpeng1987 PTAL again thanks!

@MyonKeminta
Copy link
Copy Markdown
Contributor Author

/run-all-tests

@MyonKeminta MyonKeminta added component/GC status/LGT1 Indicates that a PR has LGTM 1. type/enhancement The issue or PR belongs to an enhancement. labels Jul 17, 2019
@MyonKeminta
Copy link
Copy Markdown
Contributor Author

/run-unit-test

@MyonKeminta MyonKeminta changed the title store/tikv: Polish GC's code store/tikv: Avoid sending to channel everywhere in runGCJob Jul 17, 2019
Copy link
Copy Markdown
Contributor

@zhangjinpeng87 zhangjinpeng87 left a comment

Choose a reason for hiding this comment

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

LGTM

@MyonKeminta MyonKeminta merged commit db45460 into pingcap:master Jul 17, 2019
@MyonKeminta MyonKeminta deleted the misono/polish-gc-code branch July 17, 2019 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/GC status/LGT1 Indicates that a PR has LGTM 1. type/enhancement The issue or PR belongs to an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants