Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pD8FY-0001lv-KP for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jan 2023 18:12:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pD8FX-00072T-5L for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jan 2023 18:12:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pD8FW-00072K-Q7 for pgsql-hackers@lists.postgresql.org; Wed, 04 Jan 2023 18:12:26 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pD8FU-0005AM-7R for pgsql-hackers@postgresql.org; Wed, 04 Jan 2023 18:12:26 +0000 Received: by mail-pl1-x633.google.com with SMTP id n4so36681841plp.1 for ; Wed, 04 Jan 2023 10:12:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=uGfRve3fNoVGopnbydXXztHSNauust5ejMjk0lZvI2c=; b=M3s7xTzcfM2JvNw3uGwnaN7kn85+TaQobUT8HZBX6HKeZRxqpYsw6fOvK0v7VikgiM 17eVV6t8A4Y5uGNUw4RKeXlXWz3m/llUWtoaCdtn9HUCAzWs6HnL7Avp3UxF82k4qLCD 6xcE+k9zSumDxrm6F2QxjK+f3EapjEX3paLFmJ5sLvbkwhaTpywSyWJ7qhKgPLgvOJ9k TVUql2tS0LV6aGSUF51nR56t95MGYSVIBklyB+df36c6e5qSSuN3q42mcOrHC9b0J8yh 3Jo+X+poLnL91WwHmL6OT1tstpzJKJdXGe6yY5GbR1aM40UfSCwFSQixe6LtSfnuR2Qv M0+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uGfRve3fNoVGopnbydXXztHSNauust5ejMjk0lZvI2c=; b=ZPpealIPm81jAU1PIp6J9n04FSA2bFZ1708Sf2Zbg6XlYb8vLYgLzroocXKlNFS39f 4SN4Z20b9DsdNynTChMSmZIO/Xpzqv6gQE+sdsVyZntn1ixHi8/7jtY2A4YNcL2ghMRo 5pk7MVrbIw2G4tWZm1owSUEQCUPBRXFJrdXkEgsxa9s/qB8wvNmY4gSYlfhFEKxW/Oob hthFZUwqMf8uwNp4OGkrxNe7GA1jL7PwUWyAIJEbHsPYvaJFyICUB8Y6+b/fMYevI/5u 7Nh6t9gzN8WQVbGeJKHE8jTpX/uriAPY2eqOOljUYWktOD+W2koCM4vuIQ3jhrMnrUNJ qt+A== X-Gm-Message-State: AFqh2kpPTTkGU/V/DIWC/CmQBeUZDSKfobT9PgtF+7+/UdqhF6AdDxjK 3Z0rC/izBwx+KcOFhBYVS/0= X-Google-Smtp-Source: AMrXdXuwSVoqD/CIyskgSIvdFzwd58TtvjY2J1RukM+4SUWCbRpBQCyOVjFhQN1lXh+oYQSa8X3ZjA== X-Received: by 2002:a17:903:40cb:b0:192:8502:77f9 with SMTP id t11-20020a17090340cb00b00192850277f9mr34681833pld.27.1672855942096; Wed, 04 Jan 2023 10:12:22 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id x4-20020a1709029a4400b00189af02aba4sm24586293plv.3.2023.01.04.10.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 10:12:21 -0800 (PST) Date: Wed, 4 Jan 2023 10:12:19 -0800 From: Nathan Bossart To: Amit Kapila Cc: Tom Lane , Melih Mutlu , Thomas Munro , "Hayato Kuroda (Fujitsu)" , "pgsql-hackers@postgresql.org" Subject: Re: wake up logical workers after ALTER SUBSCRIPTION Message-ID: <20230104181219.GB296349@nathanxps13> References: <20221214171023.GA689106@nathanxps13> <2707695.1671039752@sss.pgh.pa.us> <20221214174535.GA773264@nathanxps13> <2783450.1671042198@sss.pgh.pa.us> <20221214183759.GC773264@nathanxps13> <2787771.1671044578@sss.pgh.pa.us> <20221214231727.GA828014@nathanxps13> <20230103181031.GB204418@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jan 04, 2023 at 10:57:43AM +0530, Amit Kapila wrote: > On Tue, Jan 3, 2023 at 11:40 PM Nathan Bossart wrote: >> My approach was to add a variable to LogicalRepWorker that indicated >> whether a worker needed to be restarted immediately. While this is a >> little weird because the workers array is treated as slots, it worked >> nicely for ALTER SUBSCRIPTION. > > So, are you planning to keep its in_use and subid flag as it is in > logicalrep_worker_cleanup()? Otherwise, without that it could be > reused for some other subscription. I believe I did something like this in my proof-of-concept. I might have used the new flag as another indicator that the slot was still "in use". In any case, you are right that we need to prevent the slot from being reused. > What if we maintain a hash table similar to 'last_start_times' > maintained in tablesync.c? It won't have entries for new > subscriptions, so for those we may not need to wait till > wal_retrieve_retry_interval. I proposed this upthread [0]. I still think it is a worthwhile change. Right now, if a worker needs to be restarted but another unrelated worker was restarted less than wal_retrieve_retry_interval milliseconds ago, the launcher waits to restart it. I think it makes more sense for each worker to have its own restart interval tracked. >> IIUC you are suggesting just one variable that would bypass >> wal_retrieve_retry_interval for all subscriptions, not just those newly >> altered or created. This definitely seems like it would prevent delays, >> but it would also cause wal_retrieve_retry_interval to be incorrectly >> bypassed for the other workers in some cases. > > Right, but I guess it would be rare in practical cases that someone > Altered/Created a subscription, and also some workers are restarted > due to errors/crashes as only in those cases launcher can restart the > worker when it shouldn't. However, in that case, also, it won't > restart the apply worker again and again unless there are concurrent > Create/Alter Subscription operations going on. IIUC, currently also it > can always first time restart the worker immediately after ERROR/CRASH > because we don't maintain last_start_time for each worker. I think > this is probably okay as we want to avoid repeated restarts after the > ERROR. This line of thinking is why I felt that lowering wal_retrieve_retry_interval for the tests might be sufficient. Besides the fact that it revealed multiple bugs, I don't see the point in adding much more complexity here. In practice, workers will usually start right away, unless of course there are other worker starts happening around the same time. This consistently causes testing delays because the tests stress these code paths, but I don't think what the tests are doing is a typical use-case. From the discussion thus far, it sounds like the alternatives are to 1) add a global flag that causes wal_retrieve_retry_interval to be bypassed for all workers or to 2) add a hash map in the launcher and a restart_immediately flag in each worker slot. I'll go ahead and create a patch for 2 since it seems like the most complete solution, and we can evaluate whether the complexity seems appropriate. [0] https://postgr.es/m/20221214171023.GA689106%40nathanxps13 -- Nathan Bossart Amazon Web Services: https://aws.amazon.com