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 1rc4cu-000m9n-Lp for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Feb 2024 14:28:12 +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 1rc4ct-00Fiie-Ac for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Feb 2024 14:28:11 +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 1rc4ct-00FiiV-1R for pgsql-hackers@lists.postgresql.org; Mon, 19 Feb 2024 14:28:11 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rc4cq-00808X-FW for pgsql-hackers@lists.postgresql.org; Mon, 19 Feb 2024 14:28:10 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2d204e102a9so56072411fa.0 for ; Mon, 19 Feb 2024 06:28:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708352887; x=1708957687; darn=lists.postgresql.org; 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=o5PczXJOWge1mvvO6MqpuyN6tNoPT4RYh4ue3KFvyUk=; b=OikdWhEDQcpGtD6vnKm6fmkuB9DqnCNQ8yMVsTnKxDimH7M0iU11y2XeFZspqr9/n5 jH4oJQKBRDgVNdLF9ba/zEa1DDjHB8wkfWYSQUWzXE4ovAi0P8Lpi+MKVI5qR8SmwIU/ l9bUFgrACLVFofJEeUC3WCgtJSr0qglFEdzKza840gzXBxXnBbXelVEFxtr8v2uiTXhf lhCTaQ7dHoiYP+0p+zPll04thwiuex2Rd+0W+duI66UfGhJxJrlEV8nNsMXQVlSnk47C IsXbRBqhdtAy3Kv3UUwwgYjFHM4v3tlhxXFuTbnhseR6vbSntIBD8v/OeX+CUX0Q9v0U sETQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708352887; x=1708957687; 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=o5PczXJOWge1mvvO6MqpuyN6tNoPT4RYh4ue3KFvyUk=; b=odes4fyI9ER327pAJ6x9EyXHsvgL+koLpOQFZ36tnMPZ3JA+ChK/Q8F9Gv+SOEByMQ lpQybU9xQveew2ZHLxW0ZiUwYe+rV0/aAGYLlFeCrXaPHHcMjjZQcPCxHx6IPlmyuLP6 GXcJtKDuCs7Si1xHj3c0gNfgjvQenwQ4Cdpx59fjgenEv69nZPQX5H9eHdk0OJ1sBQe0 eRcAHEgrrc2n1eb/8Jz94Zz2cc6AOoCKzyFX28V/h2Bn5VmvvGD7r9NPweY3LKpjbUrK S78Pec8C0gVLL2gHGN0ScnGduPQ7gvrzhLeGieNEsB86E/HuDQZAEnJvQNfd3gw+ihYP ZPjA== X-Gm-Message-State: AOJu0YzmaHBjPpnJtAOXp/N1B6jVv1cgxD+GVMt8vObIPzU4Tl6IjRGt pDMZCfNlEi3D7hMNZzFYYA96IbVIFooa9uTIsYEg0OeYvxxIYZ97 X-Google-Smtp-Source: AGHT+IEyinRCkMEDemQDNxSlzs42jfOGFNYyI5pz9EDClE8C1Z3989M20LSQppScUdzUSnClQ+Ua1w== X-Received: by 2002:a2e:9049:0:b0:2d2:3758:8c2a with SMTP id n9-20020a2e9049000000b002d237588c2amr2252696ljg.9.1708352887005; Mon, 19 Feb 2024 06:28:07 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id r3-20020adfce83000000b0033d2541b3e1sm8782063wrn.72.2024.02.19.06.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 06:28:05 -0800 (PST) Date: Mon, 19 Feb 2024 14:28:04 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Postgres hackers , Ashutosh Bapat Subject: Re: Injection points: some tools to wait and wake Message-ID: References: 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 Hi, On Mon, Feb 19, 2024 at 04:51:45PM +0900, Michael Paquier wrote: > On Mon, Feb 19, 2024 at 03:01:40PM +0900, Michael Paquier wrote: > > 0002 is a polished version of the TAP test that makes use of this > > facility, providing coverage for the bug fixed by 7863ee4def65 > > (reverting this commit causes the test to fail), where a restart point > > runs across a promotion request. The trick is to stop the > > checkpointer in the middle of a restart point and issue a promotion > > in-between. > > The CF bot has been screaming at this one on Windows because the > process started with IPC::Run::start was not properly finished, so > attached is an updated version to bring that back to green. Thanks for the patch, that's a very cool feature! Random comments: 1 === +CREATE FUNCTION injection_points_wake() what about injection_points_wakeup() instead? 2 === +/* Shared state information for injection points. */ +typedef struct InjectionPointSharedState +{ + /* protects accesses to wait_counts */ + slock_t lock; + + /* Counter advancing when injection_points_wake() is called */ + int wait_counts; If slock_t protects "only" one counter, then what about using pg_atomic_uint64 or pg_atomic_uint32 instead? And btw do we need wait_counts at all? (see comment number 4) 3 === + * SQL function for waking a condition variable waking up instead? 4 === + for (;;) + { + int new_wait_counts; + + SpinLockAcquire(&inj_state->lock); + new_wait_counts = inj_state->wait_counts; + SpinLockRelease(&inj_state->lock); + + if (old_wait_counts != new_wait_counts) + break; + ConditionVariableSleep(&inj_state->wait_point, injection_wait_event); + } I'm wondering if this loop and wait_counts are needed, why not doing something like (and completely get rid of wait_counts)? " ConditionVariablePrepareToSleep(&inj_state->wait_point); ConditionVariableSleep(&inj_state->wait_point, injection_wait_event); ConditionVariableCancelSleep(); " It's true that the comment above ConditionVariableSleep() mentions that: " * This should be called in a predicate loop that tests for a specific exit * condition and otherwise sleeps " but is it needed in our particular case here? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com