[exim-cvs] Improved spamd server selection.

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Exim Git Commits Mailing List
Dátum:  
Címzett: exim-cvs
Tárgy: [exim-cvs] Improved spamd server selection.
Gitweb: http://git.exim.org/exim.git/commitdiff/29cfeb94e35eb8fe2b6f02fe9c9444edb251fd71
Commit:     29cfeb94e35eb8fe2b6f02fe9c9444edb251fd71
Parent:     332f5cf3ddb43e1a85d70039211e73aa1a753ebd
Author:     Phil Pennock <pdp@???>
AuthorDate: Mon Feb 21 00:11:32 2011 -0500
Committer:  Phil Pennock <pdp@???>
CommitDate: Mon Feb 21 00:13:18 2011 -0500


    Improved spamd server selection.


    Patch from Mark Zealey.
    Fixes bug 1056.
---
 doc/doc-txt/ChangeLog |    3 +++
 doc/doc-txt/NewStuff  |    3 +++
 src/src/spam.c        |   35 ++++++++++++++++++++---------------
 3 files changed, 26 insertions(+), 15 deletions(-)


diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog
index 1fd7bd3..1fb19ca 100644
--- a/doc/doc-txt/ChangeLog
+++ b/doc/doc-txt/ChangeLog
@@ -63,6 +63,9 @@ PP/10 Use sig_atomic_t for flags set from signal handlers.
 PP/11 Bugzilla 1055: Update $message_linecount for maildir_tag.
       Patch from Mark Zealey.


+PP/12 Bugzilla 1056: Improved spamd server selection.
+      Patch from Mark Zealey.
+


 Exim version 4.74
 -----------------
diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index 7ae550b..b940afe 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -29,6 +29,9 @@ Version 4.75
     in the same way as $message_size, to reflect the real number of lines,
     including any header additions or removals from transport.


+ 5. When contacting a pool of SpamAssassin servers configured in spamd_address,
+    Exim now selects entries randomly, to better scale in a cluster setup.
+


Version 4.74
------------
diff --git a/src/src/spam.c b/src/src/spam.c
index ac96420..55999a3 100644
--- a/src/src/spam.c
+++ b/src/src/spam.c
@@ -111,10 +111,8 @@ int spam(uschar **listptr) {

   /* socket does not start with '/' -> network socket */
   if (*spamd_address_work != '/') {
-    time_t now = time(NULL);
     int num_servers = 0;
-    int current_server = 0;
-    int start_server = 0;
+    int current_server;
     uschar *address = NULL;
     uschar *spamd_address_list_ptr = spamd_address_work;
     uschar address_buffer[256];
@@ -126,6 +124,7 @@ int spam(uschar **listptr) {
                                         address_buffer,
                                         sizeof(address_buffer))) != NULL) {


+      /* Potential memory leak as we never free the store. */
       spamd_address_container *this_spamd =
         (spamd_address_container *)store_get(sizeof(spamd_address_container));


@@ -150,9 +149,10 @@ int spam(uschar **listptr) {
       return DEFER;
     };


-    current_server = start_server = (int)now % num_servers;
+    while ( num_servers > 0 ) {


-    while (1) {
+      /* Randomly pick a server to try */
+      current_server = random_number( num_servers );


       debug_printf("trying server %s, port %u\n",
                    spamd_address_vector[current_server]->tcp_addr,
@@ -180,16 +180,21 @@ int spam(uschar **listptr) {
          spamd_address_vector[current_server]->tcp_addr,
          spamd_address_vector[current_server]->tcp_port,
          strerror(errno));
-      current_server++;
-      if (current_server >= num_servers)
-        current_server = 0;
-      if (current_server == start_server) {
-        log_write(0, LOG_MAIN|LOG_PANIC, "spam acl condition: all spamd servers failed");
-        (void)fclose(mbox_file);
-        (void)close(spamd_sock);
-        return DEFER;
-      };
-    };
+
+      (void)close(spamd_sock);
+
+      /* Remove the server from the list. XXX We should free the memory */
+      num_servers--;
+      int i;
+      for( i = current_server; i < num_servers; i++ )
+        spamd_address_vector[i] = spamd_address_vector[i+1];
+    }
+
+    if ( num_servers == 0 ) {
+      log_write(0, LOG_MAIN|LOG_PANIC, "spam acl condition: all spamd servers failed");
+      (void)fclose(mbox_file);
+      return DEFER;
+    }


}
else {