-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-38632 ALTER EVENT doesn't re-run one-time AT event after first execution #5054
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
base: 10.11
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| SET GLOBAL event_scheduler = ON; | ||
| CREATE TABLE test.event_log (id INT AUTO_INCREMENT PRIMARY KEY, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP); | ||
| # Step 1: Create a one-time AT event with ON COMPLETION PRESERVE | ||
| CREATE EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND | ||
| ON COMPLETION PRESERVE ENABLE | ||
| DO INSERT INTO test.event_log(id) VALUES (NULL); | ||
| # Wait for the event to execute | ||
| # Verify: event executed, status is now DISABLED (preserved but done) | ||
| SELECT status, on_completion, last_executed IS NOT NULL AS has_last_exec | ||
| FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
| status on_completion has_last_exec | ||
| DISABLED PRESERVE 1 | ||
| # Step 2: ALTER EVENT to reschedule with explicit ENABLE | ||
| # This is the customer's scenario from the JIRA report. | ||
| ALTER EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND | ||
| ON COMPLETION PRESERVE ENABLE; | ||
| # After ALTER with ENABLE and a new schedule, last_executed should be cleared. | ||
| SELECT status, last_executed IS NOT NULL AS has_last_exec | ||
| FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
| status has_last_exec | ||
| ENABLED 0 | ||
| # The event should fire again after being rescheduled. | ||
| # Step 3: Verify event fires after server restart (the customer scenario). | ||
| ALTER EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 3 SECOND | ||
| ON COMPLETION PRESERVE ENABLE; | ||
| # last_executed should be cleared when schedule changes. | ||
| SELECT status, last_executed IS NOT NULL AS has_last_exec | ||
| FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
| status has_last_exec | ||
| ENABLED 0 | ||
| # Restart the server to trigger full reload from mysql.event. | ||
| # restart | ||
| SET GLOBAL event_scheduler = ON; | ||
| # The event should fire after server restart. | ||
| # Step 4: User-disabled event stays DISABLED after reschedule without ENABLE | ||
| ALTER EVENT test.mdev38632 DISABLE; | ||
| ALTER EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 2 HOUR; | ||
| # Status remains DISABLED — explicit ENABLE is required to reschedule. | ||
| SELECT status FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
| status | ||
| DISABLED | ||
| # Step 5: ALTER that doesn't change schedule should not clear last_executed | ||
| DROP EVENT test.mdev38632; | ||
| CREATE EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND | ||
| ON COMPLETION PRESERVE ENABLE | ||
| DO INSERT INTO test.event_log(id) VALUES (NULL); | ||
| # Event executed and is DISABLED. ALTER body only (no schedule change). | ||
| ALTER EVENT test.mdev38632 | ||
| DO INSERT INTO test.event_log(id) VALUES (NULL); | ||
| # Status should remain DISABLED (no schedule change) | ||
| SELECT status FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
| status | ||
| DISABLED | ||
| # Cleanup | ||
| DROP EVENT test.mdev38632; | ||
| DROP TABLE test.event_log; | ||
| SET GLOBAL event_scheduler = OFF; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # | ||
| # MDEV-38632: ALTER EVENT doesn't run a one-time (AT) event after its first | ||
| # execution when ON COMPLETION PRESERVE is used. | ||
| # | ||
| # After an AT event with ON COMPLETION PRESERVE executes, the scheduler sets | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not needed in the test file |
||
| # status=DISABLED and last_executed in mysql.event. A subsequent ALTER EVENT | ||
| # with explicit ENABLE and a new schedule should allow the event to fire again. | ||
| # | ||
| # The fix clears last_executed when execute_at changes, and only disables | ||
| # in compute_next_execution_time() if last_executed >= execute_at. | ||
| # | ||
|
|
||
| --source include/not_embedded.inc | ||
|
|
||
| SET GLOBAL event_scheduler = ON; | ||
| --source include/running_event_scheduler.inc | ||
|
|
||
| CREATE TABLE test.event_log (id INT AUTO_INCREMENT PRIMARY KEY, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP); | ||
|
|
||
| --echo # Step 1: Create a one-time AT event with ON COMPLETION PRESERVE | ||
| CREATE EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND | ||
| ON COMPLETION PRESERVE ENABLE | ||
| DO INSERT INTO test.event_log(id) VALUES (NULL); | ||
|
|
||
| --echo # Wait for the event to execute | ||
| let $wait_condition = SELECT COUNT(*) = 1 FROM test.event_log; | ||
| --source include/wait_condition.inc | ||
|
|
||
| --echo # Verify: event executed, status is now DISABLED (preserved but done) | ||
| SELECT status, on_completion, last_executed IS NOT NULL AS has_last_exec | ||
| FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
|
|
||
| --echo # Step 2: ALTER EVENT to reschedule with explicit ENABLE | ||
| --echo # This is the customer's scenario from the JIRA report. | ||
| ALTER EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND | ||
| ON COMPLETION PRESERVE ENABLE; | ||
|
|
||
| --echo # After ALTER with ENABLE and a new schedule, last_executed should be cleared. | ||
| SELECT status, last_executed IS NOT NULL AS has_last_exec | ||
| FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
|
|
||
| --echo # The event should fire again after being rescheduled. | ||
| let $wait_condition = SELECT COUNT(*) = 2 FROM test.event_log; | ||
| --source include/wait_condition.inc | ||
|
|
||
| --echo # Step 3: Verify event fires after server restart (the customer scenario). | ||
| ALTER EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 3 SECOND | ||
| ON COMPLETION PRESERVE ENABLE; | ||
|
|
||
| --echo # last_executed should be cleared when schedule changes. | ||
| SELECT status, last_executed IS NOT NULL AS has_last_exec | ||
| FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
|
|
||
| --echo # Restart the server to trigger full reload from mysql.event. | ||
| --source include/restart_mysqld.inc | ||
| SET GLOBAL event_scheduler = ON; | ||
| --source include/running_event_scheduler.inc | ||
|
|
||
| --echo # The event should fire after server restart. | ||
| --let $wait_timeout = 10 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 10 sec? what is wrong with standard 30 sec? |
||
| let $wait_condition = SELECT COUNT(*) = 3 FROM test.event_log; | ||
| --source include/wait_condition.inc | ||
|
|
||
| --echo # Step 4: User-disabled event stays DISABLED after reschedule without ENABLE | ||
| ALTER EVENT test.mdev38632 DISABLE; | ||
|
|
||
| ALTER EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 2 HOUR; | ||
|
|
||
| --echo # Status remains DISABLED — explicit ENABLE is required to reschedule. | ||
| SELECT status FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
|
|
||
|
gkodinov marked this conversation as resolved.
|
||
| --echo # Step 5: ALTER that doesn't change schedule should not clear last_executed | ||
| DROP EVENT test.mdev38632; | ||
| CREATE EVENT test.mdev38632 | ||
| ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 SECOND | ||
| ON COMPLETION PRESERVE ENABLE | ||
| DO INSERT INTO test.event_log(id) VALUES (NULL); | ||
|
|
||
| let $wait_condition = SELECT COUNT(*) = 4 FROM test.event_log; | ||
| --source include/wait_condition.inc | ||
|
|
||
| --echo # Event executed and is DISABLED. ALTER body only (no schedule change). | ||
| ALTER EVENT test.mdev38632 | ||
| DO INSERT INTO test.event_log(id) VALUES (NULL); | ||
|
|
||
| --echo # Status should remain DISABLED (no schedule change) | ||
| SELECT status FROM mysql.event WHERE db = 'test' AND name = 'mdev38632'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. end version marker is missed --echo # End of 10.11 tests |
||
|
|
||
| --echo # Cleanup | ||
| DROP EVENT test.mdev38632; | ||
| DROP TABLE test.event_log; | ||
| SET GLOBAL event_scheduler = OFF; | ||
| --source include/check_events_off.inc | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--echo missed to be in the output