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 */
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,
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);
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);
}