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 1t25Jn-001ohV-Tf for pgsql-bugs@arkaria.postgresql.org; Sat, 19 Oct 2024 09:00:16 +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 1t25Jk-000ALL-Gs for pgsql-bugs@arkaria.postgresql.org; Sat, 19 Oct 2024 09:00:12 +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 1t25Jk-000ALC-0Q for pgsql-bugs@lists.postgresql.org; Sat, 19 Oct 2024 09:00:12 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t25Jd-001fx9-Jd for pgsql-bugs@lists.postgresql.org; Sat, 19 Oct 2024 09:00:11 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2fb50e84ec7so23861591fa.1 for ; Sat, 19 Oct 2024 02:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729328403; x=1729933203; darn=lists.postgresql.org; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=MeysOnSSbmdJlwUXH/usxtncpglauJMeICzaRG5dlXI=; b=V6EvEQVXo3cKs40YnI5V8DWBLUw1Jvn6zAWd8ZG94uWdBnU6DtIbfLNKP5wLuRHIP/ sM66AYVKw9Ngn7Ej+68brrQ5TvCa7eb04t6xGP5zRkjSaGuo8v/iT4URCMH/jfYUEuFD 02JUv+uDkm+XvP3ecXbDWds3qHnJkSuyyLYDsKWORXjyQtDEnfDCmd5z2lOH3N+U5CZW T06pqKsvFbXh3l15MceocjQVE+CcJQQVnapDbHjQNQQD4OFUy9QFVN8zhL6WMCQp7R+O oKAifg0356jC4J4O4NQkZLbN5sJNAf6FQptuW930VKia2onigwEJC9NW8o5K+l201I0n yY/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729328403; x=1729933203; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=MeysOnSSbmdJlwUXH/usxtncpglauJMeICzaRG5dlXI=; b=VoQTsIJuYnhCfnF2bgJWPBu5Np/kujkzQW/waw3TdXy6bINJMbInnqeXSHgC/fUD82 turha2CdCZ+YRJJLMzexYpGic3OWf8tdf4uH3UgmmTty2HvbbUL9BpzVD9k8agPh+jsS 7VIhxDy3bN5PA4/E8/KqZKqODQcAhBU7rSJNIPbSfRwTmBLdYuQXZewU3o4oDuse56An +koivV+MfuFWQ2UiuJoAisz7GVgvXm+euthWA4i5xA9j59U2hJRforSlP/6fZcvpqi27 Iqkb8FYoBN/prCZQzFhR0MfCVqay1Ol7SwcpGSMFGnfe44YoVCeDuTRKDCpPhNmL9gNn +5iA== X-Forwarded-Encrypted: i=1; AJvYcCUpilys6iB2+jk+rEyvrHZVOVcckLgFdhsepy5yK4DN6J/8fd04wntd8EXcx5g1Gz3RFKNe/XjCeEEB@lists.postgresql.org X-Gm-Message-State: AOJu0Yyc0zkIK6WxRQao2/b+Cdjl/oMJ1yJUQGPxLNdNUeqR83sP4Kf2 Zv0l1GCkX2OdPmeTxSZyNKZhh6HPTBS83OzaTThKi8Ni+XpkRUee X-Google-Smtp-Source: AGHT+IHlyrxkf0cgGX663syda/tLKjCu83HEdFICS+9UUDdUy2h2d7YRjFkHQsr1mnDXu3DNtbySCw== X-Received: by 2002:a2e:4a0a:0:b0:2fb:5d41:bdac with SMTP id 38308e7fff4ca-2fb82e93cbfmr24087441fa.1.1729328402776; Sat, 19 Oct 2024 02:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.17.174]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2fb80a08e0asm4653061fa.115.2024.10.19.02.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 19 Oct 2024 02:00:01 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------UhmG3J3wLajvwy02CTT5kbGD" Message-ID: Date: Sat, 19 Oct 2024 12:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #18658: Assert in SerialAdd() due to race condition Content-Language: en-US To: Heikki Linnakangas , Andrew Bille , pgsql-bugs@lists.postgresql.org References: <18658-7dab125ec688c70b@postgresql.org> <5634e3e1-6e82-b883-ac87-52d7e926a04d@gmail.com> From: Alexander Lakhin In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------UhmG3J3wLajvwy02CTT5kbGD Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Heikki, 18.10.2024 23:15, Heikki Linnakangas wrote: > > Thanks for the repro, Andrew & Alexander! I was able to reproduce this too. It reproduces very quickly with the script > you provided, if you add this sleep to ReleasePredicateLocks(): > > @@ -3654,6 +3667,8 @@ ReleasePredicateLocks(bool isCommit, bool isReadOnlySafe) > >      LWLockRelease(SerializableFinishedListLock); > > +    pg_usleep(1000); > + >      if (needToClear) >          ClearOldPredicateLocks(); > > I think the assertion is too strict. It is normal for tailXid to be invalid in this scenario. The condition is that an > XID was added to the finished list, but the global xmin has already advanced past that XID. It gets cleared from the > finished list by the ClearOldPredicateLocks() call, but another backend might call SummarizeOldestCommittedSxact() > before that. > > The attached patch fixes it. > Thank you for your attention to this! I also encountered another (more rare) failure with that script (initially on REL_16_STABLE, but now I've reproduced this on master too), when it fails due to ENOSPC. (I could reproduce the failure more or less reliably by running that script with parallel -j4 using 4 different servers.) With additional logging added (see attached), I see the following: 2024-10-19 07:34:48.254 UTC [3032898:1][client backend][48/278:0] LOG:  !!!SerialAdd| xid: 19957, serialControl->headPage: 4294967295, tailXid: 20491, SERIAL_ENTRIESPERPAGE: 1024, firstZeroPage: 20, targetPage: 19, isNewPage: 1 2024-10-19 07:34:48.254 UTC [3032898:2][client backend][48/278:0] STATEMENT:  INSERT INTO t VALUES(42); 2024-10-19 07:34:48.254 UTC [3032898:3][client backend][48/278:0] LOG:  !!!SerialAdd: isNewPage, firstZeroPage: 20, targetPage: 19 2024-10-19 07:34:48.254 UTC [3032898:4][client backend][48/278:0] STATEMENT:  INSERT INTO t VALUES(42); 2024-10-19 07:35:05.105 UTC [3032898:5][client backend][48/278:0] ERROR:  could not access status of transaction 0 2024-10-19 07:35:05.105 UTC [3032898:6][client backend][48/278:0] DETAIL:  Could not write to file "pg_serial/11FB3" at offset 8192: No space left on device. That is, if SerialAdd() gets xid preceding tailXid and belonging to a preceding page, the page zeroing loop just runs until ENOSPC. Your proposed fix (adjusted for REL_16_STABLE) eliminates the issue for me. Thank you! Best regards, Alexander --------------UhmG3J3wLajvwy02CTT5kbGD Content-Type: text/x-patch; charset=UTF-8; name="SerialAdd-debugging.patch" Content-Disposition: attachment; filename="SerialAdd-debugging.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3N0b3JhZ2UvbG1nci9wcmVkaWNhdGUuYyBiL3Ny Yy9iYWNrZW5kL3N0b3JhZ2UvbG1nci9wcmVkaWNhdGUuYwppbmRleCAxYWY0MTIxM2I0Li40 ZjdjMTU5NzhhIDEwMDY0NAotLS0gYS9zcmMvYmFja2VuZC9zdG9yYWdlL2xtZ3IvcHJlZGlj YXRlLmMKKysrIGIvc3JjL2JhY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