pg_xlogdump follow into the future

Started by Magnus Haganderover 9 years ago8 messages
#1Magnus Hagander
magnus@hagander.net
1 attachment(s)

Currently, if you run pg_xlogdump with -f, you have to specify an end
position in an existing file, or if you don't it will only follow until the
end of the current file.

That seems like an oversight - if you specify -f with no end position, it
should follow "into the future" for any new files that appear. This allows
us to track what's happening properly.

AFAICT the actual code tracks this just fine, but the option parsing
prevents this from happening as it does not allow the end pointer to be
unset. Attach patch fixes this and makes it follow "forever" if you specify
-f without an end pointer.

I'd appreciate a review of that by someone who's done more work on the xlog
stuff, but it seems trivial to me. Not sure I can argue it's a bugfix
though, since the usecase simply did not work...

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

Attachments:

xlogdump_future.patchtext/x-patch; charset=US-ASCII; name=xlogdump_future.patchDownload
diff --git a/src/bin/pg_xlogdump/pg_xlogdump.c b/src/bin/pg_xlogdump/pg_xlogdump.c
index c0a6816..2f1018b 100644
--- a/src/bin/pg_xlogdump/pg_xlogdump.c
+++ b/src/bin/pg_xlogdump/pg_xlogdump.c
@@ -901,8 +901,14 @@ main(int argc, char **argv)
 			goto bad_argument;
 		}
 
-		/* no second file specified, set end position */
-		if (!(optind + 1 < argc) && XLogRecPtrIsInvalid(private.endptr))
+		/*
+		 * No second file specified, so unless we are in follow mode,
+		 * set the end position to the end of the same segment as
+		 * the start position.
+		 */
+		if (!(optind + 1 < argc) &&
+			XLogRecPtrIsInvalid(private.endptr) &&
+			!config.follow)
 			XLogSegNoOffsetToRecPtr(segno + 1, 0, private.endptr);
 
 		/* parse ENDSEG if passed */
@@ -933,7 +939,8 @@ main(int argc, char **argv)
 		}
 
 
-		if (!XLByteInSeg(private.endptr, segno) &&
+		if (!XLogRecPtrIsInvalid(private.endptr) &&
+			!XLByteInSeg(private.endptr, segno) &&
 			private.endptr != (segno + 1) * XLogSegSize)
 		{
 			fprintf(stderr,
#2Simon Riggs
simon@2ndquadrant.com
In reply to: Magnus Hagander (#1)
Re: pg_xlogdump follow into the future

On 14 July 2016 at 07:46, Magnus Hagander <magnus@hagander.net> wrote:

Currently, if you run pg_xlogdump with -f, you have to specify an end
position in an existing file, or if you don't it will only follow until the
end of the current file.

That seems like an oversight - if you specify -f with no end position, it
should follow "into the future" for any new files that appear. This allows
us to track what's happening properly.

AFAICT the actual code tracks this just fine, but the option parsing
prevents this from happening as it does not allow the end pointer to be
unset. Attach patch fixes this and makes it follow "forever" if you specify
-f without an end pointer.

I'd appreciate a review of that by someone who's done more work on the
xlog stuff, but it seems trivial to me. Not sure I can argue it's a bugfix
though, since the usecase simply did not work...

Good thinking.

Patch looks good, but not tested. Needs comment on the second chunk.

--
Simon Riggs http://www.2ndQuadrant.com/
<http://www.2ndquadrant.com/&gt;
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#3Andres Freund
andres@anarazel.de
In reply to: Magnus Hagander (#1)
Re: pg_xlogdump follow into the future

On 2016-07-14 13:46:23 +0200, Magnus Hagander wrote:

Currently, if you run pg_xlogdump with -f, you have to specify an end
position in an existing file, or if you don't it will only follow until the
end of the current file.

That's because specifying a file explicitly says that you only want to
look at that file, specifying two files that you want the range
inclusively between the two files. -f works if you just use -s.

I'd appreciate a review of that by someone who's done more work on the xlog
stuff, but it seems trivial to me. Not sure I can argue it's a bugfix
though, since the usecase simply did not work...

I'd say it's working as intended, and you want to change that
intent. That's fair, but I'd not call it a bug, and I'd say it's not
really 9.6 material.

diff --git a/src/bin/pg_xlogdump/pg_xlogdump.c b/src/bin/pg_xlogdump/pg_xlogdump.c
index c0a6816..2f1018b 100644
--- a/src/bin/pg_xlogdump/pg_xlogdump.c
+++ b/src/bin/pg_xlogdump/pg_xlogdump.c
@@ -901,8 +901,14 @@ main(int argc, char **argv)
goto bad_argument;
}
-		/* no second file specified, set end position */
-		if (!(optind + 1 < argc) && XLogRecPtrIsInvalid(private.endptr))
+		/*
+		 * No second file specified, so unless we are in follow mode,
+		 * set the end position to the end of the same segment as
+		 * the start position.
+		 */
+		if (!(optind + 1 < argc) &&
+			XLogRecPtrIsInvalid(private.endptr) &&
+			!config.follow)
XLogSegNoOffsetToRecPtr(segno + 1, 0, private.endptr);

/* parse ENDSEG if passed */
@@ -933,7 +939,8 @@ main(int argc, char **argv)
}

-		if (!XLByteInSeg(private.endptr, segno) &&
+		if (!XLogRecPtrIsInvalid(private.endptr) &&
+			!XLByteInSeg(private.endptr, segno) &&
private.endptr != (segno + 1) * XLogSegSize)
{
fprintf(stderr,

Other than that it looks reasonable from a quick glance.

Andres

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Magnus Hagander
magnus@hagander.net
In reply to: Andres Freund (#3)
Re: pg_xlogdump follow into the future

On Thu, Jul 14, 2016 at 8:27 PM, Andres Freund <andres@anarazel.de> wrote:

On 2016-07-14 13:46:23 +0200, Magnus Hagander wrote:

Currently, if you run pg_xlogdump with -f, you have to specify an end
position in an existing file, or if you don't it will only follow until

the

end of the current file.

That's because specifying a file explicitly says that you only want to
look at that file, specifying two files that you want the range
inclusively between the two files. -f works if you just use -s.

Hmm. It does now. I'm *sure* it didn't when I was testing it. It must've
been something else that was broken at that point :)

I'd appreciate a review of that by someone who's done more work on the

xlog

stuff, but it seems trivial to me. Not sure I can argue it's a bugfix
though, since the usecase simply did not work...

I'd say it's working as intended, and you want to change that
intent. That's fair, but I'd not call it a bug, and I'd say it's not
really 9.6 material.

Based on that, I agree that it's working as intended.

And definitely that it's not 9.6 material.

I'll stick it on the CF page so I don't forget about it.

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#5Michael Paquier
michael.paquier@gmail.com
In reply to: Magnus Hagander (#4)
Re: pg_xlogdump follow into the future

On Mon, Jul 18, 2016 at 8:10 PM, Magnus Hagander <magnus@hagander.net> wrote:

On Thu, Jul 14, 2016 at 8:27 PM, Andres Freund <andres@anarazel.de> wrote:

On 2016-07-14 13:46:23 +0200, Magnus Hagander wrote:

Currently, if you run pg_xlogdump with -f, you have to specify an end
position in an existing file, or if you don't it will only follow until
the
end of the current file.

That's because specifying a file explicitly says that you only want to
look at that file, specifying two files that you want the range
inclusively between the two files. -f works if you just use -s.

Hmm. It does now. I'm *sure* it didn't when I was testing it. It must've
been something else that was broken at that point :)

Same as Andres here, my understanding is that one file means that you
just want to look at this file, and two files permits to look at a
range of changes. But I have no argument against changing the current
behavior either.

I'd appreciate a review of that by someone who's done more work on the
xlog
stuff, but it seems trivial to me. Not sure I can argue it's a bugfix
though, since the usecase simply did not work...

I'd say it's working as intended, and you want to change that
intent. That's fair, but I'd not call it a bug, and I'd say it's not
really 9.6 material.

Based on that, I agree that it's working as intended.

And definitely that it's not 9.6 material.

I'll stick it on the CF page so I don't forget about it.

Moved to next CF. Magnus, you may want to finish wrapping that if you
still intend to change the current behavior.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Vladimir Rusinov
vrusinov@google.com
In reply to: Michael Paquier (#5)
1 attachment(s)
Re: pg_xlogdump follow into the future

This patch does not have a reviewer, so I've decided to try myself on.

Disclaimer: although I review quite a lot of code daily, this is my first
review for PostgreSQL. I don't know code very well, and frankly I don't
really know C very well.
Hope my effort are not vain and will be helpful to somebody.
I'll be happy for review on review and any tips on process.

Summary
=======

I favour this patch. Current behaviour is indeed confusing. If we keep
current behaviour we need to update docs and maybe also print a warning
when using -f with a file name.

Thank you for submission, but i'm afraid there is a bit more work here:

- There is a bug, making it hard to test. Please fix.
- Please add some tests.

Submission review
==============

Patch applies cleanly on HEAD. Tests succeed.
There are no new or affected by this patch tests. Given that I've found a
trivial bug (see below), a test should be created.

Usability review
============
I believe I've immediately hit a corner case:

1) I've created a new instance, started it and run `./bin/pg_xlogdump -f
db/pg_wal/000000010000000000000001`.
This spewed quite a lot of stuff, as expected.

2) I've connected to the same instance and ran following:
# SELECT pg_switch_xlog();
pg_switch_xlog
----------------
0/14FA3D8
(1 row)

xlogdump immediately crashed with following:

pg_xlogdump: FATAL: could not find file "000000010000000000000002": No
such file or directory

Problem is that Postgres does not create file until it's actually needed.
So 000000010000000000000002 indeed was not there until after I've run some
transactions. I believe same would happen after pg_start_backup(), etc.

Feature review
===========
See above. Can't do more testing.

Performance review
===============
n/a

Coding review
===========
LGTM

Architecture review
==============
n/a

--
Vladimir Rusinov
Bigtable SRE

Google Ireland Ltd.,Gordon House, Barrow Street, Dublin 4, Ireland
Registered in Dublin, Ireland
Registration Number: 368047

On Mon, Oct 3, 2016 at 5:44 AM, Michael Paquier <michael.paquier@gmail.com>
wrote:

Show quoted text

On Mon, Jul 18, 2016 at 8:10 PM, Magnus Hagander <magnus@hagander.net>
wrote:

On Thu, Jul 14, 2016 at 8:27 PM, Andres Freund <andres@anarazel.de>

wrote:

On 2016-07-14 13:46:23 +0200, Magnus Hagander wrote:

Currently, if you run pg_xlogdump with -f, you have to specify an end
position in an existing file, or if you don't it will only follow

until

the
end of the current file.

That's because specifying a file explicitly says that you only want to
look at that file, specifying two files that you want the range
inclusively between the two files. -f works if you just use -s.

Hmm. It does now. I'm *sure* it didn't when I was testing it. It must've
been something else that was broken at that point :)

Same as Andres here, my understanding is that one file means that you
just want to look at this file, and two files permits to look at a
range of changes. But I have no argument against changing the current
behavior either.

I'd appreciate a review of that by someone who's done more work on the
xlog
stuff, but it seems trivial to me. Not sure I can argue it's a bugfix
though, since the usecase simply did not work...

I'd say it's working as intended, and you want to change that
intent. That's fair, but I'd not call it a bug, and I'd say it's not
really 9.6 material.

Based on that, I agree that it's working as intended.

And definitely that it's not 9.6 material.

I'll stick it on the CF page so I don't forget about it.

Moved to next CF. Magnus, you may want to finish wrapping that if you
still intend to change the current behavior.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

smime.p7sapplication/pkcs7-signature; name=smime.p7sDownload
0��	*�H��
���0��10
	`�He0	*�H��
��Q0�\0�D�Hjn���D���0
	*�H��
0d10	UBE10U
GlobalSign nv-sa1:08U1GlobalSign PersonalSign Partners CA - SHA256 - G20
160615000000Z
210615000000Z0L10	UBE10U
GlobalSign nv-sa1"0 UGlobalSign HV S/MIME CA 10�"0
	*�H��
�0�
��v�R��VV�^���p��(X2��8��#~�66cmy
Q���/
_�� [�>����{��<PR1~[I^��?`��K��j(�Ox����4b����y���8���Q��w��,\l�Do`8f����n�w�_�c�T[�,R�2O$����,�L:u/�ulI7��lE7�E.�
��'"������:�|����)Nf
Z��
Kb[�������������8�������2��?������I&k(�����b"P���"0�0U�0U%0++0U�0�0U�8����x���!���&b��?0U#0�&$���D���m��t��x0KUD0B0@�>�<�:http://crl.globalsign.com/gs/gspersonalsignptnrssha2g2.crl0LU E0C0A	+�2(0402+&https://www.globalsign.com/repository/0
	*�H��
�
��!� ���Nic�As}���0z-^�xek����S`Y?t�A��W�Z�����jh@C"�����s�$J���
����hQ�D0���f�X��x�W8q����.��{D���Qz��UC��02>����5��H�V�A}�}p�w

�3���~a�����zj�t��*�,[����dKVY>�]�&�����i`$��C���CQ�����h5-K���"����Zx�e���������)s�����0�m��G0�0��1��@�0
	*�H��
0L1 0UGlobalSign Root CA - R310U

GlobalSign10U
GlobalSign0
110802100000Z
290329100000Z0d10	UBE10U
GlobalSign nv-sa1:08U1GlobalSign PersonalSign Partners CA - SHA256 - G20�"0
	*�H��
�0�
���J�����b��A*����>�S�NX)�^��'��u�K��#�	��u�F��q4�E
E�=��ZWX�~J����^�q���i����\n��������������Z7O\�����?���g2c� /���i��L��v��>�p-������v�����w���@C^Z�w}�`�=[�.������1{�z��-^`vj4�6�>)���	$y�����G����A>�Q1r�a������D �`~����7
���W������0��0U�0U�0�0U&$���D���m��t��x0GU @0>0<U 0402+&https://www.globalsign.com/repository/06U/0-0+�)�'�%http://crl.globalsign.net/root-r3.crl0U#0���K�.E$�MP�c������0
	*�H��
�Uc(Y	_���-�������4vk��F`�VY��p���������o%k@��3�N�J������)�����|��q�)��+!�������������L(�b�w^��������; ���uS����
i�b���>l,%�)~|^c�1�u�n��$^�@��a����J"��A@-bsi7�.gx�_�p��m^�l���O�������\-=��`�8Us	c�w��?�
��s��|)dY���-��H���HTww0�_0�G�!XS�0
	*�H��
0L1 0UGlobalSign Root CA - R310U

GlobalSign10U
GlobalSign0
090318100000Z
290318100000Z0L1 0UGlobalSign Root CA - R310U

GlobalSign10U
GlobalSign0�"0
	*�H��
�0�
��%v�yx"������(��v���r�FC����_$�.K�`�F�R��Gpl�d���,��=+�����y�;�w��I�jb/^��h��'�8��>��&Y
s����&���[��`�I�(�i;���(����aW7�t�t�:�r/.������=�3��+�S�:s��A :������O�.2`�W���hh�8&`u��w���� I��@H�1a^����w�d�z�_���b�
l�Ti��n���qv�i���B0@0U�0U�0�0U��K�.E$�MP�c������0
	*�H��
�K@��P������TEI��	A����(3�k�t��-��
������sgJ��D{x��nlo)�39E����Wl����S�-�$l��c��ShgV>���5!��h����S������]F���zX(/��7A��Dm�S(�~�g������L'�Lssv���z�-�
,�<�U�~6��WI��.-|`��AQ#���2k����,3:;%��@�;,�x�a/���Uo���	M�(�r��bPe����1����GX?_0�h0�P�q��KO��F���0
	*�H��
0L10	UBE10U
GlobalSign nv-sa1"0 UGlobalSign HV S/MIME CA 10
161122184556Z
170521184556Z0$1"0 	*�H��
	vrusinov@google.com0�"0
	*�H��
�0�
��FZ9UI���nzd�A
�P������vD^2s����N����4�i����������zUhp7�R�E2��lGm����x>>�y�	Z*�#�X��$��������"P2����
J�kVe��j4!�u�����	�
{sJ���Se��c`��������Xc"'j����3G�^�'�I{�JD��U�	VR�<I��zI�E���3���,��]\��	�B�<-�b�?����Zv)m/+���2���=F3=EW������p0�l0U0�vrusinov@google.com0P+D0B0@+0�4http://secure.globalsign.com/cacert/gshvsmimeca1.crt0U�^��'�����7%�����0U#0��8����x���!���&b��?0LU E0C0A	+�2(0402+&https://www.globalsign.com/repository/0;U40200�.�,�*http://crl.globalsign.com/gshvsmimeca1.crl0U��0U%0++0
	*�H��
������q��J����k[�]B�����J9-��e3��
����P��5k���T�����j�������	���&w��0�y��g�^��c�?�	�H��K^<q]�jM�o#V�\r�@SW��
�P|ny��Y���M
G���/B�C6�d2�4����8�(�t�4>�-�PPZ���d�/�0F��-�&�����:	_3e��iu�i��:`���x��!�Y�9�Z�m�����Y������D8`E���N"�	?�1�^0�Z0\0L10	UBE10U
GlobalSign nv-sa1"0 UGlobalSign HV S/MIME CA 1q��KO��F���0
	`�He���0/	*�H��
	1" �c�6p���#�ol��g�{�i��h�l�[0	*�H��
	1	*�H��
0	*�H��
	1
161201152124Z0i	*�H��
	1\0Z0	`�He*0	`�He0	`�He0
*�H��
0	*�H��

0	*�H��
0	`�He0
	*�H��
�
h������>��2(��8������eu�@ok����rB(���'��J{��������$;"�t)u;#�G�"l
	gD�;����X�9���36@@��*<`t�,W�M �B:�s��J�N��5��F����tl��]D6��D�O��_����C����i�������q�d[T`�S����S�Ew���m'QP�_F�0�����<�x����h���/�'����kfX0Dk�}������r@�������vI,Y�iQ
#7Haribabu Kommi
kommi.haribabu@gmail.com
In reply to: Vladimir Rusinov (#6)
Re: pg_xlogdump follow into the future

On Fri, Dec 2, 2016 at 2:21 AM, Vladimir Rusinov <vrusinov@google.com>
wrote:

This patch does not have a reviewer, so I've decided to try myself on.

Disclaimer: although I review quite a lot of code daily, this is my first
review for PostgreSQL. I don't know code very well, and frankly I don't
really know C very well.
Hope my effort are not vain and will be helpful to somebody.
I'll be happy for review on review and any tips on process.

Summary
=======

I favour this patch. Current behaviour is indeed confusing. If we keep
current behaviour we need to update docs and maybe also print a warning
when using -f with a file name.

Thank you for submission, but i'm afraid there is a bit more work here:

- There is a bug, making it hard to test. Please fix.
- Please add some tests.

Submission review
==============

Patch applies cleanly on HEAD. Tests succeed.
There are no new or affected by this patch tests. Given that I've found a
trivial bug (see below), a test should be created.

Usability review
============
I believe I've immediately hit a corner case:

1) I've created a new instance, started it and run `./bin/pg_xlogdump -f
db/pg_wal/000000010000000000000001`.
This spewed quite a lot of stuff, as expected.

2) I've connected to the same instance and ran following:
# SELECT pg_switch_xlog();
pg_switch_xlog
----------------
0/14FA3D8
(1 row)

xlogdump immediately crashed with following:

pg_xlogdump: FATAL: could not find file "000000010000000000000002": No
such file or directory

Problem is that Postgres does not create file until it's actually needed.
So 000000010000000000000002 indeed was not there until after I've run some
transactions. I believe same would happen after pg_start_backup(), etc.

Feature review
===========
See above. Can't do more testing.

Performance review
===============
n/a

Coding review
===========
LGTM

Architecture review
==============
n/a

Patch received feedback at the end of commitfest.
Closed in 2016-11 commitfest with "moved to next CF".
Please feel free to update the status once you submit the updated patch.

Regards,
Hari Babu
Fujitsu Australia

#8Michael Paquier
michael.paquier@gmail.com
In reply to: Haribabu Kommi (#7)
Re: pg_xlogdump follow into the future

On Fri, Dec 2, 2016 at 1:36 PM, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:

Patch received feedback at the end of commitfest.
Closed in 2016-11 commitfest with "moved to next CF".
Please feel free to update the status once you submit the updated patch.

And the thread has died as well weeks ago. I am marking that as
"returned with feedback" as there are no new patches.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers