pgsql: Implement genuine serializable isolation level.

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема pgsql: Implement genuine serializable isolation level.
Дата
Msg-id E1PmZId-0006Qf-F7@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Implement genuine serializable isolation level.

Until now, our Serializable mode has in fact been what's called Snapshot
Isolation, which allows some anomalies that could not occur in any
serialized ordering of the transactions. This patch fixes that using a
method called Serializable Snapshot Isolation, based on research papers by
Michael J. Cahill (see README-SSI for full references). In Serializable
Snapshot Isolation, transactions run like they do in Snapshot Isolation,
but a predicate lock manager observes the reads and writes performed and
aborts transactions if it detects that an anomaly might occur. This method
produces some false positives, ie. it sometimes aborts transactions even
though there is no anomaly.

To track reads we implement predicate locking, see storage/lmgr/predicate.c.
Whenever a tuple is read, a predicate lock is acquired on the tuple. Shared
memory is finite, so when a transaction takes many tuple-level locks on a
page, the locks are promoted to a single page-level lock, and further to a
single relation level lock if necessary. To lock key values with no matching
tuple, a sequential scan always takes a relation-level lock, and an index
scan acquires a page-level lock that covers the search key, whether or not
there are any matching keys at the moment.

A predicate lock doesn't conflict with any regular locks or with another
predicate locks in the normal sense. They're only used by the predicate lock
manager to detect the danger of anomalies. Only serializable transactions
participate in predicate locking, so there should be no extra overhead for
for other transactions.

Predicate locks can't be released at commit, but must be remembered until
all the transactions that overlapped with it have completed. That means that
we need to remember an unbounded amount of predicate locks, so we apply a
lossy but conservative method of tracking locks for committed transactions.
If we run short of shared memory, we overflow to a new "pg_serial" SLRU
pool.

We don't currently allow Serializable transactions in Hot Standby mode.
That would be hard, because even read-only transactions can cause anomalies
that wouldn't otherwise occur.

Serializable isolation mode now means the new fully serializable level.
Repeatable Read gives you the old Snapshot Isolation level that we have
always had.

Kevin Grittner and Dan Ports, reviewed by Jeff Davis, Heikki Linnakangas and
Anssi Kääriäinen

Branch
------
master

Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=dafaa3efb75ce1aae2e6dbefaf6f3a889dea0d21

Modified Files
--------------
doc/src/sgml/catalogs.sgml                         |    9 +-
doc/src/sgml/config.sgml                           |   70 +
doc/src/sgml/high-availability.sgml                |    9 +
doc/src/sgml/indexam.sgml                          |   13 +
doc/src/sgml/lobj.sgml                             |    2 +-
doc/src/sgml/mvcc.sgml                             |  542 ++-
doc/src/sgml/ref/begin.sgml                        |    9 +-
doc/src/sgml/ref/lock.sgml                         |    6 +-
doc/src/sgml/ref/pg_dump.sgml                      |   35 +
doc/src/sgml/ref/select.sgml                       |    2 +-
doc/src/sgml/ref/set_transaction.sgml              |   60 +-
doc/src/sgml/ref/start_transaction.sgml            |   11 +-
doc/src/sgml/spi.sgml                              |    2 +-
src/backend/access/heap/heapam.c                   |   88 +-
src/backend/access/index/indexam.c                 |   25 +-
src/backend/access/nbtree/nbtinsert.c              |   12 +
src/backend/access/nbtree/nbtpage.c                |    7 +
src/backend/access/nbtree/nbtree.c                 |    2 +
src/backend/access/nbtree/nbtsearch.c              |   13 +
src/backend/access/transam/twophase.c              |    3 +
src/backend/access/transam/twophase_rmgr.c         |    5 +
src/backend/access/transam/varsup.c                |    5 +
src/backend/access/transam/xact.c                  |   21 +
src/backend/commands/variable.c                    |   38 +
src/backend/executor/nodeBitmapHeapscan.c          |    3 +-
src/backend/executor/nodeSeqscan.c                 |    5 +
src/backend/parser/gram.y                          |    6 +
src/backend/storage/ipc/ipci.c                     |    7 +
src/backend/storage/ipc/shmem.c                    |    2 +-
src/backend/storage/ipc/shmqueue.c                 |    8 +-
src/backend/storage/lmgr/Makefile                  |    2 +-
src/backend/storage/lmgr/README                    |    4 +-
src/backend/storage/lmgr/README-SSI                |  537 +++
src/backend/storage/lmgr/lwlock.c                  |    4 +
src/backend/storage/lmgr/predicate.c               | 4439 ++++++++++++++++++++
src/backend/tcop/utility.c                         |    4 +
src/backend/utils/adt/lockfuncs.c                  |   79 +
src/backend/utils/misc/guc.c                       |   37 +
src/backend/utils/misc/postgresql.conf.sample      |    4 +-
src/backend/utils/resowner/resowner.c              |    4 +
src/backend/utils/time/snapmgr.c                   |   15 +-
src/bin/initdb/initdb.c                            |    1 +
src/bin/pg_dump/pg_dump.c                          |   35 +-
src/include/access/heapam.h                        |    4 +-
src/include/access/relscan.h                       |    1 +
src/include/access/twophase_rmgr.h                 |    5 +-
src/include/access/xact.h                          |   15 +-
src/include/catalog/pg_am.h                        |   42 +-
src/include/commands/variable.h                    |    2 +
src/include/storage/lwlock.h                       |   12 +-
src/include/storage/predicate.h                    |   67 +
src/include/storage/predicate_internals.h          |  476 +++
src/include/storage/shmem.h                        |    7 +-
src/test/isolation/.gitignore                      |   12 +
src/test/isolation/Makefile                        |   74 +
src/test/isolation/README                          |   65 +
.../isolation/expected/classroom-scheduling.out    |  299 ++
.../isolation/expected/multiple-row-versions.out   |   24 +
src/test/isolation/expected/partial-index.out      |  641 +++
src/test/isolation/expected/project-manager.out    |  299 ++
src/test/isolation/expected/receipt-report.out     | 3379 +++++++++++++++
.../isolation/expected/referential-integrity.out   |  629 +++
src/test/isolation/expected/ri-trigger.out         |  111 +
src/test/isolation/expected/simple-write-skew.out  |   41 +
.../expected/temporal-range-integrity.out          |  299 ++
src/test/isolation/expected/total-cash.out         |  281 ++
src/test/isolation/expected/two-ids.out            | 1007 +++++
src/test/isolation/isolation_main.c                |   89 +
src/test/isolation/isolation_schedule              |   11 +
src/test/isolation/isolationtester.c               |  372 ++
src/test/isolation/isolationtester.h               |   59 +
src/test/isolation/specparse.y                     |  188 +
src/test/isolation/specs/classroom-scheduling.spec |   29 +
.../isolation/specs/multiple-row-versions.spec     |   48 +
src/test/isolation/specs/partial-index.spec        |   32 +
src/test/isolation/specs/project-manager.spec      |   30 +
src/test/isolation/specs/receipt-report.spec       |   47 +
.../isolation/specs/referential-integrity.spec     |   32 +
src/test/isolation/specs/ri-trigger.spec           |   53 +
src/test/isolation/specs/simple-write-skew.spec    |   30 +
.../isolation/specs/temporal-range-integrity.spec  |   38 +
src/test/isolation/specs/total-cash.spec           |   28 +
src/test/isolation/specs/two-ids.spec              |   40 +
src/test/isolation/specscanner.l                   |  103 +
src/test/regress/expected/prepared_xacts.out       |   12 +-
src/test/regress/expected/prepared_xacts_1.out     |   12 +-
src/test/regress/expected/transactions.out         |    2 +-
src/test/regress/sql/prepared_xacts.sql            |   12 +-
src/test/regress/sql/transactions.sql              |    2 +-
src/tools/pgindent/typedefs.list                   |   18 +
90 files changed, 14994 insertions(+), 270 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Itagaki Takahiro
Дата:
Сообщение: pgsql: Fix a comment for MergeAttributes.
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: pgsql: Oops, forgot to bump catversion in the Serializable Snapshot Iso