- Minor fixes in server-side L&B dump code
authorZdeněk Šustr <sustr4@cesnet.cz>
Tue, 24 May 2011 14:23:05 +0000 (14:23 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Tue, 24 May 2011 14:23:05 +0000 (14:23 +0000)
- Benign reaction to unknown event types in edg_wll_get_event_flesh() for forward compatibility
- Refactoring of server state storing routine to avoid unnecessary error reports

org.glite.lb.server/src/dump.c
org.glite.lb.server/src/get_events.c.T
org.glite.lb.server/src/server_state.c

index ff785bd..c25f552 100644 (file)
@@ -50,7 +50,7 @@ int edg_wll_DumpEventsServer(edg_wll_Context ctx,const edg_wll_DumpRequest *req,
        char    *tmpfname;
        time_t  start,end;
        glite_lbu_Statement     q = NULL;
-       char            *res[10];
+       char            *res[11];
        int     event;
        edg_wll_Event   e;
        int     ret,dump = 2;   /* TODO: manage dump file */
@@ -76,11 +76,11 @@ int edg_wll_DumpEventsServer(edg_wll_Context ctx,const edg_wll_DumpRequest *req,
        glite_lbu_TimeToStr(to, &to_s);
 
        trio_asprintf(&stmt,
-                       "select event,dg_jobid,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived "
+                       "select event,dg_jobid,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived,seqcode "
                        "from events e,users u,jobs j "
                        "where u.userid=e.userid "
                        "and j.jobid = e.jobid "
-                       "and j.dg_jobid like 'https://%|Ss:%d%%' "
+                       "and j.dg_jobid like 'https://%|Ss:%d/%%' "
                        "and arrived > %s and arrived <= %s "
                        "order by arrived",
                        ctx->srvName,ctx->srvPort,
index 4ff6ca5..cff249e 100644 (file)
@@ -65,12 +65,18 @@ int edg_wll_get_event_flesh(edg_wll_Context ctx,int n,edg_wll_Event *e)
                edg_wll_ParseEvent(ctx,nameval[0],&f);
                free(nameval[0]);
 
-               f->any.arrived = e->any.arrived;
-               edg_wll_FreeEvent(e);
+               if(f) {
+                       f->any.arrived = e->any.arrived;
+                       edg_wll_FreeEvent(e);
 
-               memcpy(e, f, sizeof *e);
-               free(f);
-               ret=edg_wll_CheckEvent(ctx,e);
+                       memcpy(e, f, sizeof *e);
+                       free(f);
+                       ret=edg_wll_CheckEvent(ctx,e);
+               }
+               else {
+                       glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "Unknown event type encountered during dump; jobid %s, event %d", jobid, n);
+                       ret = EINVAL;
+               }
        } else ret = ENOENT;
        free(q); q = NULL;
        glite_lbu_FreeStmt(&sh);
index a95610e..f64d32a 100644 (file)
@@ -51,28 +51,39 @@ int edg_wll_GetServerState(edg_wll_Context ctx,const char *name,char **val)
 int edg_wll_SetServerState(edg_wll_Context ctx,const char *name,const char *val)
 {
        char    *stmt = NULL;
+       int sql_retval;
 
-       trio_asprintf(&stmt,"insert into server_state (prefix,name,value) "
-                       "values ('https://%|Ss:%d','%|Ss','%|Ss')",
-                       ctx->srvName,ctx->srvPort,name,val);
+       // Check if record exists
+       trio_asprintf(&stmt,"select value from server_state "
+                       "where prefix = 'https://%|Ss:%d' and name = '%|Ss'",
+                       ctx->srvName,ctx->srvPort,name);
        glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);
 
-       switch(edg_wll_ExecSQL(ctx,stmt,NULL)) {
-               case 1: break;
-               case -1: if (edg_wll_Error(ctx,NULL,NULL) == EEXIST) {
-                                free(stmt);
-                                trio_asprintf(&stmt,"update server_state set value = '%|Ss' "
-                                                "where prefix = 'https://%|Ss:%d' "
-                                                "and name = '%|Ss'",
-                                                val,ctx->srvName,ctx->srvPort,name);
-                               glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, 
-                                       LOG_PRIORITY_DEBUG, stmt);
-                                edg_wll_ExecSQL(ctx,stmt,NULL);
-                        }
-                        break;
+       sql_retval = edg_wll_ExecSQL(ctx,stmt,NULL);
 
-               default: abort();
-       }
        free(stmt);
+
+       if (!sql_retval) {
+               trio_asprintf(&stmt,"insert into server_state (prefix,name,value) "
+                               "values ('https://%|Ss:%d','%|Ss','%|Ss')",
+                               ctx->srvName,ctx->srvPort,name,val);
+               glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);
+               edg_wll_ExecSQL(ctx,stmt,NULL);
+               free(stmt);
+       }
+       else {
+               if (sql_retval > 0) {
+                       trio_asprintf(&stmt,"update server_state set value = '%|Ss' "
+                                        "where prefix = 'https://%|Ss:%d' "
+                                        "and name = '%|Ss'",
+                                        val,ctx->srvName,ctx->srvPort,name);
+                       glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, 
+                                       LOG_PRIORITY_DEBUG, stmt);
+                       edg_wll_ExecSQL(ctx,stmt,NULL);
+                       free(stmt);
+               }
+               else abort();
+        }
+
        return edg_wll_Error(ctx,NULL,NULL);
 }