-
Notifications
You must be signed in to change notification settings - Fork 129
Start one background worker on first DuckDB query #544
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
Conversation
4c84f96
to
865c10b
Compare
d41ee16
to
8338b48
Compare
src/pgduckdb_background_worker.cpp
Outdated
@@ -252,13 +341,13 @@ InitBackgroundWorker(void) { | |||
#else | |||
ShmemRequest(); | |||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should also be in InitBackgroundWorkersShmem
. And I think that's probably the reason why you now needed the BgwShmemStruct->lock
in TriggerActivity
. So if you move this code I think you can remove the changes to TriggerActivity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually still getting the segfault when moving that around. Though I agree, it makes more sense to put it there.
void | ||
InitBackgroundWorker(void) { | ||
InitBackgroundWorkersShmem(void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InitBackgroundWorkersShmem(void) { | |
InitBackgroundWorkerShmem(void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The s
was intentional - it does initialize memory of all BG workers that may be spawned (when there are one per DB). Technically it's not in this PR, so maybe I can rename later?
Following #544, remove the `duckdb.motherduck_postgres_database` GUC parameter and start a background worker for each PG database (*) For another database to synchronize with the BGW to work: * extension must be created: `CREATE EXTENSION pg_duckdb;` * `duckdb` should be able to write in `public` schema: `GRANT ALL ON SCHEMA public to duckdb;`
Up until now, we were starting the background worker as part of the extension.
The problem with this approach is that it imposes a unique worker, and thus cannot updated multiple database.
In preparation to have one BGW per database, this PR triggers the start of a background worker when
IsExtensionRegistered
is called and the cache is populated.We've prevented potential race conditions that would cause two bgw to start by checking a lock on a temporary file.
Note: a following PR will actually start one BGW per database