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 1s9zvc-006rhj-CH for pgsql-hackers@arkaria.postgresql.org; Thu, 23 May 2024 04:19:45 +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 1s9zva-007hFT-U7 for pgsql-hackers@arkaria.postgresql.org; Thu, 23 May 2024 04:19:42 +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 1s9zva-007hFJ-KO for pgsql-hackers@lists.postgresql.org; Thu, 23 May 2024 04:19:42 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s9zvX-000JpV-BN for pgsql-hackers@lists.postgresql.org; Thu, 23 May 2024 04:19:42 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-351da5838fcso5501746f8f.1 for ; Wed, 22 May 2024 21:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716437978; x=1717042778; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=t0xRtcufczdUO41Z9RlTBxaB0UH5g0gUZM1Ze6MKDdM=; b=CVMVzI0vfQxGdCiF6zlYFR9FVMM7DS5uRnV0i1eaTO3keGUegBfGgtN8Cq/MwoUMl1 r642djL899wWKXyIMakpl4AMO3+IEP3H7vJNWLmYDzS0ULw6tUVgo/tbygvThpBLj0fE c/25pAcNEH9o2XgLgGHwNmM4/c6zTNNAA2EmouJ/zd4Qk2hL+IeMCrd1Y/YtxVSJjNP5 KrrlWs1SofMxhjvG0V7DoSwNTwXlB4UWqNE/Ix06+KOHBRudnARQJE9ww9uvzaE4XJT4 sfRiPE8Jhb4sozQavIR4/snjw1q8ewPcPE70lf+65gyokaUQ/FH1aoTpZ1ITaFxHQHOG fNWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716437978; x=1717042778; h=in-reply-to:content-transfer-encoding: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=t0xRtcufczdUO41Z9RlTBxaB0UH5g0gUZM1Ze6MKDdM=; b=N2jN8bwyFQq9jQZDU1gWQqlSflFHk+QvPaqbv6NUOp4NB74UjV9M3zxZTezlkiMORN 0tde7opx70yDqSLMXnNtWMFdFc6gDMZrt2EBawMleLq0r8eWbfm7AQVG0wK79s8wZOL3 ymcQ6X41bUBlCOxb3ttAcywXPHqvFrARxx/weEApkqSQ1m43G9CJrOwcWbe7YxW3Fc5j oYG4CM0uKLHrIJmaLnrSEkwARALVARX8p6tTEOvpChJKkvpSpEcr1IE0TSDDUpqp8SH0 a17+HxE8fPCALy749NTBJIdG4WnTT38GLJOjzpeCuh5BFWHTQTCDQvy/pDchM/Rx1sbS gJLA== X-Forwarded-Encrypted: i=1; AJvYcCWlVRRcmEZK1W+wmFcaUFUy5zLelem9WrmZV0a4WR03jPa16KMWzN/e3G4dO/7KXPnj8a9wJ9bZKkTL2+kFr0Oyj3rl17VLOVwnF+60mSKiD54a X-Gm-Message-State: AOJu0Yxa1A8KnUSwC0d1f72Jkpl48mpb/0GviQU1NcUdCz95Q85wVowy gCbIkUWz5/t1D3PP1qsnSzOqgJS4ExxvSGXhdBg2rM1voV2N1AKT X-Google-Smtp-Source: AGHT+IEMe9YAMRR/OeGk+ksnNim3BemAPgdPWKJeifH2honHGi5HpHt4nhblIIDZBZqWA3vP367fWA== X-Received: by 2002:a05:6000:10d0:b0:354:eb62:365c with SMTP id ffacd0b85a97d-354eb62372amr2404869f8f.15.1716437978225; Wed, 22 May 2024 21:19:38 -0700 (PDT) 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 ffacd0b85a97d-3502baacecasm35672107f8f.82.2024.05.22.21.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 21:19:37 -0700 (PDT) Date: Thu, 23 May 2024 04:19:36 +0000 From: Bertrand Drouvot To: Robert Haas Cc: Michael Paquier , Alexander Lakhin , pgsql-hackers@lists.postgresql.org, Tom Lane Subject: Re: Avoid orphaned objects dependencies, take 3 Message-ID: References: <403075e1-4d60-09e2-a06a-749cd9d88f66@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, May 22, 2024 at 10:48:12AM -0400, Robert Haas wrote: > On Wed, May 22, 2024 at 6:21 AM Bertrand Drouvot > wrote: > > I started initially with [1] but it was focusing on function-schema only. > > Yeah, that's what I thought we would want to do. And then just extend > that to the other cases. > > > Then I proposed [2] making use of a dirty snapshot when recording the dependency. > > But this approach appeared to be "scary" and it was still failing to close > > some race conditions. > > The current patch still seems to be using dirty snapshots for some > reason, which struck me as a bit odd. My intuition is that if we're > relying on dirty snapshots to solve problems, we likely haven't solved > the problems correctly, which seems consistent with your statement > about "failing to close some race conditions". But I don't think I > understand the situation well enough to be sure just yet. The reason why we are using a dirty snapshot here is for the cases where we are recording a dependency on a referenced object that we are creating at the same time behind the scene (for example, creating a composite type while creating a relation). Without the dirty snapshot, then the object we are creating behind the scene (the composite type) would not be visible and we would wrongly assume that it has been dropped. Note that the usage of the dirty snapshot is only when the object is first reported as "non existing" by the new ObjectByIdExist() function. > > I think there is 2 cases here: > > > > First case: the "conflicting" lock mode is for one of our own lock then LockCheckConflicts() > > would report this as a NON conflict. > > > > Second case: the "conflicting" lock mode is NOT for one of our own lock then LockCheckConflicts() > > would report a conflict. But I've the feeling that the existing code would > > already lock those sessions. > > > > Was your concern about "First case" or "Second case" or both? > > The second case, I guess. It's bad to take a weaker lock first and > then a stronger lock on the same object later, because it can lead to > deadlocks that would have been avoided if the stronger lock had been > taken at the outset. In the example I shared up-thread that would be the opposite: the Session 1 would take an AccessExclusiveLock lock on the object before taking an AccessShareLock during changeDependencyFor(). > Here, it seems like things would happen in the > other order: if we took two locks, we'd probably take the stronger > lock in the higher-level code and then the weaker lock in the > dependency code. Yeah, I agree. > That shouldn't break anything; it's just a bit > inefficient. Yeah, the second lock is useless in that case (like in the example up-thread). > My concern was really more about the maintainability of > the code. I fear that if we add code that takes heavyweight locks in > surprising places, we might later find the behavior difficult to > reason about. > I think I understand your concern about code maintainability but I'm not sure that adding locks while recording a dependency is that surprising. > Tom, what is your thought about that concern? +1 Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com