Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jF0bI-0006n6-HD for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2020 19:13:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jF0bH-000792-4J for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2020 19:13:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jF0bG-00078u-Jp for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2020 19:13:02 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jF0bA-0007rS-3P for pgsql-hackers@postgresql.org; Thu, 19 Mar 2020 19:13:01 +0000 Received: by mail-lj1-x22b.google.com with SMTP id w4so3779291lji.11 for ; Thu, 19 Mar 2020 12:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0n+VdIfouGmlw+vVujiX2EWeDbeqUL+3DnO11DUsalc=; b=pZXa7cTI0k7GKB3EgStPWMwqolaDUNXOAB9b9Uc8O3mUmffTSKxCIT4ZPLcpMrYMSP 5kD5U33vIx2smfbDpgcJ7iViBzfrRcI8fI4iC1tUYGiTXTSk70VnpHWXvbVwPCBDNlm7 aHYcpCHgLIY0sXDb4ujPnqnWswBwQCXp4P2RX/NVyGLYpHrykPBvjf2BrHyqbxeBLgI/ o7nwEghPJwUxdYohJtPq0USw7RKvcmBSIJ//vDEsqEVnY2uxgEDNacv9gpZ97/Vy66oh LJvG+0HbVS3I7ztEN5W/h1uKRSWa5IsQhSprrjRu3GN5knI+v9EVAf98YhuSCTLfmOe0 XC5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0n+VdIfouGmlw+vVujiX2EWeDbeqUL+3DnO11DUsalc=; b=lrO1jqF4M7I7UgZnb2PVTj9AHICQehU5sFFXN7bfyKNR/Ijonb6YJ68lHcET1wADJV RvJrZ9dlCkQ0iOVvRd0iKWwd/Bzojmq46Ow2GOiyk1/3uoteLNp6iXVA4UwGYKZarMd5 6NYSbxsY7W020hlXFjDk5auxx0RPtAutCA1ylGGbbm96T/BMs8blPbPbdr59Ns5KHfOh ICRxioopY2DxAyrcj2ektSiymLjwfMzwMvLkgNcZuEqm7AKX0IfjcTudMs6CFPHplVfR WNxjKgvDwklvwbX0HKxN6yDKS7tTQcpYd2L3N7fxl5pmg+4aTy3ZM7dF6/Wefule6S6H m+SA== X-Gm-Message-State: ANhLgQ1SeaBaQRhwMO9cfmDKyR9bVdfB62U609tMlMYOcGaKobC2ewuu dImKxcTSmNGeWAjV63+6stE= X-Google-Smtp-Source: ADFU+vsjAYgasDL/1I9vLtNYDVgfGmFMyd6+l7gNOjD1nY+hBJC6z0PUPbfx5UNvQIiBBoKbKBvBpQ== X-Received: by 2002:a2e:811a:: with SMTP id d26mr2873063ljg.128.1584645173205; Thu, 19 Mar 2020 12:12:53 -0700 (PDT) Received: from nol (82-64-124-11.subs.proxad.net. [82.64.124.11]) by smtp.gmail.com with ESMTPSA id l17sm2355259lje.81.2020.03.19.12.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2020 12:12:52 -0700 (PDT) Date: Thu, 19 Mar 2020 20:12:47 +0100 From: Julien Rouhaud To: Michael Paquier Cc: Thomas Munro , Peter Eisentraut , Robert Haas , Laurenz Albe , Douglas Doole , Christoph Berg , Pg Hackers Subject: Re: Collation versioning Message-ID: <20200319191247.GA15412@nol> References: <20200312140026.GA1689@nol> <20200316075738.GE2331@paquier.xyz> <20200316140520.GA21497@nol> <20200317063749.GF2206@paquier.xyz> <20200317071928.psjiklzvkgqpl3dd@nol> <20200317104234.GA89737@nol> <20200318075525.GK214947@paquier.xyz> <20200318085635.GC58497@nol> <20200318153543.GA90891@nol> <20200319033154.GR214947@paquier.xyz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200319033154.GR214947@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Mar 19, 2020 at 12:31:54PM +0900, Michael Paquier wrote: > On Wed, Mar 18, 2020 at 04:35:43PM +0100, Julien Rouhaud wrote: > > On Wed, Mar 18, 2020 at 09:56:40AM +0100, Julien Rouhaud wrote: > > AFAICT it was only missing a call to index_update_collation_versions() in > > ReindexRelationConcurrently. I added regression tests to make sure that > > REINDEX, REINDEX [INDEX|TABLE] CONCURRENTLY and VACUUM FULL are doing what's > > expected. > > If you add a call to index_update_collation_versions(), the old and > invalid index will use the same refobjversion as the new index, which > is the latest collation version of the system, no? If the operation > is interrupted before the invalid index is dropped, then we would keep > a confusing value for refobjversion, because the old invalid index > does not rely on the new collation version, but on the old one. > Hence, it seems to me that it would be correct to have the old invalid > index either use an empty version string to say "we don't know" > because the index is invalid anyway, or keep a reference to the old > collation version intact. I think that the latter is much more useful > for debugging issues when upgrading a subset of indexes if the > operation is interrupted for a reason or another. Indeed, I confused the _ccold and _ccnew indexes. So, the root cause is phase 4, more precisely the dependency swap in index_concurrently_swap. A possible fix would be to teach changeDependenciesOf() to preserve the dependency version. It'd be quite bit costly as this would mean an extra index search for each dependency row found. We could probably skip the lookup if the row have a NULL recorded version, as version should either be null or non null for both objects. I'm wondering if that's a good time to make changeDependenciesOf and changeDependenciesOn private, and instead expose a swapDependencies(classid, obj1, obj2) that would call both, as preserving the version doesn't really makes sense outside a switch. It's als oa good way to ensure that no CCI is performed in the middle. > > Given discussion in nearby threads, I obviously can't add tests for failed > > REINDEX CONCURRENTLY, so here's what's happening with a manual repro: > > > > =# UPDATE pg_depend SET refobjversion = 'meh' WHERE refobjversion = '153.97'; > > UPDATE 1 > > Updates to catalogs are not an existing practice in the core > regression tests, so patches had better not do that. :p I already heavily relied on that in the previous version of the patchset. The only possible alternative would be to switch to TAP tests, and constantly restart the instance in binary upgrade mode to be able to call binary_upgrade_set_index_coll_version. I'd prefer to avoid that if that's possible, as it'll make the test way more complex and quite unreadable. > > =# REINDEX TABLE CONCURRENTLY t1 ; > > LOCATION: ReindexRelationConcurrently, indexcmds.c:2839 > > ^CCancel request sent > > ERROR: 57014: canceling statement due to user request > > LOCATION: ProcessInterrupts, postgres.c:3171 > > I guess that you used a second session here beginning a transaction > before REINDEX CONCURRENTLY ran here so as it would stop after > swapping dependencies, right? Yes, sorry for eluding that. I'm using a SELECT FOR UPDATE, same scenario as the recent issue with TOAST tables with REINDEX CONCURRENTLY.