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

use sync.Once to avoid to send drop cutover sentry table to mysql twice #755

Closed
wants to merge 8 commits into from

Conversation

MOON-CLJ
Copy link
Contributor

ref: #745 (comment)

this pr is another way to deal with issue: #737

use mutex to skip the second drop table。

@shlomi-noach pls review, thx in advance。

Copy link
Contributor

@shlomi-noach shlomi-noach left a comment

Choose a reason for hiding this comment

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

What we actually want to do is to protect two different pieces of code; one within the applier transaction, the other in this DropAtomicCutOverSentryTableIfExists() function. And we don't want to serialize them, but instead only run them once. I suggest using a Once.

@MOON-CLJ
Copy link
Contributor Author

MOON-CLJ commented Jun 11, 2019

@shlomi-noach

i am not sure how to use https://golang.org/pkg/sync/#Once to ensure the following three places which cause drop table?

1, CreateAtomicCutOverSentryTable

if err := this.CreateAtomicCutOverSentryTable(); err != nil {

2, drop cut over table

if _, err := tx.Exec(query); err != nil {

3, defer clean sentry table

this.applier.DropAtomicCutOverSentryTableIfExists()

even more, atomicCutOver will retry some times。although will sleep 1s between retry,two call to goroutine AtomicCutOverMagicLock is not serialize,because atomicCutOver don't wait AtomicCutOverMagicLock to be finished。

@shlomi-noach
Copy link
Contributor

@MOON-CLJ the way I see it, there's these two places:

gh-ost/go/logic/applier.go

Lines 862 to 865 in b38814f

if _, err := tx.Exec(query); err != nil {
log.Errore(err)
// We DO NOT return here because we must `UNLOCK TABLES`!
}

this.applier.DropAtomicCutOverSentryTableIfExists()

which are racing.
These do not retry per cut-over.

You are absolutely right that the entire cut-over operation can retry. We can create a Once variable per cut-over.

@MOON-CLJ
Copy link
Contributor Author

@shlomi-noach

"These do not retry per cut-over." yeah, you're right。

sorry, my mistake。i am confused, because in pr #745 i mv defer clean sentry table

this.applier.DropAtomicCutOverSentryTableIfExists()
from atomicCutOver to goroutine AtomicCutOverMagicLock。 so there is a race condition between

the last one cut-over

defer this.DropAtomicCutOverSentryTableIfExists()

and the next one cut-over

if err := this.CreateAtomicCutOverSentryTable(); err != nil {

We can create a Once variable per cut-over.

yes, let me try。

@MOON-CLJ
Copy link
Contributor Author

@shlomi-noach updated

go/logic/applier.go Outdated Show resolved Hide resolved
@MOON-CLJ MOON-CLJ changed the title use mutex to avoid to send drop cutover sentry table to mysql twice use sync.Once to avoid to send drop cutover sentry table to mysql twice Jul 1, 2019
@MOON-CLJ
Copy link
Contributor Author

@shlomi-noach we have test this pr in hundreds of clusters in our production env for more than 3 months。consider go forward to merge?

@MOON-CLJ
Copy link
Contributor Author

@shlomi-noach ping

@shlomi-noach
Copy link
Contributor

Sorry for the delay. It takes a context switch to dive into this PR again; I'd need to clear my desk for this. I assume this will be delayed for a bit longer.

Copy link
Contributor

@shlomi-noach shlomi-noach left a comment

Choose a reason for hiding this comment

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

This look good to me.

@timvaillancourt
Copy link
Collaborator

This was merged in #888. Thanks @MOON-CLJ!

@shlomi-noach
Copy link
Contributor

Thank you @timvaillancourt 👑

@MOON-CLJ
Copy link
Contributor Author

Thank you @timvaillancourt

RainbowDashy added a commit to RainbowDashy/gh-ost that referenced this pull request Jul 27, 2022
This reverts commit 0e2d33a.
d-bytebase pushed a commit to bytebase/gh-ost that referenced this pull request Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants