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 1kaF1S-0000aT-9m for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Nov 2020 09:24:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kaF1R-0004n9-7O for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Nov 2020 09:24:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaF1Q-0004n2-Sl for pgsql-hackers@lists.postgresql.org; Wed, 04 Nov 2020 09:24:05 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaF1O-0005w2-6u for pgsql-hackers@postgresql.org; Wed, 04 Nov 2020 09:24:03 +0000 Received: from [192.168.1.113] (dsl-hkibng22-54faa4-119.dhcp.inet.fi [84.250.164.119]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 7FF562024D; Wed, 4 Nov 2020 11:23:58 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1604481838; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6b+rm1PIw3fp0dzTYUPSeHTBB2hd40DWvC8BC1mbC4E=; b=f2uEHSq/x9A0CxiN5pIH3gF+Rw0BSD7aJUv31kNUrkrfnbQaXV3OoCrDGyM1i8qdP5gCUW T74unYWr0xxy8gjzA+x2ouMyZUCLjIbQ3nEEH1Ye9Ew50c7L+mQTAqPdlISSJ7m8TuTlB7 5Kp3KKYgf4rJ2muHil1PiOYCNK8Kkgw= Subject: Re: Refactor pg_rewind code and make it work against a standby To: Soumyadeep Chakraborty Cc: Kyotaro Horiguchi , pgsql-hackers References: <0c5b3783-af52-3ee5-f8fa-6e794061f70d@iki.fi> <20200820.173224.2258034742176021277.horikyota.ntt@gmail.com> <20200918.164150.1688011206252014871.horikyota.ntt@gmail.com> <4744063e-1a60-1b24-e1b7-7ace5e65f0d2@iki.fi> From: Heikki Linnakangas Message-ID: Date: Wed, 4 Nov 2020 11:23:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1604481838; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6b+rm1PIw3fp0dzTYUPSeHTBB2hd40DWvC8BC1mbC4E=; b=UAiFv2Ey2K5HdnHOm1cA7A1hNpJWeX9QeE+4+n/FI+JSjfCneqD9tB+yR+iMcL1CYHDrSd 0kALLc7V+8aTp1ArYs4zImujW32iKbtrLACMYhypxmgmgjm33Th+hU+Uq3pgniwEchiEYO EsKTZGjBMhxmPIUQo9OF9eKDZ9Ed47U= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1604481838; a=rsa-sha256; cv=none; b=ebDse29zW21d/WzWS/dKq9zx19HtFf3+87EjQ2iG6p1ZwwjPcE6GnOTUwg31S1Xa9yPIB9 o/iwEchwbypM84qtKG5ZJxdMkkBz8ZP0bXGW9xJx8kVqiLgSQv7s4DTqQQOTFOtKdsIhoz x2muhOVdhLAT/WSedWdDrx/rEFVnel8= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 25/09/2020 02:56, Soumyadeep Chakraborty wrote: > On Thu, Sep 24, 2020 at 10:27 AM Heikki Linnakangas wrote: >>> 7. Please address the FIXME for the symlink case: >>> /* FIXME: Check if it points to the same target? */ >> >> It's not a new issue. Would be nice to fix, of course. I'm not sure what >> the right thing to do would be. If you have e.g. replaced >> postgresql.conf with a symlink that points outside the data directory, >> would it be appropriate to overwrite it? Or perhaps we should throw an >> error? We also throw an error if a file is a symlink in the source but a >> regular file in the target, or vice versa. > > Hmm, I can imagine a use case for 2 different symlink targets on the > source and target clusters. For example the primary's pg_wal directory > can have a different symlink target as compared to a standby's > (different mount points on the same network maybe?). An end user might > not desire pg_rewind meddling with that setup or may desire pg_rewind to > treat the source as a source-of-truth with respect to this as well and > would want pg_rewind to overwrite the target's symlink. Maybe doing a > check and emitting a warning with hint/detail is prudent here while > taking no action. We have special handling for 'pg_wal' to pretend that it's a regular directory (see process_source_file()), so that's taken care of. But if you did a something similar with some other subdirectory, that would be a problem. >>> 14. queue_overwrite_range(), finish_overwrite() instead of >>> queue_fetch_range(), finish_fetch()? Similarly update\ >>> *_fetch_file_range() and *_finish_fetch() >>> >>> >>> 15. Let's have local_source.c and libpq_source.c instead of *_fetch.c >> >> Good idea! And fetch.h -> rewind_source.h. > > +1. You might have missed the changes to rename "fetch" -> "overwrite" > as was mentioned in 14. I preferred the "fetch" nomenclature in those function names. They fetch and overwrite the file ranges, so 'fetch' still seems appropriate. "fetch" -> "overwrite" would make sense if you wanted to emphasize the "overwrite" part more. Or we could rename it to "fetch_and_overwrite". But overall I think "fetch" is fine. >>> 16. >>> >>>> conn = PQconnectdb(connstr_source); >>>> >>>> if (PQstatus(conn) == CONNECTION_BAD) >>>> pg_fatal("could not connect to server: %s", >>>> PQerrorMessage(conn)); >>>> >>>> if (showprogress) >>>> pg_log_info("connected to server"); >>> >>> >>> The above hunk should be part of init_libpq_source(). Consequently, >>> init_libpq_source() should take a connection string instead of a conn. >> >> The libpq connection is also needed by WriteRecoveryConfig(), that's why >> it's not fully encapsulated in libpq_source. > > Ah. I find it pretty weird why we need to specify --source-server to > have ----write-recovery-conf work. From the code, we only need the conn > for calling PQserverVersion(), something we can easily get by slurping > pg_controldata on the source side? Maybe we can remove this limitation? Yeah, perhaps. In another patch :-). I read through the patches one more time, fixed a bunch of typos and such, and pushed patches 1-4. I'm going to spend some more time on testing the last patch. It allows using a standby server as the source, and we don't have any tests for that yet. Thanks for the review! - Heikki