Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 07b53de

Browse files
committed
Abort pgbench if script end is reached with an open pipeline
When a pipeline is opened with \startpipeline and not closed, pgbench will either error on the next transaction with a "already in pipeline mode" error or successfully end if this was the last transaction -- despite not sending anything that was piped in the pipeline. Make it an error to reach end of script is reached while there's an open pipeline. Backpatch to 14, where pgbench got support for pipelines. Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com> Reported-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/Za4IObZkDjrO4TcS@paquier.xyz
1 parent 74f770e commit 07b53de

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3756,10 +3756,21 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
37563756
case CSTATE_START_COMMAND:
37573757
command = sql_script[st->use_file].commands[st->command];
37583758

3759-
/* Transition to script end processing if done */
3759+
/*
3760+
* Transition to script end processing if done, but close up
3761+
* shop if a pipeline is open at this point.
3762+
*/
37603763
if (command == NULL)
37613764
{
3762-
st->state = CSTATE_END_TX;
3765+
if (PQpipelineStatus(st->con) == PQ_PIPELINE_OFF)
3766+
st->state = CSTATE_END_TX;
3767+
else
3768+
{
3769+
pg_log_error("client %d aborted: end of script reached with pipeline open",
3770+
st->id);
3771+
st->state = CSTATE_ABORTED;
3772+
}
3773+
37633774
break;
37643775
}
37653776

src/bin/pgbench/t/001_pgbench_with_server.pl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,34 @@
841841
}
842842
});
843843

844+
# Try \startpipeline without \endpipeline in a single transaction
845+
$node->pgbench(
846+
'-t 1 -n -M extended',
847+
2,
848+
[],
849+
[qr{end of script reached with pipeline open}],
850+
'error: call \startpipeline without \endpipeline in a single transaction',
851+
{
852+
'001_pgbench_pipeline_5' => q{
853+
-- startpipeline only with single transaction
854+
\startpipeline
855+
}
856+
});
857+
858+
# Try \startpipeline without \endpipeline
859+
$node->pgbench(
860+
'-t 2 -n -M extended',
861+
2,
862+
[],
863+
[qr{end of script reached with pipeline open}],
864+
'error: call \startpipeline without \endpipeline',
865+
{
866+
'001_pgbench_pipeline_6' => q{
867+
-- startpipeline only
868+
\startpipeline
869+
}
870+
});
871+
844872
# Working \startpipeline in prepared query mode with serializable
845873
$node->pgbench(
846874
'-c4 -t 10 -n -M prepared',

0 commit comments

Comments
 (0)