OSDN Git Service

Set old destination for changing connection from sorry server to real server. sorry-fix-switch
authorKohei TANUMA <tanuma@users.sourceforge.jp>
Sun, 6 Jun 2010 17:37:17 +0000 (02:37 +0900)
committerKohei TANUMA <tanuma@users.sourceforge.jp>
Sun, 6 Jun 2010 17:37:17 +0000 (02:37 +0900)
Fix the following pattern (a) and (b), but not (c).
(a) 1. First connection: sorry server (over max connections)
    2. Communicate to sorry server...
    3. Some other connections done. (below max connections)
    4. Change connection: sorry -> real server
(b) 1. First connection: sorry server (force-sorry-flag is on)
    2. Communicate to sorry server...
    3. Administrator change setting (force-sorry-flag is off)
    4. Change connection: sorry -> real server
(c) 1. First connection: sorry server (no real servers)
    2. Communicate to sorry server...
    3. Administrator add real servers
    4. Change connection: sorry -> real server
       (But now connection will be closed.)

src/conn.c
src/lsock.c

index fa184f2..00a043e 100644 (file)
@@ -1060,14 +1060,17 @@ l7vs_conn_is_rs_connected(struct l7vs_iomux *iom, struct l7vs_conn *conn, struct
     }
     /*------ DEBUG LOG END ------*/
 
-    //is real server connected?
     if (-1 != conn->riom->fd) {
-        // check sorry status of service
-        // argment 0 means no connection count check
+        // Connection to real/sorry server is already ESTABLISHED
+
+        // Check force-sorry-flag and existance of real servers
         sorry_state = l7vs_sched_sorry_check(conn->srv, 0);
         if (sorry_state) {
-            // check connect to sorry-server now
+            // force-sorry-flag is ON or no real servers
+
             if (!conn->sorry_conn_flag) {
+                // Current connection is to real server,
+                // so change to connect to sorry server.
                 // get sorry-server destination (argment 0)
                 d = l7vs_sched_sorry_dest(conn->srv, conn, 0);
                 /*-------- DEBUG LOG --------*/
@@ -1132,9 +1135,17 @@ l7vs_conn_is_rs_connected(struct l7vs_iomux *iom, struct l7vs_conn *conn, struct
                 }
                 conn->sorry_conn_flag = 1;
             }
+            else {
+                // Current connection is already changed to sorry server,
+                // so do nothing.
+            }
+
         } else {
-            // check connect to sorry-server now
+            // force-sorry-flag is OFF and real servers exist
+
             if (conn->sorry_conn_flag) {
+                // Current connection is to sorry server,
+                // so change to connect to real server.
                 // get old real-server destination (argment 1)
                 d = l7vs_sched_sorry_dest(conn->srv, conn, 1);
                 /*-------- DEBUG LOG --------*/
index 23b4026..693dfae 100644 (file)
@@ -492,6 +492,7 @@ l7vs_lsock_select_service(struct l7vs_lsock *lsock,
         if (ret == 0) {
             // check sorry status if ret == 0
             // sorry_check argument 1 means check connection count
+            // Check the connection count(--upper, maxconn)
             if (l7vs_sched_sorry_check(srv, 1)) {
                 if (!sorry_save) {
                     // save sorry dest to xxx_tmp only first time
@@ -517,6 +518,7 @@ l7vs_lsock_select_service(struct l7vs_lsock *lsock,
             }
         }
         // when select_dest NG
+        // No suitable realservers exist
         if (!sorry_save2) {
             // save sorry dest to xxx_tmp2 only first time
             srv_tmp2 = srv;
@@ -528,10 +530,10 @@ l7vs_lsock_select_service(struct l7vs_lsock *lsock,
         l = g_list_next(l);
     }
 
+    // Over maximum connections
     if (sorry_save) {
         // saved sorry dest is exist
         // set sorry-server destination
-        //*dest_ret = (struct l7vs_dest *)l7vs_sched_sorry_dest(srv_tmp, NULL, 1);
         *dest_ret = (struct l7vs_dest *)l7vs_sched_sorry_dest(srv_tmp, NULL, 0);
         if (!*dest_ret) {
             LOGGER_PUT_LOG_ERROR(LOG_CAT_L7VSD_SORRY_SERVER,2, "sorry-server dest is NULL");
@@ -542,13 +544,15 @@ l7vs_lsock_select_service(struct l7vs_lsock *lsock,
             return -1;
         }
         *srv_ret = srv_tmp;
+        conn->old_dest = dest_tmp;
         conn->cldata_len = len_tmp;
         conn->sorry_conn_flag = 1;
         val = 1;
+
+    // No suitable realservers exist
     } else if (sorry_save2) {
         // saved sorry dest2 is exist
         // set sorry-server destination
-        //*dest_ret = (struct l7vs_dest *)l7vs_sched_sorry_dest(srv_tmp2, NULL, 1);
         *dest_ret = (struct l7vs_dest *)l7vs_sched_sorry_dest(srv_tmp2, NULL, 0);
         if (!*dest_ret) {
             LOGGER_PUT_LOG_ERROR(LOG_CAT_L7VSD_SORRY_SERVER,3, "sorry-server dest is NULL");
@@ -559,6 +563,7 @@ l7vs_lsock_select_service(struct l7vs_lsock *lsock,
             return -1;
         }
         *srv_ret = srv_tmp2;
+        conn->old_dest = dest_tmp2;
         conn->cldata_len = len_tmp2;
         conn->sorry_conn_flag = 1;
         val = 1;