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 1r3fwK-0053Si-42 for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Nov 2023 17:14:04 +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 1r3fwI-007rrV-MD for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Nov 2023 17:14:02 +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 1r3fwI-007rrL-Cj for pgsql-hackers@lists.postgresql.org; Thu, 16 Nov 2023 17:14:02 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r3fwF-005tAJ-KN for pgsql-hackers@postgresql.org; Thu, 16 Nov 2023 17:14:01 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-9e28724ac88so148999966b.2 for ; Thu, 16 Nov 2023 09:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700154838; x=1700759638; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xT/0KOp5j/92utG+Sqng86hQrBXY0mRCpxmWPm42I/w=; b=NEI2wwWnUmhx3Nr2bcLtws6d7wGBHAPedzVNYv57+WphrLhjyn2IXt+Dl0Gx0fJdW3 qK4VHgCMtqNuMnp+QnPKZ03nVeUkBwyZvgcFxU4c23b2I5gGguICqNWDTkHfu65q7jOh vQS/+RXDqrU8v7YPKZjj7/7mHVUoJ9Pv0BQFaYpHTHhRd3hxRoj/MEhyS000bHacoEce 9Ej724b+3fMtSKTYtAzwHlwZohsLHAYAOcl+B22KMHnlsTnqjKZama3fBOdAr6ha8Dcn 9aODVl7PrGDpdSIm3LifE7GE6TYSCnEn+9QPQCoYUFZsCkPGR5h/vhGCXWN9ez5PTiLQ 80ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700154838; x=1700759638; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xT/0KOp5j/92utG+Sqng86hQrBXY0mRCpxmWPm42I/w=; b=p2NXjrXb/sWBPS3WMy1Xz6VVMziFE1lH/zXQD0pfn+56+uAIdly2V5KoXerEX/oSvD F5FvJAxe4DG3hCpKSbnT7/EfFQmBcSDBzunYNoQAjG7rvkP14fVkSeKYH2FHbOVjI98h OxhdHpNxm5FDUdnccNaWR0t1EXkSTPJNpZTg7GXvb58T3zVxOlDx0gVcacT9bg4fNhh6 +PpfKvnp5vzGE2wfxDvkry5P4jiiBI70tGFCl1/0J5J6/3IjLdBXucB7FnyZPaProg/H 1vs8rOlJE5QKVCl9Pz6xB/Hl4xspzN2jisDVG7gHF2uBaZ40piMv3Ve8913c+6SIAo7c HZFQ== X-Gm-Message-State: AOJu0Yxmix3Hj1LoKgi9eJcRPueyFtAKpZwfGprmScj6cnxl7nbWKCnf g9kAjaWSCA5WIRSWVoG6Zr5V8m+1ouoXPwupUTM= X-Google-Smtp-Source: AGHT+IGNXmNJf22VvLl6IW7VG1MiOtivXvxUv/+GPkNlJh09+oRMIlCihw1K3wL1O8YtnJsZbI1Dn1TLGTHrqQGMpS8= X-Received: by 2002:a17:906:24d9:b0:9d3:ccf0:7617 with SMTP id f25-20020a17090624d900b009d3ccf07617mr9866974ejb.44.1700154838022; Thu, 16 Nov 2023 09:13:58 -0800 (PST) MIME-Version: 1.0 References: <202311141312.u4qx5gtpvfq3@alvherre.pgsql> In-Reply-To: <202311141312.u4qx5gtpvfq3@alvherre.pgsql> From: Robert Haas Date: Thu, 16 Nov 2023 12:13:44 -0500 Message-ID: Subject: Re: trying again to get incremental backup To: Alvaro Herrera Cc: Andres Freund , Peter Eisentraut , Dilip Kumar , "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Nov 14, 2023 at 8:12=E2=80=AFAM Alvaro Herrera wrote: > 0001 looks OK to push, and since it stands on its own I would get it out > of the way soon rather than waiting for the rest of the series to be > further reviewed. All right, done. > 0003: > AmWalSummarizerProcess() is unused. Remove? The intent seems to be to have one of these per enum value, whether it gets used or not. Some of the others aren't used, either. > MaybeWalSummarizer() is called on each ServerLoop() in postmaster.c? > This causes a function call to be emitted every time through. That > looks odd. All other process starts have some triggering condition. I'm not sure how much this matters, really. I would expect that the function call overhead here wouldn't be very noticeable. Generally I think that when ServerLoop returns from WaitEventSetWait it's going to be because we need to fork a process. That's pretty expensive compared to a function call. If we can iterate through this loop lots of times without doing any real work then it might matter, but I feel like that's probably not the case, and probably something we would want to fix if it were the case. Now, I could nevertheless move some of the triggering conditions in MaybeStartWalSummarizer(), but moving, say, just the summarize_wal condition wouldn't be enough to avoid having MaybeStartWalSummarizer() called repeatedly when there was no work to do, because summarize_wal could be true and the summarizer could all be running. Similarly, if I move just the WalSummarizerPID =3D=3D 0 condition, the function gets called repeatedly without doing anything when summarize_wal =3D off. So at a minimum you have to move both of those if you care about avoiding the function call overhead, and then you have to wonder if you care about the corner cases where the function would be called repeatedly for no gain even then. Another approach would be to make the function static inline rather than just static. Or we could delete the whole function and just duplicate the logic it contains at both call sites. Personally I'm inclined to just leave it how it is in the absence of some evidence that there's a real problem here. It's nice to have all the triggering conditions in one place with nothing duplicated. > GetOldestUnsummarizedLSN uses while(true), but WaitForWalSummarization > and SummarizeWAL use while(1). Maybe settle on one style? OK. > 0004: > in PrepareForIncrementalBackup(), the logic that determines > earliest_wal_range_tli and latest_wal_range_tli looks pretty weird. I > think it works fine if there's a single timeline, but not otherwise. > Or maybe the trick is that it relies on timelines returned by > readTimeLineHistory being sorted backwards? If so, maybe add a comment > about that somewhere; I don't think other callers of readTimeLineHistory > make that assumption. It does indeed rely on that assumption, and the comment at the top of the for (i =3D 0; i < num_wal_ranges; ++i) loop explains that. Note also the comment just below that begins "If we found this TLI in the server's history". I agree with you that this logic looks strange, and it's possible that there's some better way to do encode the idea than what I've done here, but I think it might be just that the particular calculation we're trying to do here is strange. It's almost easier to understand the logic if you start by reading the sanity checks ("manifest requires WAL from initial timeline %u starting at %X/%X, but that timeline begins at %X/%X" et. al.), look at the triggering conditions for those, and then work upward to see how earliest/latest_wal_range_tli get set, and then look up from there to see how saw_earliest/latest_wal_range_tli are used in computing those values. We do rely on the ordering assumption elsewhere. For example, in XLogFileReadAnyTLI, see if (tli < curFileTLI) break. We also use it to set expectedTLEs, which is documented to have this property. And AddWALInfoToBackupManifest relies on it too; see the comment "Because the timeline history file lists newer timelines before older ones" in AddWALInfoToBackupManifest. We're not entirely consistent about this, e.g., unlike XLogFileReadAnyTLI, tliInHistory() and tliOfPointInHistory() don't have an early exit provision, but we do use it some places. -- Robert Haas EDB: http://www.enterprisedb.com