aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-10-20 21:04:54 +0000
committerChristian Grothoff <christian@grothoff.org>2010-10-20 21:04:54 +0000
commit388921507b4f56b448ec05aca67d20128f348711 (patch)
tree950c82aec9f181735fb2857d467a5de9c33ed1ec /src/datastore
parent5207a862b39021784a65a1b77f5efbca7da642a8 (diff)
downloadgnunet-388921507b4f56b448ec05aca67d20128f348711.tar.gz
gnunet-388921507b4f56b448ec05aca67d20128f348711.zip
stats and fixes
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/Makefile.am1
-rw-r--r--src/datastore/datastore_api.c161
2 files changed, 138 insertions, 24 deletions
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am
index 55d972cd7..db382f1e4 100644
--- a/src/datastore/Makefile.am
+++ b/src/datastore/Makefile.am
@@ -18,6 +18,7 @@ lib_LTLIBRARIES = \
18libgnunetdatastore_la_SOURCES = \ 18libgnunetdatastore_la_SOURCES = \
19 datastore_api.c datastore.h plugin_datastore.h 19 datastore_api.c datastore.h plugin_datastore.h
20libgnunetdatastore_la_LIBADD = \ 20libgnunetdatastore_la_LIBADD = \
21 $(top_builddir)/src/statistics/libgnunetstatistics.la \
21 $(top_builddir)/src/util/libgnunetutil.la \ 22 $(top_builddir)/src/util/libgnunetutil.la \
22 $(GN_LIBINTL) 23 $(GN_LIBINTL)
23libgnunetdatastore_la_LDFLAGS = \ 24libgnunetdatastore_la_LDFLAGS = \
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index abc8c7645..2837b0b8e 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -28,8 +28,16 @@
28#include "gnunet_arm_service.h" 28#include "gnunet_arm_service.h"
29#include "gnunet_constants.h" 29#include "gnunet_constants.h"
30#include "gnunet_datastore_service.h" 30#include "gnunet_datastore_service.h"
31#include "gnunet_statistics_service.h"
31#include "datastore.h" 32#include "datastore.h"
32 33
34/**
35 * If a client stopped asking for more results, how many more do
36 * we receive from the DB before killing the connection? Trade-off
37 * between re-doing TCP handshakes and (needlessly) receiving
38 * useless results.
39 */
40#define MAX_EXCESS_RESULTS 8
33 41
34/** 42/**
35 * Context for processing status messages. 43 * Context for processing status messages.
@@ -184,6 +192,11 @@ struct GNUNET_DATASTORE_Handle
184 struct GNUNET_CLIENT_Connection *client; 192 struct GNUNET_CLIENT_Connection *client;
185 193
186 /** 194 /**
195 * Handle for statistics.
196 */
197 struct GNUNET_STATISTICS_Handle *stats;
198
199 /**
187 * Current transmit handle. 200 * Current transmit handle.
188 */ 201 */
189 struct GNUNET_CLIENT_TransmitHandle *th; 202 struct GNUNET_CLIENT_TransmitHandle *th;
@@ -215,6 +228,13 @@ struct GNUNET_DATASTORE_Handle
215 unsigned int queue_size; 228 unsigned int queue_size;
216 229
217 /** 230 /**
231 * Number of results we're receiving for the current query
232 * after application stopped to care. Used to determine when
233 * to reset the connection.
234 */
235 unsigned int result_count;
236
237 /**
218 * Are we currently trying to receive from the service? 238 * Are we currently trying to receive from the service?
219 */ 239 */
220 int in_receive; 240 int in_receive;
@@ -249,6 +269,9 @@ GNUNET_DATASTORE_connect (const struct
249 h->client = c; 269 h->client = c;
250 h->cfg = cfg; 270 h->cfg = cfg;
251 h->sched = sched; 271 h->sched = sched;
272 h->stats = GNUNET_STATISTICS_create (sched,
273 "datastore-api",
274 cfg);
252 return h; 275 return h;
253} 276}
254 277
@@ -330,6 +353,8 @@ void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
330 } 353 }
331 GNUNET_break (0); 354 GNUNET_break (0);
332 } 355 }
356 GNUNET_STATISTICS_destroy (h->stats,
357 GNUNET_NO);
333 GNUNET_free (h); 358 GNUNET_free (h);
334} 359}
335 360
@@ -346,6 +371,10 @@ timeout_queue_entry (void *cls,
346{ 371{
347 struct GNUNET_DATASTORE_QueueEntry *qe = cls; 372 struct GNUNET_DATASTORE_QueueEntry *qe = cls;
348 373
374 GNUNET_STATISTICS_update (qe->h->stats,
375 gettext_noop ("# queue entry timeouts"),
376 1,
377 GNUNET_NO);
349 qe->task = GNUNET_SCHEDULER_NO_TASK; 378 qe->task = GNUNET_SCHEDULER_NO_TASK;
350 GNUNET_assert (qe->was_transmitted == GNUNET_NO); 379 GNUNET_assert (qe->was_transmitted == GNUNET_NO);
351 qe->response_proc (qe, NULL); 380 qe->response_proc (qe, NULL);
@@ -412,6 +441,10 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
412 pos = h->queue_head; 441 pos = h->queue_head;
413 } 442 }
414 c++; 443 c++;
444 GNUNET_STATISTICS_update (h->stats,
445 gettext_noop ("# queue entries created"),
446 1,
447 GNUNET_NO);
415 GNUNET_CONTAINER_DLL_insert_after (h->queue_head, 448 GNUNET_CONTAINER_DLL_insert_after (h->queue_head,
416 h->queue_tail, 449 h->queue_tail,
417 pos, 450 pos,
@@ -419,6 +452,10 @@ make_queue_entry (struct GNUNET_DATASTORE_Handle *h,
419 h->queue_size++; 452 h->queue_size++;
420 if (c > max_queue_size) 453 if (c > max_queue_size)
421 { 454 {
455 GNUNET_STATISTICS_update (h->stats,
456 gettext_noop ("# queue overflows"),
457 1,
458 GNUNET_NO);
422 response_proc (ret, NULL); 459 response_proc (ret, NULL);
423 return NULL; 460 return NULL;
424 } 461 }
@@ -477,6 +514,10 @@ try_reconnect (void *cls,
477 "DATASTORE reconnect failed (fatally)\n"); 514 "DATASTORE reconnect failed (fatally)\n");
478 return; 515 return;
479 } 516 }
517 GNUNET_STATISTICS_update (h->stats,
518 gettext_noop ("# datastore connections (re)created"),
519 1,
520 GNUNET_NO);
480#if DEBUG_DATASTORE 521#if DEBUG_DATASTORE
481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
482 "Reconnected to DATASTORE\n"); 523 "Reconnected to DATASTORE\n");
@@ -541,6 +582,10 @@ transmit_request (void *cls,
541 { 582 {
542 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 583 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
543 _("Failed to transmit request to DATASTORE.\n")); 584 _("Failed to transmit request to DATASTORE.\n"));
585 GNUNET_STATISTICS_update (h->stats,
586 gettext_noop ("# transmission request failures"),
587 1,
588 GNUNET_NO);
544 do_disconnect (h); 589 do_disconnect (h);
545 return 0; 590 return 0;
546 } 591 }
@@ -564,6 +609,10 @@ transmit_request (void *cls,
564 qe->response_proc, 609 qe->response_proc,
565 qe, 610 qe,
566 GNUNET_TIME_absolute_get_remaining (qe->timeout)); 611 GNUNET_TIME_absolute_get_remaining (qe->timeout));
612 GNUNET_STATISTICS_update (h->stats,
613 gettext_noop ("# bytes sent to datastore"),
614 1,
615 GNUNET_NO);
567 return msize; 616 return msize;
568} 617}
569 618
@@ -731,6 +780,11 @@ process_status_message (void *cls,
731 (int) status, 780 (int) status,
732 emsg); 781 emsg);
733#endif 782#endif
783 GNUNET_STATISTICS_update (h->stats,
784 gettext_noop ("# status messages received"),
785 1,
786 GNUNET_NO);
787 h->retry_time.value = 0;
734 process_queue (h); 788 process_queue (h);
735 if (rc.cont != NULL) 789 if (rc.cont != NULL)
736 rc.cont (rc.cont_cls, 790 rc.cont (rc.cont_cls,
@@ -806,6 +860,10 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h,
806#endif 860#endif
807 return NULL; 861 return NULL;
808 } 862 }
863 GNUNET_STATISTICS_update (h->stats,
864 gettext_noop ("# PUT requests executed"),
865 1,
866 GNUNET_NO);
809 dm = (struct DataMessage* ) &qe[1]; 867 dm = (struct DataMessage* ) &qe[1];
810 dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_PUT); 868 dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_PUT);
811 dm->header.size = htons(msize); 869 dm->header.size = htons(msize);
@@ -877,6 +935,10 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h,
877#endif 935#endif
878 return NULL; 936 return NULL;
879 } 937 }
938 GNUNET_STATISTICS_update (h->stats,
939 gettext_noop ("# RESERVE requests executed"),
940 1,
941 GNUNET_NO);
880 rm = (struct ReserveMessage*) &qe[1]; 942 rm = (struct ReserveMessage*) &qe[1];
881 rm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE); 943 rm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE);
882 rm->header.size = htons(sizeof (struct ReserveMessage)); 944 rm->header.size = htons(sizeof (struct ReserveMessage));
@@ -941,6 +1003,10 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
941#endif 1003#endif
942 return NULL; 1004 return NULL;
943 } 1005 }
1006 GNUNET_STATISTICS_update (h->stats,
1007 gettext_noop ("# RELEASE RESERVE requests executed"),
1008 1,
1009 GNUNET_NO);
944 rrm = (struct ReleaseReserveMessage*) &qe[1]; 1010 rrm = (struct ReleaseReserveMessage*) &qe[1];
945 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE); 1011 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE);
946 rrm->header.size = htons(sizeof (struct ReleaseReserveMessage)); 1012 rrm->header.size = htons(sizeof (struct ReleaseReserveMessage));
@@ -1004,6 +1070,10 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
1004#endif 1070#endif
1005 return NULL; 1071 return NULL;
1006 } 1072 }
1073 GNUNET_STATISTICS_update (h->stats,
1074 gettext_noop ("# UPDATE requests executed"),
1075 1,
1076 GNUNET_NO);
1007 um = (struct UpdateMessage*) &qe[1]; 1077 um = (struct UpdateMessage*) &qe[1];
1008 um->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE); 1078 um->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE);
1009 um->header.size = htons(sizeof (struct UpdateMessage)); 1079 um->header.size = htons(sizeof (struct UpdateMessage));
@@ -1068,7 +1138,17 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h,
1068 queue_priority, max_queue_size, timeout, 1138 queue_priority, max_queue_size, timeout,
1069 &process_status_message, &qc); 1139 &process_status_message, &qc);
1070 if (qe == NULL) 1140 if (qe == NULL)
1071 return NULL; 1141 {
1142#if DEBUG_DATASTORE
1143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1144 "Could not create queue entry for REMOVE\n");
1145#endif
1146 return NULL;
1147 }
1148 GNUNET_STATISTICS_update (h->stats,
1149 gettext_noop ("# REMOVE requests executed"),
1150 1,
1151 GNUNET_NO);
1072 dm = (struct DataMessage*) &qe[1]; 1152 dm = (struct DataMessage*) &qe[1];
1073 dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE); 1153 dm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE);
1074 dm->header.size = htons(msize); 1154 dm->header.size = htons(msize);
@@ -1141,6 +1221,8 @@ process_result_message (void *cls,
1141 rc.iter (rc.iter_cls, 1221 rc.iter (rc.iter_cls,
1142 NULL, 0, NULL, 0, 0, 0, 1222 NULL, 0, NULL, 0, 0, 0,
1143 GNUNET_TIME_UNIT_ZERO_ABS, 0); 1223 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1224 h->retry_time.value = 0;
1225 h->result_count = 0;
1144 process_queue (h); 1226 process_queue (h);
1145 return; 1227 return;
1146 } 1228 }
@@ -1158,16 +1240,29 @@ process_result_message (void *cls,
1158 GNUNET_TIME_UNIT_ZERO_ABS, 0); 1240 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1159 return; 1241 return;
1160 } 1242 }
1243 GNUNET_STATISTICS_update (h->stats,
1244 gettext_noop ("# Results received"),
1245 1,
1246 GNUNET_NO);
1161 if (rc.iter == NULL) 1247 if (rc.iter == NULL)
1162 { 1248 {
1163 /* abort iteration */ 1249 h->result_count++;
1164#if DEBUG_DATASTORE 1250 GNUNET_STATISTICS_update (h->stats,
1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1251 gettext_noop ("# Excess results received"),
1166 "Aborting iteration via disconnect (client has cancelled)\n"); 1252 1,
1167#endif 1253 GNUNET_NO);
1168 free_queue_entry (qe); 1254 if (h->result_count > MAX_EXCESS_RESULTS)
1169 h->retry_time = GNUNET_TIME_UNIT_ZERO; 1255 {
1170 do_disconnect (h); 1256 free_queue_entry (qe);
1257 GNUNET_STATISTICS_update (h->stats,
1258 gettext_noop ("# Forced database connection resets"),
1259 1,
1260 GNUNET_NO);
1261 h->retry_time = GNUNET_TIME_UNIT_ZERO;
1262 do_disconnect (h);
1263 return;
1264 }
1265 GNUNET_DATASTORE_get_next (h, GNUNET_NO);
1171 return; 1266 return;
1172 } 1267 }
1173 dm = (const struct DataMessage*) msg; 1268 dm = (const struct DataMessage*) msg;
@@ -1179,6 +1274,7 @@ process_result_message (void *cls,
1179 ntohl(dm->size), 1274 ntohl(dm->size),
1180 GNUNET_h2s(&dm->key)); 1275 GNUNET_h2s(&dm->key));
1181#endif 1276#endif
1277 h->retry_time.value = 0;
1182 rc.iter (rc.iter_cls, 1278 rc.iter (rc.iter_cls,
1183 &dm->key, 1279 &dm->key,
1184 ntohl(dm->size), 1280 ntohl(dm->size),
@@ -1230,7 +1326,17 @@ GNUNET_DATASTORE_get_random (struct GNUNET_DATASTORE_Handle *h,
1230 queue_priority, max_queue_size, timeout, 1326 queue_priority, max_queue_size, timeout,
1231 &process_result_message, &qc); 1327 &process_result_message, &qc);
1232 if (qe == NULL) 1328 if (qe == NULL)
1233 return NULL; 1329 {
1330#if DEBUG_DATASTORE
1331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1332 "Could not create queue entry for GET RANDOM\n");
1333#endif
1334 return NULL;
1335 }
1336 GNUNET_STATISTICS_update (h->stats,
1337 gettext_noop ("# GET RANDOM requests executed"),
1338 1,
1339 GNUNET_NO);
1234 m = (struct GNUNET_MessageHeader*) &qe[1]; 1340 m = (struct GNUNET_MessageHeader*) &qe[1];
1235 m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM); 1341 m->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM);
1236 m->size = htons(sizeof (struct GNUNET_MessageHeader)); 1342 m->size = htons(sizeof (struct GNUNET_MessageHeader));
@@ -1287,6 +1393,10 @@ GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
1287#endif 1393#endif
1288 return NULL; 1394 return NULL;
1289 } 1395 }
1396 GNUNET_STATISTICS_update (h->stats,
1397 gettext_noop ("# GET ZERO ANONYMITY requests executed"),
1398 1,
1399 GNUNET_NO);
1290 m = (struct GetZeroAnonymityMessage*) &qe[1]; 1400 m = (struct GetZeroAnonymityMessage*) &qe[1];
1291 m->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM); 1401 m->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET_RANDOM);
1292 m->header.size = htons(sizeof (struct GetZeroAnonymityMessage)); 1402 m->header.size = htons(sizeof (struct GetZeroAnonymityMessage));
@@ -1352,6 +1462,10 @@ GNUNET_DATASTORE_get (struct GNUNET_DATASTORE_Handle *h,
1352#endif 1462#endif
1353 return NULL; 1463 return NULL;
1354 } 1464 }
1465 GNUNET_STATISTICS_update (h->stats,
1466 gettext_noop ("# GET requests executed"),
1467 1,
1468 GNUNET_NO);
1355 gm = (struct GetMessage*) &qe[1]; 1469 gm = (struct GetMessage*) &qe[1];
1356 gm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET); 1470 gm->header.type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_GET);
1357 gm->type = htonl(type); 1471 gm->type = htonl(type);
@@ -1385,21 +1499,20 @@ GNUNET_DATASTORE_get_next (struct GNUNET_DATASTORE_Handle *h,
1385 struct ResultContext rc = qe->qc.rc; 1499 struct ResultContext rc = qe->qc.rc;
1386 1500
1387 GNUNET_assert (&process_result_message == qe->response_proc); 1501 GNUNET_assert (&process_result_message == qe->response_proc);
1388 if (GNUNET_YES == more) 1502 if (GNUNET_YES != more)
1389 { 1503 {
1390 h->in_receive = GNUNET_YES; 1504 qe->qc.rc.iter = NULL;
1391 GNUNET_CLIENT_receive (h->client, 1505 qe->qc.rc.iter_cls = NULL;
1392 qe->response_proc, 1506 if (rc.iter != NULL)
1393 qe, 1507 rc.iter (rc.iter_cls,
1394 GNUNET_TIME_absolute_get_remaining (qe->timeout)); 1508 NULL, 0, NULL, 0, 0, 0,
1395 return; 1509 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1396 } 1510 }
1397 free_queue_entry (qe); 1511 h->in_receive = GNUNET_YES;
1398 h->retry_time = GNUNET_TIME_UNIT_ZERO; 1512 GNUNET_CLIENT_receive (h->client,
1399 do_disconnect (h); 1513 qe->response_proc,
1400 rc.iter (rc.iter_cls, 1514 qe,
1401 NULL, 0, NULL, 0, 0, 0, 1515 GNUNET_TIME_absolute_get_remaining (qe->timeout));
1402 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1403} 1516}
1404 1517
1405 1518