aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-24 14:41:53 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-24 14:41:53 +0000
commitce6319e302eb86087bd15bdc9b44746c23a1c0f1 (patch)
treee2a6d387c9b5e60bee8e0961131800a65572611a /src/datastore
parent4a99626e6a02f71ed4d492d3454f22e1674c9c13 (diff)
downloadgnunet-ce6319e302eb86087bd15bdc9b44746c23a1c0f1.tar.gz
gnunet-ce6319e302eb86087bd15bdc9b44746c23a1c0f1.zip
fix plugin datastore mysql
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/plugin_datastore_mysql.c183
1 files changed, 68 insertions, 115 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 09dbdc5b6..ff21db7e5 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -265,6 +265,8 @@ mysql_plugin_estimate_size (void *cls,
265{ 265{
266 struct Plugin *plugin = cls; 266 struct Plugin *plugin = cls;
267 uint64_t total; 267 uint64_t total;
268 int ret;
269
268 struct GNUNET_MY_QueryParam params_get[] = { 270 struct GNUNET_MY_QueryParam params_get[] = {
269 GNUNET_MY_query_param_end 271 GNUNET_MY_query_param_end
270 }; 272 };
@@ -273,7 +275,6 @@ mysql_plugin_estimate_size (void *cls,
273 GNUNET_MY_result_spec_uint64 (&total), 275 GNUNET_MY_result_spec_uint64 (&total),
274 GNUNET_MY_result_spec_end 276 GNUNET_MY_result_spec_end
275 }; 277 };
276 int ret;
277 278
278 ret = GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get); 279 ret = GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get);
279 if (GNUNET_OK == ret) 280 if (GNUNET_OK == ret)
@@ -317,19 +318,18 @@ mysql_plugin_put (void *cls,
317 void *cont_cls) 318 void *cont_cls)
318{ 319{
319 struct Plugin *plugin = cls; 320 struct Plugin *plugin = cls;
320 unsigned int irepl = replication; 321
321 unsigned int ipriority = priority;
322 unsigned int ianonymity = anonymity;
323 uint64_t lexpiration = expiration.abs_value_us; 322 uint64_t lexpiration = expiration.abs_value_us;
324 uint64_t lrvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 323 uint64_t lrvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
325 UINT64_MAX); 324 UINT64_MAX);
326 unsigned long lsize; 325 unsigned long lsize = 0;
326
327 struct GNUNET_HashCode vhash; 327 struct GNUNET_HashCode vhash;
328 struct GNUNET_MY_QueryParam params_insert[] = { 328 struct GNUNET_MY_QueryParam params_insert[] = {
329 GNUNET_MY_query_param_uint32 (&irepl), 329 GNUNET_MY_query_param_uint32 (&replication),
330 GNUNET_MY_query_param_uint32 (&type), 330 GNUNET_MY_query_param_uint32 (&type),
331 GNUNET_MY_query_param_uint32 (&ipriority), 331 GNUNET_MY_query_param_uint32 (&priority),
332 GNUNET_MY_query_param_uint32 (&ianonymity), 332 GNUNET_MY_query_param_uint32 (&anonymity),
333 GNUNET_MY_query_param_uint64 (&lexpiration), 333 GNUNET_MY_query_param_uint64 (&lexpiration),
334 GNUNET_MY_query_param_uint64 (&lrvalue), 334 GNUNET_MY_query_param_uint64 (&lrvalue),
335 GNUNET_MY_query_param_auto_from_type (key), 335 GNUNET_MY_query_param_auto_from_type (key),
@@ -395,25 +395,17 @@ mysql_plugin_update (void *cls, uint64_t uid, int delta,
395 PluginUpdateCont cont, void *cont_cls) 395 PluginUpdateCont cont, void *cont_cls)
396{ 396{
397 struct Plugin *plugin = cls; 397 struct Plugin *plugin = cls;
398 uint32_t delta1 = (uint32_t)delta; 398 uint32_t idelta = (uint32_t)delta;
399 unsigned long long vkey = uid;
400// unsigned long long lexpire = expire.abs_value_us;
401 uint64_t lexpire = expire.abs_value_us; 399 uint64_t lexpire = expire.abs_value_us;
402 int ret; 400 int ret;
403 401
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
405 "Updating value %llu adding %d to priority and maxing exp at %s\n", 403 "Updating value %llu adding %d to priority and maxing exp at %s\n",
406 vkey, delta, 404 uid, delta,
407 GNUNET_STRINGS_absolute_time_to_string (expire)); 405 GNUNET_STRINGS_absolute_time_to_string (expire));
408/* ret = 406
409 GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->update_entry, NULL,
410 MYSQL_TYPE_LONG, &delta, GNUNET_NO,
411 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
412 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
413 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
414*/
415 struct GNUNET_MY_QueryParam params_update[] = { 407 struct GNUNET_MY_QueryParam params_update[] = {
416 GNUNET_MY_query_param_uint32 (&delta1), 408 GNUNET_MY_query_param_uint32 (&idelta),
417 GNUNET_MY_query_param_uint64 (&lexpire), 409 GNUNET_MY_query_param_uint64 (&lexpire),
418 GNUNET_MY_query_param_uint64 (&lexpire), 410 GNUNET_MY_query_param_uint64 (&lexpire),
419 GNUNET_MY_query_param_uint64 (&uid), 411 GNUNET_MY_query_param_uint64 (&uid),
@@ -427,7 +419,7 @@ mysql_plugin_update (void *cls, uint64_t uid, int delta,
427 if (ret != GNUNET_OK) 419 if (ret != GNUNET_OK)
428 { 420 {
429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n", 421 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n",
430 vkey); 422 uid);
431 } 423 }
432 cont (cont_cls, ret, NULL); 424 cont (cont_cls, ret, NULL);
433} 425}
@@ -546,8 +538,6 @@ mysql_plugin_get_key (void *cls,
546 struct Plugin *plugin = cls; 538 struct Plugin *plugin = cls;
547 int ret; 539 int ret;
548 uint64_t total; 540 uint64_t total;
549 unsigned long hashSize;
550 unsigned long hashSize2;
551 541
552 total = -1; 542 total = -1;
553 struct GNUNET_MY_ResultSpec results_get[] = { 543 struct GNUNET_MY_ResultSpec results_get[] = {
@@ -560,8 +550,8 @@ mysql_plugin_get_key (void *cls,
560 if (vhash != NULL) 550 if (vhash != NULL)
561 { 551 {
562 struct GNUNET_MY_QueryParam params_get[] = { 552 struct GNUNET_MY_QueryParam params_get[] = {
563 GNUNET_MY_query_param_fixed_size (key, hashSize), 553 GNUNET_MY_query_param_auto_from_type (key),
564 GNUNET_MY_query_param_fixed_size (vhash, hashSize2), 554 GNUNET_MY_query_param_auto_from_type (vhash),
565 GNUNET_MY_query_param_uint32 (&type), 555 GNUNET_MY_query_param_uint32 (&type),
566 GNUNET_MY_query_param_end 556 GNUNET_MY_query_param_end
567 }; 557 };
@@ -577,7 +567,7 @@ mysql_plugin_get_key (void *cls,
577 else 567 else
578 { 568 {
579 struct GNUNET_MY_QueryParam params_get[] = { 569 struct GNUNET_MY_QueryParam params_get[] = {
580 GNUNET_MY_query_param_fixed_size (key, hashSize), 570 GNUNET_MY_query_param_auto_from_type (key),
581 GNUNET_MY_query_param_uint32 (&type), 571 GNUNET_MY_query_param_uint32 (&type),
582 GNUNET_MY_query_param_end 572 GNUNET_MY_query_param_end
583 }; 573 };
@@ -596,8 +586,8 @@ mysql_plugin_get_key (void *cls,
596 if (vhash != NULL) 586 if (vhash != NULL)
597 { 587 {
598 struct GNUNET_MY_QueryParam params_get[] = { 588 struct GNUNET_MY_QueryParam params_get[] = {
599 GNUNET_MY_query_param_fixed_size (key, hashSize), 589 GNUNET_MY_query_param_auto_from_type (key),
600 GNUNET_MY_query_param_fixed_size (vhash, hashSize2), 590 GNUNET_MY_query_param_auto_from_type (vhash),
601 GNUNET_MY_query_param_end 591 GNUNET_MY_query_param_end
602 }; 592 };
603 593
@@ -612,7 +602,7 @@ mysql_plugin_get_key (void *cls,
612 else 602 else
613 { 603 {
614 struct GNUNET_MY_QueryParam params_get[] = { 604 struct GNUNET_MY_QueryParam params_get[] = {
615 GNUNET_MY_query_param_fixed_size (key, hashSize), 605 GNUNET_MY_query_param_auto_from_type (key),
616 GNUNET_MY_query_param_end 606 GNUNET_MY_query_param_end
617 }; 607 };
618 608
@@ -698,6 +688,7 @@ mysql_plugin_get_key (void *cls,
698 params_select); 688 params_select);
699 } 689 }
700 } 690 }
691
701} 692}
702 693
703 694
@@ -778,9 +769,14 @@ struct ReplCtx
778 * GNUNET_NO to delete the item and continue (if supported) 769 * GNUNET_NO to delete the item and continue (if supported)
779 */ 770 */
780static int 771static int
781repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size, 772repl_proc (void *cls,
782 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, 773 const struct GNUNET_HashCode * key,
783 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, 774 uint32_t size,
775 const void *data,
776 enum GNUNET_BLOCK_Type type,
777 uint32_t priority,
778 uint32_t anonymity,
779 struct GNUNET_TIME_Absolute expiration,
784 uint64_t uid) 780 uint64_t uid)
785{ 781{
786 struct ReplCtx *rc = cls; 782 struct ReplCtx *rc = cls;
@@ -829,19 +825,13 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
829 void *proc_cls) 825 void *proc_cls)
830{ 826{
831 struct Plugin *plugin = cls; 827 struct Plugin *plugin = cls;
832 struct ReplCtx rc; 828 uint64_t rvalue;
833 unsigned long long rvalue;
834 //unsigned long repl;
835 uint32_t repl; 829 uint32_t repl;
836 MYSQL_BIND results;
837 830
831 struct ReplCtx rc;
838 rc.plugin = plugin; 832 rc.plugin = plugin;
839 rc.proc = proc; 833 rc.proc = proc;
840 rc.proc_cls = proc_cls; 834 rc.proc_cls = proc_cls;
841 memset (&results, 0, sizeof (results));
842 results.buffer_type = MYSQL_TYPE_LONG;
843 results.buffer = &repl;
844 results.is_unsigned = GNUNET_YES;
845 835
846 struct GNUNET_MY_QueryParam params_get[] = { 836 struct GNUNET_MY_QueryParam params_get[] = {
847 GNUNET_MY_query_param_end 837 GNUNET_MY_query_param_end
@@ -851,14 +841,15 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
851 GNUNET_MY_result_spec_uint32 (&repl), 841 GNUNET_MY_result_spec_uint32 (&repl),
852 GNUNET_MY_result_spec_end 842 GNUNET_MY_result_spec_end
853 }; 843 };
854/* 844
855 if (1 != 845 struct GNUNET_MY_QueryParam params_select[] = {
856 GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->max_repl, 1, &results, NULL, NULL, -1)) 846 GNUNET_MY_query_param_uint32 (&repl),
857 { 847 GNUNET_MY_query_param_uint64 (&rvalue),
858 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 848 GNUNET_MY_query_param_uint32 (&repl),
859 return; 849 GNUNET_MY_query_param_uint64 (&rvalue),
860 } 850 GNUNET_MY_query_param_end
861*/ 851 };
852
862 if (1 != 853 if (1 !=
863 GNUNET_MY_exec_prepared (plugin->mc, plugin->max_repl, params_get)) 854 GNUNET_MY_exec_prepared (plugin->mc, plugin->max_repl, params_get))
864 { 855 {
@@ -876,11 +867,11 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
876 rvalue = 867 rvalue =
877 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 868 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
878 UINT64_MAX); 869 UINT64_MAX);
879 execute_select (plugin, plugin->select_replication, &repl_proc, &rc,
880 MYSQL_TYPE_LONG, &repl, GNUNET_YES, MYSQL_TYPE_LONGLONG,
881 &rvalue, GNUNET_YES, MYSQL_TYPE_LONG, &repl, GNUNET_YES,
882 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
883 870
871 execute_select (plugin,
872 plugin->select_replication,
873 &repl_proc, &rc,
874 params_select);
884} 875}
885 876
886 877
@@ -893,11 +884,10 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc,
893 */ 884 */
894static void 885static void
895mysql_plugin_get_keys (void *cls, 886mysql_plugin_get_keys (void *cls,
896 PluginKeyProcessor proc, 887 PluginKeyProcessor proc,
897 void *proc_cls) 888 void *proc_cls)
898{ 889{
899 struct Plugin *plugin = cls; 890 struct Plugin *plugin = cls;
900// const char *query = "SELECT hash FROM gn090";
901 char *query = "SELECT hash FROM gn090"; 891 char *query = "SELECT hash FROM gn090";
902 int ret; 892 int ret;
903 MYSQL_STMT *statement; 893 MYSQL_STMT *statement;
@@ -905,31 +895,11 @@ mysql_plugin_get_keys (void *cls,
905 895
906 896
907 struct GNUNET_HashCode key; 897 struct GNUNET_HashCode key;
908// MYSQL_BIND cbind[1];
909// unsigned long length;
910 898
911 statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys); 899 statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys);
912 900
913
914 statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc, 901 statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc,
915 query); 902 query);
916/*
917 if (statement == NULL)
918 {
919 GNUNET_MYSQL_statements_invalidate (plugin->mc);
920 proc (proc_cls, NULL, 0);
921 return;
922 }
923
924 if (mysql_stmt_prepare (statement, query, strlen (query)))
925 {
926 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql",
927 _("Failed to prepare statement `%s'\n"), query);
928 GNUNET_MYSQL_statements_invalidate (plugin->mc);
929 proc (proc_cls, NULL, 0);
930 return;
931 }
932*/
933 GNUNET_assert (proc != NULL); 903 GNUNET_assert (proc != NULL);
934 904
935 struct GNUNET_MY_QueryParam params_select[] = { 905 struct GNUNET_MY_QueryParam params_select[] = {
@@ -956,39 +926,7 @@ mysql_plugin_get_keys (void *cls,
956 926
957 ret = GNUNET_MY_extract_result (statements_handle_select, 927 ret = GNUNET_MY_extract_result (statements_handle_select,
958 results_select); 928 results_select);
959/* if (mysql_stmt_execute (statement)) 929
960 {
961 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
962 _("`%s' for `%s' failed at %s:%d with error: %s\n"),
963 "mysql_stmt_execute", query, __FILE__, __LINE__,
964 mysql_stmt_error (statement));
965 GNUNET_MYSQL_statements_invalidate (plugin->mc);
966 proc (proc_cls, NULL, 0);
967 return;
968 }
969 memset (cbind, 0, sizeof (cbind));
970 cbind[0].buffer_type = MYSQL_TYPE_BLOB;
971 cbind[0].buffer = &key;
972 cbind[0].buffer_length = sizeof (key);
973 cbind[0].length = &length;
974 cbind[0].is_unsigned = GNUNET_NO;
975 if (mysql_stmt_bind_result (statement, cbind))
976 {
977 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
978 _("`%s' failed at %s:%d with error: %s\n"),
979 "mysql_stmt_bind_result", __FILE__, __LINE__,
980 mysql_stmt_error (statement));
981 GNUNET_MYSQL_statements_invalidate (plugin->mc);
982 proc (proc_cls, NULL, 0);
983 return;
984 }
985 while (0 == (ret = mysql_stmt_fetch (statement)))
986 {
987 if (sizeof (struct GNUNET_HashCode) == length)
988 proc (proc_cls, &key, 1);
989 }
990 proc (proc_cls, NULL, 0);
991*/
992 if (ret != MYSQL_NO_DATA) 930 if (ret != MYSQL_NO_DATA)
993 { 931 {
994 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 932 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1048,18 +986,27 @@ struct ExpiCtx
1048 * GNUNET_NO to delete the item and continue (if supported) 986 * GNUNET_NO to delete the item and continue (if supported)
1049 */ 987 */
1050static int 988static int
1051expi_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size, 989expi_proc (void *cls,
1052 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, 990 const struct GNUNET_HashCode * key,
1053 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, 991 uint32_t size,
992 const void *data,
993 enum GNUNET_BLOCK_Type type,
994 uint32_t priority,
995 uint32_t anonymity,
996 struct GNUNET_TIME_Absolute expiration,
1054 uint64_t uid) 997 uint64_t uid)
1055{ 998{
1056 struct ExpiCtx *rc = cls; 999 struct ExpiCtx *rc = cls;
1057 struct Plugin *plugin = rc->plugin; 1000 struct Plugin *plugin = rc->plugin;
1058 1001
1002 struct GNUNET_MY_QueryParam params_select[] = {
1003 GNUNET_MY_query_param_end
1004 };
1005
1059 if (NULL == key) 1006 if (NULL == key)
1060 { 1007 {
1061 execute_select (plugin, plugin->select_priority, rc->proc, rc->proc_cls, 1008 execute_select (plugin, plugin->select_priority, rc->proc, rc->proc_cls,
1062 -1); 1009 params_select);
1063 return GNUNET_SYSERR; 1010 return GNUNET_SYSERR;
1064 } 1011 }
1065 return rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, 1012 return rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity,
@@ -1080,15 +1027,21 @@ mysql_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
1080 void *proc_cls) 1027 void *proc_cls)
1081{ 1028{
1082 struct Plugin *plugin = cls; 1029 struct Plugin *plugin = cls;
1083 long long nt; 1030 uint64_t nt;
1084 struct ExpiCtx rc; 1031 struct ExpiCtx rc;
1085 1032
1086 rc.plugin = plugin; 1033 rc.plugin = plugin;
1087 rc.proc = proc; 1034 rc.proc = proc;
1088 rc.proc_cls = proc_cls; 1035 rc.proc_cls = proc_cls;
1089 nt = (long long) GNUNET_TIME_absolute_get ().abs_value_us; 1036 nt = GNUNET_TIME_absolute_get ().abs_value_us;
1037
1038 struct GNUNET_MY_QueryParam params_select[] = {
1039 GNUNET_MY_query_param_uint64 (&nt),
1040 GNUNET_MY_query_param_end
1041 };
1042
1090 execute_select (plugin, plugin->select_expiration, expi_proc, &rc, 1043 execute_select (plugin, plugin->select_expiration, expi_proc, &rc,
1091 MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1); 1044 params_select);
1092 1045
1093} 1046}
1094 1047