From: Zdeněk Šustr Date: Tue, 24 May 2011 14:23:05 +0000 (+0000) Subject: - Minor fixes in server-side L&B dump code X-Git-Tag: glite-lb-client_R_4_1_10_1~16 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=55025245b1001c4468312aae606540a44084ab85;p=jra1mw.git - Minor fixes in server-side L&B dump code - 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 --- diff --git a/org.glite.lb.server/src/dump.c b/org.glite.lb.server/src/dump.c index ff785bd..c25f552 100644 --- a/org.glite.lb.server/src/dump.c +++ b/org.glite.lb.server/src/dump.c @@ -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, diff --git a/org.glite.lb.server/src/get_events.c.T b/org.glite.lb.server/src/get_events.c.T index 4ff6ca5..cff249e 100644 --- a/org.glite.lb.server/src/get_events.c.T +++ b/org.glite.lb.server/src/get_events.c.T @@ -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); diff --git a/org.glite.lb.server/src/server_state.c b/org.glite.lb.server/src/server_state.c index a95610e..f64d32a 100644 --- a/org.glite.lb.server/src/server_state.c +++ b/org.glite.lb.server/src/server_state.c @@ -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); }