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 1ty0Ii-0011mb-ER for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Mar 2025 03:22:32 +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 1ty0Ig-001REZ-QO for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Mar 2025 03:22:30 +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 1ty0Ig-001RER-4n for pgsql-hackers@lists.postgresql.org; Fri, 28 Mar 2025 03:22:30 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1ty0Id-001Y19-2M for pgsql-hackers@postgresql.org; Fri, 28 Mar 2025 03:22:28 +0000 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2264aefc45dso47157105ad.0 for ; Thu, 27 Mar 2025 20:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1743132147; x=1743736947; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=S50np1Q9og6WyO5F06VDBMh0djHvzvUt4ZhGMVwrkTo=; b=SuMzijLKsrF239qbBdS33h/Bf0QT45EfQFfqp3WtePRjQUeWYaYenOKU0ZptIibbz7 3MT6kn0oc87wxQ5AvHvek9SxtPqMRb8CPf6LO47DXHMvyovoOTcNS3gWx/wlAFpc8DRt ArWPOQGxIa0/5wuE2Er66urLRMrCz76+WTVdo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743132147; x=1743736947; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S50np1Q9og6WyO5F06VDBMh0djHvzvUt4ZhGMVwrkTo=; b=W6e2AORGgDGnfe9Mu6L1HFFjdYBxKadLoZqQI/5qIiioLoJ7xbGVlOOj0p7v4K/N8P 5r45BBq+euDGr/vBwm9Cgk/Pw5yc5NcBmE1WDQk3IQ/DyI4q+VzlZ0M6KIhjkrWvFIlC lbwUnUqRQf0KPLKFjT8bI/B+R16UEciuBbdLt1msodT12jD1Qj64pbadnKyzaXEHNjs0 UUcCajdKO9uoOGlGq+wLRoC/zLC+buOh1MRlOWb/DLK2AHuLp/gnsXIuaeHna877Yp8a 6CeCP7IRyyiafTo3oHvGamYuidTmZqdEnTVrIbYlydJIMf56nBq6F5MEJtimUGGBm6V2 U7iQ== X-Gm-Message-State: AOJu0YwYtCa/b6cuMHdagf0XWyWQwywsslJiuvoSirQFDkWTGnbMfQaN d+8ueH98OhMSa9uuQfnw5JiuoRUGCySo9Mrwn+8dvkTe9hXxiNv8tHlhb32RaQ== X-Gm-Gg: ASbGnctN/LcFvP/P7rgaWjQkMVAvwn/IZ3yeWlj/tu3DAv8p4s3Y+6niAKxh9xwrLiG 4dJNQm28I8sDAkz+4gYi8GmTdu5JBe0zBoO4D6aSELk+a/9wD+wSurkpghiq4KjLDYMYEOEFL4s QOqFfmjST6XvVvzvVR6gCmcTSynY+P7sf3PQIkizoKvktF59mvzc3JV8jXAtONpD/Vw9Afv12EE 3Gzl0IAfEJyXRleKZ3WbumjmCFivNCDL+HtVCf+4lvMg2GVBttTX7EF4Tx6qs1hCvxcl5un6uar G/KSMSXf05iavwqV9xwvdzZNAU+BzHxeSQlq8h87iIjx0kFw/m6C X-Google-Smtp-Source: AGHT+IESjv4mfst1oKxkBaqQUmwKYdBbDg5B4ENqMsYVdTupgYhAL1oOAdNWpOAH3aNV+shEC7Dxuw== X-Received: by 2002:a05:6a00:1904:b0:736:ab21:8a69 with SMTP id d2e1a72fcca58-73960cc502bmr8478346b3a.0.1743132146489; Thu, 27 Mar 2025 20:22:26 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73970e2233asm651996b3a.43.2025.03.27.20.22.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Mar 2025 20:22:25 -0700 (PDT) Date: Thu, 27 Mar 2025 20:22:23 -0700 From: Noah Misch To: Andres Freund Cc: pgsql-hackers@postgresql.org, Thomas Munro , Heikki Linnakangas , Robert Haas , Jakub Wartak , Jelte Fennema-Nio , Antonin Houska Subject: Re: AIO v2.5 Message-ID: <20250328032223.34.nmisch@google.com> References: <4b3f32ug3cayekysqlgspz2qjmeb7lca3gvazayglxr2m3d4dv@il33accgsji7> <17906.1741863183@localhost> <3yxd5r23zly5bytvgyktbxtxq2r3gbpi7xd4dugevh3h4w4q6c@lu6oatjjpltz> <6ak556uyqiptdwjaci4kbi5eykwkmzqgkbtkyaosjnopjhncrc@2v4ac2jwyz22> <5tyic6epvdlmd6eddgelv47syg2b5cpwffjam54axp25xyq2ga@ptwkinxqo3az> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5tyic6epvdlmd6eddgelv47syg2b5cpwffjam54axp25xyq2ga@ptwkinxqo3az> 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 On Thu, Mar 27, 2025 at 04:58:11PM -0400, Andres Freund wrote: > I now wrote some tests. And I both regret doing so (because it found problems, > which would have been apparent long ago, if the feature had come with *any* > tests, if I had gone the same way I could have just pushed stuff) and am glad > I did (because I dislike pushing broken stuff). > > I have to admit, I was tempted to just ignore this issue and just not say > anything about tests for checksum failures anymore. I don't blame you. > 3) We can't pgstat_report_checksum_failure() during the completion callback, > as it *sometimes* allocates memory > > Aside from the allocation-in-critical-section asserts, I think this is > *extremely* unlikely to actually cause a problem in practice. But we don't > want to rely on that, obviously. > Addressing 3) is not at all trivial. Here's what I've thought of so far: > > > Approach I) > Unfortunately that fails because to access the shared memory with the stats > data we need to do dsa_get_address() > Approach II) > > Don't report the error in the completion callback. The obvious place would be > to do it where we we'll raise the warning/error in the issuing process. The > big disadvantage is that that that could lead to under-counting checksum > errors: > > a) A read stream does 2+ concurrent reads for the same relation, and more than > one encounters checksum errors. When processing the results for the first > failed read, we raise an error and thus won't process the results of the > second+ reads with errors. > > b) A read is started asynchronously, but before the backend gets around to > processing the result of the IO, it errors out during that other work > (possibly due to a cancellation). Because the backend never looked at the > results of the IOs, the checksum errors don't get accounted for. > > b) doesn't overly bother me, but a) seems problematic. While neither are great, I could live with both. I guess I'm optimistic that clusters experiencing checksum failures won't lose enough reports to these loss sources to make the difference in whether monitoring catches them. In other words, a cluster will report N failures without these losses and N-K after these losses. If N is large enough for relevant monitoring to flag the cluster appropriately, N-K will also be large enough. > Approach III) > > Accumulate checksum errors in two backend local variables (one for database > specific errors, one for errors on shared relations), which will be flushed by > the backend that issued IO during the next pgstat_report_start(). > > Two disadvantages: > > - Accumulation of errors will be delayed until the next > pgstat_report_start(). That seems acceptable, after all we do so far a lot > of other stats. Yep, acceptable. > - We need to register a local callback for shared buffer reads, which don't > need them today . That's a small bit of added overhead. It's a shame to do > so for counters that approximately never get incremented. Fair concern. An idea is to let the complete_shared callback change the callback list associated with the IO, so it could change PGAIO_HCB_SHARED_BUFFER_READV to PGAIO_HCB_SHARED_BUFFER_READV_SLOW. The latter would differ from the former only in having the extra local callback. Could that help? I think the only overhead is using more PGAIO_HCB numbers. We currently reserve 256 (uint8), but one could imagine trying to pack into fewer bits. That said, this wouldn't paint us into a corner. We could change the approach later. pgaio_io_call_complete_local() starts a critical section. Is that a problem for this approach? > Approach IV): > > Embracy piercing abstractions / generic infrastructure and put two atomic > variables (one for shared one for the backend's database) in some > backend-specific shared memory (e.g. the backend's PgAioBackend or PGPROC) and > update that in the completion callback. Flush that variable to the shared > stats in pgstat_report_start() or such. I could live with that. I feel better about Approach III currently, though. Overall, I'm feeling best about III long-term, but II may be the right tactical choice. > Does anybody have better ideas? I think no, but here are some ideas I tossed around: - Like your Approach III, but have the completing process store the count locally and flush it, instead of the staging process doing so. Would need more than 2 slots, but we could have a fixed number of slots and just discard any reports that arrive with all slots full. Reporting checksum failures in, say, 8 databases in quick succession probably tells the DBA there's "enough corruption to start worrying". Missing the 9th database would be okay. - Pre-warm the memory allocations and DSAs we could possibly need, so we can report those stats in critical sections, from the completing process. Bad since there's an entry per database, hence no reasonable limit on how much memory a process might need to pre-warm. We could even end up completing an IO for a database that didn't exist on entry to our critical section. - Skip the checksum pgstats if we're completing in a critical section. Doesn't work since we _always_ make a critical section to complete I/O. This email isn't as well-baked as I like, but the alternative was delaying it 24-48h depending on how other duties go over those hours. My v2.13 review is still in-progress, too.