19
19
* Portions Copyright (c) 1994, Regents of the University of California
20
20
*
21
21
* IDENTIFICATION
22
- * $PostgreSQL: pgsql/src/backend/utils/time/snapmgr.c,v 1.7 2008/11/25 20:28:29 alvherre Exp $
22
+ * $PostgreSQL: pgsql/src/backend/utils/time/snapmgr.c,v 1.8 2008/12/04 14:51:02 alvherre Exp $
23
23
*
24
24
*-------------------------------------------------------------------------
25
25
*/
@@ -136,7 +136,8 @@ GetTransactionSnapshot(void)
136
136
*/
137
137
if (IsXactIsoLevelSerializable )
138
138
{
139
- CurrentSnapshot = RegisterSnapshot (CurrentSnapshot );
139
+ CurrentSnapshot = RegisterSnapshotOnOwner (CurrentSnapshot ,
140
+ TopTransactionResourceOwner );
140
141
registered_serializable = true;
141
142
}
142
143
@@ -345,14 +346,27 @@ ActiveSnapshotSet(void)
345
346
346
347
/*
347
348
* RegisterSnapshot
348
- * Register a snapshot as being in use
349
+ * Register a snapshot as being in use by the current resource owner
349
350
*
350
351
* If InvalidSnapshot is passed, it is not registered.
351
352
*/
352
353
Snapshot
353
354
RegisterSnapshot (Snapshot snapshot )
354
355
{
355
- Snapshot snap ;
356
+ if (snapshot == InvalidSnapshot )
357
+ return InvalidSnapshot ;
358
+
359
+ return RegisterSnapshotOnOwner (snapshot , CurrentResourceOwner );
360
+ }
361
+
362
+ /*
363
+ * RegisterSnapshotOnOwner
364
+ * As above, but use the specified resource owner
365
+ */
366
+ Snapshot
367
+ RegisterSnapshotOnOwner (Snapshot snapshot , ResourceOwner owner )
368
+ {
369
+ Snapshot snap ;
356
370
357
371
if (snapshot == InvalidSnapshot )
358
372
return InvalidSnapshot ;
@@ -361,9 +375,9 @@ RegisterSnapshot(Snapshot snapshot)
361
375
snap = snapshot -> copied ? snapshot : CopySnapshot (snapshot );
362
376
363
377
/* and tell resowner.c about it */
364
- ResourceOwnerEnlargeSnapshots (CurrentResourceOwner );
378
+ ResourceOwnerEnlargeSnapshots (owner );
365
379
snap -> regd_count ++ ;
366
- ResourceOwnerRememberSnapshot (CurrentResourceOwner , snap );
380
+ ResourceOwnerRememberSnapshot (owner , snap );
367
381
368
382
RegisteredSnapshots ++ ;
369
383
@@ -379,14 +393,27 @@ RegisterSnapshot(Snapshot snapshot)
379
393
*/
380
394
void
381
395
UnregisterSnapshot (Snapshot snapshot )
396
+ {
397
+ if (snapshot == NULL )
398
+ return ;
399
+
400
+ UnregisterSnapshotFromOwner (snapshot , CurrentResourceOwner );
401
+ }
402
+
403
+ /*
404
+ * UnregisterSnapshotFromOwner
405
+ * As above, but use the specified resource owner
406
+ */
407
+ void
408
+ UnregisterSnapshotFromOwner (Snapshot snapshot , ResourceOwner owner )
382
409
{
383
410
if (snapshot == NULL )
384
411
return ;
385
412
386
413
Assert (snapshot -> regd_count > 0 );
387
414
Assert (RegisteredSnapshots > 0 );
388
415
389
- ResourceOwnerForgetSnapshot (CurrentResourceOwner , snapshot );
416
+ ResourceOwnerForgetSnapshot (owner , snapshot );
390
417
RegisteredSnapshots -- ;
391
418
if (-- snapshot -> regd_count == 0 && snapshot -> active_count == 0 )
392
419
{
@@ -463,6 +490,26 @@ AtSubAbort_Snapshot(int level)
463
490
SnapshotResetXmin ();
464
491
}
465
492
493
+ /*
494
+ * AtEarlyCommit_Snapshot
495
+ *
496
+ * Snapshot manager's cleanup function, to be called on commit, before
497
+ * doing resowner.c resource release.
498
+ */
499
+ void
500
+ AtEarlyCommit_Snapshot (void )
501
+ {
502
+ /*
503
+ * On a serializable transaction we must unregister our private refcount to
504
+ * the serializable snapshot.
505
+ */
506
+ if (registered_serializable )
507
+ UnregisterSnapshotFromOwner (CurrentSnapshot ,
508
+ TopTransactionResourceOwner );
509
+ registered_serializable = false;
510
+
511
+ }
512
+
466
513
/*
467
514
* AtEOXact_Snapshot
468
515
* Snapshot manager's cleanup function for end of transaction
@@ -475,13 +522,6 @@ AtEOXact_Snapshot(bool isCommit)
475
522
{
476
523
ActiveSnapshotElt * active ;
477
524
478
- /*
479
- * On a serializable snapshot we must first unregister our private
480
- * refcount to the serializable snapshot.
481
- */
482
- if (registered_serializable )
483
- UnregisterSnapshot (CurrentSnapshot );
484
-
485
525
if (RegisteredSnapshots != 0 )
486
526
elog (WARNING , "%d registered snapshots seem to remain after cleanup" ,
487
527
RegisteredSnapshots );
0 commit comments