open only one lb_export file (prevent open files limit exhaustion on large lb dumps)
authorMiloš Mulač <mulac@civ.zcu.cz>
Thu, 23 Aug 2007 11:55:19 +0000 (11:55 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Thu, 23 Aug 2007 11:55:19 +0000 (11:55 +0000)
- the file stays open until new jobid in dump occures
=> only number_of_unique_jobids open/close pairs should occure
hence events in lb dump are clustered by jobids

org.glite.lb.client/src/lb_dump_exporter.c

index 97a63ab..e4d4f1c 100644 (file)
@@ -69,10 +69,11 @@ static void dump_storage_free(dump_storage_t *);
 
 int main(int argc, char **argv)
 {
-       edg_wll_Context         ctx;
-       edg_wll_Event      *ev = NULL;
-       dump_storage_t     *dstorage = NULL,
-                                          *st;
+       edg_wll_Context ctx;
+       edg_wll_Event   *ev = NULL;
+       dump_storage_t  *dstorage = NULL,
+                       *last_st = NULL,
+                       *st;
        buffer_t                        buf;
        char                       *store_pref = DUMP_FILE_STORE_PREFIX,
                                           *lb_maildir = LB_MAILDIR_PATH,
@@ -171,14 +172,34 @@ int main(int argc, char **argv)
                                }
                                break;
                        }
+                       if (last_st) { 
+                               close(last_st->fhnd);
+                               last_st->fhnd = 0;
+                       }
 
                        if ( !(st = dump_storage_add(&dstorage, jobid, fname, fd)) ) {
                                perror("Can't record dump informations");
                                cleanup(1);
                        }
                }
+               else {
+                       if (strcmp(last_st->fname,st->fname)) {
+                               /* new jobid data */
+                               // this is only fallback code, because data in lb dump 
+                               // are clustered by jobids, hence files are created by
+                               // open() above
+                               close(last_st->fhnd);
+                               last_st->fhnd = 0;
+
+                               if ( (st->fhnd = open(st->fname, O_APPEND|O_RDWR)) < 0 ) {
+                                       perror(st->fname);
+                                       cleanup(1);
+                               }
+                       }
+               }
                free(jobid);
                free(unique);
+               last_st = st;
 
                lnsz = strlen(ln);
                ln[lnsz++] = '\n';