short/long_fileds removal patch (for sharing).
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 30 Jan 2008 14:42:54 +0000 (14:42 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 30 Jan 2008 14:42:54 +0000 (14:42 +0000)
org.glite.lb.server/Makefile
org.glite.lb.server/config/glite-lb-dbsetup.sql
org.glite.lb.server/interface/store.h
org.glite.lb.server/src/db_store.c
org.glite.lb.server/src/get_events.c.T
org.glite.lb.server/src/load.c
org.glite.lb.server/src/store.c.T

index 758789c..9cd80ac 100644 (file)
@@ -107,6 +107,10 @@ ifdef LBS_DB_PROFILE
        CFLAGS:=${CFLAGS} -DLBS_DB_PROFILE
 endif
 
+ifdef LB_EVENTS_BLOB
+       CFLAGS:=${CFLAGS} -DLB_EVENTS_BLOB
+endif
+
 TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit
 TEST_INC:=-I${cppunit_prefix}/include
 
index 4a65ff3..530353b 100644 (file)
@@ -41,7 +41,7 @@ create table events (
        level           int             null,
 
        arrived         datetime        not null,
-       
+       ulm             mediumblob      not null,   -- testing (1)
 
        primary key (jobid,event),
        index (time_stamp),
@@ -49,6 +49,16 @@ create table events (
        index (arrived)
 ) engine=innodb;
 
+-- testing (2)
+create table events_flesh (
+       jobid           char(32)        binary not null,
+       event           int             not null,
+       ulm             mediumblob      binary not null;
+       
+       primary key (jobid,event),
+) engine=innodb;
+
+-- for compatibility
 create table short_fields (
        jobid           char(32)        binary not null,
        event           int             not null,
@@ -58,6 +68,7 @@ create table short_fields (
        primary key (jobid,event,name)
 ) engine=innodb;
 
+-- for compatibility
 create table long_fields (
        jobid           char(32)        binary not null,
        event           int             not null,
index bb0bb38..fa76165 100644 (file)
@@ -15,6 +15,7 @@ extern "C" {
 int edg_wll_StoreEvent(
        edg_wll_Context,        /* INOUT */
        edg_wll_Event *,        /* IN */
+       const char *,           /* IN */
        int *
 );
 
index 36ec72e..8a1787b 100644 (file)
@@ -108,7 +108,7 @@ db_store(edg_wll_Context ctx,char *ucs, char *event)
 
   if(use_db) {
     if (ctx->strict_locking && edg_wll_LockJob(ctx,ev->any.jobId)) goto err;
-    if(edg_wll_StoreEvent(ctx, ev,&seq)) {
+    if(edg_wll_StoreEvent(ctx, ev, event, &seq)) {
        edg_wll_UnlockJob(ctx,ev->any.jobId);
        goto err;
     }
@@ -185,7 +185,7 @@ db_parent_store(edg_wll_Context ctx, edg_wll_Event *ev, intJobStat *is)
   assert(ev->any.user);
 
   if(use_db) {
-    if(edg_wll_StoreEvent(ctx, ev,&seq))
+    if(edg_wll_StoreEvent(ctx, ev, NULL, &seq))
       goto err;
   }
 
index 5f05332..8dc5f9f 100644 (file)
@@ -33,9 +33,24 @@ int edg_wll_get_event_flesh(edg_wll_Context ctx,int n,edg_wll_Event *e)
        glite_lbu_Statement     sh;
        int     ret,t;
        const char      *tables[] = { "short_fields","long_fields" };
+       edg_wll_Event *f;
 
        edg_wll_ResetError(ctx);
 
+       trio_asprintf(&q, "select ulm from events_flesh where jobid = '%|Ss' and event = %d", jobid, n);
+       if ((ret=edg_wll_ExecSQL(ctx,q,&sh)) < 0) goto cleanup;
+       if (edg_wll_FetchRow(ctx,sh,1,NULL,&nameval[0]) == 1) {
+               //fprintf(stderr, "got ulm: '%s'\n", nameval[0]);
+               // nasty ;-)
+               edg_wll_ParseEvent(ctx,nameval[0],&f);
+               memcpy(e, f, sizeof *e);
+               free(f);
+               ret=edg_wll_CheckEvent(ctx,e);
+       } else ret = ENOENT;
+       free(q); q = NULL;
+
+       // old way keeped for compatibility/slow migration
+       if (ret != 0) {
        for (t=0; t<=1; t++) {
                trio_asprintf(&q,"select name,value from %s "
                                "where jobid = '%|Ss' and event = %d ",
@@ -56,8 +71,8 @@ int edg_wll_get_event_flesh(edg_wll_Context ctx,int n,edg_wll_Event *e)
                glite_lbu_FreeStmt(&sh);
                free(q); q=NULL;
        }
-
        ret=edg_wll_CheckEvent(ctx,e);
+       }
 
 cleanup:
        if (sh) glite_lbu_FreeStmt(&sh);
index 6cacb0d..183c2d0 100644 (file)
@@ -84,7 +84,7 @@ int edg_wll_LoadEventsServer(edg_wll_Context ctx,const edg_wll_LoadRequest *req,
                        result->to = event->any.arrived.tv_sec;
                }
                ctx->event_load = 1;
-               if ( edg_wll_StoreEvent(ctx, event, NULL) )
+               if ( edg_wll_StoreEvent(ctx, event, line, NULL) )
                {
                        char            *errdesc;
                        int             len = strlen(line),
index 404f1f5..1bb3623 100644 (file)
@@ -38,7 +38,7 @@ static int store_job(edg_wll_Context,glite_jobid_const_t,const char *, int, int)
 static int store_job_block(edg_wll_Context, glite_jobid_const_t, const char *, glite_lbu_bufInsert *, int, int);
 #endif
 static int store_job_grey(edg_wll_Context,glite_jobid_const_t,time_t);
-static int store_flesh(edg_wll_Context,edg_wll_Event *,char *,int);
+static int store_flesh(edg_wll_Context,edg_wll_Event *,const char *ulm, char *,int);
 static int store_seq(edg_wll_Context,edg_wll_Event *,int);
 static int check_dup(edg_wll_Context,edg_wll_Event *);
 static int check_auth(edg_wll_Context,edg_wll_Event *e); 
@@ -51,7 +51,7 @@ void edg_wll_StoreAnonymous(edg_wll_Context ctx,int anon) {
        ctx->allowAnonymous = anon;
 }
 
-int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq)
+int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,const char *ulm,int *seq)
 {
        edg_wll_ErrorCode       err = 0;
        char            *userid = NULL,*jobid,*stmt;
@@ -161,7 +161,7 @@ int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq)
 
        free(stmt); stmt = NULL;
        if ((err = store_seq(ctx,e,next)) ||
-               (err = store_flesh(ctx,e,jobid,next))) {
+               (err = store_flesh(ctx,e,ulm,jobid,next))) {
        /* attempt to cleanup, ignore new errors */
                char            *desc;
                edg_wll_ErrorCode       oerr = edg_wll_Error(ctx,NULL,&desc);
@@ -543,7 +543,7 @@ static int store_seq(edg_wll_Context ctx,edg_wll_Event *e,int no)
 
 #define SHORT_LEN      255     /* short_fiels.value db column lenght */
 
-static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,char *jobid,int no)
+static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,const char *ulm,char *jobid,int no)
 {
        struct {
                char    *key;
@@ -554,7 +554,17 @@ static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,char *jobid,int no)
        unsigned int    i;
        int     err = 0;
 
+       assert(ulm || e);
        edg_wll_ResetError(ctx);
+       if (!ulm) ulm = edg_wll_UnparseEvent(ctx, e);
+       if (!ulm) return edg_wll_Error(ctx, NULL, NULL);
+
+#ifndef LB_EVENTS_BLOB
+       // in both ways if some preparsed flesh fields in events too
+       if (!e) {
+               if (edg_wll_ParseEvent(ctx, (char *)ulm, &e) != 0) return edg_wll_Error(ctx, NULL, NULL);
+       }
+
        memset(f,0,sizeof(f)); assert(f[0].key == NULL);
 
        switch (e->type) {
@@ -613,6 +623,11 @@ static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,char *jobid,int no)
                if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
                free(stmt);
        }
+#else
+       if (!ulm) ulm = edg_wll_UnparseEvent(ctx, e);
+       trio_asprintf(&stmt, "insert into events_flesh (jobid, event, ulm) values ('%|Ss', %d, '%|Ss')", jobid, no, ulm);
+       if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
+#endif
 
        return err;
 }
@@ -786,7 +801,7 @@ static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e)
                e2.regJob.jobtype = EDG_WLL_REGJOB_SIMPLE;
                e2.regJob.jdl = strdup("");
 
-               switch (edg_wll_StoreEvent(ctx,&e2,&seq)) {
+               switch (edg_wll_StoreEvent(ctx,&e2,NULL,&seq)) {
 
                        case 0: break;
                        /* maybe some non-ignorable errors should be handled here */
@@ -1022,6 +1037,12 @@ int edg_wll_delete_event(edg_wll_Context ctx,const char *jobid,int event)
        free(stmt);
 
        trio_asprintf(&stmt,
+               "delete from events_flesh where jobid='%|Ss' and event=%d",
+               jobid,event);
+       edg_wll_ExecSQL(ctx,stmt,NULL);
+       free(stmt);
+
+       trio_asprintf(&stmt,
                "delete from events where jobid='%|Ss' and event=%d",
                jobid,event);
        edg_wll_ExecSQL(ctx,stmt,NULL);