enable very minimal dht logging
authorNathan S. Evans <evans@in.tum.de>
Tue, 8 Feb 2011 14:46:17 +0000 (14:46 +0000)
committerNathan S. Evans <evans@in.tum.de>
Tue, 8 Feb 2011 14:46:17 +0000 (14:46 +0000)
src/dht/dhtlog.h
src/dht/gnunet-dht-driver.c
src/dht/plugin_dhtlog_dummy.c
src/dht/plugin_dhtlog_mysql.c
src/dht/plugin_dhtlog_mysql_dump.c
src/dht/plugin_dhtlog_mysql_dump_load.c
src/dht/test_dhtlog.c

index d53167a5cb6b873d5d0c768c6f0e8184f3271937..c86d98ee2459181b76bcb98e77ed991096474d11 100644 (file)
@@ -277,6 +277,20 @@ struct GNUNET_DHTLOG_Handle
    */
   int (*insert_round) (unsigned int round_type, unsigned int round_count);
 
+  /*
+   * Inserts the specified round results into the
+   * dhttests.processed_round_details table
+   *
+   * @param round_type the type of round that is being started
+   * @param round_count counter for the round (if applicable)
+   * @param num_messages the total number of messages initiated
+   * @param num_messages_succeeded the number of messages that succeeded
+   *
+   * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+   */
+  int (*insert_round_details) (unsigned int round_type, unsigned int round_count,
+                               unsigned int num_messages, unsigned int num_messages_succeeded);
+
   /*
    * Update dhttests.trials table with total connections information
    *
index 772b96d6efd2f618b497ce184b861115b41d77a3..16e3aa93d63b997740adedd6ca6e59c1069dc994 100644 (file)
@@ -42,7 +42,7 @@
 #define DEFAULT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
 
 /* Timeout for waiting for (individual) replies to get requests */
-#define DEFAULT_GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
+#define DEFAULT_GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
 
 #define DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
 
@@ -292,8 +292,6 @@ struct FindPeerContext
   /**
    * How long to send find peer requests, once the settle time
    * is over don't send any more out!
-   *
-   * TODO: Add option for settle time and find peer sending time?
    */
   struct GNUNET_TIME_Absolute endtime;
 
@@ -701,6 +699,12 @@ static unsigned int previous_connections;
  */
 static unsigned int failed_connections;
 
+/**
+ * If GNUNET_YES, only log PUT/GET round data to mysql, otherwise
+ * log everything (including each dht service logging).
+ */
+static unsigned int dhtlog_minimal;
+
 /* Task handle to use to schedule shutdown if something goes wrong */
 GNUNET_SCHEDULER_TaskIdentifier die_task;
 
@@ -920,15 +924,13 @@ log_topology_cb (void *cls,
   struct TopologyIteratorContext *topo_ctx = cls;
   if ((first != NULL) && (second != NULL))
     {
-      /* GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "According to CORE, peer %s is connected to %s\n", GNUNET_i2s(first), GNUNET_h2s(&second->hashPubKey));*/
       if ((topo_ctx->peers_seen != NULL) && (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(topo_ctx->peers_seen, &first->hashPubKey)))
         {
           GNUNET_CONTAINER_multihashmap_put(topo_ctx->peers_seen, &first->hashPubKey, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
           topo_ctx->total_peers++;
         }
       topo_ctx->total_connections++;
-      if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(config, "dht_testing", "mysql_logging")) ||
-          (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(config, "dht_testing", "mysql_logging_extended")))
+      if ((GNUNET_NO == dhtlog_minimal) && (dhtlog_handle != NULL))
         dhtlog_handle->insert_extended_topology(first, second);
     }
   else
@@ -1571,7 +1573,6 @@ static void churn_complete (void *cls, const char *emsg)
         }
       GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Added %d peers to heap, total size %d\n", count_added, GNUNET_CONTAINER_heap_get_size(find_peer_context->peer_min_heap));
       GNUNET_SCHEDULER_add_delayed(DEFAULT_PEER_DISCONNECT_TIMEOUT, &schedule_churn_get_topology, find_peer_context);
-      //GNUNET_TESTING_get_topology (pg, &count_peers_churn_cb, find_peer_context);
     }
   else
     {
@@ -1589,6 +1590,7 @@ static void churn_complete (void *cls, const char *emsg)
           die_task = GNUNET_SCHEDULER_add_delayed (calc_timeout,
                                                    &end_badly, "from do gets (churn_complete)");
           GNUNET_SCHEDULER_add_delayed(DEFAULT_PEER_DISCONNECT_TIMEOUT, &capture_current_topology, topo_ctx);
+          dhtlog_handle->insert_round(DHT_ROUND_GET, rounds_finished);
         }
       else
         {
@@ -1596,8 +1598,6 @@ static void churn_complete (void *cls, const char *emsg)
           calc_timeout = GNUNET_TIME_relative_add(calc_timeout, DEFAULT_PEER_DISCONNECT_TIMEOUT);
           die_task = GNUNET_SCHEDULER_add_delayed (calc_timeout,
                                                    &end_badly, "from do gets (churn_complete)");
-          if (dhtlog_handle != NULL)
-            dhtlog_handle->insert_round(DHT_ROUND_GET, rounds_finished);
           GNUNET_SCHEDULER_add_delayed(DEFAULT_PEER_DISCONNECT_TIMEOUT, &do_get, all_gets);
         }
     }
@@ -1692,6 +1692,8 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
   if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0))
     {
       fprintf(stderr, "Canceling die task (get_stop_finished) %llu gets completed, %llu gets failed\n", gets_completed, gets_failed);
+      if ((GNUNET_YES == dhtlog_minimal) && (NULL != dhtlog_handle))
+        dhtlog_handle->insert_round_details(DHT_ROUND_GET, rounds_finished, num_gets, gets_completed);
       GNUNET_SCHEDULER_cancel(die_task);
       reset_meter(put_meter);
       reset_meter(get_meter);
@@ -1703,7 +1705,7 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
        */
       if (rounds_finished == total_rounds - 1) /* Everything is finished, end testing */
         {
-          if (dhtlog_handle != NULL)
+          if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
             {
               topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
               topo_ctx->cont = &log_dht_statistics;
@@ -1907,7 +1909,7 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
     {
       GNUNET_assert(outstanding_puts == 0);
       GNUNET_SCHEDULER_cancel (die_task);
-      if (dhtlog_handle != NULL)
+      if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
         {
           topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext));
           topo_ctx->cont = &do_get;
@@ -2265,7 +2267,7 @@ continue_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * t
   struct TopologyIteratorContext *topo_ctx;
   struct FindPeerContext *find_peer_context;
   GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "In continue_puts_and_gets\n");
-  if (dhtlog_handle != NULL)
+  if ((dhtlog_handle != NULL) && (GNUNET_NO == dhtlog_minimal))
     {
       if (settle_time >= 180 * 2)
         max = (settle_time / 180) - 2;
@@ -2818,8 +2820,12 @@ run (void *cls,
    * Get DHT specific testing options.
    */
   if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging")) ||
-      (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended")))
+      (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended")) ||
+      (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_minimal")))
     {
+      if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_minimal"))
+        dhtlog_minimal = GNUNET_YES;
+
       dhtlog_handle = GNUNET_DHTLOG_connect(cfg);
       if (dhtlog_handle == NULL)
         {
index 96a29af896e4b156187b661737963e70895067bb..0a7091030016ab9a0ffbcc7c77ff0756eef1b236 100644 (file)
@@ -57,6 +57,23 @@ int add_round (unsigned int round_type, unsigned int round_count)
   return GNUNET_OK;
 }
 
+/*
+ * Inserts the specified round results into the
+ * dhttests.processed_round_details table
+ *
+ * @param round_type the type of round that is being started
+ * @param round_count counter for the round (if applicable)
+ * @param num_messages the total number of messages initiated
+ * @param num_messages_succeeded the number of messages that succeeded
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int add_round_details (unsigned int round_type, unsigned int round_count,
+                       unsigned int num_messages, unsigned int num_messages_succeded)
+{
+  return GNUNET_OK;
+}
+
 /*
  * Inserts the specified dhtkey into the dhttests.dhtkeys table,
  * stores return value of dhttests.dhtkeys.dhtkeyuid into dhtkeyuid
@@ -292,6 +309,7 @@ libgnunet_plugin_dhtlog_dummy_init (void * cls)
   plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
   plugin->dhtlog_api->add_generic_stat = &add_generic_stat;
   plugin->dhtlog_api->insert_round = &add_round;
+  plugin->dhtlog_api->insert_round_details = &add_round_details;
   plugin->dhtlog_api->insert_stat = &insert_stat;
   plugin->dhtlog_api->insert_trial = &add_trial;
   plugin->dhtlog_api->insert_query = &add_query;
index 5510163b00251363aa8b13db2a5cae418f83fb6a..0cce99d6d8f7bc050cf3049268bddbb9f2bef3e6 100644 (file)
@@ -108,6 +108,11 @@ static struct StatementHandle *insert_node;
 
 static struct StatementHandle *insert_round;
 
+#define INSERT_ROUND_DETAILS_STMT "INSERT INTO rounds (trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded) "\
+                          "VALUES (?, ?, ?, NOW(), NOW(), ?, ?)"
+
+static struct StatementHandle *insert_round_details;
+
 #define INSERT_TRIALS_STMT "INSERT INTO trials"\
                             "(starttime, other_trial_identifier, numnodes, topology,"\
                             "topology_percentage, topology_probability,"\
@@ -454,6 +459,7 @@ iopen (struct GNUNET_DHTLOG_Plugin *plugin)
       PINIT (insert_route, INSERT_ROUTES_STMT) ||
       PINIT (insert_trial, INSERT_TRIALS_STMT) ||
       PINIT (insert_round, INSERT_ROUNDS_STMT) ||
+      PINIT (insert_round, INSERT_ROUND_DETAILS_STMT) ||
       PINIT (insert_stat, INSERT_STAT_STMT) ||
       PINIT (insert_generic_stat, INSERT_GENERIC_STAT_STMT) ||
       PINIT (insert_node, INSERT_NODES_STMT) ||
@@ -917,6 +923,38 @@ int add_round (unsigned int round_type, unsigned int round_count)
   return ret;
 }
 
+/*
+ * Inserts the specified round results into the
+ * dhttests.processed_round_details table
+ *
+ * @param round_type the type of round that is being started
+ * @param round_count counter for the round (if applicable)
+ * @param num_messages the total number of messages initiated
+ * @param num_messages_succeeded the number of messages that succeeded
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int add_round_details (unsigned int round_type, unsigned int round_count,
+                       unsigned int num_messages, unsigned int num_messages_succeeded)
+{
+  MYSQL_STMT *stmt;
+  int ret;
+
+  stmt = mysql_stmt_init(conn);
+  ret = prepared_statement_run (insert_round_details,
+                                NULL,
+                                MYSQL_TYPE_LONGLONG, &current_trial, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &round_type, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &round_count, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &num_messages, GNUNET_YES,
+                                MYSQL_TYPE_LONG, &num_messages_succeeded, GNUNET_YES,
+                                -1);
+  mysql_stmt_close(stmt);
+  if (ret != GNUNET_OK)
+    return GNUNET_SYSERR;
+  return ret;
+}
+
 /*
  * Inserts the specified stats into the dhttests.node_statistics table
  *
@@ -1561,6 +1599,7 @@ libgnunet_plugin_dhtlog_mysql_init (void * cls)
   plugin->dhtlog_api->insert_trial = &add_trial;
   plugin->dhtlog_api->insert_stat = &add_stat;
   plugin->dhtlog_api->insert_round = &add_round;
+  plugin->dhtlog_api->insert_round_details = &add_round_details;
   plugin->dhtlog_api->add_generic_stat = &add_generic_stat;
   plugin->dhtlog_api->insert_query = &add_query;
   plugin->dhtlog_api->update_trial = &update_trials;
@@ -1593,6 +1632,7 @@ libgnunet_plugin_dhtlog_mysql_done (void * cls)
   prepared_statement_close(insert_route);
   prepared_statement_close(insert_trial);
   prepared_statement_close(insert_round);
+  prepared_statement_close(insert_round_details);
   prepared_statement_close(insert_node);
   prepared_statement_close(insert_dhtkey);
   prepared_statement_close(update_trial);
index 1e549d115da0fec01bad347096fb1a6a0a36abe8..3033be535423ea7e313c19da60fac8883071a785 100644 (file)
@@ -65,6 +65,10 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
 
 #define INSERT_ROUND_STMT "prepare insert_round from 'INSERT INTO rounds (trialuid, round_type, round_count, starttime) VALUES (@temp_trial, @rtype, @rcount, @curr_time)'"
 
+#define INSERT_ROUND_DETAILS_STMT "prepare insert_round_details from 'INSERT INTO processed_trial_rounds "\
+                                  "(trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded)"\
+                                  "VALUES (@temp_trial, @rtype, @rcount, @curr_time, @curr_time, @totalmsgs, @msgssucceeded)'"
+
 #define EXTEND_TOPOLOGY_STMT "prepare extend_topology from 'INSERT INTO extended_topology (topology_uid, uid_first, uid_second) "\
                              "VALUES (@temp_topology, ?, ?)'"
 
@@ -161,6 +165,7 @@ iopen ()
   if (PINIT (INSERT_QUERIES_STMT) ||
       PINIT (INSERT_ROUTES_STMT) ||
       PINIT (INSERT_ROUND_STMT) ||
+      PINIT (INSERT_ROUND_DETAILS_STMT) ||
       PINIT (INSERT_TRIALS_STMT) ||
       PINIT (SET_MALICIOUS_STMT) ||
       PINIT (INSERT_GENERIC_STAT_STMT) ||
@@ -209,6 +214,36 @@ int add_round (unsigned int round_type, unsigned int round_count)
   return GNUNET_SYSERR;
 }
 
+/*
+ * Inserts the specified round results into the
+ * dhttests.processed_round_details table
+ *
+ * @param round_type the type of round that is being started
+ * @param round_count counter for the round (if applicable)
+ * @param num_messages the total number of messages initiated
+ * @param num_messages_succeeded the number of messages that succeeded
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int add_round_details (unsigned int round_type, unsigned int round_count,
+                       unsigned int num_messages, unsigned int num_messages_succeeded)
+{
+  int ret;
+  if (outfile == NULL)
+    return GNUNET_SYSERR;
+
+  ret = fprintf(outfile, "set @curr_time = \"%s\", @rtype = \"%u\", @rcount = \"%u\", @totalmsgs = \"%u\", @msgssucceeded = \"%u\";\n",
+                          get_sql_time(), round_type, round_count, num_messages, num_messages_succeeded);
+
+  if (ret < 0)
+    return GNUNET_SYSERR;
+  ret = fprintf(outfile, "execute insert_round_details;\n");
+
+  if (ret >= 0)
+    return GNUNET_OK;
+  return GNUNET_SYSERR;
+}
+
 /*
  * Records the current topology (number of connections, time, trial)
  *
@@ -821,6 +856,7 @@ libgnunet_plugin_dhtlog_mysql_dump_init (void * cls)
   plugin->dhtlog_api = GNUNET_malloc(sizeof(struct GNUNET_DHTLOG_Handle));
   plugin->dhtlog_api->insert_trial = &add_trial;
   plugin->dhtlog_api->insert_round = &add_round;
+  plugin->dhtlog_api->insert_round_details = &add_round_details;
   plugin->dhtlog_api->insert_stat = &add_stat;
   plugin->dhtlog_api->insert_query = &add_query;
   plugin->dhtlog_api->update_trial = &update_trials;
index 6fa6ab2c748955ab844e0a5e05fc76222a1b66f7..956af6bdd371e9850100c6f0ec0c7d5ec4e8006e 100644 (file)
@@ -131,6 +131,32 @@ int add_round (unsigned int round_type, unsigned int round_count)
 
 }
 
+/*
+ * Inserts the specified round results into the
+ * dhttests.processed_round_details table
+ *
+ * @param round_type the type of round that is being started
+ * @param round_count counter for the round (if applicable)
+ * @param num_messages the total number of messages initiated
+ * @param num_messages_succeeded the number of messages that succeeded
+ *
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int add_round_details (unsigned int round_type, unsigned int round_count,
+                       unsigned int num_messages, unsigned int num_messages_succeeded)
+{
+  int ret;
+  if (outfile == NULL)
+    return GNUNET_SYSERR;
+
+  ret = fprintf(outfile, "insert into processed_trial_rounds (trialuid, round_type, round_count, starttime, endtime, num_messages, num_messages_succeeded) values (@temp_trial, \"%u\", \"%u\", \"%s\", \"%s\", \"%u\", \"%u\");\n",
+                                                              round_type, round_count, get_sql_time(), get_sql_time(), num_messages, num_messages_succeeded);
+
+  if (ret >= 0)
+    return GNUNET_OK;
+  return GNUNET_SYSERR;
+}
+
 /*
  * Records a connection between two peers in the current topology
  *
@@ -824,6 +850,7 @@ libgnunet_plugin_dhtlog_mysql_dump_load_init (void * cls)
   plugin->dhtlog_api->insert_trial = &add_trial;
   plugin->dhtlog_api->insert_stat = &add_stat;
   plugin->dhtlog_api->insert_round = &add_round;
+  plugin->dhtlog_api->insert_round_details = &add_round_details;
   plugin->dhtlog_api->insert_query = &add_query;
   plugin->dhtlog_api->update_trial = &update_trials;
   plugin->dhtlog_api->insert_route = &add_route;
index 955781ef2068051d0d20a7902073b9a2cfb8357e..5c6d5c57861538dfd2e1b5b17f184725b74a623d 100644 (file)
@@ -180,6 +180,8 @@ test (struct GNUNET_DHTLOG_Handle * api)
 #endif
   ret = api->insert_round(401, 507);
   CHECK(ret);
+  ret = api->insert_round_details(402, 507, 1123, 985);
+  CHECK(ret);
 #if VERBOSE
   fprintf(stderr, "Insert round succeeded!\n");
 #endif