From ba0ac79036289d7c0ba57386ffef91fadea58ae4 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 21 Sep 2006 04:03:08 +0000 Subject: [PATCH] serv_network.c and msgbase.c: preliminary work for making the networker more quickly aware of which rooms have recently posted messages. This still runs at a one minute granularity, which is still too slow. Need to reduce it to seconds in order to submit rooms for Sieve processing using the networker. --- citadel/msgbase.c | 4 ++++ citadel/serv_network.c | 31 ++++++++++++++++++++++++++++--- citadel/serv_network.h | 2 ++ citadel/serv_sieve.c | 1 - citadel/server.h | 1 + citadel/sysdep.c | 1 + 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index cefc3edb8..978b19e9d 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -52,6 +52,7 @@ #include "euidindex.h" #include "journaling.h" #include "citadel_dirs.h" +#include "serv_network.h" long config_msgnum; struct addresses_to_be_filed *atbf = NULL; @@ -2032,6 +2033,9 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms lprintf(CTDL_DEBUG, "CtdlSaveMsgPointerInRoom() skips repl checks\n"); } + /* Submit this room for net processing */ + network_queue_room(&CC->room, NULL); + /* Go back to the room we were in before we wandered here... */ getroom(&CC->room, hold_rm); diff --git a/citadel/serv_network.c b/citadel/serv_network.c index a769aab3e..a3b98a4f8 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -77,8 +77,7 @@ static int doing_queue = 0; /* * When we do network processing, it's accomplished in two passes; one to * gather a list of rooms and one to actually do them. It's ok that rplist - * is global; this process *only* runs as part of the housekeeping loop and - * therefore only one will run at a time. + * is global; we have a mutex that keeps it safe. */ struct RoomProcList *rplist = NULL; @@ -890,6 +889,11 @@ void network_spoolout_room(char *room_to_spool) { int skipthisline = 0; int i; + /* + * If the room doesn't exist, don't try to perform its networking tasks. + * Normally this should never happen, but once in a while maybe a room gets + * queued for networking and then deleted before it can happen. + */ if (getroom(&CC->room, room_to_spool) != 0) { lprintf(CTDL_CRIT, "ERROR: cannot load <%s>\n", room_to_spool); return; @@ -900,6 +904,7 @@ void network_spoolout_room(char *room_to_spool) { begin_critical_section(S_NETCONFIGS); + /* Only do net processing for rooms that have netconfigs */ fp = fopen(filename, "r"); if (fp == NULL) { end_critical_section(S_NETCONFIGS); @@ -1171,8 +1176,10 @@ void network_queue_room(struct ctdlroom *qrbuf, void *data) { if (ptr == NULL) return; safestrncpy(ptr->name, qrbuf->QRname, sizeof ptr->name); + begin_critical_section(S_RPLIST); ptr->next = rplist; rplist = ptr; + end_critical_section(S_RPLIST); } @@ -1949,13 +1956,31 @@ void network_do_queue(void) { if (full_processing) { lprintf(CTDL_DEBUG, "network: loading outbound queue\n"); ForEachRoom(network_queue_room, NULL); + } + if (rplist != NULL) { lprintf(CTDL_DEBUG, "network: running outbound queue\n"); while (rplist != NULL) { - network_spoolout_room(rplist->name); + char spoolroomname[ROOMNAMELEN]; + safestrncpy(spoolroomname, rplist->name, sizeof spoolroomname); + begin_critical_section(S_RPLIST); + + /* pop this record off the list */ ptr = rplist; rplist = rplist->next; free(ptr); + + /* invalidate any duplicate entries to prevent double processing */ + for (ptr=rplist; ptr!=NULL; ptr=ptr->next) { + if (!strcasecmp(ptr->name, spoolroomname)) { + ptr->name[0] = 0; + } + } + + end_critical_section(S_RPLIST); + if (spoolroomname[0] != 0) { + network_spoolout_room(spoolroomname); + } } } diff --git a/citadel/serv_network.h b/citadel/serv_network.h index 5c48b8d28..39e04b9d7 100644 --- a/citadel/serv_network.h +++ b/citadel/serv_network.h @@ -41,3 +41,5 @@ struct FilterList { }; extern struct FilterList *filterlist; + +void network_queue_room(struct ctdlroom *, void *); diff --git a/citadel/serv_sieve.c b/citadel/serv_sieve.c index 430f35970..e9fca4f50 100644 --- a/citadel/serv_sieve.c +++ b/citadel/serv_sieve.c @@ -53,7 +53,6 @@ */ void log_the_sieve2_credits(void) { char *cred = NULL; - char *ptr; cred = strdup(sieve2_credits()); if (cred == NULL) return; diff --git a/citadel/server.h b/citadel/server.h index c45b081c3..3e59e13f5 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -221,6 +221,7 @@ enum { S_DEBUGMEMLEAKS, S_ATBF, S_JOURNAL_QUEUE, + S_RPLIST, MAX_SEMAPHORES }; diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 7d65e6c8a..3e3e2cff6 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -248,6 +248,7 @@ void begin_critical_section(int which_one) #ifdef DEBUG_MEMORY_LEAKS && (which_one != S_DEBUGMEMLEAKS) #endif + && (which_one != S_RPLIST) ) { cdb_check_handles(); } -- 2.39.2