mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
Fix up pgstats counting of live and dead tuples to recognize that committed
and aborted transactions have different effects; also teach it not to assume that prepared transactions are always committed. Along the way, simplify the pgstats API by tying counting directly to Relations; I cannot detect any redeeming social value in having stats pointers in HeapScanDesc and IndexScanDesc structures. And fix a few corner cases in which counts might be missed because the relation's pgstat_info pointer hadn't been set.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.30 2007/04/30 21:01:52 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.31 2007/05/27 03:50:39 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Each global transaction is associated with a global transaction
|
||||
@@ -1211,7 +1211,8 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
|
||||
else
|
||||
ProcessRecords(bufptr, xid, twophase_postabort_callbacks);
|
||||
|
||||
pgstat_count_xact_commit();
|
||||
/* Count the prepared xact as committed or aborted */
|
||||
AtEOXact_PgStat(isCommit);
|
||||
|
||||
/*
|
||||
* And now we can clean up our mess.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase_rmgr.c,v 1.4 2007/01/05 22:19:23 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase_rmgr.c,v 1.5 2007/05/27 03:50:39 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "access/twophase_rmgr.h"
|
||||
#include "commands/async.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/lock.h"
|
||||
#include "utils/flatfiles.h"
|
||||
#include "utils/inval.h"
|
||||
@@ -27,7 +28,8 @@ const TwoPhaseCallback twophase_recover_callbacks[TWOPHASE_RM_MAX_ID + 1] =
|
||||
lock_twophase_recover, /* Lock */
|
||||
NULL, /* Inval */
|
||||
NULL, /* flat file update */
|
||||
NULL /* notify/listen */
|
||||
NULL, /* notify/listen */
|
||||
NULL /* pgstat */
|
||||
};
|
||||
|
||||
const TwoPhaseCallback twophase_postcommit_callbacks[TWOPHASE_RM_MAX_ID + 1] =
|
||||
@@ -36,7 +38,8 @@ const TwoPhaseCallback twophase_postcommit_callbacks[TWOPHASE_RM_MAX_ID + 1] =
|
||||
lock_twophase_postcommit, /* Lock */
|
||||
inval_twophase_postcommit, /* Inval */
|
||||
flatfile_twophase_postcommit, /* flat file update */
|
||||
notify_twophase_postcommit /* notify/listen */
|
||||
notify_twophase_postcommit, /* notify/listen */
|
||||
pgstat_twophase_postcommit /* pgstat */
|
||||
};
|
||||
|
||||
const TwoPhaseCallback twophase_postabort_callbacks[TWOPHASE_RM_MAX_ID + 1] =
|
||||
@@ -45,5 +48,6 @@ const TwoPhaseCallback twophase_postabort_callbacks[TWOPHASE_RM_MAX_ID + 1] =
|
||||
lock_twophase_postabort, /* Lock */
|
||||
NULL, /* Inval */
|
||||
NULL, /* flat file update */
|
||||
NULL /* notify/listen */
|
||||
NULL, /* notify/listen */
|
||||
pgstat_twophase_postabort /* pgstat */
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.242 2007/04/30 21:01:52 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.243 2007/05/27 03:50:39 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1661,8 +1661,7 @@ CommitTransaction(void)
|
||||
AtEOXact_Files();
|
||||
AtEOXact_ComboCid();
|
||||
AtEOXact_HashTables(true);
|
||||
pgstat_clear_snapshot();
|
||||
pgstat_count_xact_commit();
|
||||
AtEOXact_PgStat(true);
|
||||
pgstat_report_txn_timestamp(0);
|
||||
|
||||
CurrentResourceOwner = NULL;
|
||||
@@ -1796,6 +1795,7 @@ PrepareTransaction(void)
|
||||
AtPrepare_UpdateFlatFiles();
|
||||
AtPrepare_Inval();
|
||||
AtPrepare_Locks();
|
||||
AtPrepare_PgStat();
|
||||
|
||||
/*
|
||||
* Here is where we really truly prepare.
|
||||
@@ -1853,6 +1853,8 @@ PrepareTransaction(void)
|
||||
|
||||
/* notify and flatfiles don't need a postprepare call */
|
||||
|
||||
PostPrepare_PgStat();
|
||||
|
||||
PostPrepare_Inval();
|
||||
|
||||
PostPrepare_smgr();
|
||||
@@ -1880,7 +1882,7 @@ PrepareTransaction(void)
|
||||
AtEOXact_Files();
|
||||
AtEOXact_ComboCid();
|
||||
AtEOXact_HashTables(true);
|
||||
pgstat_clear_snapshot();
|
||||
/* don't call AtEOXact_PgStat here */
|
||||
|
||||
CurrentResourceOwner = NULL;
|
||||
ResourceOwnerDelete(TopTransactionResourceOwner);
|
||||
@@ -2035,8 +2037,7 @@ AbortTransaction(void)
|
||||
AtEOXact_Files();
|
||||
AtEOXact_ComboCid();
|
||||
AtEOXact_HashTables(false);
|
||||
pgstat_clear_snapshot();
|
||||
pgstat_count_xact_rollback();
|
||||
AtEOXact_PgStat(false);
|
||||
pgstat_report_txn_timestamp(0);
|
||||
|
||||
/*
|
||||
@@ -3749,6 +3750,7 @@ CommitSubTransaction(void)
|
||||
AtEOSubXact_Files(true, s->subTransactionId,
|
||||
s->parent->subTransactionId);
|
||||
AtEOSubXact_HashTables(true, s->nestingLevel);
|
||||
AtEOSubXact_PgStat(true, s->nestingLevel);
|
||||
|
||||
/*
|
||||
* We need to restore the upper transaction's read-only state, in case the
|
||||
@@ -3861,6 +3863,7 @@ AbortSubTransaction(void)
|
||||
AtEOSubXact_Files(false, s->subTransactionId,
|
||||
s->parent->subTransactionId);
|
||||
AtEOSubXact_HashTables(false, s->nestingLevel);
|
||||
AtEOSubXact_PgStat(false, s->nestingLevel);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user