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 1mdRbJ-0000Wi-0Z for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Oct 2021 06:30:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdRbG-00052h-Nb for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Oct 2021 06:30:50 +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 1mdRbG-00052Y-Ds for pgsql-hackers@lists.postgresql.org; Thu, 21 Oct 2021 06:30:50 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mdRbD-0007rh-PE for pgsql-hackers@lists.postgresql.org; Thu, 21 Oct 2021 06:30:49 +0000 Received: by mail-wr1-x431.google.com with SMTP id i12so255635wrb.7 for ; Wed, 20 Oct 2021 23:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; h=from:to:cc:subject:date:message-id:organization:in-reply-to :references:mime-version:content-transfer-encoding; bh=DoGI9m5ZtCALXN3xHoIiqqvRl1RBJ1BYwIWgCE4bCBA=; b=BbaoWfdP22MKLJmuFbVCmUX6qpAhZQRrMG41aVZRgN0AAhzb4IuYX6KO597aejjSS/ Rf263xDMoQizPz2CsWuSBpDGBPHypsv0Wr6ibJf3+EzSXfVjlXTNuHZHl9Tfj/5JkMv/ g7SYHX6CHRfvQHM7KZ72FXp9kn+yypTucFD+E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :in-reply-to:references:mime-version:content-transfer-encoding; bh=DoGI9m5ZtCALXN3xHoIiqqvRl1RBJ1BYwIWgCE4bCBA=; b=mdsIGW4E/v1Sje304nUClz70ECNDgf4EnKFy7e1DbGwlEyOqrtoWIMyXoLRQK0pTeM rizEpN/xTbikvH1IBQgNuvpUQiioQmlFSMDN5RO05+B4k3dLlZuP3fr9bYMpnEV+ZCur 7GskS3Q/KhheVu9x/EgoKX6CEfes8YK628dXEZ/4+8tpcMWP+o9c3OZ7RerciRaaKQNW Mg9BB3LNg94liyJ6S4PsZSiodfXlAWZH4f4pf+3chPI0DvVcXSN0mVsRk+jur5eB3pMm 8/C8BIxkkJN5xMWbqzdnDp1lyu5rCnTZOpHTxrOVPAtSO4czqBE9p3hDjY3IzBheA1tv 512Q== X-Gm-Message-State: AOAM5330QTGmBz0kHdZI00PTF8yXsi5Za9qjAJAe9c18Yz3Ei0AZi97r wT/CKlVvvX57dtDPvXakLSmX4+h4a5XJ+A== X-Google-Smtp-Source: ABdhPJw3wz6rTaJVgFzvMALJZGBCsgHIOpZLVF8Eq+TYwtBHtTFtNmUnJrS2vnjuj3lkUgoY0M2jTQ== X-Received: by 2002:a05:6000:1449:: with SMTP id v9mr4694452wrx.433.1634797846165; Wed, 20 Oct 2021 23:30:46 -0700 (PDT) Received: from aivenronan.localnet (static-176-158-121-96.ftth.abo.bbox.fr. [176.158.121.96]) by smtp.gmail.com with ESMTPSA id k17sm3950624wrq.7.2021.10.20.23.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 23:30:45 -0700 (PDT) From: Ronan Dunklau To: pgsql-hackers@lists.postgresql.org Cc: Bharath Rupireddy , Kyotaro Horiguchi , PostgreSQL Hackers , Masahiko Sawada , Michael Paquier Subject: Re: pg_receivewal starting position Date: Thu, 21 Oct 2021 08:29:54 +0200 Message-ID: <5336539.LvFx2qVVIh@aivenronan> Organization: aiven In-Reply-To: References: <4755573.0VBMTVartN@aivenronan> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Le jeudi 21 octobre 2021, 07:35:08 CEST Michael Paquier a =E9crit : > On Wed, Oct 20, 2021 at 02:58:26PM +0200, Ronan Dunklau wrote: > > After sending the previous patch suite, I figured it would be worthwhile > > to > > also have tests covering timeline switches, which was not covered befor= e. >=20 > That seems independent to me. I'll take a look. >=20 > > So please find attached a new version with an additional patch for those > > tests, covering both "resume from last know archive" and "resume from > > the replication slots position" cases. >=20 > So, taking things in order, I have looked at 0003 and 0001, and > attached are refined versions for both of them. >=20 > 0003 is an existing hole in the docs, which I think we had better > address first and backpatch, taking into account that the starting > point calculation considers compressed segments when looking for > completed segments. Ok, do you want me to propose a different patch for previous versions ? >=20 > Regarding 0001, I have found the last test to check for NULL values > returned by READ_REPLICATION_SLOT after dropping the slot overlaps > with the first test, so I have removed that. I have expanded a bit > the use of like(), and there were some confusion with > PostgresNode::psql and some extra arguments (see DROP_REPLICATION_SLOT > and CREATE_REPLICATION_SLOT, and no need for return values in the > CREATE case either). Some comments, docs and code have been slightly > tweaked. Thank you for this.=20 >=20 > Here are some comments about 0002. >=20 > + /* The commpand should always return precisely one tuple */ > s/commpand/command/ >=20 > + pg_log_error("could not fetch replication slot: got %d rows and %d > fields, expected %d rows and %d or more fields", + =20 > PQntuples(res), PQnfields(res), 1, 3); > Should this be "could not read" instead? >=20 > + if (sscanf(PQgetvalue(res, 0, 1), "%X/%X", &hi, &lo) !=3D 2) > + { > + pg_log_error("could not parse slot's restart_lsn \"%s\"", > + PQgetvalue(res, 0, 1)); > + PQclear(res); > + return false; > + } > Wouldn't it be saner to initialize *restart_lsn and *restart_tli to > some default values at the top of GetSlotInformation() instead, if > they are specified by the caller? =20 Ok. > And I think that we should still > complain even if restart_lsn is NULL. Do you mean restart_lsn as the pointer argument to the function, or=20 restart_lsn as the field returned by the command ? If it's the first, I'll= =20 change it but if it's the latter it is expected that we sometime run this o= n a=20 slot where WAL has never been reserved yet. >=20 > On a quick read of 0004, I find the split of the logic with > change_timeline() a bit hard to understand. It looks like we should > be able to make a cleaner split, but I am not sure how that would > look, though. Thanks, at least if the proposal to test this seems sensible I can move=20 forward. I wanted to avoid having a lot of code duplication since the test= =20 setup is a bit more complicated.=20 My first approach was to split it into two functions, setup_standby and=20 change_timeline, but then realized that what would happen between the two=20 invocations would basically be the same for the two test cases, so I ended = up=20 with that patch. I'll try to see if I can see a better way of organizing th= at=20 code. =2D-=20 Ronan Dunklau