Refactor pg_rewind code and make it work against a standby

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-08-19T12:50:16Z
Lists: pgsql-hackers

Attachments

Hi,

I started to hack on making pg_rewind crash-safe (see [1]), but I 
quickly got side-tracked into refactoring and tidying up up the code in 
general. I ended up with this series of patches:

The first four patches are just refactoring that make the code and the 
logic more readable. Tom Lane commented about the messy comments earlier 
(see [2]), and I hope these patches will alleviate that confusion. See 
commit messages for details.

The last patch refactors the logic in libpq_fetch.c, so that it no 
longer uses a temporary table in the source system. That allows using a 
hot standby server as the pg_rewind source.

This doesn't do anything about pg_rewind's crash-safety yet, but I'll 
try work on that after these patches.

[1] 
https://www.postgresql.org/message-id/d8dcc760-8780-5084-f066-6d663801d2e2%40iki.fi

[2] https://www.postgresql.org/message-id/30255.1522711675%40sss.pgh.pa.us

- Heikki

Commits

  1. Make pg_rewind test case more stable.

  2. Fix timing issue in pg_rewind test.

  3. Allow pg_rewind to use a standby server as the source system.

  4. pg_rewind: Refactor the abstraction to fetch from local/libpq source.

  5. pg_rewind: Replace the hybrid list+array data structure with simplehash.

  6. Refactor pg_rewind for more clear decision making.

  7. pg_rewind: Move syncTargetDirectory() to file_ops.c