Skip to content
Snippets Groups Projects
Commit 9eacd427 authored by Magnus Hagander's avatar Magnus Hagander
Browse files

Make sure walsender state is only read while holding the spinlock

Noted by Robert Haas.
parent 712dd953
No related branches found
No related tags found
No related merge requests found
...@@ -1050,6 +1050,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) ...@@ -1050,6 +1050,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
volatile WalSnd *walsnd = &WalSndCtl->walsnds[i]; volatile WalSnd *walsnd = &WalSndCtl->walsnds[i];
char sent_location[MAXFNAMELEN]; char sent_location[MAXFNAMELEN];
XLogRecPtr sentPtr; XLogRecPtr sentPtr;
WalSndState state;
Datum values[PG_STAT_GET_WAL_SENDERS_COLS]; Datum values[PG_STAT_GET_WAL_SENDERS_COLS];
bool nulls[PG_STAT_GET_WAL_SENDERS_COLS]; bool nulls[PG_STAT_GET_WAL_SENDERS_COLS];
...@@ -1058,6 +1059,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) ...@@ -1058,6 +1059,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
SpinLockAcquire(&walsnd->mutex); SpinLockAcquire(&walsnd->mutex);
sentPtr = walsnd->sentPtr; sentPtr = walsnd->sentPtr;
state = walsnd->state;
SpinLockRelease(&walsnd->mutex); SpinLockRelease(&walsnd->mutex);
snprintf(sent_location, sizeof(sent_location), "%X/%X", snprintf(sent_location, sizeof(sent_location), "%X/%X",
...@@ -1065,7 +1067,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) ...@@ -1065,7 +1067,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
memset(nulls, 0, sizeof(nulls)); memset(nulls, 0, sizeof(nulls));
values[0] = Int32GetDatum(walsnd->pid); values[0] = Int32GetDatum(walsnd->pid);
values[1] = CStringGetTextDatum(WalSndGetStateString(walsnd->state)); values[1] = CStringGetTextDatum(WalSndGetStateString(state));
values[2] = CStringGetTextDatum(sent_location); values[2] = CStringGetTextDatum(sent_location);
tuplestore_putvalues(tupstore, tupdesc, values, nulls); tuplestore_putvalues(tupstore, tupdesc, values, nulls);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment