Skip to content

Conversation

Y--
Copy link
Collaborator

@Y-- Y-- commented Jan 16, 2025

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;

@Y-- Y-- requested a review from JelteF January 16, 2025 16:54
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from 56429f3 to 0a0f3c4 Compare January 16, 2025 21:41
@Y-- Y-- force-pushed the yl/md-bgw-per-db branch 2 times, most recently from 2b13b4c to 9afec02 Compare January 17, 2025 09:30
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch 2 times, most recently from 9e1ac92 to f2834ac Compare January 17, 2025 10:12
@JelteF JelteF added this to the 0.4.0 milestone Jan 28, 2025
@JelteF JelteF added the MotherDuck Issues related to MotherDuck label Jan 28, 2025
@Y-- Y-- force-pushed the yl/md-bgw-per-db branch 2 times, most recently from eaf7065 to d41ee16 Compare March 5, 2025 11:12
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from f2834ac to de20e22 Compare March 5, 2025 13:21
@Y-- Y-- force-pushed the yl/md-bgw-per-db branch from d41ee16 to 8338b48 Compare March 5, 2025 14:12
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from de20e22 to 4c38556 Compare March 5, 2025 14:15
@Y-- Y-- force-pushed the yl/md-bgw-per-db branch from d51b095 to 9afb7ec Compare March 10, 2025 13:00
Base automatically changed from yl/md-bgw-per-db to main March 10, 2025 13:08
Y-- added a commit that referenced this pull request Mar 10, 2025
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](#545)
will actually start one BGW per database

---------

Co-authored-by: Jelte Fennema-Nio <github-tech@jeltef.nl>
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from 4c38556 to 00c4103 Compare March 11, 2025 11:51
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch 2 times, most recently from 6b09a92 to a4adf47 Compare March 11, 2025 13:06
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from a4adf47 to f1ea6cc Compare March 21, 2025 15:51
@Y-- Y-- requested a review from JelteF March 25, 2025 10:28
@Y-- Y-- enabled auto-merge (squash) March 25, 2025 10:28
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from c1f9d80 to a0d0a73 Compare March 25, 2025 11:02
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from a0d0a73 to 9e0c5c2 Compare April 16, 2025 06:43
@Y-- Y-- requested a review from JelteF April 16, 2025 07:45
@@ -417,11 +451,9 @@ TriggerActivity(void) {
}

SpinLockAcquire(&BgwShmemStruct->lock);
BgwShmemStruct->activity_count++;
/* Force wake up the background worker */
if (BgwShmemStruct->bgw_latch) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This if meant that somehow we were notifying changes before the bgw was available.
This should not happen anymore.

@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from 31ce8df to f8f2846 Compare April 16, 2025 07:56
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from 7ef8b29 to 637be4e Compare April 16, 2025 10:00
Y-- added a commit that referenced this pull request Apr 17, 2025
In order to correctly test #545
we will need to have multiple test users.

This PR paves the way to generate as many MotherDuck test user as we
want.

I am considering removing the support for `MOTHERDUCK_TEST_TOKEN`, but I
have kept it for now.

The main change is now we can run the test suite with a token that can
generate test users and it will generates one and use it through the
test suite.
@Y-- Y-- force-pushed the yl/md-bgw-per-db-2 branch from 637be4e to 8779f9f Compare April 17, 2025 14:16
@Y-- Y-- merged commit 423a941 into main Apr 22, 2025
6 checks passed
@Y-- Y-- deleted the yl/md-bgw-per-db-2 branch April 22, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MotherDuck Issues related to MotherDuck
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants