8000 Fix Postgres connection handling in Large Object related code. by dimitri · Pull Request #579 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Postgres connection handling in Large Object related code. #579

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
Dec 15, 2023
Merged
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
31 changes: 25 additions & 6 deletions src/bin/pgcopydb/blobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ copydb_blob_worker(CopyDataSpec *specs)

log_notice("Started Large Objects worker %d [%d]", pid, getppid());

/* make sure that we have our own process local connection */
TransactionSnapshot snapshot = { 0 };

if (!copydb_copy_snapshot(specs, &snapshot))
{
/* errors have already been logged */
return false;
}

/* swap the new instance in place of the previous one */
specs->sourceSnapshot = snapshot;

/* connect once to the source database for the whole process */
if (!copydb_set_snapshot(specs))
{
Expand Down Expand Up @@ -403,7 +415,7 @@ copydb_send_lo_stop(CopyDataSpec *specs)
if (!queue_send(&(specs->loQueue), &stop))
{
/* errors have already been logged */
continue;
return false;
}
}

Expand All @@ -417,21 +429,27 @@ copydb_send_lo_stop(CopyDataSpec *specs)
bool
copydb_queue_largeobject_metadata(CopyDataSpec *specs, uint64_t *count)
{
/* connect to the source database and set snapshot */
if (!copydb_set_snapshot(specs))
/* make sure that we have our own process local connection */
TransactionSnapshot snapshot = { 0 };

if (!copydb_copy_snapshot(specs, &snapshot))
{
/* errors have already been logged */
return false;
}

PGSQL *src = &(specs->sourceSnapshot.pgsql);
/* swap the new instance in place of the previous one */
specs->sourceSnapshot = snapshot;

if (!pgsql_begin(src))
/* connect to the source database and set snapshot */
if (!copydb_set_snapshot(specs))
{
/* errors have already been logged */
return false;
}

PGSQL *src = &(specs->sourceSnapshot.pgsql);

BlobMetadataArrayContext context = { 0 };
char *sql =
"DECLARE bloboid CURSOR FOR "
Expand Down Expand Up @@ -459,6 +477,7 @@ copydb_queue_largeobject_metadata(CopyDataSpec *specs, uint64_t *count)
&context, &parseBlobMetadataArray))
{
/* errors have already been logged */
(void) pgsql_finish(src);
return false;
}

Expand Down Expand Up @@ -486,7 +505,7 @@ copydb_queue_largeobject_metadata(CopyDataSpec *specs, uint64_t *count)
}
}

if (!pgsql_commit(src))
if (!copydb_close_snapshot(specs))
{
/* errors have already been logged */
return false;
Expand Down
0