[or-cvs] r11225: Clean up MTBF storage code. Do not count times that we have (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Mon Aug 20 16:34:18 UTC 2007


Author: nickm
Date: 2007-08-20 12:34:17 -0400 (Mon, 20 Aug 2007)
New Revision: 11225

Modified:
   tor/trunk/
   tor/trunk/src/or/config.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/rephist.c
Log:
 r14733 at catbus:  nickm | 2007-08-20 12:32:44 -0400
 Clean up MTBF storage code. Do not count times that we have been down toward the current run.  Handle backward timewarps correctly.  Store MTBF data on exit in addition to periodically.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14733] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2007-08-20 16:32:00 UTC (rev 11224)
+++ tor/trunk/src/or/config.c	2007-08-20 16:34:17 UTC (rev 11225)
@@ -1006,12 +1006,7 @@
       return -1;
 
     /* XXXX020 make this conditional? */
-    len = strlen(options->DataDirectory)+32;
-    fn = tor_malloc(len);
-    tor_snprintf(fn, len, "%s"PATH_SEPARATOR"router-stability",
-                 options->DataDirectory);
-    rep_hist_load_mtbf_data(fn, time(NULL));
-    tor_free(fn);
+    rep_hist_load_mtbf_data(time(NULL));
   }
 
   /* Bail out at this point if we're not going to be a client or server:

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2007-08-20 16:32:00 UTC (rev 11224)
+++ tor/trunk/src/or/main.c	2007-08-20 16:34:17 UTC (rev 11225)
@@ -845,8 +845,7 @@
   static time_t time_to_add_entropy = 0;
   static time_t time_to_write_hs_statistics = 0;
   static time_t time_to_downrate_stability = 0;
-  /* XXXX020 this is way too low. */
-#define SAVE_STABILITY_INTERVAL (10*60)
+#define SAVE_STABILITY_INTERVAL (30*60)
   static time_t time_to_save_stability = 0;
   or_options_t *options = get_options();
   int i;
@@ -942,14 +941,9 @@
     if (!time_to_save_stability)
       time_to_save_stability = now + SAVE_STABILITY_INTERVAL;
     if (time_to_save_stability < now) {
-      size_t len = strlen(options->DataDirectory)+32;
-      char *fn = tor_malloc(len);
-      tor_snprintf(fn, len, "%s"PATH_SEPARATOR"router-stability",
-                   options->DataDirectory);
-      if (rep_hist_record_mtbf_data(fn)<0) {
-        log_warn(LD_GENERAL, "Couldn't store mtbf data in %s", fn);
+      if (rep_hist_record_mtbf_data()<0) {
+        log_warn(LD_GENERAL, "Couldn't store mtbf data.");
       }
-      tor_free(fn);
 
       time_to_save_stability = now + SAVE_STABILITY_INTERVAL;
     }
@@ -1851,6 +1845,8 @@
       accounting_record_bandwidth_usage(time(NULL), get_or_state());
     or_state_mark_dirty(get_or_state(), 0); /* force an immediate save. */
     or_state_save(time(NULL));
+    if (authdir_mode_tests_reachability(options))
+      rep_hist_record_mtbf_data();
   }
 #ifdef USE_DMALLOC
   dmalloc_log_stats();

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-08-20 16:32:00 UTC (rev 11224)
+++ tor/trunk/src/or/or.h	2007-08-20 16:34:17 UTC (rev 11225)
@@ -3119,8 +3119,8 @@
 
 void rep_hist_note_router_reachable(const char *id, time_t when);
 void rep_hist_note_router_unreachable(const char *id, time_t when);
-int rep_hist_record_mtbf_data(const char *filename);
-int rep_hist_load_mtbf_data(const char *filename, time_t now);
+int rep_hist_record_mtbf_data(void);
+int rep_hist_load_mtbf_data(time_t now);
 
 time_t rep_hist_downrate_old_runs(time_t now);
 double rep_hist_get_stability(const char *id, time_t when);

Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c	2007-08-20 16:32:00 UTC (rev 11224)
+++ tor/trunk/src/or/rephist.c	2007-08-20 16:34:17 UTC (rev 11225)
@@ -503,8 +503,19 @@
 }
 
 /** DOCDOC */
+static char *
+get_mtbf_filename(void)
+{
+  const char *datadir = get_options()->DataDirectory;
+  size_t len = strlen(datadir)+32;
+  char *fn = tor_malloc(len);
+  tor_snprintf(fn, len, "%s"PATH_SEPARATOR"router-stability", datadir);
+  return fn;
+}
+
+/** DOCDOC */
 int
-rep_hist_record_mtbf_data(const char *filename)
+rep_hist_record_mtbf_data(void)
 {
   char buf[128];
   char time_buf[ISO_TIME_LEN+1];
@@ -529,7 +540,6 @@
     smartlist_add(lines, tor_strdup(buf));
   }
 
-
   smartlist_add(lines, tor_strdup("data\n"));
 
   for (orhist_it = digestmap_iter_init(history_map);
@@ -557,10 +567,12 @@
     size_t sz;
     /* XXXX This isn't terribly efficient; line-at-a-time would be
      * way faster. */
+    char *filename = get_mtbf_filename();
     char *data = smartlist_join_strings(lines, "", 0, &sz);
     int r = write_bytes_to_file(filename, data, sz, 0);
 
     tor_free(data);
+    tor_free(filename);
     SMARTLIST_FOREACH(lines, char *, cp, tor_free(cp));
     smartlist_free(lines);
     return r;
@@ -569,16 +581,18 @@
 
 /** DOCDOC */
 int
-rep_hist_load_mtbf_data(const char *filename, time_t now)
+rep_hist_load_mtbf_data(time_t now)
 {
   /* XXXX won't handle being called while history is already populated. */
   smartlist_t *lines;
   const char *line = NULL;
   int r=0, i;
-  time_t last_downrated = 0;
+  time_t last_downrated = 0, stored_at = 0;
 
   {
+    char *filename = get_mtbf_filename();
     char *d = read_file_to_str(filename, RFTS_IGNORE_MISSING, NULL);
+    tor_free(filename);
     if (!d)
       return -1;
     lines = smartlist_create();
@@ -599,9 +613,20 @@
         log_warn(LD_GENERAL,"Couldn't parse downrate time in mtbf "
                  "history file.");
     }
-    if (last_downrated > now)
-      last_downrated = now;
+    if (!strcmpstart(line, "stored-at ")) {
+      if (parse_iso_time(line+strlen("stored-at "), &stored_at)<0)
+        log_warn(LD_GENERAL,"Couldn't parse stored time in mtbf "
+                 "history file.");
+    }
   }
+  if (last_downrated > now)
+    last_downrated = now;
+
+  if (!stored_at) {
+    log_warn(LD_GENERAL, "No stored time recorded.");
+    goto err;
+  }
+
   if (line && !strcmp(line, "data"))
     ++i;
 
@@ -636,15 +661,19 @@
     hist = get_or_history(digest);
     if (!hist)
       continue;
-    if (start_of_run > now)
-      start_of_run = now;
-    hist->start_of_run = start_of_run;
+
+    if (!start_of_run || start_of_run > stored_at) {
+      hist->start_of_run = 0;
+    } else {
+      long run_length = stored_at - start_of_run;
+      hist->start_of_run = now - run_length;
+    }
+
     hist->weighted_run_length = wrl;
     hist->total_run_weights = trw;
-    /* Subtract time in which */
   }
   if (strcmp(line, "."))
-    log_warn(LD_GENERAL, "Truncated MTBF file %s", escaped(filename));
+    log_warn(LD_GENERAL, "Truncated MTBF file.");
 
   stability_last_downrated = last_downrated;
 



More information about the tor-commits mailing list