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 1s9vy3-006Bcr-45 for pgsql-hackers@arkaria.postgresql.org; Thu, 23 May 2024 00:06:00 +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 1s9vy2-005eLr-GP for pgsql-hackers@arkaria.postgresql.org; Thu, 23 May 2024 00:05:58 +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 1s9vy2-005eLj-6d for pgsql-hackers@lists.postgresql.org; Thu, 23 May 2024 00:05:58 +0000 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s9vxy-000Hfe-RZ for pgsql-hackers@postgresql.org; Thu, 23 May 2024 00:05:57 +0000 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-df4e40a3cb6so1370489276.0 for ; Wed, 22 May 2024 17:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1716422752; x=1717027552; darn=postgresql.org; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=8MymOg3VQWJyZAkDWKWrqIga/SHCEbPSCny2ep5GXB0=; b=QOrY2H2Yby3Kwhb8Ps3xZj4oN0oEsD1TLkF/5jKQiWt+E1yZevnDLnh1IUHOxLAxcb 5/G4EjzcYVBC9zzJ3JxLjs6fhpmghO4dJdJF52LyTyHCGCPdkFJ72hJn5itzsVEiTdme MvpgbVJZxMcwxDz/9mrcwaCy4DEu61OqoHTx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716422752; x=1717027552; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8MymOg3VQWJyZAkDWKWrqIga/SHCEbPSCny2ep5GXB0=; b=eZNO36yZzIlkzqbulnyKTpP182xtOqv1VyusKPntFrbJ19LUjgdZ7/bL+OUuGhqcsV raexhXJWaeHqcQYBBnv4JvmfWEb9bn2hYx/CWhz/ulDXhiPbubGGoYDijUjjPJweKllt 7+nnQ24AWDh6ZXl1FhusXu2F4fcwdURCUto6vLQaFRBZSGfJzsdAfI5I3UhZV5BvoR+e rbWSVekJTv8K+rhbvTAyuhF/H18G+lgmzvSu9BaT88UaUvrsnJyxmr/gfooExp7CCC5c aq39+BgCj38Ll7UPCj66u6xsT2yNPTqqeqQPAVPAdt5XJX8gnLrAY1x4JoUjHPnM7p3S Wu8w== X-Gm-Message-State: AOJu0Yws6kNx9on8LZ0XUHvL4aUBmgrs8jGNm23XKZjpOLYSF2z9skty nnW5t7hQ7Fe9Tfrhsbi20GNiBf3oynEnuelCkjFKvjbS9bjirCGtNwV8kS6w4hoNYShXeOaJ5lt hmA== X-Google-Smtp-Source: AGHT+IEOwpgfGb+3AZxUYYm3ESZtuP5GlxIglVPjcHmpxFH6e5d3G4KKK1CbgqptOLbfPt74PAdR8w== X-Received: by 2002:a25:a229:0:b0:de6:151d:e082 with SMTP id 3f1490d57ef6-df4e0dfbd8cmr3309606276.59.1716422751843; Wed, 22 May 2024 17:05:51 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-debd3827c9asm5860388276.50.2024.05.22.17.05.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2024 17:05:51 -0700 (PDT) Date: Wed, 22 May 2024 17:05:48 -0700 From: Noah Misch To: pgsql-hackers@postgresql.org Subject: Inval reliability, especially for inplace updates Message-ID: <20240523000548.58.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 https://postgr.es/m/20240512232923.aa.nmisch@google.com wrote: > Separable, nontrivial things not fixed in the attached patch stack: > > - Inplace update uses transactional CacheInvalidateHeapTuple(). ROLLBACK of > CREATE INDEX wrongly discards the inval, leading to the relhasindex=t loss > still seen in inplace-inval.spec. CacheInvalidateRelmap() does this right. I plan to fix that like CacheInvalidateRelmap(): send the inval immediately, inside the critical section. Send it in heap_xlog_inplace(), too. The interesting decision is how to handle RelationCacheInitFilePreInvalidate(), which has an unlink_initfile() that can fail with e.g. EIO. Options: 1. Unlink during critical section, and accept that EIO becomes PANIC. Replay may reach the same EIO, and the system won't reopen to connections until the storage starts cooperating.a Interaction with checkpoints is not ideal. If we checkpoint and then crash between inplace XLogInsert() and inval, we'd be relying on StartupXLOG() -> RelationCacheInitFileRemove(). That uses elevel==LOG, so replay would neglect to PANIC on EIO. 2. Unlink before critical section, so normal xact abort suffices. This would hold RelCacheInitLock and a buffer content lock at the same time. In RecordTransactionCommit(), it would hold RelCacheInitLock and e.g. slru locks at the same time. The PANIC risk of (1) seems similar to the risk of PANIC at RecordTransactionCommit() -> XLogFlush(), which hasn't been a problem. The checkpoint-related risk bothers me more, and (1) generally makes it harder to reason about checkpoint interactions. The lock order risk of (2) feels tolerable. I'm leaning toward (2), but that might change. Other preferences? Another decision is what to do about LogLogicalInvalidations(). Currently, inplace update invalidations do reach WAL via LogLogicalInvalidations() at the next CCI. Options: a. Within logical decoding, cease processing invalidations for inplace updates. Inplace updates don't affect storage or interpretation of table rows, so they don't affect logicalrep_write_tuple() outcomes. If they did, invalidations wouldn't make it work. Decoding has no way to retrieve a snapshot-appropriate version of the inplace-updated value. b. Make heap_decode() of XLOG_HEAP_INPLACE recreate the invalidation. This would be, essentially, cheap insurance against invalidations having a benefit I missed in (a). I plan to pick (a). > - AtEOXact_Inval(true) is outside the RecordTransactionCommit() critical > section, but it is critical. We must not commit transactional DDL without > other backends receiving an inval. (When the inplace inval becomes > nontransactional, it will face the same threat.) This faces the same RelationCacheInitFilePreInvalidate() decision, and I think the conclusion should be the same as for inplace update. Thanks, nm