Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5eb15c9

Browse files
committed
SERIALIZABLE transactions are actually implemented beneath the covers with
transaction snapshots, i.e. a snapshot registered at the beginning ofa transaction. Change variable naming and comments to reflect this realityin preparation for a future, truly serializable mode, e.g.Serializable Snapshot Isolation (SSI).For the moment transaction snapshots are still used to implementSERIALIZABLE, but hopefully not for too much longer. Patch by KevinGrittner and Dan Ports with review and some minor wording changes by me.
1 parent262c71a commit5eb15c9

File tree

11 files changed

+49
-49
lines changed

11 files changed

+49
-49
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.293 2010/07/29 16:14:36 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.294 2010/09/11 18:38:55 joe Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2173,7 +2173,7 @@ heap_delete(Relation relation, ItemPointer tid,
21732173

21742174
if (crosscheck!=InvalidSnapshot&&result==HeapTupleMayBeUpdated)
21752175
{
2176-
/* Perform additional check forserializable RI updates */
2176+
/* Perform additional check fortransaction-snapshot mode RI updates */
21772177
if (!HeapTupleSatisfiesVisibility(&tp,crosscheck,buffer))
21782178
result=HeapTupleUpdated;
21792179
}
@@ -2525,7 +2525,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
25252525

25262526
if (crosscheck!=InvalidSnapshot&&result==HeapTupleMayBeUpdated)
25272527
{
2528-
/* Perform additional check forserializable RI updates */
2528+
/* Perform additional check fortransaction-snapshot mode RI updates */
25292529
if (!HeapTupleSatisfiesVisibility(&oldtup,crosscheck,buffer))
25302530
result=HeapTupleUpdated;
25312531
}

‎src/backend/catalog/index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.338 2010/08/13 20:10:50 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.339 2010/09/11 18:38:56 joe Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2049,7 +2049,7 @@ IndexCheckExclusion(Relation heapRelation,
20492049
*
20502050
* After completing validate_index(), we wait until all transactions that
20512051
* were alive at the time of the reference snapshot are gone; this is
2052-
* necessary to be sure there are none left with aserializable snapshot
2052+
* necessary to be sure there are none left with atransaction snapshot
20532053
* older than the reference (and hence possibly able to see tuples we did
20542054
* not index).Then we mark the index "indisvalid" and commit. Subsequent
20552055
* transactions will be able to use it for queries.

‎src/backend/commands/trigger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.265 2010/08/19 15:46:18 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.266 2010/09/11 18:38:56 joe Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2387,7 +2387,7 @@ ltrmark:;
23872387

23882388
caseHeapTupleUpdated:
23892389
ReleaseBuffer(buffer);
2390-
if (IsXactIsoLevelSerializable)
2390+
if (IsolationUsesXactSnapshot())
23912391
ereport(ERROR,
23922392
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
23932393
errmsg("could not serialize access due to concurrent update")));

‎src/backend/executor/execMain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.354 2010/08/05 14:45:02 rhaas Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.355 2010/09/11 18:38:56 joe Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -1554,7 +1554,7 @@ EvalPlanQualFetch(EState *estate, Relation relation, int lockmode,
15541554

15551555
caseHeapTupleUpdated:
15561556
ReleaseBuffer(buffer);
1557-
if (IsXactIsoLevelSerializable)
1557+
if (IsolationUsesXactSnapshot())
15581558
ereport(ERROR,
15591559
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
15601560
errmsg("could not serialize access due to concurrent update")));

‎src/backend/executor/nodeLockRows.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeLockRows.c,v 1.6 2010/07/28 17:21:56tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeLockRows.c,v 1.7 2010/09/11 18:38:56joe Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -130,7 +130,7 @@ ExecLockRows(LockRowsState *node)
130130
break;
131131

132132
caseHeapTupleUpdated:
133-
if (IsXactIsoLevelSerializable)
133+
if (IsolationUsesXactSnapshot())
134134
ereport(ERROR,
135135
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
136136
errmsg("could not serialize access due to concurrent update")));

‎src/backend/executor/nodeModifyTable.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeModifyTable.c,v 1.9 2010/08/18 21:52:24 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeModifyTable.c,v 1.10 2010/09/11 18:38:56 joe Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -310,7 +310,7 @@ ExecDelete(ItemPointer tupleid,
310310
* Note: if es_crosscheck_snapshot isn't InvalidSnapshot, we check that
311311
* the row to be deleted is visible to that snapshot, and throw a can't-
312312
* serialize error if not.This is a special-case behavior needed for
313-
* referential integrity updates inserializable transactions.
313+
* referential integrity updates intransaction-snapshot mode transactions.
314314
*/
315315
ldelete:;
316316
result=heap_delete(resultRelationDesc,tupleid,
@@ -328,7 +328,7 @@ ldelete:;
328328
break;
329329

330330
caseHeapTupleUpdated:
331-
if (IsXactIsoLevelSerializable)
331+
if (IsolationUsesXactSnapshot())
332332
ereport(ERROR,
333333
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
334334
errmsg("could not serialize access due to concurrent update")));
@@ -499,7 +499,7 @@ lreplace:;
499499
* Note: if es_crosscheck_snapshot isn't InvalidSnapshot, we check that
500500
* the row to be updated is visible to that snapshot, and throw a can't-
501501
* serialize error if not.This is a special-case behavior needed for
502-
* referential integrity updates inserializable transactions.
502+
* referential integrity updates intransaction-snapshot mode transactions.
503503
*/
504504
result=heap_update(resultRelationDesc,tupleid,tuple,
505505
&update_ctid,&update_xmax,
@@ -516,7 +516,7 @@ lreplace:;
516516
break;
517517

518518
caseHeapTupleUpdated:
519-
if (IsXactIsoLevelSerializable)
519+
if (IsolationUsesXactSnapshot())
520520
ereport(ERROR,
521521
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
522522
errmsg("could not serialize access due to concurrent update")));

‎src/backend/tcop/postgres.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.596 2010/08/12 23:24:54 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.597 2010/09/11 18:38:56 joe Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -2802,7 +2802,7 @@ RecoveryConflictInterrupt(ProcSignalReason reason)
28022802
*
28032803
* PROCSIG_RECOVERY_CONFLICT_SNAPSHOT if no snapshots are held
28042804
* by parent transactions and the transaction is not
2805-
*serializable
2805+
*transaction-snapshot mode
28062806
*
28072807
* PROCSIG_RECOVERY_CONFLICT_TABLESPACE if no temp files or
28082808
* cursors open in parent transactions

‎src/backend/tcop/pquery.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.137 2010/02/26 02:01:02 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/pquery.c,v 1.138 2010/09/11 18:38:56 joe Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1163,8 +1163,8 @@ PortalRunUtility(Portal portal, Node *utilityStmt, bool isTopLevel,
11631163
* Set snapshot if utility stmt needs one.Most reliable way to do this
11641164
* seems to be to enumerate those that do not need one; this is a short
11651165
* list. Transaction control, LOCK, and SET must *not* set a snapshot
1166-
* since they need to be executable at the start of aserializable
1167-
* transaction without freezing a snapshot. By extension we allow SHOW
1166+
* since they need to be executable at the start of atransaction-snapshot
1167+
*modetransaction without freezing a snapshot. By extension we allow SHOW
11681168
* not to set a snapshot. The other stmts listed are just efficiency
11691169
* hacks. Beware of listing anything that can modify the database --- if,
11701170
* say, it has to update an index with expressions that invoke

‎src/backend/utils/adt/ri_triggers.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
1717
*
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.120 2010/07/28 05:22:24 sriggs Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.121 2010/09/11 18:38:56 joe Exp $
1919
*
2020
* ----------
2121
*/
@@ -2784,10 +2784,10 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
27842784

27852785
/*
27862786
* Run the plan. For safety we force a current snapshot to be used. (In
2787-
*serializable mode, this arguably violatesserializability, but we
2788-
* really haven't got much choice.) We don't need to register the
2789-
*snapshot, because SPI_execute_snapshot will seetoit. We need at most
2790-
* one tuple returned, so pass limit = 1.
2787+
*transaction-snapshot mode, this arguably violatestransaction
2788+
*isolation rules, but wereally haven't got much choice.)
2789+
*We don't needtoregister the snapshot, because SPI_execute_snapshot
2790+
*will see to it. We need at mostone tuple returned, so pass limit = 1.
27912791
*/
27922792
spi_result=SPI_execute_snapshot(qplan,
27932793
NULL,NULL,
@@ -3332,15 +3332,15 @@ ri_PerformCheck(RI_QueryKey *qkey, SPIPlanPtr qplan,
33323332
/*
33333333
* In READ COMMITTED mode, we just need to use an up-to-date regular
33343334
* snapshot, and we will see all rows that could be interesting. But in
3335-
*SERIALIZABLE mode, we can't change the transaction snapshot. If the
3336-
* caller passes detectNewRows == false then it's okay to do the query
3335+
*transaction-snapshot mode, we can't change the transaction snapshot.
3336+
*If thecaller passes detectNewRows == false then it's okay to do the query
33373337
* with the transaction snapshot; otherwise we use a current snapshot, and
33383338
* tell the executor to error out if it finds any rows under the current
33393339
* snapshot that wouldn't be visible per the transaction snapshot. Note
33403340
* that SPI_execute_snapshot will register the snapshots, so we don't need
33413341
* to bother here.
33423342
*/
3343-
if (IsXactIsoLevelSerializable&&detectNewRows)
3343+
if (IsolationUsesXactSnapshot()&&detectNewRows)
33443344
{
33453345
CommandCounterIncrement();/* be sure all my own work is visible */
33463346
test_snapshot=GetLatestSnapshot();

‎src/backend/utils/time/snapmgr.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Portions Copyright (c) 1994, Regents of the University of California
2020
*
2121
* IDENTIFICATION
22-
* $PostgreSQL: pgsql/src/backend/utils/time/snapmgr.c,v 1.15 2010/02/26 02:01:15 momjian Exp $
22+
* $PostgreSQL: pgsql/src/backend/utils/time/snapmgr.c,v 1.16 2010/09/11 18:38:56 joe Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -37,10 +37,10 @@
3737

3838

3939
/*
40-
* CurrentSnapshot points to the only snapshot taken ina serializable
41-
*transaction, and to the latest one taken in a read-committed transaction.
40+
* CurrentSnapshot points to the only snapshot taken intransaction-snapshot
41+
*mode, and to the latest one taken in a read-committed transaction.
4242
* SecondarySnapshot is a snapshot that's always up-to-date as of the current
43-
* instant, evenon a serializabletransaction. It should only be used for
43+
* instant, evenintransaction-snapshot mode. It should only be used for
4444
* special-purpose code (say, RI checking.)
4545
*
4646
* These SnapshotData structs are static to simplify memory allocation
@@ -97,11 +97,11 @@ static intRegisteredSnapshots = 0;
9797
boolFirstSnapshotSet= false;
9898

9999
/*
100-
* Remembers whether this transaction registered aserializable snapshot at
100+
* Remembers whether this transaction registered atransaction snapshot at
101101
* start. We cannot trust FirstSnapshotSet in combination with
102-
*IsXactIsoLevelSerializable, because GUC may be reset before us.
102+
*IsolationUsesXactSnapshot(), because GUC may be reset before us.
103103
*/
104-
staticboolregistered_serializable= false;
104+
staticboolregistered_xact_snapshot= false;
105105

106106

107107
staticSnapshotCopySnapshot(Snapshotsnapshot);
@@ -130,21 +130,21 @@ GetTransactionSnapshot(void)
130130
FirstSnapshotSet= true;
131131

132132
/*
133-
* Inserializable mode, the first snapshot must live until end of
134-
* xact regardless of what the caller does with it, so we must
133+
* Intransaction-snapshot mode, the first snapshot must live until
134+
*end ofxact regardless of what the caller does with it, so we must
135135
* register it internally here and unregister it at end of xact.
136136
*/
137-
if (IsXactIsoLevelSerializable)
137+
if (IsolationUsesXactSnapshot())
138138
{
139139
CurrentSnapshot=RegisterSnapshotOnOwner(CurrentSnapshot,
140140
TopTransactionResourceOwner);
141-
registered_serializable= true;
141+
registered_xact_snapshot= true;
142142
}
143143

144144
returnCurrentSnapshot;
145145
}
146146

147-
if (IsXactIsoLevelSerializable)
147+
if (IsolationUsesXactSnapshot())
148148
returnCurrentSnapshot;
149149

150150
CurrentSnapshot=GetSnapshotData(&CurrentSnapshotData);
@@ -155,7 +155,7 @@ GetTransactionSnapshot(void)
155155
/*
156156
* GetLatestSnapshot
157157
*Get a snapshot that is up-to-date as of the current instant,
158-
*even if we are executing inSERIALIZABLE mode.
158+
*even if we are executing intransaction-snapshot mode.
159159
*/
160160
Snapshot
161161
GetLatestSnapshot(void)
@@ -515,13 +515,13 @@ void
515515
AtEarlyCommit_Snapshot(void)
516516
{
517517
/*
518-
*On a serializabletransaction we must unregister our private refcount
519-
* to theserializablesnapshot.
518+
*Intransaction-snapshot mode we must unregister our private refcount
519+
* to thetransaction-snapshot.
520520
*/
521-
if (registered_serializable)
521+
if (registered_xact_snapshot)
522522
UnregisterSnapshotFromOwner(CurrentSnapshot,
523523
TopTransactionResourceOwner);
524-
registered_serializable= false;
524+
registered_xact_snapshot= false;
525525

526526
}
527527

@@ -557,5 +557,5 @@ AtEOXact_Snapshot(bool isCommit)
557557
SecondarySnapshot=NULL;
558558

559559
FirstSnapshotSet= false;
560-
registered_serializable= false;
560+
registered_xact_snapshot= false;
561561
}

‎src/include/access/xact.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.103 2010/02/26 02:01:21 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.104 2010/09/11 18:38:58 joe Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -35,7 +35,7 @@ extern intXactIsoLevel;
3535
* We only implement two isolation levels internally. This macro should
3636
* be used to check which one is selected.
3737
*/
38-
#defineIsXactIsoLevelSerializable (XactIsoLevel >= XACT_REPEATABLE_READ)
38+
#defineIsolationUsesXactSnapshot() (XactIsoLevel >= XACT_REPEATABLE_READ)
3939

4040
/* Xact read-only state */
4141
externboolDefaultXactReadOnly;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp