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 1mnbTv-00043K-Fi for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Nov 2021 07:05:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mnbTu-00084c-EH for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Nov 2021 07:05:14 +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 1mnbTt-00084R-TZ for pgsql-hackers@lists.postgresql.org; Thu, 18 Nov 2021 07:05:14 +0000 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mnbTr-0000NG-MB for pgsql-hackers@postgresql.org; Thu, 18 Nov 2021 07:05:13 +0000 Received: by mail-qt1-x82f.google.com with SMTP id 8so5176984qtx.5 for ; Wed, 17 Nov 2021 23:05:11 -0800 (PST) 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:in-reply-to:user-agent; bh=g/9XFhkqzI6x8tzRY8CsntJPStj2RtfonFoJ2jCP/Bw=; b=f9UnW+QVfcW96iIjxwBiUPf190tikDOTsQ/IZBTXEPmvNvGn+IofQoKNgevrnGtABf xFdT/wQg5Gof789SMDDExz9ybnYyTzFZKzDe+UpQMVLAUh8AiEkMteK+MvOAh2tir54M +qReSg4D2MbZmDJQTsdLYzxO+b38vcDcZt5B8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=g/9XFhkqzI6x8tzRY8CsntJPStj2RtfonFoJ2jCP/Bw=; b=uxI37bn/huHjq/qFVlFIXKTMFaT5ls5tjUT2arUf3HE1O9hpK/JbJXMQ/v05DZPck9 DCZSKRhjonwGVv4hiCGhZBZgg7mbDHraArUlY4keaMxH9dUYC2db7jSFJ9wn3pbBlNRF iI0Xj3mpvOIO1Q6So4/ido/2zxZj9G+no/PqUq3EdHdCH3KCPeFH2q87pBWevw+bInXq 1HZxONHFuLuN2JpJDycgHrewNpTo12Sp4AmmMh+GPxHyB1e6nR72qUr743/z46W52ulU UxfIE6clfCLbAD+Z+i6zlD180cfX9P/rj8G51VbShUVnYCUvcKhMXoS8IjGubgGm8c2f HnLQ== X-Gm-Message-State: AOAM5307ZO7PPpoxFV3T8eeZy2soDLBbeW48zTtgMIPE0qDejqd6IyuG MhW6TKv122ImdKxTjfCpAz/rqg== X-Google-Smtp-Source: ABdhPJyZ++Fq2GkSqOL9XRELiJouRBMHfAKsHNl50sNK8RGvMDcxEiTOUsKVymekd+dyok6lsUyGJQ== X-Received: by 2002:ac8:7dd5:: with SMTP id c21mr21493353qte.176.1637219109836; Wed, 17 Nov 2021 23:05:09 -0800 (PST) Received: from rfd.leadboat.com ([2600:1702:a20:5750::46]) by smtp.gmail.com with ESMTPSA id y10sm1264722qkp.128.2021.11.17.23.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Nov 2021 23:05:09 -0800 (PST) Date: Wed, 17 Nov 2021 23:05:06 -0800 From: Noah Misch To: Tom Lane Cc: Michael Paquier , pgsql-hackers@postgresql.org Subject: Re: XLogReadRecord() error in XlogReadTwoPhaseData() Message-ID: <20211118070506.GA1294133@rfd.leadboat.com> References: <20211107013157.GB790288@rfd.leadboat.com> <20211112012234.GA1020314@rfd.leadboat.com> <2782601.1637189230@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2782601.1637189230@sss.pgh.pa.us> 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 On Wed, Nov 17, 2021 at 05:47:10PM -0500, Tom Lane wrote: > Noah Misch writes: > > Each of the three failures happened on a sparc64 Debian+gcc machine. I had > > tried ~8000 iterations on thorntail, another sparc64 Debian+gcc animal, > > without reproducing this. > # 'pgbench: error: client 0 script 1 aborted in command 4 query 0: ERROR: could not read two-phase state from WAL at 0/159EF88: unexpected pageaddr 0/0 in log segment 000000010000000000000001, offset 5890048 > [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=tadarida&dt=2021-11-17%2013%3A01%3A24 Two others: ERROR: could not read two-phase state from WAL at 0/16F1850: invalid record length at 0/16F1850: wanted 24, got 0 -- https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=tadarida&dt=2021-11-12%2013%3A01%3A15 ERROR: could not read two-phase state from WAL at 0/1668020: incorrect resource manager data checksum in record at 0/1668020 -- https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=kittiwake&dt=2021-11-16%2015%3A00%3A52 > I suppose "unexpected pageaddr 0/0" is most easily explained by supposing > that XlogReadTwoPhaseData tried to read a WAL page that hadn't been > written out yet. Have we got any synchronization around that? If the WAL address isn't on disk, that error doesn't happen. Instead, read_local_xlog_page() blocks waiting for the WAL to become available. It's still possible that we make the WAL region exist, but it somehow doesn't contain the right data until shortly later. FinishPreparedTransaction() takes TwoPhaseStateLock and looks for an entry having gxact->valid. EndPrepare() fills gxact->prepare_end_lsn, then calls MarkAsPrepared() to set gxact->valid under TwoPhaseStateLock. All freelist (freeGXacts) interaction holds TwoPhaseStateLock. I'm not seeing a gap in that synchronization. I don't have a great theory, but here are candidates to examine next: - Run with wal_debug=on to confirm logged write location matches read location. - Run "PGDATA=contrib/amcheck/tmp_check/t_003_cic_2pc_CIC_2PC_test_data/pgdata pg_waldump -s 0/01000000" at the end of the test. - Dump WAL page binary image at the point of failure. - Log which branches in XLogReadRecord() are taken. What else might help?