v2_fix_pgbench_fix_assertion_in_pipeline.patch.txt
text/plain
Filename: v2_fix_pgbench_fix_assertion_in_pipeline.patch.txt
Type: text/plain
Part: 0
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 6e9304e254f..cd5faf3370a 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -3078,7 +3078,13 @@ commandFailed(CState *st, const char *cmd, const char *message)
static void
commandError(CState *st, const char *message)
{
- Assert(sql_script[st->use_file].commands[st->command]->type == SQL_COMMAND);
+ /*
+ Errors should only be detected during an SQL command or the \endpipeline
+ meta command. Any other case triggers an assertion failure.
+ */
+ Assert(sql_script[st->use_file].commands[st->command]->type == SQL_COMMAND ||
+ sql_script[st->use_file].commands[st->command]->meta == META_ENDPIPELINE);
+
pg_log_info("client %d got an error in command %d (SQL) of script %d; %s",
st->id, st->command, st->use_file, message);
}
@@ -3525,9 +3531,7 @@ discardUntilSync(CState *st)
{
PGresult *res = PQgetResult(st->con);
- if (PQresultStatus(res) == PGRES_PIPELINE_SYNC)
- received_sync = true;
- else if (received_sync)
+ if (received_sync == true)
{
/*
* PGRES_PIPELINE_SYNC must be followed by another
@@ -3541,11 +3545,23 @@ discardUntilSync(CState *st)
*/
st->num_syncs = 0;
PQclear(res);
- break;
+ goto done;
}
- PQclear(res);
+
+ switch (PQresultStatus(res))
+ {
+ case PGRES_PIPELINE_SYNC:
+ received_sync = true;
+ case PGRES_FATAL_ERROR:
+ PQclear(res);
+ goto done;
+ default:
+ PQclear(res);
+ }
+
}
+done:
/* exit pipeline */
if (PQexitPipelineMode(st->con) != 1)
{