pgsql: Fix skip-empty-xacts with sequences in test_decoding

Started by Tomas Vondraalmost 5 years ago6 messagescommitters
Jump to latest
#1Tomas Vondra
tomas.vondra@postgresql.org

Fix skip-empty-xacts with sequences in test_decoding

Regression tests need to use skip-empty-xacts = false, because there
might be accidental concurrent activity (like autovacuum), particularly
on slow machines. The tests added by 80901b3291 failed to do that in a
couple places, triggering occasional failures on buildfarm.

Fixing the tests however uncovered a bug in the code, because sequence
callbacks did not handle skip-empty-xacts properly. For trasactional
increments we need to check/update the xact_wrote_changes flag, and emit
the BEGIN if it's the first change in the transaction.

Reported-by: Andres Freund
Discussion: /messages/by-id/20220212220413.b25amklo7t4xb7ni@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b779d7d8fdae088d70da5ed9fcd8205035676df3

Modified Files
--------------
contrib/test_decoding/expected/sequence.out | 12 +++++-------
contrib/test_decoding/sql/sequence.sql | 8 ++++----
contrib/test_decoding/test_decoding.c | 22 ++++++++++++++++++++++
3 files changed, 31 insertions(+), 11 deletions(-)

#2Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Tomas Vondra (#1)
Re: pgsql: Fix skip-empty-xacts with sequences in test_decoding

On 2022-Feb-12, Tomas Vondra wrote:

Fix skip-empty-xacts with sequences in test_decoding

Regression tests need to use skip-empty-xacts = false, because there
might be accidental concurrent activity (like autovacuum), particularly
on slow machines. The tests added by 80901b3291 failed to do that in a
couple places, triggering occasional failures on buildfarm.

I think you meant "... need to use skip-empty-xacts = true", since you
changed the value from 0 to 1, and the point is precisely to *skip*
those transactions. (The hidden double negative "skip=false" seems
quite confusing BTW.)

Fixing the tests however uncovered a bug in the code, because sequence
callbacks did not handle skip-empty-xacts properly. For trasactional
increments we need to check/update the xact_wrote_changes flag, and emit
the BEGIN if it's the first change in the transaction.

Hmm. Perhaps there should be a separate test script that runs various
things under skip-empty-xacts=0 and somehow protected against ancillary
activities (maybe a TAP test using autovacuum=0), just so that this new
code is covered ...

--
Álvaro Herrera 39°49'30"S 73°17'W — https://www.EnterpriseDB.com/
"Nadie está tan esclavizado como el que se cree libre no siéndolo" (Goethe)

#3Tomas Vondra
tomas.vondra@enterprisedb.com
In reply to: Alvaro Herrera (#2)
Re: pgsql: Fix skip-empty-xacts with sequences in test_decoding

On 2/13/22 16:26, Alvaro Herrera wrote:

On 2022-Feb-12, Tomas Vondra wrote:

Fix skip-empty-xacts with sequences in test_decoding

Regression tests need to use skip-empty-xacts = false, because there
might be accidental concurrent activity (like autovacuum), particularly
on slow machines. The tests added by 80901b3291 failed to do that in a
couple places, triggering occasional failures on buildfarm.

I think you meant "... need to use skip-empty-xacts = true", since you
changed the value from 0 to 1, and the point is precisely to *skip*
those transactions. (The hidden double negative "skip=false" seems
quite confusing BTW.)

Yeah, that's what I meant :-(

Fixing the tests however uncovered a bug in the code, because sequence
callbacks did not handle skip-empty-xacts properly. For trasactional
increments we need to check/update the xact_wrote_changes flag, and emit
the BEGIN if it's the first change in the transaction.

Hmm. Perhaps there should be a separate test script that runs various
things under skip-empty-xacts=0 and somehow protected against ancillary
activities (maybe a TAP test using autovacuum=0), just so that this new
code is covered ...

I'm not sure what exactly would be the benefit? I mean, it'd be testing
exactly the same thing as now - actually less than now, because instead
of ignoring empty transactions in the last step (output plugin), we'd
make sure not to have any empty transactions.

For the record, the new code in sequence decoding is tested already, at
least for transactional increments.

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#4Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Tomas Vondra (#3)
Re: pgsql: Fix skip-empty-xacts with sequences in test_decoding

On 2022-Feb-13, Tomas Vondra wrote:

Fixing the tests however uncovered a bug in the code, because sequence
callbacks did not handle skip-empty-xacts properly. For trasactional
increments we need to check/update the xact_wrote_changes flag, and emit
the BEGIN if it's the first change in the transaction.

Hmm. Perhaps there should be a separate test script that runs various
things under skip-empty-xacts=0 and somehow protected against ancillary
activities (maybe a TAP test using autovacuum=0), just so that this new
code is covered ...

I'm not sure what exactly would be the benefit?

Yeah, it's pointless.

I propose the attached comment additions instead.

--
Álvaro Herrera 39°49'30"S 73°17'W — https://www.EnterpriseDB.com/

Attachments:

comments.patchtext/x-diff; charset=utf-8Download+12-0
#5Tomas Vondra
tomas.vondra@enterprisedb.com
In reply to: Alvaro Herrera (#4)
Re: pgsql: Fix skip-empty-xacts with sequences in test_decoding

On 2/14/22 14:36, Alvaro Herrera wrote:

On 2022-Feb-13, Tomas Vondra wrote:

Fixing the tests however uncovered a bug in the code, because sequence
callbacks did not handle skip-empty-xacts properly. For trasactional
increments we need to check/update the xact_wrote_changes flag, and emit
the BEGIN if it's the first change in the transaction.

Hmm. Perhaps there should be a separate test script that runs various
things under skip-empty-xacts=0 and somehow protected against ancillary
activities (maybe a TAP test using autovacuum=0), just so that this new
code is covered ...

I'm not sure what exactly would be the benefit?

Yeah, it's pointless.

I propose the attached comment additions instead.

The comments seem fine to me (although not really related to these
commits about sequence decoding).

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#6Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Tomas Vondra (#5)
Re: pgsql: Fix skip-empty-xacts with sequences in test_decoding

On 2022-Feb-14, Tomas Vondra wrote:

On 2/14/22 14:36, Alvaro Herrera wrote:

I propose the attached comment additions instead.

The comments seem fine to me (although not really related to these commits
about sequence decoding).

Thanks, pushed.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Now I have my system running, not a byte was off the shelf;
It rarely breaks and when it does I fix the code myself.
It's stable, clean and elegant, and lightning fast as well,
And it doesn't cost a nickel, so Bill Gates can go to hell."