]> andersk Git - moira.git/commitdiff
Added the cache_commit() and cache_abort() routines, along with
authorgenoa <genoa>
Fri, 26 Jun 1992 13:08:02 +0000 (13:08 +0000)
committergenoa <genoa>
Fri, 26 Jun 1992 13:08:02 +0000 (13:08 +0000)
supporting changes.

server/cache.dc

index 23087adb38f05b4ac304eb7132f423bee75fcebe..6e621b80d59fb0e7fbe47f6444c473311f833b75 100644 (file)
@@ -15,6 +15,7 @@ static char *rcsid_cache_dc = "$Header$";
 #include "mr_server.h"
 EXEC SQL INCLUDE sqlca;
 
+
 extern char *whoami, *strsave();
 extern int ingres_errno, mr_errcode;
 
@@ -47,6 +48,7 @@ struct item {
     int id;
     struct item *next;
     struct item *prev;
+    struct item *trans;                /* keep track of transactions */
 };
 
 static struct item cachehead;
@@ -92,6 +94,7 @@ flush_cache()
     if (cachehead.prev != &cachehead)
       free(cachehead.prev);
     cachehead.next = cachehead.prev = &cachehead;
+    cachehead.trans = (struct item *)NULL;
 }
 
 
@@ -104,7 +107,7 @@ char *name;
 char *type;
 int *id;
 {
-    register struct item *i;
+    register struct item *i, *t;
     EXEC SQL BEGIN DECLARE SECTION;
     char *iname;
     int j, rowcount;
@@ -142,8 +145,7 @@ int *id;
        break;
     case 'M':
     case 'm':
-       uppercase(iname);
-       EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=:iname;
+       EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=uppercase(:iname);
        break;
     case 'C':
     case 'c':
@@ -185,6 +187,12 @@ int *id;
     i->prev = &cachehead;
     cachehead.next->prev = i;
     cachehead.next = i;
+    /* find the end of the transaction chain & add this item */
+    for (t = &cachehead; t->trans && t != i; t = t->trans);
+    if (t != i) {
+       t->trans = i;
+       i->trans = (struct item *)NULL;
+    }
     return(MR_SUCCESS);
 }
 
@@ -281,6 +289,12 @@ char **name;
     i->prev = &cachehead;
     cachehead.next->prev = i;
     cachehead.next = i;
+    /* find the end of the transaction chain & add this item */
+    for (t = &cachehead; t->trans && t != i; t = t->trans);
+    if (t != i) {
+       t->trans = i;
+       i->trans = (struct item *)NULL;
+    }
     return(MR_SUCCESS);
 }
 
@@ -294,11 +308,16 @@ char *name;
 char *type;
 int id;
 {
-    register struct item *i;
+    register struct item *i, *t;
 
     for (i = cachehead.next; i != &cachehead; i = i->next)
-      if (i->id == id && !strcmp(i->type, type))
-       return(MR_SUCCESS);
+      if (i->id == id && !strcmp(i->type, type)) {
+         if (strcmp(i->name, name)) {
+             strcpy(i->name, name);
+             i->nhash = hashname(name, type);
+         }
+         return(MR_SUCCESS);
+      }
     if (cachesize < CACHESIZE) {
        i = (struct item *) malloc(sizeof(struct item));
        cachesize++;
@@ -315,6 +334,12 @@ int id;
     i->prev = &cachehead;
     cachehead.next->prev = i;
     cachehead.next = i;
+    /* find the end of the transaction chain & add this item */
+    for (t = &cachehead; t->trans && t != i; t = t->trans);
+    if (t != i) {
+       t->trans = i;
+       i->trans = (struct item *)NULL;
+    }
     return(MR_SUCCESS);
 }
 
@@ -340,3 +365,29 @@ char *type;
        }
     }
 }
+
+
+/* Called when a transaction is committed to also commit any cache changes.
+ * Just throws away the list of cache changes for this transaction.
+ */
+
+cache_commit()
+{
+    cachehead.trans = (struct item *)NULL;
+}
+
+
+/* Called whan a transaction is aborted to throw away any cache changes
+ * from that transaction.
+ */
+
+cache_abort()
+{
+    register struct item *i, *t;
+
+    for (i = cachehead.trans; i; i = t) {
+       t = i->trans;
+       flush_name(i->name, i->type);
+    }
+    cachehead.trans = (struct item *)NULL;
+}
This page took 0.045001 seconds and 5 git commands to generate.