Skip to content

MDEV-32947 Async conflicts with semi-sync in multi-source - #5615

Open
ParadoxV5 wants to merge 2 commits into
11.4from
MDEV-32947
Open

ParadoxV5 wants to merge 2 commits into
11.4from
MDEV-32947

Conversation

@ParadoxV5

@ParadoxV5 ParadoxV5 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

@@rpl_semi_sync_slave_enabled can be changed without stopping replication, because it takes effect when a connection is established.
But when it takes effect, it applies to all replication connections.
This means that starting an async connection will switch any ongoing semi-sync connections to async as well, and vice versa, which will cause those connections to fail to replicate in the wrong mode.

This fix resolves this oversight by changing the value application to be specific to only the establishing connection (technically, moving the singleton’s field Repl_semi_sync_slave::m_slave_enabled to the instance variable Master_info::semi_sync_enabled).
This design builds toward MDEV-40941, which proposes migrating @@rpl_semi_sync_slave_enabled to a proper per-connection config.
Note, Master_info::semi_sync_reply_enabled must remain separate, because it only disables ACK replying in async slave fallback (whether that’s the right move is a separate topic), whereas the semi-sync slave setting also controls whether the IO thread should expect additional semi-sync flags in event packets.
(It’s also a possible design to ACK in async replication as slave heartbeating.)

To maintain backward compatibility until MDEV-40941, the status variable Rpl_semi_sync_slave_status is kept showing the applied @@rpl_semi_sync_slave_enabled for the most recent START SLAVE in any connection; that is, not yet made per-connection.

@ParadoxV5
ParadoxV5 requested a review from bnestere August 29, 2026 04:48
@ParadoxV5 ParadoxV5 added MariaDB Corporation Replication Patches involved in replication labels Aug 29, 2026

@ParadoxV5 ParadoxV5 left a comment

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.

Repl_semi_sync_slave is merely a singleton that does not give enough value as a namespace.
Maybe a main-branch refactor is worth to dissolve it into Master_info…
(Relates to MDEV-40941)

Comment thread sql/semisync_slave.cc
@ParadoxV5
ParadoxV5 marked this pull request as draft August 30, 2026 07:37
@ParadoxV5
ParadoxV5 marked this pull request as ready for review August 31, 2026 03:13
Comment thread mysql-test/suite/multi_source/mix_semisync_async.test Outdated

@bnestere bnestere left a comment •

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.

Hi @ParadoxV5 !

I only have one note. The rest looks good. Thanks!

Also note pl.rpl_semi_sync_fail_over fails on debug builds

Comment thread sql/semisync_slave.cc Outdated
var->value= (char*) &local_semi_sync_enabled;
if (Master_info *mi=
get_master_info(&thd->variables.default_master_connection,
Sql_condition::WARN_LEVEL_NOTE))

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 don't think we should do this in GA. I imagine it may break existing user scripts. Maybe we can re-visit it with MDEV-40941. For GA, I think Monty's original suggestion makes the most sense:

Repl_semi_sync_slave.m_slave_enabled should also be changed to a counter to know how many slaves are actually enabled.

Alternatively, we don't need a counter. As far as I see, the only time this is used is for showing status variables. We can probably just iterate through the mi cache and check if any are enabled. It'll need a lock, but so does SHOW SLAVE STATUS.

Maybe @knielsen has a preference. I don't.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Brandon, yes it sounds reasonable.
Seems best to add per-channel configuration of semisync_slave only in main, not older GA releases.
And yes, seems a counter would not be needed as you explained.

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.

I don't think we should do this in GA.

Do we leave GA unfixed, then?

I imagine it may break existing user scripts. Maybe we can re-visit it with MDEV-40941.

Reminds me of those malformed Replication packets. We need clear lines: What’s intended, what’s unïntended, and what’s merely undefined behaviour that MDEV-40941 is now defining?

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 we should fix the error and replication break in GA. I mean this particular code change will change the result of rpl_semi_sync_slave_status depending on which connection is configured. My understanding of the pre-patch behavior is if any connections have semi_sync working, the status var will output ON. The behavior proposed here may be ON or OFF depending on default_master_connection. We should maintain the behavior of ON if any channel is actively using semi_sync.

I agree we should define behaviors to enforce (for everything, always), but that should be done in new versions (not GA). I.e., if we've already released a version with some behavior, we shouldn't switch it on a whim in a minor release (unless it is a bug, of course).

So then whenever we'd decide to do MDEV-40941, that would be in a new release, where we could change things if it is well justified.

Does this answer your question?

@ParadoxV5 ParadoxV5 Oct 9, 2026 •

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.

I mean this particular code change will change the result of rpl_semi_sync_slave_status depending on which connection is configured. My understanding of the pre-patch behavior is if any connections have semi_sync working, the status var will output ON. The behavior proposed here may be ON or OFF depending on default_master_connection. We should maintain the behavior of ON if any channel is actively using semi_sync.

We can test this, but I’m pretty sure the old behaviour is equivalent to showing what @@rpl_semi_sync_slave_enabled (which my patch does not change, so scripts (that aren’t relying on broken behaviour) shouldn’t break) was last applied for any connection.
I should be able to maintain this, for whatever it’s worth.

We should maintain the behavior of ON if any channel is actively using semi_sync.

This would make it reminiscent of #5753 (review).

Does this answer your question?

Yes, I suppose.

@ParadoxV5 ParadoxV5 Oct 11, 2026 •

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.

@bnestere change applied (current 2nd commit).
I’ve also squashed the original commits into one and rebased onto 11.4.

@ParadoxV5
ParadoxV5 changed the base branch from 10.11 to 11.4 October 11, 2026 19:43
`@@rpl_semi_sync_slave_enabled` can be changed without stopping
replication, because it takes effect when a connection is established.
But when it takes effect, it applies to *all* replication connections.
This means that starting an async connection will switch any ongoing
semi-sync connections to async as well, and vice versa, which will
cause those connections to fail to replicate in the wrong mode.

This fix resolves this oversight by changing the value application
to specific to only the establishing connection (technically,
moving the singleton’s field `Repl_semi_sync_slave::m_slave_enabled`
to the instance variable `Master_info::semi_sync_enabled`).
This designs build toward MDEV-40941, which proposes migrating
`@@rpl_semi_sync_slave_enabled` to a proper per-connection config.
Note, `Master_info::semi_sync_reply_enabled` must remain separate,
because it only disables ACK replying in async slave fallback,
whereas the semi-sync slave setting also controls whether the IO
thread should expect additional semi-sync flags in event packets.

The status variable `Rpl_semi_sync_slave_status` is left referencing ???
???

Reviewed-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
the status variable `Rpl_semi_sync_slave_status` is kept showing
the applied `@@rpl_semi_sync_slave_enabled` for the most recent
START SLAVE in any connection; that is, not yet made per-connection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Corporation Replication Patches involved in replication

Development

Successfully merging this pull request may close these issues.

3 participants