Skip to content
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

compare: implement --snapshot option for source database #524

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

acritox
Copy link
Contributor

@acritox acritox commented Oct 31, 2023

to compare a source snapshot to the target

usecase: to check and make sure that data on source and target has not diverged when CDC has been ongoing for a while

  1. pause the ongoing CDC
  2. create new snapshot on source:
$ pgcopydb snapshot --follow --slot pgcopydbcompare --dir /tmp/pgcopydb-cmpsnap &
INFO   Created logical replication slot "pgcopydbcompare" with plugin "test_decoding" at 11/11111110 and exported snapshot 00000000-00000000-0
  1. pgcopydb follow --resume with endpos set to the position the snapshot is at (e.g. 11/11111110)
  2. wait until the target has been caught up to that position
  3. now pgcopydb compare --snapshot 00000000-00000000-0 can be used to compare

to compare a source snapshot to the target
Copy link
Owner

@dimitri dimitri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

Would you consider adding some coverage about your use case or even an example (with an actual snapshot and all) in the documentation too?

Comment on lines +417 to +429
if (!pgsql_set_transaction(&src, ISOLATION_REPEATABLE_READ, false, true))
{
/* errors have already been logged */
(void) pgsql_finish(&src);
return false;
}

if (!pgsql_set_snapshot(&src, copySpecs->sourceSnapshot.snapshot))
{
/* errors have already been logged */
(void) pgsql_finish(&src);
return false;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use copydb_set_snapshot from snapshot.c?

Comment on lines +825 to +828
/* unset sourceSnapshot snapshot for target */
targetSpecs->consistent = false;
(void) memset(&(targetSpecs->sourceSnapshot.snapshot), 0, sizeof(targetSpecs->sourceSnapshot.snapshot));

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to do this? can't we use copydb_close_snapshot ?

@@ -301,11 +312,23 @@ cli_compare_schema(int argc, char **argv)
exit(EXIT_CODE_INTERNAL_ERROR);
}

if (!IS_EMPTY_STRING_BUFFER(compareOptions.snapshot) && !copydb_set_snapshot(&copySpecs))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: please make it fit in two lines, or even with embedded if statements, for ease of maintenance and also to respect line length (does it fit within 80 chars, per project policy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants