]> andersk Git - moira.git/blobdiff - dcm/dcm.pc
inprogress was only being cleared for replicated serverhosts if the
[moira.git] / dcm / dcm.pc
index 4a1018d3fa9cf6d9f4df20b206751bbdffbf68ce..c34b8263401a647790c7555bf964ea80a6833b84 100644 (file)
@@ -31,7 +31,7 @@ RCSID("$Header$");
 
 int generate_service(char *name, int force);
 void do_hosts(char *service);
-int dcm_send_file(char *service, char *host, char *target);
+int dcm_send_file(char *service, int type, char *host, char *target);
 int dcm_execute(char *service, char *host, char *script);
 void dbmserr(void);
 
@@ -40,6 +40,8 @@ void dbmserr(void);
 
 char whobuf[256], *whoami = whobuf, *db = "moira";
 
+enum { UNIQUE, DISTRIBUTED, REPLICATED };
+
 int main(int argc, char **argv)
 {
   int i;
@@ -241,13 +243,13 @@ gen_cleanup:
 void do_hosts(char *service)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  char type[SERVERS_TYPE_SIZE], host[MACHINE_NAME_SIZE];
+  char server_type[SERVERS_TYPE_SIZE], host[MACHINE_NAME_SIZE], *name;
   char target[SERVERS_TARGET_FILE_SIZE], script[SERVERS_SCRIPT_SIZE];
   const char *errmsg;
-  int status = 0, dfgen, replicated, mid;
+  int status = 0, dfgen, type, mid;
   time_t now;
   EXEC SQL END DECLARE SECTION;
-  struct save_queue sq;
+  struct save_queue *sq;
 
   time(&now);
   mr_init();
@@ -255,9 +257,14 @@ void do_hosts(char *service)
   EXEC SQL CONNECT :db IDENTIFIED BY :db;
 
   EXEC SQL SELECT dfgen, type, target_file, script
-    INTO :dfgen, :type, :target, :script
+    INTO :dfgen, :server_type, :target, :script
     FROM servers WHERE name = UPPER(:service);
-  replicated = !strncmp(type, "REPLICAT", 8);
+  if (!strncmp(strtrim(server_type), "REPLICAT", 8))
+    type = REPLICATED;
+  else if (!strncmp(server_type, "DISTRIB", 8))
+    type = DISTRIBUTED;
+  else
+    type = UNIQUE;
   strtrim(target);
   strtrim(script);
 
@@ -287,34 +294,34 @@ void do_hosts(char *service)
       EXEC SQL UPDATE serverhosts SET inprogress = 1
        WHERE service = UPPER(:service) AND mach_id = :mid;
       EXEC SQL COMMIT;
-      status = dcm_send_file(service, name, target);
+      status = dcm_send_file(service, type, name, target);
       if (status)
        {
          errmsg = error_message(status);
          EXEC SQL UPDATE serverhosts SET hosterrmsg = :errmsg,
            inprogress = 0, success = 0, ltt = :now
-           WHERE service = UPPER(:service) AND mach_id = :mach_id;
+           WHERE service = UPPER(:service) AND mach_id = :mid;
          if (!SOFT_FAIL(status))
            {
              EXEC SQL UPDATE serverhosts SET hosterror = :status
-               WHERE CURRENT OF csr_hst1;
+               WHERE service = UPPER(:service) AND mach_id = :mid;
              critical_alert("DCM", "DCM updating %s:%s: %s",
                             service, name, errmsg);
            }
          EXEC SQL COMMIT;
 
-         if (replicated)
+         if (type == REPLICATED)
            break;
        }
     }
   sq_destroy(sq);
 
-  if (status == MR_SUCCESS || !replicated)
+  if (status == MR_SUCCESS || type != REPLICATED)
     {
       EXEC SQL DECLARE csr_hst2 CURSOR FOR
        SELECT m.name, m.mach_id FROM machine m, serverhosts sh
        WHERE sh.service = UPPER(:service) AND sh.inprogress = 1
-       AND sh.mach_id = m.mach_id;
+       AND sh.enable = 1 AND sh.hosterror = 0 AND sh.mach_id = m.mach_id;
       EXEC SQL OPEN csr_hst2;
       sq = sq_create();
 
@@ -346,17 +353,11 @@ void do_hosts(char *service)
                  EXEC SQL UPDATE serverhosts SET hosterror = :status
                    WHERE service = UPPER(:service) AND mach_id = :mid;
                  critical_alert("DCM", "DCM updating %s:%s: %s",
-                                service, host, errmsg);
+                                service, name, errmsg);
                }
 
-             if (replicated)
-               {
-                 /* We're giving up, so clear the inprogress flag on
-                    any hosts in this service we haven't gotten to yet */
-                 EXEC SQL UPDATE serverhosts SET inprogress = 0
-                   WHERE service = UPPER(:service);
-                 break;
-               }
+             if (type == REPLICATED)
+               break;
            }
          else
            {
@@ -369,8 +370,17 @@ void do_hosts(char *service)
       EXEC SQL CLOSE csr_hst2;
     }
 
+  if (type == REPLICATED)
+    {
+      /* Clear inprogress flag on any hosts we started but didn't
+       * finish.
+       */
+      EXEC SQL UPDATE serverhosts SET inprogress = 0
+       WHERE service = UPPER(:service);
+    }
+
   EXEC SQL WHENEVER SQLERROR DO dbmserr();
-  if (status && replicated)
+  if (status && !SOFT_FAIL(status) && type == REPLICATED)
     {
       EXEC SQL UPDATE servers SET harderror = :status, errmsg = :errmsg
        WHERE name = UPPER(:service);
@@ -383,14 +393,14 @@ host_cleanup:
   EXEC SQL UPDATE serverhosts SET inprogress = 0, success = 0, ltt = :now,
     hosterror = MR_INTERNAL, hosterrmsg = 'DBMS Internal Error'
     WHERE service = UPPER(:service) AND mach_id = :mid;
-  if (replicated)
+  if (type == REPLICATED)
     {
       EXEC SQL UPDATE servers SET harderror = MR_INTERNAL,
        errmsg = 'DBMS Internal Error' WHERE name = UPPER(:service);
     }
 }
 
-int dcm_send_file(char *service, char *host, char *target)
+int dcm_send_file(char *service, int type, char *host, char *target)
 {
   char data[MAXPATHLEN];
   int code, conn;
@@ -409,7 +419,10 @@ int dcm_send_file(char *service, char *host, char *target)
       goto done;
     }
 
-  sprintf(data, "%s/%s.out", DCM_DIR, service);
+  if (type == DISTRIBUTED)
+    sprintf(data, "%s/%s/%s", DCM_DIR, service, host);
+  else
+    sprintf(data, "%s/%s.out", DCM_DIR, service);
   code = send_file(conn, data, target, 0);
   if (code)
     com_err(whoami, code, "sending data to %s", host);
This page took 0.042474 seconds and 4 git commands to generate.