Bug #98299 When setting a different master using setPrimaryInstance() Events aren't updated
Submitted: 20 Jan 2020 15:56 Modified: 26 Oct 2021 10:10
Reporter: IGG t Email Updates:
Status: Duplicate Impact on me:
None 
Category:Shell AdminAPI InnoDB Cluster / ReplicaSet Severity:S4 (Feature request)
Version:8.0.19 OS:Any
Assigned to: CPU Architecture:Any
Tags: Event, Replicaset

[20 Jan 2020 15:56] IGG t
Description:
If you make use of MySQL Events to carry out queries at set times, then you generally want those events to run on the master database, and then replicate to the slaves.

If you have setup a replicaset using MySQL 8.0.19 and MySQL Shell you have the option to use setPrimaryInstance() to promote a slave database to be the new master. Doing so however, still leaves all events running on the original database (now a slave) where they will fail to run due to being on a database that is 'super_read_only'=1.

It would be useful to have the option to update all events at the same time as promoting the database, so they now run on the new master.

How to repeat:
Set up a replicatSet with two databases Master (3306) and Slave (3307).

Set up an event on the master (3306). e.g.

DELIMITER $$
CREATE DEFINER=`username`@`%` EVENT `event_test` ON SCHEDULE EVERY 1 MINUTE STARTS NOW() ON COMPLETION PRESERVE ENABLE COMMENT 'test' DO BEGIN
    insert into test.table1 values (1);
END$$
DELIMITER ;

Check the Master (3306) is showing as enabled and the Slave (3307) is showing the event as 'slaveside_disabled'.

MASTER:
+------------+---------+
| EVENT_NAME | STATUS  |
+------------+---------+
| event_test | ENABLED |
+------------+---------+

SLAVE:
+------------+--------------------+
| EVENT_NAME | STATUS             |
+------------+--------------------+
| event_test | SLAVESIDE_DISABLED |
+------------+--------------------+

Change 3307 to become the new master

MySQL  localhost:3306 ssl JS> rs.setPrimaryInstance('DB1:3307')

Now connect to the Master (now 3307) and check the event
+------------+--------------------+
| EVENT_NAME | STATUS             |
+------------+--------------------+
| event_test | SLAVESIDE_DISABLED |
+------------+--------------------+

Connect to the Slave (now 3306) and check the event
+------------+---------+
| EVENT_NAME | STATUS  |
+------------+---------+
| event_test | ENABLED |
+------------+---------+

Suggested fix:
One option could be to have it as an option on setPrimaryInstance. e.g:

rs.setPrimaryInstance('dbname:3306',{moveAllEvents: true})

Alternatively could be the option to run a custom script, that contains the SQL required to move the Events, and anything else that may be required.

rs.setPrimaryInstance('dbname2:3306',{scriptOnNewMaster: /tmp/myscript.sql})

This option could be useful in other circumstances as well if you need to set other flags on the new master.
[25 Oct 2021 11:14] MySQL Verification Team
Hi,

Thanks for the feature request. It makes sense :)

thanks
[26 Oct 2021 9:23] Miguel Araujo
Posted by developer:
 
Duplicate of BUG#31078087. There's already a WL to handle this: WL#14398.

However, considering that the users can manually "move" the events and there are other higher priorities, this WL hasn't been scheduled yet.
[26 Oct 2021 10:10] MySQL Verification Team
Marked as duplicate of Bug#99065