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 1szmjd-0080ID-OU for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Oct 2024 00:45:25 +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 1szmjb-00Cpub-0b for pgsql-hackers@arkaria.postgresql.org; Sun, 13 Oct 2024 00:45:23 +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 1szmja-00CpuT-Ev for pgsql-hackers@lists.postgresql.org; Sun, 13 Oct 2024 00:45:23 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1szmjT-000b7r-VI for pgsql-hackers@postgresql.org; Sun, 13 Oct 2024 00:45:21 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-20ca7fc4484so11188925ad.3 for ; Sat, 12 Oct 2024 17:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1728780315; x=1729385115; darn=postgresql.org; h=user-agent: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=aCYBbj9WIgPPbwRpcu8OSkbQH3y/IsF/6de+r3rSqoI=; b=Q+BiDq7QLL3fsDL8gfRCuRqgkVJAd6WQJg1ElkvjE8onmwreqTOR09aoNa3okPMpc2 uaKAVu/2ggbzdhbkPRzYnQIuz2CzVXTpbJxdKiYtjc80cBYW53Wld0gwaq0ep9RbVFfo Me8uVToSnQiGfb2w6DazUFXT7NhfbLSlUndtE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728780315; x=1729385115; h=user-agent: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=aCYBbj9WIgPPbwRpcu8OSkbQH3y/IsF/6de+r3rSqoI=; b=i2Fb4GKf7esp+zdhF82AimJahXtqlVv3ksBo4vbFB7Mt6n1dCiNm/0kJ5vck7rtZkf zRKCQelP1xUyigmEwHgtoPbAolTIvLvAjp8mJSBjV5l7l9d7x/oAMNhAwXW3nYWHbrVC omRpK13OiVoDlWqKBxim9DhTmmupwyX51XNJkjAOhxqp4ZkNnGfx25cEjXQI+QxoyurB o8/ln1EVFoWItm0paF7UHAmflkmsf33Bq0zU5AVuZPNrvyWYnvZUyqd9mH/+zJQm8l1S jSLCGKD3owo+CGLaKoBLT5aWBO3uWgsHjEIsQb3BqYn4vp7WmsPgVWQj38jd6KKu05gY feXg== X-Forwarded-Encrypted: i=1; AJvYcCVLtEyf6GkBmzeV+XlGqiC5sTHGnr0yQem8PJTJ/97IBlz5+CZ2McN5rMEMvmDpdbC/zm30qHJm7bEW7L2X@postgresql.org X-Gm-Message-State: AOJu0YzSeA+FmOEzqQ/8tVag14XGhERNGg23RYBIEDUdB3ZTL4sPD54v W5EjGEprBRsnKsDOUAsdMZKX37ml3++2rWMxmcQvnnIjimmV8ox/xEhzTjZ5YQ== X-Google-Smtp-Source: AGHT+IEavbPXesDnU5QvRFyDTV33N7d7+1H38xMebyhgXptuiK9abeLFg00cA2CcLNP5pCRM+KYudg== X-Received: by 2002:a17:903:2406:b0:20c:a8cf:fa19 with SMTP id d9443c01a7336-20cbb198f19mr67622515ad.22.1728780314771; Sat, 12 Oct 2024 17:45:14 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8bc1a17fsm42582435ad.70.2024.10.12.17.45.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Oct 2024 17:45:13 -0700 (PDT) Date: Sat, 12 Oct 2024 17:45:11 -0700 From: Noah Misch To: Nitin Motiani Cc: Andres Freund , pgsql-hackers@postgresql.org Subject: Re: Inval reliability, especially for inplace updates Message-ID: <20241013004511.9c.nmisch@google.com> References: <20240523000548.58.nmisch@google.com> <20240615223718.42.nmisch@google.com> <20240617235854.f8.nmisch@google.com> <20240618015730.jijhox2a3w3t26en@awork3.anarazel.de> <20240618152349.7f.nmisch@google.com> <20240831010711.67.nmisch@google.com> <20240930193350.04.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Oct 12, 2024 at 06:05:06PM +0530, Nitin Motiani wrote: > 1. In heap_inplace_update_and_unlock, currently both buffer and tuple > are unlocked outside the critical section. Why do we have to move the > buffer unlock within the critical section here? My guess is that it > needs to be unlocked for the inplace invals to be processed. But what > is the reasoning behind that? AtInplace_Inval() acquires SInvalWriteLock. There are two reasons to want to release the buffer lock before acquiring SInvalWriteLock: 1. Otherwise, we'd need to maintain the invariant that no other part of the system tries to lock the buffer while holding SInvalWriteLock. (That would cause an undetected deadlock.) 2. Concurrency is better if we release a no-longer-needed LWLock before doing something time-consuming, like acquiring another LWLock potentially is. Inplace invals do need to happen in the critical section, because we've already written the change to shared buffers, making it the new authoritative value. If we fail to invalidate, other backends may continue operating with stale caches. > 2. Is there any benefit in CacheInvalidateHeapTupleCommon taking the > preapre_callback argument? Wouldn't it be simpler to just pass an > InvalidationInfo* to the function? CacheInvalidateHeapTupleCommon() has three conditions that cause it to return without invoking the callback. Every heap_update() calls CacheInvalidateHeapTuple(). In typical performance-critical systems, non-DDL changes dwarf DDL. Hence, the overwhelming majority of heap_update() calls involve !IsCatalogRelation(). I wouldn't want to allocate InvalidationInfo in DDL-free transactions. To pass in InvalidationInfo*, I suppose I'd move those three conditions to a function and make the callers look like: CacheInvalidateHeapTuple(Relation relation, HeapTuple tuple, HeapTuple newtuple) { if (NeedsInvalidateHeapTuple(relation)) CacheInvalidateHeapTupleCommon(relation, tuple, newtuple, PrepareInvalidationState()); } I don't have a strong preference between that and the callback way. > Also is inval-requires-xid-v0.patch planned to be fixed up to inplace160? I figure I'll pursue that on a different thread, after inplace160 and inplace180. If there's cause to pursue it earlier, let me know. Thanks, nm