Fix no open transaction in clone --follow --snapshot #927
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: tests fail for me without #925
Issue
When calling snapshot then using the snapshot id with
clone --follow --snapshotthe code fails withBUG: call to pgsql_commit() without holding an open multi statement connectionThis happens because:
clone_and_followcallscopydb_fetch_schema_and_prepare_specswhich callscopydb_prepare_snapshot, sincespecs->sourceSnapshot.stateis initiallySNAPSHOT_STATE_UNKNOWN.copydb_fetch_schema_and_prepare_specslater callscopydb_close_snapshotwhich commits the transaction and sets the snapshot state toSNAPSHOT_STATE_CLOSEDclone_and_followlater callsstart_clone_processwhich callscloneDBwhich callscopydb_fetch_schema_and_prepare_specsagain. This timespecs->sourceSnapshot.stateisSNAPSHOT_STATE_CLOSEDsocopydb_prepare_snapshotis not called. The code later tries to set the search path, which fails with a warning, then tries to commit the transaction, which fails with this error since no transaction was opened.Fix:
copydb_prepare_snapshotchecks if the source snapshot state isSNAPSHOT_STATE_UNKNOWNorSNAPSHOT_STATE_CLOSEDin order to prepare the snapshshot and open a transaction.copydb_fetch_schema_and_prepare_specson the other hand, only callscopydb_prepare_snapshotif the snapshot state isSNAPSHOT_STATE_UNKNOWN.This code changes
copydb_fetch_schema_and_prepare_specsto matchcopydb_prepare_snapshotand call it in either state.Full code invocation notes:
clone --snapshot --follow:clone --snapshotwithout follow, works without any issues because: