8000 Fix "database is locked" due to concurrent writes between follow and clone. by shubhamdhama · Pull Request #712 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix "database is locked" due to concurrent writes between follow and clone. #712

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
Mar 21, 2024
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
18 changes: 18 additions & 0 deletions src/bin/pgcopydb/cli_clone_follow.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ clone_and_follow(CopyDataSpec *copySpecs)
exit(EXIT_CODE_INTERNAL_ERROR);
}

/*
* We fetch the schema here, rather than later in the clone subprocess,
* which simply reuses this cached data. This is done to avoid lock
* contention between the clone and follow subprocesses, as they both try to
* write concurrently to the source.db SQLite database, leading one to
* failure. This is also necessary for plugins like test_decoding, which
* require information such as primary keys.
*
* In the future, if the follow subprocess doesn't need a catalog (e.g. if
* we remove test_decoding), we should separate out tables for the follow
* subprocess into their own database.
*/
if (!copydb_fetch_schema_and_prepare_specs(copySpecs))
{
/* errors have already been logged */
exit(EXIT_CODE_INTERNAL_ERROR);
}

/*
* Preparation and snapshot are now done, time to fork our two main worker
* processes.
Expand Down
0