diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 4bdf21c319c..663fa7fafbb 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -1855,7 +1855,7 @@ asyncQueueReadAllNotifications(void) Snapshot snapshot; /* page_buffer must be adequately aligned */ - alignas(AsyncQueueEntry) char page_buffer[QUEUE_PAGESIZE]; + alignas(alignof(AsyncQueueEntry)) char page_buffer[QUEUE_PAGESIZE]; /* Fetch current state */ LWLockAcquire(NotifyQueueLock, LW_SHARED); diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index f165fabce36..8e8564ae8ae 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -3246,7 +3246,7 @@ sendCommand(CState *st, Command *command) /* * Read and discard all available results from the connection. */ -static void +static PGresult * discardAvailableResults(CState *st) { PGresult *res = NULL; @@ -3255,6 +3255,21 @@ discardAvailableResults(CState *st) { res = PQgetResult(st->con); + printf("EVAN: discardAvailableResults: Got result: res=%d, conn=%d\n", + PQresultStatus(res), PQstatus(st->con)); + if (PQresultStatus(res) == PGRES_TUPLES_OK) + { + char *val = PQgetvalue(res, 0, 0); + printf("EVAN: discardAvailableResults: Got result value: %s, conn=%d\n", + val, PQstatus(st->con)); + } + if (PQresultStatus(res) == PGRES_PIPELINE_SYNC) + { + printf("EVAN: discardAvailableResults: Got sync, returning, conn=%d\n", + PQstatus(st->con)); + return res; + } + /* * Read and discard results until PQgetResult() returns NULL (no more * results) or a connection failure is detected. If the pipeline @@ -3264,11 +3279,16 @@ discardAvailableResults(CState *st) */ if ((res == NULL && PQpipelineStatus(st->con) != PQ_PIPELINE_ABORTED) || PQstatus(st->con) == CONNECTION_BAD) + { + printf("EVAN: discardAvailableResults: breaking loop, conn=%d\n", + PQstatus(st->con)); break; + } PQclear(res); } PQclear(res); + return NULL; } /* @@ -3277,7 +3297,10 @@ discardAvailableResults(CState *st) static EStatus getSQLErrorStatus(CState *st, const char *sqlState) { - discardAvailableResults(st); + //discardAvailableResults(st); + if (st->estatus == ESTATUS_NO_ERROR) + return ESTATUS_NO_ERROR; + if (PQstatus(st->con) == CONNECTION_BAD) return ESTATUS_CONN_ERROR; @@ -3338,13 +3361,28 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) ((meta == META_GSET || meta == META_ASET) && varprefix != NULL)); res = PQgetResult(st->con); - + printf("EVAN: readCommandResponse: Got result: res=%d, conn=%d\n", + PQresultStatus(res), PQstatus(st->con)); + if (PQresultStatus(res) == PGRES_TUPLES_OK) + { + char *val = PQgetvalue(res, 0, 0); + printf("EVAN: readCommandResponse: Got result value: %s, conn=%d\n", + val, PQstatus(st->con)); + } while (res != NULL) { bool is_last; /* peek at the next result to know whether the current is last */ next_res = PQgetResult(st->con); + printf("EVAN: readCommandResponse2: Got result: next_res=%d, conn=%d\n", + PQresultStatus(next_res), PQstatus(st->con)); + if (PQresultStatus(next_res) == PGRES_TUPLES_OK) + { + char *val = PQgetvalue(next_res, 0, 0); + printf("EVAN: readCommandResponse2: Got next-result value: %s, conn=%d\n", + val, PQstatus(st->con)); + } is_last = (next_res == NULL); switch (PQresultStatus(res)) @@ -3431,8 +3469,19 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) case PGRES_NONFATAL_ERROR: case PGRES_FATAL_ERROR: + { + PGresult *temp_res = discardAvailableResults(st); + if (temp_res != NULL) + { + next_res = temp_res; + break; + } st->estatus = getSQLErrorStatus(st, PQresultErrorField(res, PG_DIAG_SQLSTATE)); + if (st->estatus == ESTATUS_NO_ERROR) + { + break; + } if (canRetryError(st->estatus) || canContinueOnError(st->estatus)) { if (verbose_errors) @@ -3440,6 +3489,7 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) goto error; } /* fall through */ + } default: /* anything else is unexpected */ @@ -3460,6 +3510,8 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) return false; } + printf("EVAN: readCommandResponse: completed, conn=%d\n", + PQstatus(st->con)); return true; error: @@ -3588,9 +3640,14 @@ discardUntilSync(CState *st) PGresult *res = PQgetResult(st->con); if (PQresultStatus(res) == PGRES_PIPELINE_SYNC) + { + printf("EVAN: Got sync while discarding until sync, conn=%d\n", PQstatus(st->con)); received_sync = true; - else if (received_sync && res == NULL) + } + else if (received_sync) // && res == NULL) { + printf("EVAN: Got null while discarding until sync, conn=%d\n", PQstatus(st->con)); + Assert(res == NULL); /* * Reset ongoing sync count to 0 since all PGRES_PIPELINE_SYNC * results have been discarded. @@ -3599,23 +3656,31 @@ discardUntilSync(CState *st) PQclear(res); break; } - else - { - if (PQstatus(st->con) == CONNECTION_BAD) - { - pg_log_error("client %d aborted: the backend died while rolling back the failed transaction after", - st->id); - PQclear(res); - return 0; - } - - /* - * If a PGRES_PIPELINE_SYNC is followed by something other than - * PGRES_PIPELINE_SYNC or NULL, another PGRES_PIPELINE_SYNC will - * eventually follow. - */ - received_sync = false; - } + //else + //{ + // printf("EVAN: Got result while discarding until sync: %d, conn=%d\n", + // PQresultStatus(res), PQstatus(st->con)); + // if (PQresultStatus(res) == PGRES_TUPLES_OK) + // { + // char *val = PQgetvalue(res, 0, 0); + // printf("EVAN: Got result value while discarding until sync: %s, conn=%d\n", + // val, PQstatus(st->con)); + // } + // if (PQstatus(st->con) == CONNECTION_BAD) + // { + // pg_log_error("client %d aborted: the backend died while rolling back the failed transaction after", + // st->id); + // PQclear(res); + // return 0; + // } + // + // /* + // * If a PGRES_PIPELINE_SYNC is followed by something other than + // * PGRES_PIPELINE_SYNC or NULL, another PGRES_PIPELINE_SYNC will + // * eventually follow. + // */ + // received_sync = false; + //} PQclear(res); }