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

Only start SQL thread temporarily to WaitForPosition if needed #10104

Merged
merged 5 commits into from
Apr 18, 2022

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Apr 15, 2022

Description

After #9512 we always attempted to start the replication SQL_Thread(s) when waiting for a given position. The problem with this, however, is that if the SQL_Thread is running but the IO_Thread is not then the tablet repair does not try and start replication on a replica tablet. So in certain states such as when initializing a shard, replication may end up in a non-healthy state and never be repaired.

This changes the behavior so that:

  1. We only attempt to start the SQL_Thread(s) if it's not already running
  2. If we explicitly start the SQL_Thread(s) then we also explicitly reset it to what it was (stopped) as we exit the call

Because the caller should be/have a TabletManager which has a mutex, this should ensure that the replication manager calls are serialized and because we are resetting the replication state after mutating it, everything should work as it did before #9512 with the exception being that when waiting we ensure that the replica at least has the possibility of catching up.

Related Issue(s)

Checklist

  • "Backport me!" label has been added if this change should be backported
  • Tests are not required
  • Documentation is not required

It will then be stopped again after we've reached the desired position.

This was the table repair will function normally and start replication
again if it's a replica table and the IO and SQL threads are stopped.

Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the wait_for_source_fixes branch 4 times, most recently from bf2d61b to d030da5 Compare April 17, 2022 05:29
Signed-off-by: Matt Lord <mattalord@gmail.com>
…on exit

A race between hitting the position and stopping the sql thread(s) again in
MySQL, and the vitess operations going on. We could end up with another case
of only one of the IO or SQL threads being stopped and the tablet repair
never happening because of it.

Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord marked this pull request as ready for review April 17, 2022 18:37
Signed-off-by: Matt Lord <mattalord@gmail.com>
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

This is an amazing catch and fix! I messed up the first time around. Then we had thought that we would only be wanting to wait for position only if there was some way to reach it. But, I see now that we mutated the state of replication, which this PR fixes! Thankyou for this. 💯💕

@mattlord mattlord merged commit 2571b36 into vitessio:main Apr 18, 2022
@mattlord mattlord deleted the wait_for_source_fixes branch April 18, 2022 15:33
mattlord added a commit to planetscale/vitess that referenced this pull request Apr 21, 2022
…sio#10104)

After vitessio#9512 we always attempted to start the replication SQL_Thread(s) when waiting for a given position. The problem with this, however, is that if the SQL_Thread is running but the IO_Thread is not then the tablet repair does not try and start replication on a replica tablet. So in certain states such as when initializing a shard, replication may end up in a non-healthy state and never be repaired.

This changes the behavior so that:
  1. We only attempt to start the SQL_Thread(s) if it's not already running
  2. If we explicitly start the SQL_Thread(s) then we also explicitly reset it to what it was (stopped) as we exit the call

Because the caller should be/have a TabletManager which has a mutex, this should ensure that the replication manager calls are serialized and because we are resetting the replication state after mutating it, everything should work as it did before vitessio#9512 with the exception being that when waiting we ensure that the replica at least has the possibility of catching up.

Signed-off-by: Matt Lord <mattalord@gmail.com>
mattlord added a commit that referenced this pull request Apr 24, 2022
…ded (#10123)

* Only start SQL thread temporarily to WaitForPosition if needed (#10104)

After #9512 we always attempted to start the replication SQL_Thread(s) when waiting for a given position. The problem with this, however, is that if the SQL_Thread is running but the IO_Thread is not then the tablet repair does not try and start replication on a replica tablet. So in certain states such as when initializing a shard, replication may end up in a non-healthy state and never be repaired.

This changes the behavior so that:
  1. We only attempt to start the SQL_Thread(s) if it's not already running
  2. If we explicitly start the SQL_Thread(s) then we also explicitly reset it to what it was (stopped) as we exit the call

Because the caller should be/have a TabletManager which has a mutex, this should ensure that the replication manager calls are serialized and because we are resetting the replication state after mutating it, everything should work as it did before #9512 with the exception being that when waiting we ensure that the replica at least has the possibility of catching up.

Signed-off-by: Matt Lord <mattalord@gmail.com>

* Use older replication status interface

As release-13.0 does not have this:
  #9853

Signed-off-by: Matt Lord <mattalord@gmail.com>
notfelineit pushed a commit to planetscale/vitess that referenced this pull request May 3, 2022
…sio#561)

* Only start SQL thread temporarily to WaitForPosition if needed (vitessio#10104)

After vitessio#9512 we always attempted to start the replication SQL_Thread(s) when waiting for a given position. The problem with this, however, is that if the SQL_Thread is running but the IO_Thread is not then the tablet repair does not try and start replication on a replica tablet. So in certain states such as when initializing a shard, replication may end up in a non-healthy state and never be repaired.

This changes the behavior so that:
  1. We only attempt to start the SQL_Thread(s) if it's not already running
  2. If we explicitly start the SQL_Thread(s) then we also explicitly reset it to what it was (stopped) as we exit the call

Because the caller should be/have a TabletManager which has a mutex, this should ensure that the replication manager calls are serialized and because we are resetting the replication state after mutating it, everything should work as it did before vitessio#9512 with the exception being that when waiting we ensure that the replica at least has the possibility of catching up.

Signed-off-by: Matt Lord <mattalord@gmail.com>

* Use older replication status interface

As vitess-private does not have this:
  vitessio#9853

Signed-off-by: Matt Lord <mattalord@gmail.com>
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.

2 participants