Repository navigation
[#1013] Add finalize workflow to prevent race conditions - #1052
Abdelrhmansersawy wants to merge 1 commit into
Conversation
|
@jesperpedersen |
|
@Abdelrhmansersawy Yes, this is the right direction |
cd349ac to
48c1994
Compare
|
A few updates:
|
|
No, I mean repo lock release don't happen in pgmoneta/src/libpgmoneta/verify.c Lines 541 to 546 in 414e908 For consistent I think I can move this to replace finialize... |
76d013b to
bd8292f
Compare
|
@jesperpedersen PTAL |
|
@Abdelrhmansersawy The comments for backup applies for the others as well |
|
@Abdelrhmansersawy I think this depend on #1038 ... |
|
@jesperpedersen Or skip wal_compression_encryption part for now (as it's not PR focused) and open new PR later. |
|
@Abdelrhmansersawy Just leave it for now - we will circle back soon as #1038 is close |
|
Yes I think we can have this on hold till #1038 is settled |
834f84b to
6fd6da8
Compare
|
@jesperpedersen PTAL |
|
@Abdelrhmansersawy You need to start the backup/restore/verify workflow with the finalizer... Then in each workflow check that you have the lock. And in finalizer's teardown send the recorded result. There are no loops inside a workflow node - that is handled by workflow.c |
|
|
|
@jesperpedersen That means the repository lock could be released too early - before the rest of the steps finish cleaning up. In that case, a new backup might grab the lock while the previous one is still freeing memory or removing files. Do you think it would be better to run teardowns in reverse order (LIFO) inside |
|
@Abdelrhmansersawy Yes, it sounds correct to run setup in order, and teardown in reserve. Of course we have to go through the current teardown implementation will work with that |
6fd6da8 to
7143dd1
Compare
7143dd1 to
df61aa0
Compare
|
@jesperpedersen PTAL A few follow-up:
|
| config->common.servers[server].active_backup = false; | ||
| atomic_store(&config->common.servers[server].repository, false); | ||
|
|
||
| pgmoneta_management_response_error(NULL, client_fd, config->common.servers[server].name, |
There was a problem hiding this comment.
This should be moved, right ?
There was a problem hiding this comment.
@jesperpedersen
The problem that there are two types of errors that exist:
-
Early errors - things like invalid server or WAL streaming not enabled. These happen before
pgmoneta_workflow_executeruns, sofinalize_teardownnever gets called. The error response inbackup.cis needed here. -
Workflow errors - when something fails inside
pgmoneta_workflow_execute, it already callsfinalize_teardown, which sends the error response. Then we fall through to the sameerror:label and send it again. So the client gets the response twice.
How should I handle this? I was thinking of checking if NODE_ERROR_CODE is already set to skip the duplicate, but I'm not sure if there's a better way. This also applies to restore.c and verify.c.
There was a problem hiding this comment.
The things is that we need to move the logic up to workflow.c such that if there is an existing error code, then the execute isn't called. I think it is ok for all setup/teardown to be called.
finalizer should always send the repsonse.
For now, we have backup, restore and verify - but long term all workflows should use finalizer
|
|
||
| workflow = pgmoneta_workflow_create(WORKFLOW_TYPE_POST_ROLLUP, tmp_backup); | ||
| if (carry_out_workflow(workflow, nodes) != RESTORE_OK) | ||
| if (pgmoneta_workflow_execute(workflow, nodes, &en, &ec)) |
|
|
||
| workflow = pgmoneta_workflow_create(WORKFLOW_TYPE_RESTORE, backup); | ||
| if ((ret = carry_out_workflow(workflow, nodes) != RESTORE_OK)) | ||
| if (pgmoneta_workflow_execute(workflow, nodes, &en, &ec)) |
| } | ||
|
|
||
| if ((ret = carry_out_workflow(workflow, nodes) != RESTORE_OK)) | ||
| if (pgmoneta_workflow_execute(workflow, nodes, &en, &ec)) |
There was a problem hiding this comment.
@jesperpedersen
I will revert pgmoneta_rollup_backups back to carry_out_workflow. But should I update carry_out_workflow to run teardowns in reverse order and also run teardowns when an error happens? Right now it skips teardowns on error and runs them forward.
There was a problem hiding this comment.
The main thing is that only workflow.c should call those - there might be pre checks inside the execute's that will fail, but that means there is a bug in the previous workflow nodes...
If we need to split the existing nodes up even more then be it
| } | ||
|
|
||
| if (pgmoneta_management_create_response(payload, server, &response)) | ||
| if (pgmoneta_workflow_execute(workflow, nodes, &en, &ec)) |
There was a problem hiding this comment.
This looks wrong as well...
| error: | ||
|
|
||
| pgmoneta_delete_directory((char*)pgmoneta_art_search(nodes, NODE_TARGET_BASE)); | ||
| pgmoneta_management_response_error(ssl, client_fd, config->common.servers[server].name, |
There was a problem hiding this comment.
This is wrong - its finalizer::teardown
|
@Abdelrhmansersawy Rebase, please |
|
@jesperpedersen
WDYT? |
|
Please, rebase |
2 similar comments
|
Please, rebase |
|
Please, rebase |
|
The race from #1013 is still on main (fbc7e6f), so this is still needed. In
so a script that starts the next backup as soon as the CLI returns can still get "Server primary is active". The branch is 299 commits behind main and conflicts in 10 files (workflow.h, workflow_funcs.h, backup.c, restore.c, se_s3.c, se_ssh.c, verify.c, wf_backup.c, wf_restore.c, workflow.c), so it needs a substantial rebase. If that is a lot of work, one option would be to split it: first a small PR for #1013 that sends the response last, after the WAL compress/encrypt and the lock release, then the finalize/teardown rework on top. (Releasing the lock earlier instead would not be safe: retention skips a server while |
|
Please, rebase |
2 similar comments
|
Please, rebase |
|
Please, rebase |
resolved #1013
Changes
Finalizeworkflow step to guarantee repository locks are released.