1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-09 06:21:09 +03:00

Make sure walsender state is only read while holding the spinlock

Noted by Robert Haas.
This commit is contained in:
Magnus Hagander
2011-01-13 18:51:13 +01:00
parent 712dd95370
commit 9eacd427e8

View File

@@ -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)
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)
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);