[1759] in Moira
remove object name <-> id cache
daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Wed Mar 28 01:52:21 2001
Message-Id: <200103280652.BAA16415@riff-raff.mit.edu>
To: moiradev@MIT.EDU
Date: Wed, 28 Mar 2001 01:52:13 -0500
From: Garry Zacheiss <zacheiss@MIT.EDU>
No one screamed, so I did the work to remove the cache. I also
modified check_query_access() to not cache list_ids of capacls anymore,
since it gets on my nerves. I still need to run more performance tests,
but I figured I'd send in the patches if anyone wants to comment. Not
shown here is the removal of cache.pc entirely.
Garry
Index: Makefile.in
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/Makefile.in,v
retrieving revision 2.7
diff -u -r2.7 Makefile.in
--- Makefile.in 2000/01/28 00:03:33 2.7
+++ Makefile.in 2001/03/27 22:21:03
@@ -28,12 +28,12 @@
SERVER_OBJS= mr_main.o mr_sauth.o mr_scall.o mr_shutdown.o mr_util.o \
qvalidate.o qaccess.o qsetup.o qsupport.o qfollow.o \
- queries2.o qrtn.o qsubs.o increment.o cache.o
+ queries2.o qrtn.o qsubs.o increment.o
SCHEMA_OBJS= ../db/moira_schema.o
START_OBJS= startmoira.o
CFILES= qvalidate.c qaccess.c qsetup.c qsupport.c qfollow.c \
- qrtn.c increment.c cache.c
+ qrtn.c increment.c
TARGET=moirad startmoira
Index: qfollow.pc
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/qfollow.pc,v
retrieving revision 2.20
diff -u -r2.20 qfollow.pc
--- qfollow.pc 2000/12/19 07:32:46 2.20
+++ qfollow.pc 2001/03/27 22:26:15
@@ -812,7 +812,6 @@
if (dbms_errno)
return mr_errcode;
- flush_name(argv[0], table);
if (q->type == APPEND)
{
EXEC SQL UPDATE tblstats SET appends = appends + 1, modtime = SYSDATE
@@ -877,7 +876,6 @@
if (dbms_errno)
return mr_errcode;
- flush_name(argv[0], table);
EXEC SQL UPDATE tblstats SET deletes = deletes + 1, modtime = SYSDATE
WHERE table_name = :tname;
Index: qrtn.pc
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/qrtn.pc,v
retrieving revision 2.21
diff -u -r2.21 qrtn.pc
--- qrtn.pc 2000/01/28 00:03:36 2.21
+++ qrtn.pc 2001/03/28 06:32:31
@@ -101,7 +101,6 @@
mr_sqlda = mr_alloc_sqlda();
incremental_init();
- flush_cache();
}
dbms_errno = 0;
@@ -123,7 +122,6 @@
void mr_close_database(void)
{
- flush_cache();
EXEC SQL COMMIT RELEASE;
}
@@ -266,7 +264,6 @@
incremental_after(q->rtable, qual, argv_ro);
if (status != MR_SUCCESS)
break;
- flush_name(argv_ro[0], q->rtable);
table = table_name[q->rtable];
if (strcmp(q->shortname, "sshi") && strcmp(q->shortname, "ssif"))
{
@@ -345,7 +342,6 @@
incremental_clear_after();
if (status != MR_SUCCESS)
break;
- flush_name(argv_ro[0], q->rtable);
EXEC SQL UPDATE tblstats
SET deletes = deletes + 1, modtime = SYSDATE
WHERE table_name = :table;
@@ -401,12 +397,10 @@
}
else
{
- cache_abort();
EXEC SQL ROLLBACK WORK;
incremental_flush();
}
}
- cache_commit(); /* commit following abort is safe */
if (status != MR_SUCCESS)
com_err(whoami, status, " (Query failed)");
@@ -600,11 +594,6 @@
return privileged ? MR_SUCCESS : MR_PERM;
}
-
-/* This routine caches info from the database. Each query acl is stored
- * in the query structure, and whether that acl contains everybody.
- */
-
int check_query_access(struct query *q, char *argv[], client *cl)
{
EXEC SQL BEGIN DECLARE SECTION;
@@ -617,29 +606,23 @@
if (def_uid == 0)
EXEC SQL SELECT users_id INTO :def_uid FROM users WHERE login = 'default';
- /* get query access control list */
- if (q->acl != 0)
- acl_id = q->acl;
+ name = q->shortname;
+ EXEC SQL SELECT list_id INTO :acl_id FROM capacls WHERE tag = :name;
+ if (sqlca.sqlcode < 0)
+ return MR_DBMS_ERR;
+ if (sqlca.sqlcode == SQL_NO_MATCH)
+ return MR_PERM;
+ q->acl = acl_id;
+
+ /* check for default access */
+ EXEC SQL SELECT member_id INTO :acl_id FROM imembers
+ WHERE list_id = :acl_id AND member_type = 'USER'
+ AND member_id = :def_uid;
+ if (sqlca.sqlerrd[2] == 0)
+ q->everybody = 0;
else
- {
- name = q->shortname;
- EXEC SQL SELECT list_id INTO :acl_id FROM capacls WHERE tag = :name;
- if (sqlca.sqlcode < 0)
- return MR_DBMS_ERR;
- if (sqlca.sqlcode == SQL_NO_MATCH)
- return MR_PERM;
- q->acl = acl_id;
+ q->everybody = 1;
- /* check for default access */
- EXEC SQL SELECT member_id INTO :acl_id FROM imembers
- WHERE list_id = :acl_id AND member_type = 'USER'
- AND member_id = :def_uid;
- if (sqlca.sqlerrd[2] == 0)
- q->everybody = 0;
- else
- q->everybody = 1;
- }
-
if (q->everybody)
return MR_SUCCESS;
@@ -981,5 +964,124 @@
return MR_SUCCESS;
}
+/* Do a name to ID translation. Moved from cache.pc because we did away
+ * with the cache, but what this function does is still useful to us.
+ */
+
+int name_to_id(char *name, enum tables type, int *id)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ char *iname;
+ int j;
+ EXEC SQL END DECLARE SECTION;
+
+ iname = name;
+
+ switch (type)
+ {
+ case USERS_TABLE:
+ if (strchr(iname, '@') || (strlen(iname) > 8))
+ {
+ sqlca.sqlcode = SQL_NO_MATCH;
+ break;
+ }
+ EXEC SQL SELECT users_id INTO :j FROM users WHERE login = :iname;
+ break;
+ case LIST_TABLE:
+ EXEC SQL SELECT list_id INTO :j FROM list WHERE name = :iname;
+ break;
+ case MACHINE_TABLE:
+ EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name = UPPER(:iname);
+ break;
+ case SUBNET_TABLE:
+ EXEC SQL SELECT snet_id INTO :j FROM subnet WHERE name = UPPER(:iname);
+ break;
+ case CLUSTERS_TABLE:
+ EXEC SQL SELECT clu_id INTO :j FROM clusters WHERE name = :iname;
+ break;
+ case FILESYS_TABLE:
+ EXEC SQL SELECT filsys_id INTO :j FROM filesys WHERE label = :iname;
+ break;
+ case STRINGS_TABLE:
+ if (!iname[0]) /* special-case empty string */
+ {
+ *id = 0;
+ return MR_SUCCESS;
+ }
+ EXEC SQL SELECT string_id INTO :j FROM strings WHERE string = :iname;
+ break;
+ default:
+ return MR_INTERNAL;
+ }
+ if (sqlca.sqlcode == SQL_NO_MATCH)
+ return MR_NO_MATCH;
+ if (sqlca.sqlerrd[2] > 1)
+ return MR_NOT_UNIQUE;
+ if (sqlca.sqlcode)
+ return MR_DBMS_ERR;
+ *id = j;
+
+ return MR_SUCCESS;
+}
+
+/* Perform an ID to name mapping. name should be a pointer to a pointer to
+ * malloc'ed data. The buffer it refers to will be freed, and a new buffer
+ * allocated with the answer.
+ *
+ * This used to be in cache.pc, but we've removed the cache, and this function
+ * is still useful to us.
+ */
+
+int id_to_name(int id, enum tables type, char **name)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ char iname[MAX_FIELD_WIDTH];
+ int j;
+ EXEC SQL END DECLARE SECTION;
+
+ j = id;
+
+ switch (type)
+ {
+ case USERS_TABLE:
+ EXEC SQL SELECT login INTO :iname FROM users WHERE users_id = :j;
+ break;
+ case LIST_TABLE:
+ EXEC SQL SELECT name INTO :iname FROM list WHERE list_id = :j;
+ break;
+ case MACHINE_TABLE:
+ EXEC SQL SELECT name INTO :iname FROM machine WHERE mach_id = :j;
+ break;
+ case SUBNET_TABLE:
+ EXEC SQL SELECT name INTO :iname FROM subnet WHERE snet_id = :j;
+ break;
+ case CLUSTERS_TABLE:
+ EXEC SQL SELECT name INTO :iname FROM clusters WHERE clu_id = :j;
+ break;
+ case FILESYS_TABLE:
+ EXEC SQL SELECT label INTO :iname FROM filesys WHERE filsys_id = :j;
+ break;
+ case STRINGS_TABLE:
+ EXEC SQL SELECT string INTO :iname FROM strings WHERE string_id = :j;
+ break;
+ default:
+ return MR_INTERNAL;
+ }
+ if (sqlca.sqlcode == SQL_NO_MATCH)
+ {
+ free(*name);
+ sprintf(iname, "#%d", j);
+ *name = xstrdup(iname);
+ return MR_NO_MATCH;
+ }
+ if (sqlca.sqlerrd[2] > 1)
+ return MR_INTERNAL;
+ if (sqlca.sqlcode)
+ return MR_DBMS_ERR;
+ free(*name);
+ *name = xstrdup(strtrim(iname));
+
+ return MR_SUCCESS;
+}
/* eof:qrtn.dc */
Index: qsupport.pc
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/qsupport.pc,v
retrieving revision 2.31
diff -u -r2.31 qsupport.pc
--- qsupport.pc 2001/01/05 03:28:03 2.31
+++ qsupport.pc 2001/03/27 23:02:41
@@ -1642,10 +1642,6 @@
com_err(whoami, 0, "set login name to %s", login);
incremental_after(USERS_TABLE, buffer, 0);
- /* We've just changed the login name in the DB; recache it in case
- the wrong thing got into the cache earlier. */
- cache_entry(login, USERS_TABLE, users_id);
-
/* create filesystem */
if (set_next_object_id("filsys_id", FILESYS_TABLE, 0))
return MR_NO_ID;
Index: query.h
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/query.h,v
retrieving revision 2.13
diff -u -r2.13 query.h
--- query.h 2000/01/11 19:46:04 2.13
+++ query.h 2001/03/27 23:09:45
@@ -65,16 +65,6 @@
int error;
};
-
-/* prototypes from cache.dc */
-void flush_cache(void);
-int name_to_id(char *name, enum tables type, int *id);
-int id_to_name(int id, enum tables type, char **name);
-int cache_entry(char *name, enum tables type, int id);
-void flush_name(char *name, enum tables type);
-void cache_commit(void);
-void cache_abort(void);
-
/* prototypes from increment.dc */
void incremental_before(enum tables table, char *qualx, char **argv);
void incremental_clear_before(void);
@@ -84,6 +74,8 @@
/* prototypes from qrtn.dc */
int check_query_access(struct query *q, char *argv[], client *cl);
int set_next_object_id(char *objectx, enum tables table, int limit);
+int name_to_id(char *name, enum tables type, int *id);
+int id_to_name(int id, enum tables type, char **name);
/* prototypes from qsubs.c */
void list_queries(client *cl, int (*action)(int, char *[], void *),
Index: qvalidate.pc
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/server/qvalidate.pc,v
retrieving revision 2.20
diff -u -r2.20 qvalidate.pc
--- qvalidate.pc 2000/10/18 19:00:48 2.20
+++ qvalidate.pc 2001/03/27 22:30:30
@@ -209,7 +209,6 @@
if (strlen(name) >= STRINGS_STRING_SIZE)
return MR_ARG_TOO_LONG;
id = add_string(name);
- cache_entry(name, STRINGS_TABLE, id);
*(int *)argv[vo->index] = id;
return MR_EXISTS;
}
@@ -417,7 +416,6 @@
if (strlen(name) >= STRINGS_STRING_SIZE)
return MR_ARG_TOO_LONG;
id = add_string(name);
- cache_entry(name, STRINGS_TABLE, id);
}
else if (status)
return status;