On Mon, Feb 26, 2018 at 06:24:02PM +0900, Michael Paquier wrote:
> Anything like that would be work only for HEAD I think as that's a bit
> of refactoring.  And indeed it could give you a good introduction to the
> TAP facility.

So I would propose to just do that later.  I have looked a second time
at your patch, attached is the set of tests I have run:
- With assertions enabled, I see pg_rewind failing on an assertion as
mentioned upthread.
- With assertion disabled (look at rewind_logs.log as generated by the
script attached), then all the files from the tablespace are copied with
all the file chunks fetched at the second phase of the rewind.
- With the patch, both the assertion and the handling of tablespace
files are fixed.  Again, in the logs produced by the script you would
see that tablespace files are not completely copied anymore, and that
only portions of them are.

I have one small comment though.  The comment block at the beginning of
isRelDataFile() refers to "pg_tblspc/<tblspc oid>/PG_9.4_201403261/".
Could you switch that to "pg_tblspc/<tblspc oid>/<tblspc version>"?
That's not directly the fault of your patch, but as long as we are on
it..

So I am marking this as ready for committer.  Thanks for the report,
Tsunakawa-san!
--
Michael
#!/bin/bash

set -e

PRIMARY_PGDATA=$HOME/data/primary
STANDBY_PGDATA=$HOME/data/standby
PRIMARY_TBSPACE=$HOME/data/tbspace
STANDBY_TBSPACE=$HOME/data/tbspace_standby

rm -rf $PRIMARY_PGDATA $STANDBY_PGDATA
rm -rf $PRIMARY_TBSPACE
rm -rf $STANDBY_TBSPACE

mkdir $PRIMARY_TBSPACE

# Create primary with its tablespace
initdb --noclean --nosync -D $PRIMARY_PGDATA
cat >> $PRIMARY_PGDATA/postgresql.conf <<EOF
logging_collector = on
log_directory = 'log'
wal_keep_segments=20
wal_log_hints=on
port=5432
EOF
pg_ctl start -D $PRIMARY_PGDATA
createdb $USER
# Counts for 350MB of data
psql -p 5432 <<EOF
create tablespace toto location '$PRIMARY_TBSPACE';
create table aa (a int) tablespace toto;
insert into aa values (generate_series(1,1000000));
EOF

# Create standby with its tablespace
pg_basebackup -D $STANDBY_PGDATA --wal-method=stream \
                          -T $PRIMARY_TBSPACE=$STANDBY_TBSPACE \
                          -c fast

cat >> $STANDBY_PGDATA/postgresql.conf <<EOF
port=5433
EOF
cat > $STANDBY_PGDATA/recovery.conf <<EOF
standby_mode = on
recovery_target_timeline = 'latest'
primary_conninfo = 'port=5432 application_name=node_5433'
EOF
pg_ctl start -D $STANDBY_PGDATA/

# Enforce streaming of some data
psql -p 5432 <<EOF
insert into aa values (generate_series(1,1));
EOF

# Promote and diverge, prepare for rewind
pg_ctl promote -D $STANDBY_PGDATA/
psql -p 5433 -c 'checkpoint;'

# Diverge data between both bodes
psql -p 5432 <<EOF
insert into aa values (generate_series(1,1));
EOF
psql -p 5433 <<EOF
insert into aa values (generate_series(1,4));
create table ab tablespace toto as select generate_series (1,100000) as b;
EOF

# Rewind and replug
pg_ctl stop -D $PRIMARY_PGDATA
pg_rewind -D $PRIMARY_PGDATA --source-server="port=5433" \
 --debug > $HOME/data/rewind_logs.log
echo "port=5432" >> $PRIMARY_PGDATA/postgresql.conf
cat > $PRIMARY_PGDATA/recovery.conf <<EOF
standby_mode = 'on'
primary_conninfo = 'port=5433'
EOF
pg_ctl start -D $PRIMARY_PGDATA

Attachment: signature.asc
Description: PGP signature

Reply via email to