-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#22260] YSQL: pg_cron: Set one node as cron leader and add test
Summary: Use shared memory `is_cron_leader` field to indicate which node will be the cron leader. Only the leader will schedule and run cron jobs. This ensures that cron jobs are run at most once. Distributed job scheduling and execution will happen as part of #22336. If we had two or more leaders in the same minute we would not run the task multiple times since cron does not run tasks for the first minute of leadership. Interval jobs do not have this guarantee since their timer starts when we become the leader. Non Yugabyte pg_cron has the same behavior when pg restarts. Check comments in `YbCheckLeadership` and `StartAllPendingRuns` for more details. For testing purposes we set `is_cron_leader` via `FLAG_TEST_is_ysql_cron_leader`. `TabletServer` uses a flag callback to set the shared memory to the value of the flag. #22360 will add a StatefulService that will ensure one and only one tserver is always picked as the pg_cron leader. - Moved `YBCPgResetCatalogReadTime` inside `RefreshTaskHash` as we do not need to do this every time - Added `YbUpdateCatalogCacheVersion` since without it we hit `The catalog snapshot used for this transaction has been invalidated`. - Replaced `YBCDeleteSysCatalogTuple` with `CatalogTupleDelete` so that indexes entries are also deleted. Fixes #22260 Jira: DB-11179 Test Plan: PgCronTest.AtMostOnceTest PgCronTest.PerMinuteTask yb_pg_cron-test Reviewers: tnayak, fizaa Reviewed By: tnayak Subscribers: yql, ybase Differential Revision: https://phorge.dev.yugabyte.com/D34926
- Loading branch information
Showing
20 changed files
with
368 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/postgres/third-party-extensions/pg_cron/expected/yb_pg_cron-test.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
CREATE EXTENSION pg_cron; | ||
-- Recreate job with same name | ||
SELECT cron.schedule('myjob', '0 11 * * *', 'SELECT 1'); | ||
schedule | ||
---------- | ||
1 | ||
(1 row) | ||
|
||
SELECT cron.unschedule('myjob'); | ||
unschedule | ||
------------ | ||
t | ||
(1 row) | ||
|
||
SELECT cron.schedule('myjob', '0 11 * * *', 'SELECT 1'); | ||
schedule | ||
---------- | ||
2 | ||
(1 row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/postgres/third-party-extensions/pg_cron/sql/yb_pg_cron-test.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE EXTENSION pg_cron; | ||
|
||
-- Recreate job with same name | ||
SELECT cron.schedule('myjob', '0 11 * * *', 'SELECT 1'); | ||
SELECT cron.unschedule('myjob'); | ||
SELECT cron.schedule('myjob', '0 11 * * *', 'SELECT 1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# third-party-extensions/pg_cron/yb_schedule | ||
|
||
test: pg_cron-test | ||
test: yb_pg_cron-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.