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 1mFUwG-0000UR-VF for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Aug 2021 05:13:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mFUwF-0005Vn-Pu for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Aug 2021 05:13:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mFUwF-0005Vf-C5 for pgsql-bugs@lists.postgresql.org; Mon, 16 Aug 2021 05:13:31 +0000 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mFUwA-0003hT-HM for pgsql-bugs@lists.postgresql.org; Mon, 16 Aug 2021 05:13:30 +0000 Received: by mail-qt1-x82d.google.com with SMTP id x5so4843924qtq.13 for ; Sun, 15 Aug 2021 22:13:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=G2GXiRpwdPSoSrDMspL0jaJNLw9V2aCx1qJeb8LmRf0=; b=P3BNXC663KISjSZTOa9I6GphlEEEgZBTjRK3EN+cv7vnc/Kc9MNHzwZr2wNnPD3nsq JhAd/Dhy/8vwEkWmGqXidaB345drviRgXG1yts1R/VjTmyGHnxpinj2ZGBV3JInlaSX6 AUzkWyaFkIQXxFLe43Lh9EpVZAMNh3eSSgTIM= 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:content-transfer-encoding :in-reply-to:user-agent; bh=G2GXiRpwdPSoSrDMspL0jaJNLw9V2aCx1qJeb8LmRf0=; b=fCfJ8WlxjHyZAfA73kXppUzsVBhOICELFFxYsXe3hzXR59ABAMTOf5d15lj900oms3 B0AiJwRjofXItVRlwbUsexJKyjNQhhV/mwyyjFKFburOfImrk8LZvvyj6XxRP1N+m1im GEHJweMU9D1GnS+YQxIC4KYr08eHKxFs2zdmtLgS6VOUPHTGBS9YGslfBBaAQNTk5drn KdJO/M/h9zmi518suiunonaRzjLnIWYa2V1olHgU/hJP49Qp5mG9+9Ym5OQt6UNMMves d5EoNYmlaGJcgyI/CCTclfqtPtnRQyyR0X/2qiz9/b2X1ojoZsNKbmVnCq31DqNHpfYP 73vA== X-Gm-Message-State: AOAM531e+j2BpBOV5zv/LuyLX+lHDlyHmcuGES9qN/cwGASlyTsJ7NUK bFMlqH26xTIRv2buMm0v2qYIzA== X-Google-Smtp-Source: ABdhPJyBwCOsCdhECQdySRXAr/oy5a8XK3CKGy++pleGv+yRQ2MQHCQYlpqdAQ2fntV79Isqk/Wigw== X-Received: by 2002:a05:622a:174e:: with SMTP id l14mr12364393qtk.26.1629090804441; Sun, 15 Aug 2021 22:13:24 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::46]) by smtp.gmail.com with ESMTPSA id n19sm3841798qtx.37.2021.08.15.22.13.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Aug 2021 22:13:20 -0700 (PDT) Date: Sun, 15 Aug 2021 22:13:17 -0700 From: Noah Misch To: Andrey Borodin Cc: PostgreSQL mailing lists , Michael Paquier , Tom Lane , Peter Geoghegan Subject: Re: CREATE INDEX CONCURRENTLY does not index prepared xact's data Message-ID: <20210816051317.GA1409586@rfd.leadboat.com> References: <85D32B53-FB25-4F2F-A253-0D7B26F72881@yandex-team.ru> <341252AE-B633-471E-9FF4-B09FC5D036E2@yandex-team.ru> <20210807221957.GA169359@rfd.leadboat.com> <5E041A70-4946-489C-9B6D-764DF627A92D@yandex-team.ru> <20210808163752.GB23176@rfd.leadboat.com> <20210814221328.GA146778@rfd.leadboat.com> <20210815084535.GA1227376@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --DocE+STaALJfprDB Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Aug 15, 2021 at 04:09:37PM +0500, Andrey Borodin wrote: > > 15 авг. 2021 г., в 13:45, Noah Misch написал(а): > >> Do you see failures with that loop? If so, can you diagnose them? > I do not observe failure on my laptop, though reproduced it on a linux server. > I've fixed one bug in TwoPhaseGetXidByVXid(). Also rebased on actual master. > > Just one 1PC failure in six hours of 1PC test runtime, though. > I've attached a patch that reproduces the problem in 30sec on my server. Having studied the broader inval situation, I found just one additional gap that seemed potentially relevant. It didn't stop the failures under current tests, however. The attached patch replaces my last patch on this thread, so it should replace v12-0002-PoC-fix-for-race-in-RelationBuildDesc-and-relcac.patch in your series. (Like its predecessor, it's an unfinished proof-of-concept.) With v12, on my machine, the same loop took 2000s to get three failures, both of which were in the 1PC tests. I ran out of time to study the failure mechanism. Would you diagnose what happens when it fails on your server? Also see the larger review from Andres. --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="inval-build-race-v0.1.patch" Author: Noah Misch Commit: Noah Misch diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 13d9994..da6d8d6 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -997,9 +997,16 @@ equalRSDesc(RowSecurityDesc *rsdesc1, RowSecurityDesc *rsdesc2) * (suggesting we are trying to access a just-deleted relation). * Any other error is reported via elog. */ +typedef struct InProgressRels { + Oid relid; + bool invalidated; +} InProgressRels; +static InProgressRels inProgress[100]; + static Relation RelationBuildDesc(Oid targetRelId, bool insertIt) { + int in_progress_offset; Relation relation; Oid relid; HeapTuple pg_class_tuple; @@ -1033,6 +1040,14 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) } #endif + for (in_progress_offset = 0; + OidIsValid(inProgress[in_progress_offset].relid); + in_progress_offset++) + ; + inProgress[in_progress_offset].relid = targetRelId; +retry: + inProgress[in_progress_offset].invalidated = false; + /* * find the tuple in pg_class corresponding to the given relation id */ @@ -1213,6 +1228,10 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) */ heap_freetuple(pg_class_tuple); + if (inProgress[in_progress_offset].invalidated) + goto retry; /* TODO free old one */ + inProgress[in_progress_offset].relid = InvalidOid; + /* * Insert newly created relation into relcache hash table, if requested. * @@ -2805,6 +2824,13 @@ RelationCacheInvalidateEntry(Oid relationId) relcacheInvalsReceived++; RelationFlushRelation(relation); } + else + { + int i; + for (i = 0; OidIsValid(inProgress[i].relid); i++) + if (inProgress[i].relid == relationId) + inProgress[i].invalidated = true; + } } /* @@ -2845,6 +2871,7 @@ RelationCacheInvalidate(void) List *rebuildFirstList = NIL; List *rebuildList = NIL; ListCell *l; + int i; /* * Reload relation mapping data before starting to reconstruct cache. @@ -2931,6 +2958,10 @@ RelationCacheInvalidate(void) RelationClearRelation(relation, true); } list_free(rebuildList); + + /* Any RelationBuildDesc() on the stack must start over. */ + for (i = 0; OidIsValid(inProgress[i].relid); i++) + inProgress[i].invalidated = true; } /* --DocE+STaALJfprDB--