From 5947574f1155b13045c871465ed9c591a928199d Mon Sep 17 00:00:00 2001 From: Nathan Bryant Date: Sun, 29 Jul 2001 22:24:04 +0000 Subject: [PATCH] - added a new function to the database interface, cdb_close_cursor(). always call this when you're finished with a traversal but didn't bother reading all the way to the end. - removed several cdb_begin_transaction()/cdb_end_transaction() calls that are no longer needed because of the read-only cursor support. --- citadel/ChangeLog | 9 +++++++++ citadel/database.c | 22 ++++++++++++++++++++++ citadel/database.h | 1 + citadel/database_sleepycat.c | 7 +++++++ citadel/room_ops.c | 8 -------- citadel/serv_expire.c | 3 --- citadel/serv_upgrade.c | 2 -- citadel/serv_vandelay.c | 2 -- citadel/user_ops.c | 8 ++------ 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 4066afaaf..8149fe484 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,12 @@ $Log$ + Revision 580.15 2001/07/29 22:24:04 nbryant + - added a new function to the database interface, cdb_close_cursor(). always + call this when you're finished with a traversal but didn't bother reading all + the way to the end. + + - removed several cdb_begin_transaction()/cdb_end_transaction() calls that are + no longer needed because of the read-only cursor support. + Revision 580.14 2001/07/29 20:56:09 nbryant change ForEachRoom to use read-only cursors by default. it can be overridden to still use read/write cursors by doing: @@ -2633,3 +2641,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/database.c b/citadel/database.c index dc247df97..7bb650384 100644 --- a/citadel/database.c +++ b/citadel/database.c @@ -278,6 +278,28 @@ void cdb_free(struct cdbdata *cdb) phree(cdb); } +void cdb_close_cursor(cdb) +{ + while (max_keys <= CC->cs_pid) { + ++max_keys; + if (dtkey == NULL) { + dtkey = (datum *) + mallok((sizeof(datum) * max_keys)); + } else { + dtkey = (datum *) + reallok(dtkey, (sizeof(datum) * max_keys)); + } + dtkey[max_keys - 1].dsize = 0; + dtkey[max_keys - 1].dptr = NULL; + } + + if (dtkey[CC->cs_pid].dptr != NULL) { + phree(dtkey[CC->cs_pid].dptr); + } + dtkey[CC->cs_pid].dptr = NULL; + dtkey[CC->cs_pid].dsize = 0; +} + /* * Prepare for a sequential search of an entire database. (In the gdbm model, diff --git a/citadel/database.h b/citadel/database.h index b4dbc6f47..ba74d70a5 100644 --- a/citadel/database.h +++ b/citadel/database.h @@ -8,6 +8,7 @@ struct cdbdata *cdb_fetch (int cdb, void *key, int keylen); void cdb_free (struct cdbdata *cdb); void cdb_rewind (int cdb); struct cdbdata *cdb_next_item (int cdb); +void cdb_close_cursor(int cdb); void cdb_begin_transaction(void); void cdb_end_transaction(void); void cdb_allocate_tsd(void); diff --git a/citadel/database_sleepycat.c b/citadel/database_sleepycat.c index 3c52989ae..8579e7332 100644 --- a/citadel/database_sleepycat.c +++ b/citadel/database_sleepycat.c @@ -570,6 +570,13 @@ void cdb_free(struct cdbdata *cdb) phree(cdb); } +void cdb_close_cursor(int cdb) +{ + if (MYCURSORS[cdb] != NULL) + cclose(MYCURSORS[cdb]); + + MYCURSORS[cdb] = NULL; +} /* * Prepare for a sequential search of an entire database. diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 3566a66ec..51b8cf4c0 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -839,7 +839,6 @@ void cmd_whok(void) struct usersupp temp; struct cdbdata *cdbus; - cdb_begin_transaction(); getuser(&CC->usersupp, CC->curr_user); if (CtdlAccessCheck(ac_room_aide)) return; @@ -855,7 +854,6 @@ void cmd_whok(void) ) cprintf("%s\n", temp.fullname); } - cdb_end_transaction(); cprintf("000\n"); } @@ -1335,11 +1333,6 @@ unsigned create_room(char *new_room_name, */ if (!really_create) return (qrbuf.QRflags); - /* cdb_begin_transaction(); commented out because a transaction - is already open when creating __CtdlSMTPspoolout__ while - initializing serv_smtp.c - */ - qrbuf.QRnumber = get_new_room_number(); qrbuf.QRhighest = 0L; /* No messages in this room yet */ time(&qrbuf.QRgen); /* Use a timestamp as the generation number */ @@ -1362,7 +1355,6 @@ unsigned create_room(char *new_room_name, lputuser(&CC->usersupp); /* resume our happy day */ - /* cdb_end_transaction(); */ return (qrbuf.QRflags); } diff --git a/citadel/serv_expire.c b/citadel/serv_expire.c index 149ad0e6c..e153b99bf 100644 --- a/citadel/serv_expire.c +++ b/citadel/serv_expire.c @@ -475,7 +475,6 @@ int PurgeVisits(void) { ForEachUser(AddValidUser, NULL); /* Now traverse through the visits, purging irrelevant records... */ - cdb_begin_transaction(); cdb_rewind(CDB_VISIT); while(cdbvisit = cdb_next_item(CDB_VISIT), cdbvisit != NULL) { memset(&vbuf, 0, sizeof(struct visit)); @@ -513,8 +512,6 @@ int PurgeVisits(void) { } - cdb_end_transaction(); - /* Free the valid room/gen combination list */ while (ValidRoomList != NULL) { vrptr = ValidRoomList->next; diff --git a/citadel/serv_upgrade.c b/citadel/serv_upgrade.c index 17730bd35..1b03efb2f 100644 --- a/citadel/serv_upgrade.c +++ b/citadel/serv_upgrade.c @@ -59,7 +59,6 @@ void do_pre555_usersupp_upgrade(void) { strcpy(tempfilename, tmpnam(NULL)); /* First, back out all old version records to a flat file */ - cdb_begin_transaction(); cdb_rewind(CDB_USERSUPP); while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) { memset(&usbuf, 0, sizeof(struct pre555usersupp)); @@ -69,7 +68,6 @@ void do_pre555_usersupp_upgrade(void) { cdb_free(cdbus); fwrite(&usbuf, sizeof(struct pre555usersupp), 1, fp); } - cdb_end_transaction(); /* ...and overwrite the records with new format records */ rewind(fp); diff --git a/citadel/serv_vandelay.c b/citadel/serv_vandelay.c index bc54ced0f..bd613e0c0 100644 --- a/citadel/serv_vandelay.c +++ b/citadel/serv_vandelay.c @@ -155,7 +155,6 @@ void artv_export_visits(void) { struct visit vbuf; struct cdbdata *cdbv; - cdb_begin_transaction(); cdb_rewind(CDB_VISIT); while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) { @@ -179,7 +178,6 @@ void artv_export_visits(void) { cprintf("%u\n", vbuf.v_flags); } - cdb_end_transaction(); } diff --git a/citadel/user_ops.c b/citadel/user_ops.c index ce4b0b33e..2cbcb0c86 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -280,7 +280,6 @@ int getuserbynumber(struct usersupp *usbuf, long int number) { struct cdbdata *cdbus; - cdb_begin_transaction(); cdb_rewind(CDB_USERSUPP); while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) { @@ -290,11 +289,10 @@ int getuserbynumber(struct usersupp *usbuf, long int number) sizeof(struct usersupp) : cdbus->len)); cdb_free(cdbus); if (usbuf->usernum == number) { - cdb_end_transaction(); + cdb_close_cursor(CDB_USERSUPP); return (0); } } - cdb_end_transaction(); return (-1); } @@ -1006,7 +1004,6 @@ void cmd_gnur(void) /* There are unvalidated users. Traverse the usersupp database, * and return the first user we find that needs validation. */ - cdb_begin_transaction(); cdb_rewind(CDB_USERSUPP); while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) { memset(&usbuf, 0, sizeof(struct usersupp)); @@ -1017,11 +1014,10 @@ void cmd_gnur(void) if ((usbuf.flags & US_NEEDVALID) && (usbuf.axlevel > 0)) { cprintf("%d %s\n", MORE_DATA, usbuf.fullname); - cdb_end_transaction(); + cdb_close_cursor(CDB_USERSUPP); return; } } - cdb_end_transaction(); /* If we get to this point, there are no more unvalidated users. * Therefore we clear the "users need validation" flag. -- 2.30.2