aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/user.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-11-16 22:30:52 +0000
commita933ee38bbb8dffbc48a3363a94ff6f2a9f7964d (patch)
tree1c32737389b2530e7152dc2287161b36d9001e8c /src/backend/commands/user.c
parentcff23842a4c68301ddf34559c7af383bb5557054 (diff)
downloadpostgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.tar.gz
postgresql-a933ee38bbb8dffbc48a3363a94ff6f2a9f7964d.zip
Change SearchSysCache coding conventions so that a reference count is
maintained for each cache entry. A cache entry will not be freed until the matching ReleaseSysCache call has been executed. This eliminates worries about cache entries getting dropped while still in use. See my posting to pg-hackers of even date for more info.
Diffstat (limited to 'src/backend/commands/user.c')
-rw-r--r--src/backend/commands/user.c89
1 files changed, 42 insertions, 47 deletions
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 55064bf5126..a33098b2e0b 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.69 2000/10/19 03:55:51 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.70 2000/11/16 22:30:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -363,9 +363,9 @@ AlterUser(AlterUserStmt *stmt)
pg_shadow_rel = heap_openr(ShadowRelationName, AccessExclusiveLock);
pg_shadow_dsc = RelationGetDescr(pg_shadow_rel);
- tuple = SearchSysCacheTuple(SHADOWNAME,
- PointerGetDatum(stmt->user),
- 0, 0, 0);
+ tuple = SearchSysCache(SHADOWNAME,
+ PointerGetDatum(stmt->user),
+ 0, 0, 0);
if (!HeapTupleIsValid(tuple))
{
heap_close(pg_shadow_rel, AccessExclusiveLock);
@@ -470,10 +470,13 @@ AlterUser(AlterUserStmt *stmt)
CatalogOpenIndices(Num_pg_shadow_indices,
Name_pg_shadow_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_shadow_indices, pg_shadow_rel,
- tuple);
+ new_tuple);
CatalogCloseIndices(Num_pg_shadow_indices, idescs);
}
+ ReleaseSysCache(tuple);
+ heap_freetuple(new_tuple);
+
/*
* Write the updated pg_shadow data to the flat password file.
*/
@@ -525,9 +528,9 @@ DropUser(DropUserStmt *stmt)
int32 usesysid;
const char *user = strVal(lfirst(item));
- tuple = SearchSysCacheTuple(SHADOWNAME,
- PointerGetDatum(user),
- 0, 0, 0);
+ tuple = SearchSysCache(SHADOWNAME,
+ PointerGetDatum(user),
+ 0, 0, 0);
if (!HeapTupleIsValid(tuple))
{
heap_close(pg_shadow_rel, AccessExclusiveLock);
@@ -579,6 +582,8 @@ DropUser(DropUserStmt *stmt)
*/
heap_delete(pg_shadow_rel, &tuple->t_self, NULL);
+ ReleaseSysCache(tuple);
+
/*
* Remove user from groups
*
@@ -633,24 +638,21 @@ CheckPgUserAclNotNull()
{
HeapTuple htup;
- htup = SearchSysCacheTuple(RELNAME,
- PointerGetDatum(ShadowRelationName),
- 0, 0, 0);
+ htup = SearchSysCache(RELNAME,
+ PointerGetDatum(ShadowRelationName),
+ 0, 0, 0);
if (!HeapTupleIsValid(htup))
- {
- /* BIG problem */
- elog(ERROR, "IsPgUserAclNull: \"%s\" not found",
+ elog(ERROR, "CheckPgUserAclNotNull: \"%s\" not found",
ShadowRelationName);
- }
if (heap_attisnull(htup, Anum_pg_class_relacl))
- {
elog(ERROR,
"To use passwords, you have to revoke permissions on %s "
"so normal users cannot read the passwords. "
"Try 'REVOKE ALL ON \"%s\" FROM PUBLIC'.",
ShadowRelationName, ShadowRelationName);
- }
+
+ ReleaseSysCache(htup);
}
@@ -716,24 +718,21 @@ CreateGroup(CreateGroupStmt *stmt)
/*
* Translate the given user names to ids
*/
-
foreach(item, stmt->initUsers)
{
const char *groupuser = strVal(lfirst(item));
Value *v;
- tuple = SearchSysCacheTuple(SHADOWNAME,
- PointerGetDatum(groupuser),
- 0, 0, 0);
+ tuple = SearchSysCache(SHADOWNAME,
+ PointerGetDatum(groupuser),
+ 0, 0, 0);
if (!HeapTupleIsValid(tuple))
- {
- heap_close(pg_group_rel, AccessExclusiveLock);
elog(ERROR, "CREATE GROUP: user \"%s\" does not exist", groupuser);
- }
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
if (!member(v, newlist))
newlist = lcons(v, newlist);
+ ReleaseSysCache(tuple);
}
/* build an array to insert */
@@ -817,20 +816,19 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
pg_group_dsc = RelationGetDescr(pg_group_rel);
/*
- * Verify that group exists. If we find a tuple, will take that the
- * rest of the way and make our modifications on it.
+ * Fetch existing tuple for group.
*/
- if (!HeapTupleIsValid(group_tuple = SearchSysCacheTupleCopy(GRONAME, PointerGetDatum(stmt->name), 0, 0, 0)))
- {
- heap_close(pg_group_rel, AccessExclusiveLock);
+ group_tuple = SearchSysCache(GRONAME,
+ PointerGetDatum(stmt->name),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(group_tuple))
elog(ERROR, "%s: group \"%s\" does not exist", tag, stmt->name);
- }
-
- AssertState(stmt->action == +1 || stmt->action == -1);
/*
* Now decide what to do.
*/
+ AssertState(stmt->action == +1 || stmt->action == -1);
+
if (stmt->action == +1) /* add users, might also be invoked by
* create user */
{
@@ -876,15 +874,14 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
if (strcmp(tag, "ALTER GROUP") == 0)
{
/* Get the uid of the proposed user to add. */
- tuple = SearchSysCacheTuple(SHADOWNAME,
- PointerGetDatum(strVal(lfirst(item))),
- 0, 0, 0);
+ tuple = SearchSysCache(SHADOWNAME,
+ PointerGetDatum(strVal(lfirst(item))),
+ 0, 0, 0);
if (!HeapTupleIsValid(tuple))
- {
- heap_close(pg_group_rel, AccessExclusiveLock);
- elog(ERROR, "%s: user \"%s\" does not exist", tag, strVal(lfirst(item)));
- }
+ elog(ERROR, "%s: user \"%s\" does not exist",
+ tag, strVal(lfirst(item)));
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
+ ReleaseSysCache(tuple);
}
else if (strcmp(tag, "CREATE USER") == 0)
{
@@ -999,15 +996,13 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
if (!is_dropuser)
{
/* Get the uid of the proposed user to drop. */
- tuple = SearchSysCacheTuple(SHADOWNAME,
- PointerGetDatum(strVal(lfirst(item))),
- 0, 0, 0);
+ tuple = SearchSysCache(SHADOWNAME,
+ PointerGetDatum(strVal(lfirst(item))),
+ 0, 0, 0);
if (!HeapTupleIsValid(tuple))
- {
- heap_close(pg_group_rel, AccessExclusiveLock);
elog(ERROR, "ALTER GROUP: user \"%s\" does not exist", strVal(lfirst(item)));
- }
v = makeInteger(((Form_pg_shadow) GETSTRUCT(tuple))->usesysid);
+ ReleaseSysCache(tuple);
}
else
{
@@ -1056,9 +1051,9 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
} /* endif group not null */
} /* endif alter group drop user */
- heap_close(pg_group_rel, AccessExclusiveLock);
+ ReleaseSysCache(group_tuple);
- pfree(group_tuple);
+ heap_close(pg_group_rel, AccessExclusiveLock);
}