From a49e54ea3ce119603156bac190b76ec03524fe4a Mon Sep 17 00:00:00 2001 From: genoa Date: Fri, 26 Jun 1992 13:08:02 +0000 Subject: [PATCH 1/1] Added the cache_commit() and cache_abort() routines, along with supporting changes. --- server/cache.dc | 63 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/server/cache.dc b/server/cache.dc index 23087adb..6e621b80 100644 --- a/server/cache.dc +++ b/server/cache.dc @@ -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; +} -- 2.45.2