Branch: Tag:

2004-05-18

2004-05-18 15:52:02 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fixed various output to be debug-log compatible.

Rev: server/bin/garbagecollector.pike:1.22

6:    * doc = "This is the proxy garbage collector";    */    - string cvs_version = "$Id: garbagecollector.pike,v 1.21 2004/05/11 19:07:10 grubba Exp $"; + string cvs_version = "$Id: garbagecollector.pike,v 1.22 2004/05/18 15:52:02 grubba Exp $";      //#define DEBUG   
21:      mapping log = ([]);    + #define LOGGER(x) if(gc_log) gc_log->write(x); else werror(" : %s", x) + Stdio.File gc_log; +    string _order(int from)   {    return sprintf("%08x", from);
61:       if(catch(log = decode_value( s ))) {   #ifdef DEBUG -  werror("Could not decode cachelog file ("+file+") - removed\n"); +  LOGGER("Could not decode cachelog file ("+file+") - removed\n");   #endif    rm_log(num);    return 0;
82:    if(sizeof(log)<=0)    return;    if(!Stdio.write_file(file, encode_value(log))) -  werror("Could not write cachelog file ("+file+")\n"); +  LOGGER("Could not write cachelog file ("+file+")\n");   }      #define BLOCK_SIZE 2048
101:    disk_i_max, disk_i_used, disk_i_avail, disk_i_capacity, disk_time;   string disk_name, disk_type;    - #define LOGGER(x) if(gc_log)gc_log->write(x);else werror(x) - Stdio.File gc_log; -  +    string disk_info()   {    return
161:    file = lp+"cache_status";    mkdir(lp);    if(Stdio.file_size(file)<=0) { -  werror("read_cache_status: "+file+" is missing\n"); +  LOGGER("read_cache_status: "+file+" is missing\n");    return 0;    }    if(!(s=Stdio.read_bytes(file))) { -  werror("read_cache_status: "+file+" could not be read\n"); +  LOGGER("read_cache_status: "+file+" could not be read\n");    rm(file);    return 0;    }    if(catch(status = decode_value(s))) { -  werror("read_cache_status: "+file+" could not be decoded\n"); +  LOGGER("read_cache_status: "+file+" could not be decoded\n");    rm(file);    return 0;    }
187:    (max_cache_size>0&&cache_size <= 0)||    (max_num_files>0&&num_files <= 0)||    (first_log <= 0)) { -  werror("read_cache_status: "+file+" contains rubbish\n"); +  LOGGER("read_cache_status: "+file+" contains rubbish\n");    rm(file);    return 0;    }
237: Inside #if 0
   log = ([]);       if(last_log < 0) -  werror("CACHE: Failed to read existing logfile.\n"); +  LOGGER("CACHE: Failed to read existing logfile.\n");   #endif   }   
257:    status->lastgc = lastgc;       if(!Stdio.write_file(file+"+", encode_value(status))) -  werror("write_cache_status: "+file+"+"+" could not be written\n"); +  LOGGER("write_cache_status: "+file+"+"+" could not be written\n");    if(!mv(file+"+", file)) -  werror("write_cache_status: "+file+" could not be written\n"); +  LOGGER("write_cache_status: "+file+" could not be written\n");   }      void write_log()
271:    file = lp+"cachelog"+_order(last_log);    rm(file);    if (!Stdio.write_file(file, encode_value(log))) -  werror("Could not write cachelog file ("+file+")\n"); +  LOGGER("Could not write cachelog file ("+file+")\n");    log = ([]);    write_cache_status();   }      void update(string file, int tim, int|void score)   { - //werror(file+" "+(time(1)-tim)+" seconds old, "+score+" \"bonus\" seconds.\n"); + //LOGGER(file+" "+(time(1)-tim)+" seconds old, "+score+" \"bonus\" seconds.\n");    if((search(file, ".done")!=-1)&&log[file-".done"]) {    m_delete(log, file-".done");    num_files--;
375:    last_log++;    if((Stdio.file_size(lp+"cachelog"+_order(1))>0) &&    !mv(lp+"cachelog"+_order(1), lp+"cachelog"+_order(last_log))) -  werror("find_all_files_and_log_it - mv failed\n"); +  LOGGER("find_all_files_and_log_it - mv failed\n");       write_cache_status();    current_cache_message();
392:       write_log();    - // werror("Collect. first_log="+first_log+"; last_log="+last_log+"\n"); + // LOGGER("Collect. first_log="+first_log+"; last_log="+last_log+"\n");    r = catch {    while((amnt>0)&&(first_log <= last_log))    {    mapping rl; - // werror("Collecting log "+i+"\n"); - // werror("Collect. first_log="+first_log+"; last_log="+last_log+"\n"); + // LOGGER("Collecting log "+i+"\n"); + // LOGGER("Collect. first_log="+first_log+"; last_log="+last_log+"\n");    if(rl = parse_log(first_log))    {    logsize = sizeof(rl);
410:    };    if(r)    { -  werror("Error while garbagecollecting: "+r[0]+"\n" +  LOGGER("Error while garbagecollecting: "+r[0]+"\n"    +describe_backtrace(r[1]));    return;    }
447:      void cache_stream_closed()   { -  werror("garbagecollector: cache command stream closed. Exiting\n"); +  LOGGER("garbagecollector: cache command stream closed. Exiting\n");   #ifdef LPC_GARB    write_log();   #endif
459:    mixed res;    if(!arrayp(what))    { -  werror(sprintf("Got strange command (%O)\n", what)); +  LOGGER(sprintf("Got strange command (%O)\n", what));    return 0;    }      #ifdef DEBUG - // werror(sprintf("Got command %O\n", what)); + // LOGGER(sprintf("Got command %O\n", what));   #endif       return this_object()[what[0]](@what[1..]);
475:   {    cmd = _cache+cmd;    - // werror("Got some data: '"+cmd+"'\n"); + // LOGGER("Got some data: '"+cmd+"'\n");       while(strlen(cmd))    {
495:       cmd=cmd[l..]; // Remove the 'command' field of this command    } - // werror("data parsed ("+strlen(cmd)+" bytes in cache).\n"); + // LOGGER("data parsed ("+strlen(cmd)+" bytes in cache).\n");       _cache=cmd;   }
506:   {    mixed s;   #ifdef DEBUG - // werror("remove one file? "+fname+" --- "); + // LOGGER("remove one file? "+fname+" --- ");   #endif    s=stat_cache[fname];    if(!s)
550:       catch {   #ifdef DEBUG -  // werror("really_gc ("+(int)BLOCK_TO_KB(amnt)+" Kb)\n"); +  // LOGGER("really_gc ("+(int)BLOCK_TO_KB(amnt)+" Kb)\n");   #endif    collect(amnt, remove_one_file);    write_cache_status();    current_cache_message();   #ifdef DEBUG -  // werror("--------- ("+(int)BLOCK_TO_KB(removed)+" Kb really removed)\n"); +  // LOGGER("--------- ("+(int)BLOCK_TO_KB(removed)+" Kb really removed)\n");   #endif    };    stat_cache = ([]);
617:       gc_log = Stdio.File();    if(!gc_log->open(lf, "rwac")) { -  werror("init_log_file("+lf+"): open failed\n"); +  werror(" : init_log_file("+lf+"): open failed\n");    destruct(gc_log);    return;    }
680:    init_log_file(gc_lf);      #ifdef DEBUG -  werror("Initalizing cache, cache-dir is "+cdir+"\n"); +  LOGGER("Initalizing cache, cache-dir is "+cdir+"\n");   #endif    cd(cdir);    cache_normal_garb = cng*(1048576/BLOCK_SIZE);