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 1qIq92-0006ir-6E for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jul 2023 12:37:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qIq91-0004sg-1Z for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Jul 2023 12:37:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qIq8z-0004sX-94 for pgsql-hackers@lists.postgresql.org; Mon, 10 Jul 2023 12:37:34 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qIq8v-0034St-TL for pgsql-hackers@postgresql.org; Mon, 10 Jul 2023 12:37:32 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 15BD032008FA; Mon, 10 Jul 2023 08:37:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 10 Jul 2023 08:37:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding: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=fm1; t=1688992646; x=1689079046; bh=YCNrrjhwOlKABursHByZoe120 TDkydju9H7gJuR4OmY=; b=dQ2ZKz5GTciMAQHR4HjNg5x944pkdmdo/VTyxQiKx 5x+I1D6JYtRofOikhgX/VysJkaGb0soE6HQMyi+N3YBdoK37+F8EbVeeIMgudOdM zBk54XnxmatSxYvM0oJTZkouQZNcGaVkrHwLFn3iT9uEaP1wMXwzUH18NUEyQHng wD2KUkkosxgqO3lt14AhrXsiLq7/d6340Dv9btokrkv4oMO4X1QOFoTF8ig1c8tr B/CD+4SQVjQKZiLH76PG+5iJo3zZ8BpUTbDebI96bGT/6wozKBcJ74V8LE9M2pKY XmzsTg/TpbV4apyDQTaBP7c5xhRMsz11oPmC7S4THwLyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=fm2; t= 1688992646; x=1689079046; bh=YCNrrjhwOlKABursHByZoe120TDkydju9H7 gJuR4OmY=; b=MpNTCUV432ITujx9A/7sBKPH0wlGykBffNkVdQcWD0pBZbbSRl0 PT25TSRKaD4cklCCbNDmCn9JykzuIqzsfkVWXDwl91B4FTn4J3b57vBzoOiNO7WP CYqTQpfUgUrhurcybUfk23bptz3plkPU4Crna+2krt5bVtnygTJ9gwIm761l7WWI BHi2m6SyVThEBpHlh+rrhXgQBgNk/1Db8I0HqB7ujdLnS8R4D1I4EsUCXxbLsFxB lz9NPWqkTsCcopwMXxBIqzKkrHJ/5MUjNG9jLBlfB7EskIZFz67LwgBjS3Z5iDX2 iEZSXYtqVbo++hLd4S4C0ywaMOCz0X8A5Ew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrvdekgdeghecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfevfhfhjggtgfesthejredttdefjeenucfhrhhomheprfgvthgv rhcugfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgqe enucggtffrrghtthgvrhhnpeehieeuhfelleefieekheekgfekgefgveehuedvjeevtedt geelkeffffeikeeutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 10 Jul 2023 08:37:25 -0400 (EDT) Message-ID: Date: Mon, 10 Jul 2023 14:37:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: ResourceOwner refactoring Content-Language: en-US To: Heikki Linnakangas , Aleksander Alekseev , "pgsql-hackers@postgresql.org" Cc: Andres Freund , Julien Rouhaud , Robert Haas References: <908491f9-57ff-5061-30c6-d15d3dbf0e67@iki.fi> <1377f062-13ea-ebfb-ef8a-97739c156a05@iki.fi> <2e10b71b-352e-b97b-1e47-658e2669cecb@iki.fi> <20221101001523.lsgmohl6fjwppbgx@awork3.anarazel.de> <9a3245db-ca03-4a47-5706-73404cfe5108@iki.fi> <20221101154251.64vyq7wy6w7aykrn@awork3.anarazel.de> <527af829-4a03-03b0-121c-46ff79c61887@iki.fi> From: Peter Eisentraut In-Reply-To: <527af829-4a03-03b0-121c-46ff79c61887@iki.fi> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk A few suggestions on the API: > +static ResourceOwnerFuncs tupdesc_resowner_funcs = These aren't all "functions", so maybe another word like "info" or "description" would be more appropriate? > + .release_phase = RESOURCE_RELEASE_AFTER_LOCKS, > + .release_priority = RELEASE_PRIO_TUPDESC_REFS, I suggest assigning explicit non-zero numbers to the RESOURCE_RELEASE_* constants, as well as changing RELEASE_PRIO_FIRST to 1 and adding an assertion that the priority is not zero. Otherwise, someone might forget to assign these fields and would implicitly get phase 0 and priority 0, which would probably work in most cases, but wouldn't be the explicit intention. Then again, you are using RELEASE_PRIO_FIRST for the pgcrypto patch. Is it the recommendation that if there are no other requirements, external users should use that? If we are going to open this up to external users, we should probably have some documented guidance around this. > + .PrintLeakWarning = ResOwnerPrintTupleDescLeakWarning I think this can be refactored further. We really just need a function to describe a resource, like maybe static char * ResOwnerDescribeTupleDesc(Datum res) { TupleDesc tupdesc = (TupleDesc) DatumGetPointer(res); return psprintf("TupleDesc %p (%u,%d)", tupdesc, tupdesc->tdtypeid, tupdesc->tdtypmod); } and then the common code can generate the warnings from that like elog(WARNING, "%s leak: %s still referenced", kind->name, kind->describe(value)); That way, we could more easily develop further options, such as turning this warning into an error (useful for TAP tests). Also, maybe, you could supply a default description that just prints "%p", which appears to be applicable in about half the places. Possible bonus project: I'm not sure these descriptions are so useful anyway. It doesn't help me much in debugging if "File 55 was not released" or some such. If would be cool if ResourceOwnerRemember() in some debug mode could remember the source code location, and then print that together with the leak warning. > +#define ResourceOwnerRememberTupleDesc(owner, tupdesc) \ > + ResourceOwnerRemember(owner, PointerGetDatum(tupdesc), &tupdesc_resowner_funcs) > +#define ResourceOwnerForgetTupleDesc(owner, tupdesc) \ > + ResourceOwnerForget(owner, PointerGetDatum(tupdesc), &tupdesc_resowner_funcs) I would prefer that these kinds of things be made inline functions, so that we maintain the type safety of the previous interface. And it's also easier when reading code to see type decorations. (But I suspect the above bonus project would require these to be macros?) > + if (context->resowner) > + ResourceOwnerForgetJIT(context->resowner, context); It seems most ResourceOwnerForget*() calls have this kind of check before them. Could this be moved inside the function?