Обсуждение: pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop

Поиск
Список
Период
Сортировка

pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop

От
sriggs@postgresql.org (Simon Riggs)
Дата:
Log Message:
-----------
Tune GetSnapshotData() during Hot Standby by avoiding loop
through normal backends. Makes code clearer also, since we
avoid various Assert()s. Performance of snapshots taken
during recovery no longer depends upon number of read-only
backends.

Modified Files:
--------------
    pgsql/src/backend/access/transam:
        xlog.c (r1.397 -> r1.398)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/access/transam/xlog.c?r1=1.397&r2=1.398)
    pgsql/src/backend/storage/ipc:
        procarray.c (r1.62 -> r1.63)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/storage/ipc/procarray.c?r1=1.62&r2=1.63)
    pgsql/src/include/access:
        xlog.h (r1.106 -> r1.107)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/access/xlog.h?r1=1.106&r2=1.107)

Re: pgsql: Tune GetSnapshotData() during Hot Standby by avoiding loop

От
Heikki Linnakangas
Дата:
Simon Riggs wrote:
> Log Message:
> -----------
> Tune GetSnapshotData() during Hot Standby by avoiding loop
> through normal backends. Makes code clearer also, since we
> avoid various Assert()s. Performance of snapshots taken
> during recovery no longer depends upon number of read-only
> backends.

I think there's a little race condition there.
snapshot->takenDuringRecovery is set before acquiring ProcArrayLock, so
it's possible that by the time we acquire the lock, we're no longer in
recovery. So this can happen:

1. Backend A starts to take a snapshot, while we're still in recovery.
takenDuringRecovery is assigned true.
2. Recovery ends, and a normal transaction X begins in backend B.
3. A skips scanning ProcArray because takenDuringRecovery is true.

The snapshot doesn't include X, so any changes done in that transaction
will not be visible to the snapshot while the transaction is still
running, but will be after it commits.

Of course, it's highly improbable for 2. to happen, but it's there.

--
  Heikki Linnakangas
  EnterpriseDB   http://www.enterprisedb.com