aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/user.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-09-16 16:58:44 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-09-16 16:58:44 +0000
commit8f9f1986034a2273e09ad10671e10d1adda21d1f (patch)
tree4c2c8a226db335cf1e653b09026402363d0488e7 /src/backend/commands/user.c
parent42c0d1f3cd01ac737b182353934531d1fd382c80 (diff)
downloadpostgresql-8f9f1986034a2273e09ad10671e10d1adda21d1f.tar.gz
postgresql-8f9f1986034a2273e09ad10671e10d1adda21d1f.zip
Restructure subtransaction handling to reduce resource consumption,
as per recent discussions. Invent SubTransactionIds that are managed like CommandIds (ie, counter is reset at start of each top transaction), and use these instead of TransactionIds to keep track of subtransaction status in those modules that need it. This means that a subtransaction does not need an XID unless it actually inserts/modifies rows in the database. Accordingly, don't assign it an XID nor take a lock on the XID until it tries to do that. This saves a lot of overhead for subtransactions that are only used for error recovery (eg plpgsql exceptions). Also, arrange to release a subtransaction's XID lock as soon as the subtransaction exits, in both the commit and abort cases. This avoids holding many unique locks after a long series of subtransactions. The price is some additional overhead in XactLockTableWait, but that seems acceptable. Finally, restructure the state machine in xact.c to have a more orthogonal set of states for subtransactions.
Diffstat (limited to 'src/backend/commands/user.c')
-rw-r--r--src/backend/commands/user.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index e365f946b17..0221fe17e18 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.144 2004/08/29 05:06:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.145 2004/09/16 16:58:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -45,28 +45,30 @@
extern bool Password_encryption;
/*
- * The need-to-update-files flags are a pair of TransactionIds that show what
- * level of the transaction tree requested the update. To register an update,
- * the transaction saves its own TransactionId in the flag, unless the value
- * was already set to a valid TransactionId. If it aborts and the value is its
- * TransactionId, it resets the value to InvalidTransactionId. If it commits,
- * it changes the value to its parent's TransactionId. This way the value is
- * propagated up to the topmost transaction, which will update the files if a
- * valid TransactionId is detected.
+ * The need-to-update-files flags are a pair of SubTransactionIds that show
+ * what level of the subtransaction tree requested the update. To register
+ * an update, the subtransaction saves its own SubTransactionId in the flag,
+ * unless the value was already set to a valid SubTransactionId (which implies
+ * that it or a parent level has already requested the same). If it aborts
+ * and the value is its SubTransactionId, it resets the flag to
+ * InvalidSubTransactionId. If it commits, it changes the value to its
+ * parent's SubTransactionId. This way the value is propagated up to the
+ * top-level transaction, which will update the files if a valid
+ * SubTransactionId is detected.
*/
-static TransactionId user_file_update_xid = InvalidTransactionId;
-static TransactionId group_file_update_xid = InvalidTransactionId;
+static SubTransactionId user_file_update_subid = InvalidSubTransactionId;
+static SubTransactionId group_file_update_subid = InvalidSubTransactionId;
#define user_file_update_needed() \
do { \
- if (user_file_update_xid == InvalidTransactionId) \
- user_file_update_xid = GetCurrentTransactionId(); \
+ if (user_file_update_subid == InvalidSubTransactionId) \
+ user_file_update_subid = GetCurrentSubTransactionId(); \
} while (0)
#define group_file_update_needed() \
do { \
- if (group_file_update_xid == InvalidTransactionId) \
- group_file_update_xid = GetCurrentTransactionId(); \
+ if (group_file_update_subid == InvalidSubTransactionId) \
+ group_file_update_subid = GetCurrentSubTransactionId(); \
} while (0)
@@ -451,14 +453,14 @@ AtEOXact_UpdatePasswordFile(bool isCommit)
Relation urel = NULL;
Relation grel = NULL;
- if (user_file_update_xid == InvalidTransactionId &&
- group_file_update_xid == InvalidTransactionId)
+ if (user_file_update_subid == InvalidSubTransactionId &&
+ group_file_update_subid == InvalidSubTransactionId)
return;
if (!isCommit)
{
- user_file_update_xid = InvalidTransactionId;
- group_file_update_xid = InvalidTransactionId;
+ user_file_update_subid = InvalidSubTransactionId;
+ group_file_update_subid = InvalidSubTransactionId;
return;
}
@@ -470,22 +472,22 @@ AtEOXact_UpdatePasswordFile(bool isCommit)
* pg_shadow or pg_group, which likely won't have gotten a strong
* enough lock), so get the locks we need before writing anything.
*/
- if (user_file_update_xid != InvalidTransactionId)
+ if (user_file_update_subid != InvalidSubTransactionId)
urel = heap_openr(ShadowRelationName, ExclusiveLock);
- if (group_file_update_xid != InvalidTransactionId)
+ if (group_file_update_subid != InvalidSubTransactionId)
grel = heap_openr(GroupRelationName, ExclusiveLock);
/* Okay to write the files */
- if (user_file_update_xid != InvalidTransactionId)
+ if (user_file_update_subid != InvalidSubTransactionId)
{
- user_file_update_xid = InvalidTransactionId;
+ user_file_update_subid = InvalidSubTransactionId;
write_user_file(urel);
heap_close(urel, NoLock);
}
- if (group_file_update_xid != InvalidTransactionId)
+ if (group_file_update_subid != InvalidSubTransactionId)
{
- group_file_update_xid = InvalidTransactionId;
+ group_file_update_subid = InvalidSubTransactionId;
write_group_file(grel);
heap_close(grel, NoLock);
}
@@ -503,24 +505,25 @@ AtEOXact_UpdatePasswordFile(bool isCommit)
* need-to-update-files flags.
*/
void
-AtEOSubXact_UpdatePasswordFile(bool isCommit, TransactionId myXid,
- TransactionId parentXid)
+AtEOSubXact_UpdatePasswordFile(bool isCommit,
+ SubTransactionId mySubid,
+ SubTransactionId parentSubid)
{
if (isCommit)
{
- if (user_file_update_xid == myXid)
- user_file_update_xid = parentXid;
+ if (user_file_update_subid == mySubid)
+ user_file_update_subid = parentSubid;
- if (group_file_update_xid == myXid)
- group_file_update_xid = parentXid;
+ if (group_file_update_subid == mySubid)
+ group_file_update_subid = parentSubid;
}
else
{
- if (user_file_update_xid == myXid)
- user_file_update_xid = InvalidTransactionId;
+ if (user_file_update_subid == mySubid)
+ user_file_update_subid = InvalidSubTransactionId;
- if (group_file_update_xid == myXid)
- group_file_update_xid = InvalidTransactionId;
+ if (group_file_update_subid == mySubid)
+ group_file_update_subid = InvalidSubTransactionId;
}
}