diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-08-26 12:11:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-08-26 12:11:33 +0000 |
commit | e5b17382d5d0ef9b80e95d1780d1ca1c1eb47f29 (patch) | |
tree | 0ec3925dea14ec0fe092b592d7998d237bfeec65 /src/datastore | |
parent | f02fbbebd73bfe88dc3122e9f8eb0b2c55837d16 (diff) | |
download | gnunet-e5b17382d5d0ef9b80e95d1780d1ca1c1eb47f29.tar.gz gnunet-e5b17382d5d0ef9b80e95d1780d1ca1c1eb47f29.zip |
fix
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 63 | ||||
-rw-r--r-- | src/datastore/test_datastore_api.c | 2 | ||||
-rw-r--r-- | src/datastore/test_datastore_api_data_postgres.conf | 2 |
3 files changed, 55 insertions, 12 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 332c8a768..b4540828a 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c | |||
@@ -332,7 +332,7 @@ init_connection (struct Plugin *plugin) | |||
332 | "getvt", | 332 | "getvt", |
333 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " | 333 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " |
334 | "WHERE hash=$1 AND vhash=$2 AND type=$3 " | 334 | "WHERE hash=$1 AND vhash=$2 AND type=$3 " |
335 | "AND oid >= $4 ORDER BY oid ASC LIMIT 1 OFFSET $5", | 335 | "AND oid > $4 ORDER BY oid ASC LIMIT 1 OFFSET $5", |
336 | 5, | 336 | 5, |
337 | __LINE__)) || | 337 | __LINE__)) || |
338 | (GNUNET_OK != | 338 | (GNUNET_OK != |
@@ -340,7 +340,7 @@ init_connection (struct Plugin *plugin) | |||
340 | "gett", | 340 | "gett", |
341 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " | 341 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " |
342 | "WHERE hash=$1 AND type=$2" | 342 | "WHERE hash=$1 AND type=$2" |
343 | "AND oid >= $3 ORDER BY oid ASC LIMIT 1 OFFSET $4", | 343 | "AND oid > $3 ORDER BY oid ASC LIMIT 1 OFFSET $4", |
344 | 4, | 344 | 4, |
345 | __LINE__)) || | 345 | __LINE__)) || |
346 | (GNUNET_OK != | 346 | (GNUNET_OK != |
@@ -348,7 +348,7 @@ init_connection (struct Plugin *plugin) | |||
348 | "getv", | 348 | "getv", |
349 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " | 349 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " |
350 | "WHERE hash=$1 AND vhash=$2" | 350 | "WHERE hash=$1 AND vhash=$2" |
351 | "AND oid >= $3 ORDER BY oid ASC LIMIT 1 OFFSET $4", | 351 | "AND oid > $3 ORDER BY oid ASC LIMIT 1 OFFSET $4", |
352 | 4, | 352 | 4, |
353 | __LINE__)) || | 353 | __LINE__)) || |
354 | (GNUNET_OK != | 354 | (GNUNET_OK != |
@@ -356,7 +356,7 @@ init_connection (struct Plugin *plugin) | |||
356 | "get", | 356 | "get", |
357 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " | 357 | "SELECT size, type, prio, anonLevel, expire, hash, value, oid FROM gn080 " |
358 | "WHERE hash=$1" | 358 | "WHERE hash=$1" |
359 | "AND oid >= $2 ORDER BY oid ASC LIMIT 1 OFFSET $3", | 359 | "AND oid > $2 ORDER BY oid ASC LIMIT 1 OFFSET $3", |
360 | 3, | 360 | 3, |
361 | __LINE__)) || | 361 | __LINE__)) || |
362 | (GNUNET_OK != | 362 | (GNUNET_OK != |
@@ -523,6 +523,11 @@ postgres_plugin_put (void *cls, | |||
523 | return GNUNET_SYSERR; | 523 | return GNUNET_SYSERR; |
524 | PQclear (ret); | 524 | PQclear (ret); |
525 | plugin->payload += size; | 525 | plugin->payload += size; |
526 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
527 | "postgres", | ||
528 | "Stored %u bytes in database, new payload is %llu\n", | ||
529 | (unsigned int) size, | ||
530 | (unsigned long long) plugin->payload); | ||
526 | return GNUNET_OK; | 531 | return GNUNET_OK; |
527 | } | 532 | } |
528 | 533 | ||
@@ -553,20 +558,26 @@ postgres_next_request_cont (void *next_cls, | |||
553 | 558 | ||
554 | plugin->next_task = GNUNET_SCHEDULER_NO_TASK; | 559 | plugin->next_task = GNUNET_SCHEDULER_NO_TASK; |
555 | plugin->next_task_nc = NULL; | 560 | plugin->next_task_nc = NULL; |
556 | if (GNUNET_YES == nrc->end_it) | 561 | if ( (GNUNET_YES == nrc->end_it) || |
562 | (nrc->count == nrc->total) ) | ||
557 | { | 563 | { |
564 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
565 | "postgres", | ||
566 | "Ending iteration (%s)\n", | ||
567 | (GNUNET_YES == nrc->end_it) ? "client requested it" : "completed result set"); | ||
558 | nrc->iter (nrc->iter_cls, | 568 | nrc->iter (nrc->iter_cls, |
559 | NULL, NULL, 0, NULL, 0, 0, 0, | 569 | NULL, NULL, 0, NULL, 0, 0, 0, |
560 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 570 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
561 | GNUNET_free (nrc); | 571 | GNUNET_free (nrc); |
562 | return; | 572 | return; |
563 | } | 573 | } |
564 | |||
565 | 574 | ||
566 | if (nrc->count == 0) | 575 | if (nrc->count == 0) |
567 | nrc->blimit_off = GNUNET_htonll (nrc->off); | 576 | nrc->blimit_off = GNUNET_htonll (nrc->off); |
568 | else | 577 | else |
569 | nrc->blimit_off = GNUNET_htonll (0); | 578 | nrc->blimit_off = GNUNET_htonll (0); |
579 | if (nrc->count + nrc->off == nrc->total) | ||
580 | nrc->blast_rowid = htonl (0); /* back to start */ | ||
570 | 581 | ||
571 | res = PQexecPrepared (plugin->dbh, | 582 | res = PQexecPrepared (plugin->dbh, |
572 | nrc->pname, | 583 | nrc->pname, |
@@ -581,6 +592,9 @@ postgres_next_request_cont (void *next_cls, | |||
581 | nrc->pname, | 592 | nrc->pname, |
582 | __LINE__)) | 593 | __LINE__)) |
583 | { | 594 | { |
595 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
596 | "postgres", | ||
597 | "Ending iteration (postgres error)\n"); | ||
584 | nrc->iter (nrc->iter_cls, | 598 | nrc->iter (nrc->iter_cls, |
585 | NULL, NULL, 0, NULL, 0, 0, 0, | 599 | NULL, NULL, 0, NULL, 0, 0, 0, |
586 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 600 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
@@ -591,6 +605,9 @@ postgres_next_request_cont (void *next_cls, | |||
591 | if (0 == PQntuples (res)) | 605 | if (0 == PQntuples (res)) |
592 | { | 606 | { |
593 | /* no result */ | 607 | /* no result */ |
608 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
609 | "postgres", | ||
610 | "Ending iteration (no more results)\n"); | ||
594 | nrc->iter (nrc->iter_cls, | 611 | nrc->iter (nrc->iter_cls, |
595 | NULL, NULL, 0, NULL, 0, 0, 0, | 612 | NULL, NULL, 0, NULL, 0, 0, 0, |
596 | GNUNET_TIME_UNIT_ZERO_ABS, 0); | 613 | GNUNET_TIME_UNIT_ZERO_ABS, 0); |
@@ -639,8 +656,14 @@ postgres_next_request_cont (void *next_cls, | |||
639 | 656 | ||
640 | nrc->blast_prio = htonl (priority); | 657 | nrc->blast_prio = htonl (priority); |
641 | nrc->blast_expire = GNUNET_htonll (expiration_time.value); | 658 | nrc->blast_expire = GNUNET_htonll (expiration_time.value); |
642 | nrc->blast_rowid = htonl (rowid + 1); | 659 | nrc->blast_rowid = htonl (rowid); |
643 | nrc->count++; | 660 | nrc->count++; |
661 | |||
662 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
663 | "postgres", | ||
664 | "Found result of size %u bytes and type %u in database\n", | ||
665 | (unsigned int) size, | ||
666 | (unsigned int) type); | ||
644 | iret = nrc->iter (nrc->iter_cls, | 667 | iret = nrc->iter (nrc->iter_cls, |
645 | nrc, | 668 | nrc, |
646 | &key, | 669 | &key, |
@@ -653,11 +676,29 @@ postgres_next_request_cont (void *next_cls, | |||
653 | rowid); | 676 | rowid); |
654 | PQclear (res); | 677 | PQclear (res); |
655 | if (iret == GNUNET_SYSERR) | 678 | if (iret == GNUNET_SYSERR) |
656 | return; | 679 | { |
680 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
681 | "postgres", | ||
682 | "Ending iteration (client error)\n"); | ||
683 | return; | ||
684 | } | ||
657 | if (iret == GNUNET_NO) | 685 | if (iret == GNUNET_NO) |
658 | { | 686 | { |
659 | plugin->payload -= size; | 687 | if (GNUNET_OK == delete_by_rowid (plugin, rowid)) |
660 | delete_by_rowid (plugin, rowid); | 688 | { |
689 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
690 | "postgres", | ||
691 | "Deleting %u bytes from database, current payload is %llu\n", | ||
692 | (unsigned int) size, | ||
693 | (unsigned long long) plugin->payload); | ||
694 | GNUNET_assert (plugin->payload >= size); | ||
695 | plugin->payload -= size; | ||
696 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
697 | "postgres", | ||
698 | "Deleted %u bytes from database, new payload is %llu\n", | ||
699 | (unsigned int) size, | ||
700 | (unsigned long long) plugin->payload); | ||
701 | } | ||
661 | } | 702 | } |
662 | } | 703 | } |
663 | 704 | ||
@@ -1007,6 +1048,8 @@ postgres_plugin_get (void *cls, | |||
1007 | return; | 1048 | return; |
1008 | } | 1049 | } |
1009 | nrc->total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0)); | 1050 | nrc->total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0)); |
1051 | fprintf (stderr, "Total number of results: %llu\n", | ||
1052 | (unsigned long long) nrc->total); | ||
1010 | PQclear (ret); | 1053 | PQclear (ret); |
1011 | if (nrc->total == 0) | 1054 | if (nrc->total == 0) |
1012 | { | 1055 | { |
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 0ea3c4c86..aaa00bdd8 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_protocols.h" | 31 | #include "gnunet_protocols.h" |
32 | #include "gnunet_datastore_service.h" | 32 | #include "gnunet_datastore_service.h" |
33 | 33 | ||
34 | #define VERBOSE GNUNET_NO | 34 | #define VERBOSE GNUNET_YES |
35 | 35 | ||
36 | #define START_DATASTORE GNUNET_YES | 36 | #define START_DATASTORE GNUNET_YES |
37 | 37 | ||
diff --git a/src/datastore/test_datastore_api_data_postgres.conf b/src/datastore/test_datastore_api_data_postgres.conf index 0bc55852e..4d4b94d05 100644 --- a/src/datastore/test_datastore_api_data_postgres.conf +++ b/src/datastore/test_datastore_api_data_postgres.conf | |||
@@ -30,7 +30,7 @@ DISABLE_SOCKET_FORWARDING = YES | |||
30 | # REJECT_FROM = | 30 | # REJECT_FROM = |
31 | # REJECT_FROM6 = | 31 | # REJECT_FROM6 = |
32 | # PREFIX = | 32 | # PREFIX = |
33 | # DEBUG = YES | 33 | DEBUG = YES |
34 | # PREFIX = xterm -T datastore -e gdb --args | 34 | # PREFIX = xterm -T datastore -e gdb --args |
35 | # PREFIX = valgrind --tool=memcheck --leak-check=yes | 35 | # PREFIX = valgrind --tool=memcheck --leak-check=yes |
36 | BINARY = gnunet-service-datastore | 36 | BINARY = gnunet-service-datastore |