Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qPD8q-00AJq4-DR for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jul 2023 02:23:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qPD8n-00D45a-Vc for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jul 2023 02:23:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qPD8m-00D45R-U1 for pgsql-hackers@lists.postgresql.org; Fri, 28 Jul 2023 02:23:41 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qPD8j-000nVP-RT for pgsql-hackers@lists.postgresql.org; Fri, 28 Jul 2023 02:23:40 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 5F4FE5C016D; Thu, 27 Jul 2023 22:23:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 27 Jul 2023 22:23:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1690511015; x=1690597415; bh=eL c4P6upVqyOvMtroPbpZr23gyzzaeR6HIn/qodACUk=; b=VNQDHEk0+CA+iW51+4 TEDsYleyPOKGSOVgw+JmiK+MwiQAZ0CkJXDagefoQoSEOvo9ktMx0JFQ4ieJLq0o O4bq4RBWXmgrcnkThJtTakiTK3i43Mi/kkiUjDZ0BZ/sBipUt/tYIqIbkhLqRM0a IQkRXanStMn9E5VKK6ExUNSyacZTAHTLhu3yf8RaH/lECpEGh5jz117cxgEQecMG hJrDcKVQm8ZjkIy6bXgyRCAq0uJmBr0ASkGWGnveLgwsfgt9jg0FgaV7lMQSVRez CzZ6fhi32N5nFDZKCWLUMbd1U4JitC+wjnDUXniJCozxdU8X8MvHhfwC3MEGdYX7 R2iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1690511015; x=1690597415; bh=eLc4P6upVqyOv MtroPbpZr23gyzzaeR6HIn/qodACUk=; b=sBHUyz71LV3JkgAh6R1w8I3k5YLpK Y5HzrNdjRBnCqeP3q+aH4Ql+ZPHFklvmX+OtWZ7lJv/PgFrW1kT6h24uNJaV3lV9 AgUNJ8T1tWftTqOksCC+HaxMe2NuQ2vQqIEE1mZ2JfDYaxQLBPpwhXvHvsBRMPFH ywnjtSCeT4u9aH1wqtTAP4WmumZAOX9DaC3CjnAg2737gNr0H86Uf7fw6sihgSUy fpC1Sqt/4/VFfGgcW/1WCnFv3kp8d2k7/xTQOdvat638Et3A7PDFNIBNfSgz3E1B KePJMqyWzNpdGzpArRza0HOoIrn+lN4INfGkwqwu0xKQnyASvpSf/r8vQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrieehgdehiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehmtderredttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpeekieeugeevudeguedtieefffeivdfgueegkefhfedtveefkefflefggeev hfdujeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 27 Jul 2023 22:23:34 -0400 (EDT) Date: Thu, 27 Jul 2023 19:23:32 -0700 From: Andres Freund To: Bharath Rupireddy Cc: Masahiro Ikeda , michael@paquier.xyz, pgsql-hackers@lists.postgresql.org Subject: Re: Support worker_spi to execute the function dynamically. Message-ID: <20230728022332.egqzobhskmlf6ntr@awork3.anarazel.de> References: <46e53055d8d1c92704d3cd2709c722e7@oss.nttdata.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="3ze2tblfw5hlebx5" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --3ze2tblfw5hlebx5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, The new test fails with my AIO branch occasionally. But I'm fairly certain that's just due to timing differences. Excerpt from the log: 2023-07-27 21:43:00.385 UTC [42339] LOG: worker_spi worker 3 initialized with schema3.counted 2023-07-27 21:43:00.399 UTC [42344] 001_worker_spi.pl LOG: statement: SELECT datname, count(datname) FROM pg_stat_activity WHERE backend_type = 'worker_spi' GROUP BY datname; 2023-07-27 21:43:00.403 UTC [42340] LOG: worker_spi worker 2 initialized with schema2.counted 2023-07-27 21:43:00.407 UTC [42341] LOG: worker_spi worker 1 initialized with schema1.counted 2023-07-27 21:43:00.420 UTC [42346] 001_worker_spi.pl LOG: statement: SELECT worker_spi_launch(1); 2023-07-27 21:43:00.423 UTC [42347] LOG: worker_spi dynamic worker 1 initialized with schema1.counted 2023-07-27 21:43:00.432 UTC [42349] 001_worker_spi.pl LOG: statement: SELECT worker_spi_launch(2); 2023-07-27 21:43:00.437 UTC [42350] LOG: worker_spi dynamic worker 2 initialized with schema2.counted 2023-07-27 21:43:00.443 UTC [42347] ERROR: duplicate key value violates unique constraint "pg_namespace_nspname_index" 2023-07-27 21:43:00.443 UTC [42347] DETAIL: Key (nspname)=(schema1) already exists. 2023-07-27 21:43:00.443 UTC [42347] CONTEXT: SQL statement "CREATE SCHEMA "schema1" CREATE TABLE "counted" ( type text CHECK (type IN ('total', 'delta')), value integer)CREATE UNIQUE INDEX "counted_unique_total" ON "counted" (type) WHERE type = 'total'" As written, dynamic and static workers race each other. It doesn't make a lot of sense to me to use the same ids for either? The attached patch reproduces the problem on master. Note that without the sleep(3) in the test the workers don't actually finish starting, the test shuts down the cluster before that happens... Greetings, Andres Freund --3ze2tblfw5hlebx5 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="repro.diff" diff --git i/src/test/modules/worker_spi/t/001_worker_spi.pl w/src/test/modules/worker_spi/t/001_worker_spi.pl index c2938713134..093a038b005 100644 --- i/src/test/modules/worker_spi/t/001_worker_spi.pl +++ w/src/test/modules/worker_spi/t/001_worker_spi.pl @@ -52,6 +52,7 @@ $node->append_conf( shared_preload_libraries = 'worker_spi' worker_spi.database = 'mydb' worker_spi.total_workers = 3 +log_statement=all }); $node->restart; @@ -68,6 +69,9 @@ ok( $node->poll_query_until( # check their existence. my $worker1_pid = $node->safe_psql('mydb', 'SELECT worker_spi_launch(1);'); my $worker2_pid = $node->safe_psql('mydb', 'SELECT worker_spi_launch(2);'); + +sleep(3); + ok( $node->poll_query_until( 'mydb', qq[SELECT datname, count(datname) FROM pg_stat_activity diff --git i/src/test/modules/worker_spi/worker_spi.c w/src/test/modules/worker_spi/worker_spi.c index 903dcddef97..ebd2120ec11 100644 --- i/src/test/modules/worker_spi/worker_spi.c +++ w/src/test/modules/worker_spi/worker_spi.c @@ -120,6 +120,8 @@ initialize_worker_spi(worktable *table) elog(FATAL, "failed to create my schema"); debug_query_string = NULL; /* rest is not statement-specific */ + + pg_usleep(USECS_PER_SEC*1); } SPI_finish(); @@ -127,6 +129,8 @@ initialize_worker_spi(worktable *table) CommitTransactionCommand(); debug_query_string = NULL; pgstat_report_activity(STATE_IDLE, NULL); + + elog(LOG, "done"); } void --3ze2tblfw5hlebx5--