aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-21 13:17:16 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-21 13:17:16 +0000
commit1732154b8c021e7ee0e34c28cf3b1a843454727a (patch)
tree3cb7fd79f409467c07d831ec055ebcdc8bfe61a2 /src/datastore
parent8919055de77f692ce3f0c1b9781fc9011de9cb6f (diff)
downloadgnunet-1732154b8c021e7ee0e34c28cf3b1a843454727a.tar.gz
gnunet-1732154b8c021e7ee0e34c28cf3b1a843454727a.zip
towards fixing mysql plugin
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/plugin_datastore_mysql.c120
1 files changed, 54 insertions, 66 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 4b0479a7f..3bfdf004f 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -250,9 +250,12 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid)
250 plugin->delete_entry_by_uid, 250 plugin->delete_entry_by_uid,
251 params_delete); 251 params_delete);
252 if (ret >= 0) 252 if (ret >= 0)
253 {
253 return GNUNET_OK; 254 return GNUNET_OK;
255 }
254 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
255 "Deleting value %llu from gn090 table failed\n", uid); 257 "Deleting value %llu from gn090 table failed\n",
258 uid);
256 return ret; 259 return ret;
257} 260}
258 261
@@ -288,18 +291,18 @@ mysql_plugin_estimate_size (void *cls, unsigned long long *estimate)
288 GNUNET_MY_result_spec_uint64 (&total), 291 GNUNET_MY_result_spec_uint64 (&total),
289 GNUNET_MY_result_spec_end 292 GNUNET_MY_result_spec_end
290 }; 293 };
294 int ret;
291 295
292// if (GNUNET_OK == 296// if (GNUNET_OK ==
293// GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1)) 297// GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1))
294 if (GNUNET_OK == 298 ret = GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get);
295 GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get)) 299 if (GNUNET_OK == ret)
296 { 300 {
297 if (GNUNET_OK == GNUNET_MY_extract_result (plugin->get_size, results_get)) 301 if (GNUNET_OK == GNUNET_MY_extract_result (plugin->get_size, results_get))
298 { 302 {
299 *estimate = (unsigned long long)total; 303 *estimate = (unsigned long long)total;
300 } 304 }
301 } 305 }
302
303 //*estimate = total; 306 //*estimate = total;
304 else 307 else
305 *estimate = 0; 308 *estimate = 0;
@@ -339,7 +342,7 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
339 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 342 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
340 UINT64_MAX); 343 UINT64_MAX);
341*/ 344*/
342 uint64_t lrvalue = 345 uint64_t lrvalue =
343 (uint64_t) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 346 (uint64_t) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
344 UINT64_MAX); 347 UINT64_MAX);
345 unsigned long hashSize; 348 unsigned long hashSize;
@@ -387,15 +390,14 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
387 return; 390 return;
388 } 391 }
389*/ 392*/
390 if (GNUNET_OK != 393 if (GNUNET_OK !=
391 GNUNET_MY_exec_prepared (plugin->mc, 394 GNUNET_MY_exec_prepared (plugin->mc,
392 plugin->insert_entry, 395 plugin->insert_entry,
393 params_insert)) 396 params_insert))
394 { 397 {
395 cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure")); 398 cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure"));
396 return; 399 return;
397 } 400 }
398
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
400 "Inserted value `%s' with size %u into gn090 table\n", 402 "Inserted value `%s' with size %u into gn090 table\n",
401 GNUNET_h2s (key), (unsigned int) size); 403 GNUNET_h2s (key), (unsigned int) size);
@@ -494,12 +496,11 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
494 unsigned int anonymity; 496 unsigned int anonymity;
495// unsigned long long exp; 497// unsigned long long exp;
496 uint64_t exp; 498 uint64_t exp;
497 unsigned long hashSize = 0;
498 //size_t hashSize; 499 //size_t hashSize;
499// unsigned long size; 500// unsigned long size;
500 uint64_t size; 501 size_t size;
501 unsigned long long uid = 0; 502 uint64_t uid;
502 char value[GNUNET_DATASTORE_MAX_VALUE_SIZE]; 503 void *value;
503 struct GNUNET_HashCode key; 504 struct GNUNET_HashCode key;
504 struct GNUNET_TIME_Absolute expiration; 505 struct GNUNET_TIME_Absolute expiration;
505// MYSQL_BIND rbind[7]; 506// MYSQL_BIND rbind[7];
@@ -541,9 +542,8 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
541 GNUNET_MY_result_spec_uint32 (&anonymity), 542 GNUNET_MY_result_spec_uint32 (&anonymity),
542 GNUNET_MY_result_spec_uint64 (&exp), 543 GNUNET_MY_result_spec_uint64 (&exp),
543 GNUNET_MY_result_spec_auto_from_type (&key), 544 GNUNET_MY_result_spec_auto_from_type (&key),
544// GNUNET_MY_result_spec_variable_size (&key, &hashSize), 545 GNUNET_MY_result_spec_variable_size (&value, &size),
545 GNUNET_MY_result_spec_fixed_size (value, sizeof (value)), 546 GNUNET_MY_result_spec_uint64 (&uid),
546 GNUNET_MY_result_spec_uint64 (&size),
547 GNUNET_MY_query_param_end 547 GNUNET_MY_query_param_end
548 }; 548 };
549 549
@@ -570,12 +570,6 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt
570 (hashSize != sizeof (struct GNUNET_HashCode))) 570 (hashSize != sizeof (struct GNUNET_HashCode)))
571 { 571 {
572*/ 572*/
573 if (hashSize != sizeof (struct GNUNET_HashCode))
574 {
575 GNUNET_break (0);
576 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
577 return;
578 }
579 expiration.abs_value_us = exp; 573 expiration.abs_value_us = exp;
580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
581 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n", 575 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n",
@@ -662,17 +656,16 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
662 GNUNET_MY_query_param_fixed_size (key, hashSize), 656 GNUNET_MY_query_param_fixed_size (key, hashSize),
663 GNUNET_MY_query_param_fixed_size (vhash, hashSize2), 657 GNUNET_MY_query_param_fixed_size (vhash, hashSize2),
664 GNUNET_MY_query_param_uint32 (&type), 658 GNUNET_MY_query_param_uint32 (&type),
665 GNUNET_MY_query_param_end 659 GNUNET_MY_query_param_end
666 }; 660 };
667 661
668 ret = 662 ret =
669 GNUNET_MY_exec_prepared (plugin->mc, 663 GNUNET_MY_exec_prepared (plugin->mc,
670 plugin->count_entry_by_hash_vhash_and_type, 664 plugin->count_entry_by_hash_vhash_and_type,
671 params_get); 665 params_get);
672 ret = 666 ret =
673 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 667 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type,
674 results_get); 668 results_get);
675
676 } 669 }
677 else 670 else
678 { 671 {
@@ -686,17 +679,17 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
686 struct GNUNET_MY_QueryParam params_get[] = { 679 struct GNUNET_MY_QueryParam params_get[] = {
687 GNUNET_MY_query_param_fixed_size (key, hashSize), 680 GNUNET_MY_query_param_fixed_size (key, hashSize),
688 GNUNET_MY_query_param_uint32 (&type), 681 GNUNET_MY_query_param_uint32 (&type),
689 GNUNET_MY_query_param_end 682 GNUNET_MY_query_param_end
690 }; 683 };
691 684
692 685
693 ret = 686 ret =
694 GNUNET_MY_exec_prepared (plugin->mc, 687 GNUNET_MY_exec_prepared (plugin->mc,
695 plugin->count_entry_by_hash_and_type, 688 plugin->count_entry_by_hash_and_type,
696 params_get); 689 params_get);
697 ret = 690 ret =
698 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 691 GNUNET_MY_extract_result (plugin->count_entry_by_hash_and_type,
699 results_get); 692 results_get);
700 } 693 }
701 } 694 }
702 else 695 else
@@ -713,16 +706,16 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
713 struct GNUNET_MY_QueryParam params_get[] = { 706 struct GNUNET_MY_QueryParam params_get[] = {
714 GNUNET_MY_query_param_fixed_size (key, hashSize), 707 GNUNET_MY_query_param_fixed_size (key, hashSize),
715 GNUNET_MY_query_param_fixed_size (vhash, hashSize2), 708 GNUNET_MY_query_param_fixed_size (vhash, hashSize2),
716 GNUNET_MY_query_param_end 709 GNUNET_MY_query_param_end
717 }; 710 };
718 711
719 712
720 ret = 713 ret =
721 GNUNET_MY_exec_prepared (plugin->mc, 714 GNUNET_MY_exec_prepared (plugin->mc,
722 plugin->count_entry_by_hash_and_type, 715 plugin->count_entry_by_hash_and_vhash,
723 params_get); 716 params_get);
724 ret = 717 ret =
725 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 718 GNUNET_MY_extract_result (plugin->count_entry_by_hash_and_vhash,
726 results_get); 719 results_get);
727 } 720 }
728 else 721 else
@@ -734,16 +727,16 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
734*/ 727*/
735 struct GNUNET_MY_QueryParam params_get[] = { 728 struct GNUNET_MY_QueryParam params_get[] = {
736 GNUNET_MY_query_param_fixed_size (key, hashSize), 729 GNUNET_MY_query_param_fixed_size (key, hashSize),
737 GNUNET_MY_query_param_end 730 GNUNET_MY_query_param_end
738 }; 731 };
739 732
740 733
741 ret = 734 ret =
742 GNUNET_MY_exec_prepared (plugin->mc, 735 GNUNET_MY_exec_prepared (plugin->mc,
743 plugin->count_entry_by_hash_and_type, 736 plugin->count_entry_by_hash,
744 params_get); 737 params_get);
745 ret = 738 ret =
746 GNUNET_MY_extract_result (plugin->count_entry_by_hash_vhash_and_type, 739 GNUNET_MY_extract_result (plugin->count_entry_by_hash,
747 results_get); 740 results_get);
748 } 741 }
749 742
@@ -756,7 +749,9 @@ mysql_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode *
756 offset = offset % total; 749 offset = offset % total;
757 off = (unsigned long long) offset; 750 off = (unsigned long long) offset;
758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
759 "Obtaining %llu/%lld result for GET `%s'\n", off, total, 752 "Obtaining %llu/%lld result for GET `%s'\n",
753 (unsigned long long) off,
754 (unsigned long long) total,
760 GNUNET_h2s (key)); 755 GNUNET_h2s (key));
761 if (type != GNUNET_BLOCK_TYPE_ANY) 756 if (type != GNUNET_BLOCK_TYPE_ANY)
762 { 757 {
@@ -873,7 +868,6 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
873{ 868{
874 struct ReplCtx *rc = cls; 869 struct ReplCtx *rc = cls;
875 struct Plugin *plugin = rc->plugin; 870 struct Plugin *plugin = rc->plugin;
876 unsigned long long oid;
877 int ret; 871 int ret;
878 int iret; 872 int iret;
879 873
@@ -882,18 +876,13 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
882 expiration, uid); 876 expiration, uid);
883 if (NULL != key) 877 if (NULL != key)
884 { 878 {
885 oid = (unsigned long long) uid;
886 iret =
887 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->dec_repl, NULL,
888 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
889
890 struct GNUNET_MY_QueryParam params_proc[] = { 879 struct GNUNET_MY_QueryParam params_proc[] = {
891 GNUNET_MY_query_param_uint64 (&oid), 880 GNUNET_MY_query_param_uint64 (&uid),
892 GNUNET_MY_query_param_end 881 GNUNET_MY_query_param_end
893 }; 882 };
894 883
895 iret = 884 iret =
896 GNUNET_MY_exec_prepared (plugin->mc, 885 GNUNET_MY_exec_prepared (plugin->mc,
897 plugin->dec_repl, 886 plugin->dec_repl,
898 params_proc); 887 params_proc);
899 if (iret == GNUNET_SYSERR) 888 if (iret == GNUNET_SYSERR)
@@ -926,7 +915,7 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
926 struct ReplCtx rc; 915 struct ReplCtx rc;
927 unsigned long long rvalue; 916 unsigned long long rvalue;
928 //unsigned long repl; 917 //unsigned long repl;
929 uint32_t repl; 918 uint32_t repl;
930 MYSQL_BIND results; 919 MYSQL_BIND results;
931 920
932 rc.plugin = plugin; 921 rc.plugin = plugin;
@@ -1002,12 +991,11 @@ mysql_plugin_get_keys (void *cls,
1002// MYSQL_BIND cbind[1]; 991// MYSQL_BIND cbind[1];
1003// unsigned long length; 992// unsigned long length;
1004 993
1005 statement = GNUNET_MYSQL_statement_get_stmt (plugin->mc, 994 statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys);
1006 plugin->get_all_keys); 995
1007 996
1008
1009 statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc, 997 statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc,
1010 query); 998 query);
1011/* 999/*
1012 if (statement == NULL) 1000 if (statement == NULL)
1013 { 1001 {
@@ -1033,7 +1021,7 @@ mysql_plugin_get_keys (void *cls,
1033 1021
1034 struct GNUNET_MY_ResultSpec results_select[] = { 1022 struct GNUNET_MY_ResultSpec results_select[] = {
1035 GNUNET_MY_result_spec_auto_from_type (&key), 1023 GNUNET_MY_result_spec_auto_from_type (&key),
1036 GNUNET_MY_result_spec_end 1024 GNUNET_MY_result_spec_end
1037 }; 1025 };
1038 1026
1039 if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc, 1027 if (GNUNET_OK != GNUNET_MY_exec_prepared (plugin->mc,
@@ -1046,7 +1034,7 @@ mysql_plugin_get_keys (void *cls,
1046 mysql_stmt_error (statement)); 1034 mysql_stmt_error (statement));
1047 GNUNET_MYSQL_statements_invalidate (plugin->mc); 1035 GNUNET_MYSQL_statements_invalidate (plugin->mc);
1048 proc (proc_cls, NULL, 0); 1036 proc (proc_cls, NULL, 0);
1049 return; 1037 return;
1050 } 1038 }
1051 1039
1052 ret = GNUNET_MY_extract_result (statements_handle_select, 1040 ret = GNUNET_MY_extract_result (statements_handle_select,