8000 Fix pgcopydb stream cleanup. by dimitri · Pull Request #351 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix pgcopydb stream cleanup. #351

8000
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

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/bin/pgcopydb/cli_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,23 @@ cli_stream_cleanup(int argc, char **argv)
exit(EXIT_CODE_INTERNAL_ERROR);
}

copySpecs.resume = true; /* pretend --resume has been used */
copySpecs.restart = false; /* pretend --restart has NOT been used */
bool resume = true; /* pretend --resume has been used */
bool restart = false; /* pretend --restart has NOT been used */

bool createWorkDir = false;
bool service = false;

if (!copydb_init_workdir(&copySpecs,
NULL,
service,
NULL,
restart,
resume,
createWorkDir))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
}

if (!stream_cleanup_databases(&copySpecs,
streamDBoptions.slot.slotName,
Expand Down
24 changes: 24 additions & 0 deletions src/bin/pgcopydb/ld_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,8 @@ stream_cleanup_databases(CopyDataSpec *copySpecs, char *slotName, char *origin)
return false;
}

log_info("Removing schema pgcopydb and its objects");

if (!pgsql_execute(&src, "drop schema if exists pgcopydb cascade"))
{
/* errors have already been logged */
Expand All @@ -2234,6 +2236,28 @@ stream_cleanup_databases(CopyDataSpec *copySpecs, char *slotName, char *origin)
return false;
}

/*
* When we have dropped the replication slot, we can remove the slot file
* on-disk and also the snapshot file.
*/
log_notice("Removing slot file \"%s\"", copySpecs->cfPaths.cdc.slotfile);

if (!unlink_file(copySpecs->cfPaths.cdc.slotfile))
{
log_error("Failed to unlink the slot file \"%s\"",
copySpecs->cfPaths.cdc.slotfile);
return false;
}

log_notice("Removing snapshot file \"%s\"", copySpecs->cfPaths.snfile);

if (!unlink_file(copySpecs->cfPaths.snfile))
{
log_error("Failed to unlink the snapshot file \"%s\"",
copySpecs->cfPaths.snfile);
return false;
}

/*
* Now cleanup the target database (replication origin).
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/cdc-low-level/copydb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ done
pgcopydb stream replay --resume --endpos "${lsn}"

# cleanup
pgcopydb stream cleanup
pgcopydb stream cleanup --verbose
0