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 1rche3-001ZaS-4t for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Feb 2024 08:07:59 +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 1rche1-003dzY-JM for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Feb 2024 08:07:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rche1-003dzO-9W for pgsql-hackers@lists.postgresql.org; Wed, 21 Feb 2024 08:07:57 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rchdv-000EYH-HE for pgsql-hackers@lists.postgresql.org; Wed, 21 Feb 2024 08:07:56 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3392b12dd21so277093f8f.0 for ; Wed, 21 Feb 2024 00:07:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708502870; x=1709107670; 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=PGX/WidrKT6lhn/49KzFWUdCeedFj3VPSiRe1qblXLs=; b=clA1vpT1O9FyAvqIEzkoY2WFWRKyUJmmTefXjQOBC+XAEIz0xB8c9Ptn3Xdc8kY5yW d4OPnOuxwru8T49u/g2fvoXhT9BTESc6YqGuR4cmI8s8DwGhdHmdc9nC9gTIRvXzbbEy 02Zm6/9RZDlwHjB4b4oSvWLeTQS7punhv6OnmTnEm7phGILBgbxbkmLHKqxTI4vcvVPZ lPFlTkA+maJ24xijITPbN+nzypVlbdne79Y8IK8ChgS9Y+OWGCMFOjWXeZdzYVkxOY+X VFhLlDk7AbEbFZOgG4yllztCsbEDQsXV808Xq15OMDai4XuuzBGkujIQsM4/4YEKWbu1 /UuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708502870; x=1709107670; 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=PGX/WidrKT6lhn/49KzFWUdCeedFj3VPSiRe1qblXLs=; b=vyFT/xVapyaKt6+TtBp//1Mv4oyQ4sQGy0Y2aJu+GtcYXtiHJTIkknZVdc+mS6g21B rY2iKRKenzGWpNkbMNcbVf+yuAo734OZ1GvUxPhsaYEpyTienFHGy//Yk+uVuW8Sf8vK EQFzeYjAexAz42XyxoQDQdL68DY1OOKjiYG02D0MDl+vUW5dleSduLZ7cq6yTybcihnC B4hKnxuds86f4lyUVxmMo+m+zAs4ymDzbG3yJ82+gBxgOI2sZ6226WJzDg/EnjRguf3T jMqwEQh8kjnW0ortS9o3TeohKj0R/2EHOqHn0tzXksJ/rFruOI+O6cMalHtO+1H88GNx 8UPw== X-Gm-Message-State: AOJu0YwYNqr5qQ9hu7zjmP+F303awcLXg84IDeNwC+60uIhbQlQg3HqI cJ0jHwmjzaVgCnZJj07G6WRXuZgN/q/aGlWnm+L3ArgHYhpeWeFb X-Google-Smtp-Source: AGHT+IHi4SWxZ1pN/6lEvkw+FSnZUwLJu6C+veMs/ZkzEwJphVVWerz5UA00ufnYLt3wbllP/cfd1w== X-Received: by 2002:a5d:5402:0:b0:33d:3b19:a2c3 with SMTP id g2-20020a5d5402000000b0033d3b19a2c3mr7169970wrv.57.1708502869432; Wed, 21 Feb 2024 00:07:49 -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 e6-20020adfa446000000b0033d76a5bec1sm1828645wra.15.2024.02.21.00.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 00:07:48 -0800 (PST) Date: Wed, 21 Feb 2024 08:07:47 +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 Wed, Feb 21, 2024 at 07:08:03AM +0900, Michael Paquier wrote: > On Tue, Feb 20, 2024 at 03:55:08PM +0000, Bertrand Drouvot wrote: > > +PG_FUNCTION_INFO_V1(injection_points_wake); > > +Datum > > +injection_points_wake(PG_FUNCTION_ARGS) > > +{ > > > > I think that This function will wake up all the "wait" injection points. > > Would that make sense to implement some filtering based on the name? That could > > be useful for tests that would need multiple wait injection points and that want > > to wake them up "sequentially". > > > > We could think about it if there is such a need in the future though. > > Well, both you and Andrey are asking for it now, so let's do it. Thanks! > The implementation is simple: > - Store in InjectionPointSharedState an array of wait_counts and an > array of names. There is only one condition variable. > - When a point wants to wait, it takes the spinlock and looks within > the array of names until it finds a free slot, adds its name into the > array to reserve a wait counter at the same position, releases the > spinlock. Then it loops on the condition variable for an update of > the counter it has reserved. It is possible to make something more > efficient, but at a small size it would not really matter. > - The wakeup takes a point name in argument, acquires the spinlock, > and checks if it can find the point into the array, pinpoints the > location of the counter to update and updates it. Then it broadcasts > the change. > - The wait loop checks its counter, leaves its loop, cancels the > sleep, takes the spinlock to unregister from the array, and leaves. > I think that makes sense and now the "counter" makes more sense to me (thanks to it we don't need multiple CV). > I would just hardcode the number of points that can wait, say 5 of > them tracked in shmem? Does that look like what you are looking at? I think so yes and more than 5 points would look like a complicated test IMHO. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com