Re: A new function to wait for the backend exit after termination

Fujii Masao <masao.fujii@oss.nttdata.com>

From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Magnus Hagander <magnus@hagander.net>
Cc: "Hou, Zhijie" <houzj.fnst@cn.fujitsu.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Muhammad Usama <m.usama@gmail.com>
Date: 2021-03-15T05:08:15Z
Lists: pgsql-hackers

On 2021/03/15 12:27, Bharath Rupireddy wrote:
> On Sun, Mar 7, 2021 at 2:39 PM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
>> Attaching v7 patch for further review.
> 
> Attaching v8 patch after rebasing on to the latest master.

Thanks for rebasing the patch!

-       WAIT_EVENT_XACT_GROUP_UPDATE
+       WAIT_EVENT_XACT_GROUP_UPDATE,
+       WAIT_EVENT_BACKEND_TERMINATION

These should be listed in alphabetical order.

In pg_wait_until_termination's do-while loop, ResetLatch() should be called. Otherwise, it would enter busy-loop after any signal arrives. Because the latch is kept set and WaitLatch() always exits immediately in that case.

+	/*
+	 * Wait in steps of waittime milliseconds until this function exits or
+	 * timeout.
+	 */
+	int64	waittime = 10;

10 ms per cycle seems too frequent?

+			ereport(WARNING,
+					(errmsg("timeout cannot be negative or zero: %lld",
+							(long long int) timeout)));
+
+			result = false;

IMO the parameter should be verified before doing the actual thing.

Why is WARNING thrown in this case? Isn't it better to throw ERROR like pg_promote() does?

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION



Commits

  1. Copy-edit text for the pg_terminate_backend() "timeout" parameter.

  2. Remove pg_wait_for_backend_termination().

  3. Add functions to wait for backend termination

  4. Fix typo in comment.