diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-21 09:04:08 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-21 09:04:08 +0000 |
commit | d59784c8e1b20313f580984465685bc4061db93e (patch) | |
tree | d43c011b92287d25a4a6f31cc699e8c67e4c0e92 /src/datastore | |
parent | 801dd2f76471f55616f9c5d22dc78bd82c654684 (diff) | |
download | gnunet-d59784c8e1b20313f580984465685bc4061db93e.tar.gz gnunet-d59784c8e1b20313f580984465685bc4061db93e.zip |
plugin datastore mysql
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 73 | ||||
-rw-r--r-- | src/datastore/test_defaults.conf | 2 | ||||
-rw-r--r-- | src/datastore/test_plugin_datastore_data_mysql.conf | 2 |
3 files changed, 44 insertions, 33 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index eb04ac56b..4b0479a7f 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @brief mysql-based datastore backend | 23 | * @brief mysql-based datastore backend |
24 | * @author Igor Wronsky | 24 | * @author Igor Wronsky |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | * @author Christophe Genevey | ||
26 | * | 27 | * |
27 | * NOTE: This db module does NOT work with mysql prior to 4.1 since | 28 | * NOTE: This db module does NOT work with mysql prior to 4.1 since |
28 | * it uses prepared statements. MySQL 5.0.46 promises to fix a bug | 29 | * it uses prepared statements. MySQL 5.0.46 promises to fix a bug |
@@ -236,8 +237,8 @@ do_delete_entry (struct Plugin *plugin, unsigned long long uid) | |||
236 | &uid, | 237 | &uid, |
237 | GNUNET_YES, | 238 | GNUNET_YES, |
238 | -1); | 239 | -1); |
239 | */ | ||
240 | 240 | ||
241 | */ | ||
241 | uint64_t uid64 = (uint64_t) uid; | 242 | uint64_t uid64 = (uint64_t) uid; |
242 | 243 | ||
243 | struct GNUNET_MY_QueryParam params_delete[] = { | 244 | struct GNUNET_MY_QueryParam params_delete[] = { |
@@ -270,12 +271,12 @@ mysql_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
270 | // MYSQL_BIND cbind[1]; | 271 | // MYSQL_BIND cbind[1]; |
271 | uint64_t total; | 272 | uint64_t total; |
272 | // long long total; | 273 | // long long total; |
273 | 274 | /* | |
274 | if (NULL == estimate) | 275 | if (NULL == estimate) |
275 | return; | 276 | return; |
276 | // memset (cbind, 0, sizeof (cbind)); | 277 | memset (cbind, 0, sizeof (cbind)); |
277 | total = 0; | 278 | total = 0; |
278 | /* cbind[0].buffer_type = MYSQL_TYPE_LONGLONG; | 279 | cbind[0].buffer_type = MYSQL_TYPE_LONGLONG; |
279 | cbind[0].buffer = &total; | 280 | cbind[0].buffer = &total; |
280 | cbind[0].is_unsigned = GNUNET_NO; | 281 | cbind[0].is_unsigned = GNUNET_NO; |
281 | */ | 282 | */ |
@@ -288,9 +289,9 @@ mysql_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
288 | GNUNET_MY_result_spec_end | 289 | GNUNET_MY_result_spec_end |
289 | }; | 290 | }; |
290 | 291 | ||
291 | /* if (GNUNET_OK == | 292 | // if (GNUNET_OK == |
292 | GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1)) | 293 | // GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->get_size, 1, cbind, NULL, NULL, -1)) |
293 | */ if (GNUNET_OK == | 294 | if (GNUNET_OK == |
294 | GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get)) | 295 | GNUNET_MY_exec_prepared (plugin->mc, plugin->get_size, params_get)) |
295 | { | 296 | { |
296 | if (GNUNET_OK == GNUNET_MY_extract_result (plugin->get_size, results_get)) | 297 | if (GNUNET_OK == GNUNET_MY_extract_result (plugin->get_size, results_get)) |
@@ -299,7 +300,7 @@ mysql_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
299 | } | 300 | } |
300 | } | 301 | } |
301 | 302 | ||
302 | // *estimate = total; | 303 | //*estimate = total; |
303 | else | 304 | else |
304 | *estimate = 0; | 305 | *estimate = 0; |
305 | } | 306 | } |
@@ -331,10 +332,16 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
331 | unsigned int irepl = replication; | 332 | unsigned int irepl = replication; |
332 | unsigned int ipriority = priority; | 333 | unsigned int ipriority = priority; |
333 | unsigned int ianonymity = anonymity; | 334 | unsigned int ianonymity = anonymity; |
334 | unsigned long long lexpiration = expiration.abs_value_us; | 335 | // unsigned long long lexpiration = expiration.abs_value_us; |
335 | unsigned long long lrvalue = | 336 | uint64_t lexpiration = expiration.abs_value_us; |
337 | |||
338 | /* unsigned long long lrvalue = | ||
336 | (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 339 | (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
337 | UINT64_MAX); | 340 | UINT64_MAX); |
341 | */ | ||
342 | uint64_t lrvalue = | ||
343 | (uint64_t) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
344 | UINT64_MAX); | ||
338 | unsigned long hashSize; | 345 | unsigned long hashSize; |
339 | unsigned long hashSize2; | 346 | unsigned long hashSize2; |
340 | unsigned long lsize; | 347 | unsigned long lsize; |
@@ -363,8 +370,8 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
363 | GNUNET_MY_query_param_fixed_size (data, lsize), | 370 | GNUNET_MY_query_param_fixed_size (data, lsize), |
364 | GNUNET_MY_query_param_end | 371 | GNUNET_MY_query_param_end |
365 | }; | 372 | }; |
366 | 373 | /* | |
367 | /* if (GNUNET_OK != | 374 | if (GNUNET_OK != |
368 | GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->insert_entry, NULL, | 375 | GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->insert_entry, NULL, |
369 | MYSQL_TYPE_LONG, &irepl, GNUNET_YES, | 376 | MYSQL_TYPE_LONG, &irepl, GNUNET_YES, |
370 | MYSQL_TYPE_LONG, &type, GNUNET_YES, | 377 | MYSQL_TYPE_LONG, &type, GNUNET_YES, |
@@ -379,7 +386,7 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
379 | cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure")); | 386 | cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure")); |
380 | return; | 387 | return; |
381 | } | 388 | } |
382 | */ | 389 | */ |
383 | if (GNUNET_OK != | 390 | if (GNUNET_OK != |
384 | GNUNET_MY_exec_prepared (plugin->mc, | 391 | GNUNET_MY_exec_prepared (plugin->mc, |
385 | plugin->insert_entry, | 392 | plugin->insert_entry, |
@@ -482,12 +489,14 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt | |||
482 | va_list ap; | 489 | va_list ap; |
483 | int ret; | 490 | int ret; |
484 | unsigned int type; | 491 | unsigned int type; |
485 | unsigned int priority; | 492 | // unsigned int priority; |
493 | uint32_t priority; | ||
486 | unsigned int anonymity; | 494 | unsigned int anonymity; |
487 | unsigned long long exp; | 495 | // unsigned long long exp; |
488 | //unsigned long hashSize; | 496 | uint64_t exp; |
489 | size_t hashSize; | 497 | unsigned long hashSize = 0; |
490 | //unsigned long size; | 498 | //size_t hashSize; |
499 | // unsigned long size; | ||
491 | uint64_t size; | 500 | uint64_t size; |
492 | unsigned long long uid = 0; | 501 | unsigned long long uid = 0; |
493 | char value[GNUNET_DATASTORE_MAX_VALUE_SIZE]; | 502 | char value[GNUNET_DATASTORE_MAX_VALUE_SIZE]; |
@@ -495,8 +504,9 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt | |||
495 | struct GNUNET_TIME_Absolute expiration; | 504 | struct GNUNET_TIME_Absolute expiration; |
496 | // MYSQL_BIND rbind[7]; | 505 | // MYSQL_BIND rbind[7]; |
497 | 506 | ||
507 | /* | ||
498 | hashSize = sizeof (struct GNUNET_HashCode); | 508 | hashSize = sizeof (struct GNUNET_HashCode); |
499 | /* memset (rbind, 0, sizeof (rbind)); | 509 | memset (rbind, 0, sizeof (rbind)); |
500 | rbind[0].buffer_type = MYSQL_TYPE_LONG; | 510 | rbind[0].buffer_type = MYSQL_TYPE_LONG; |
501 | rbind[0].buffer = &type; | 511 | rbind[0].buffer = &type; |
502 | rbind[0].is_unsigned = 1; | 512 | rbind[0].is_unsigned = 1; |
@@ -555,8 +565,8 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt | |||
555 | } | 565 | } |
556 | 566 | ||
557 | GNUNET_assert (size <= sizeof (value)); | 567 | GNUNET_assert (size <= sizeof (value)); |
558 | 568 | /* | |
559 | /* if ((rbind[4].buffer_length != sizeof (struct GNUNET_HashCode)) || | 569 | if ((rbind[4].buffer_length != sizeof (struct GNUNET_HashCode)) || |
560 | (hashSize != sizeof (struct GNUNET_HashCode))) | 570 | (hashSize != sizeof (struct GNUNET_HashCode))) |
561 | { | 571 | { |
562 | */ | 572 | */ |
@@ -580,7 +590,7 @@ execute_select (struct Plugin *plugin, struct GNUNET_MYSQL_StatementHandle *stmt | |||
580 | { | 590 | { |
581 | do_delete_entry (plugin, uid); | 591 | do_delete_entry (plugin, uid); |
582 | if (size != 0) | 592 | if (size != 0) |
583 | plugin->env->duc (plugin->env->cls, -size); | 593 | plugin->env->duc (plugin->env->cls, -size); |
584 | } | 594 | } |
585 | } | 595 | } |
586 | 596 | ||
@@ -877,7 +887,7 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
877 | GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->dec_repl, NULL, | 887 | GNUNET_MYSQL_statement_run_prepared (plugin->mc, plugin->dec_repl, NULL, |
878 | MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1); | 888 | MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1); |
879 | 889 | ||
880 | /* struct GNUNET_MY_QueryParam params_proc[] = { | 890 | struct GNUNET_MY_QueryParam params_proc[] = { |
881 | GNUNET_MY_query_param_uint64 (&oid), | 891 | GNUNET_MY_query_param_uint64 (&oid), |
882 | GNUNET_MY_query_param_end | 892 | GNUNET_MY_query_param_end |
883 | }; | 893 | }; |
@@ -886,7 +896,7 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
886 | GNUNET_MY_exec_prepared (plugin->mc, | 896 | GNUNET_MY_exec_prepared (plugin->mc, |
887 | plugin->dec_repl, | 897 | plugin->dec_repl, |
888 | params_proc); | 898 | params_proc); |
889 | */ if (iret == GNUNET_SYSERR) | 899 | if (iret == GNUNET_SYSERR) |
890 | { | 900 | { |
891 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 901 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
892 | "Failed to reduce replication counter\n"); | 902 | "Failed to reduce replication counter\n"); |
@@ -915,7 +925,7 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc, | |||
915 | struct Plugin *plugin = cls; | 925 | struct Plugin *plugin = cls; |
916 | struct ReplCtx rc; | 926 | struct ReplCtx rc; |
917 | unsigned long long rvalue; | 927 | unsigned long long rvalue; |
918 | // unsigned long repl; | 928 | //unsigned long repl; |
919 | uint32_t repl; | 929 | uint32_t repl; |
920 | MYSQL_BIND results; | 930 | MYSQL_BIND results; |
921 | 931 | ||
@@ -935,8 +945,8 @@ mysql_plugin_get_replication (void *cls, PluginDatumProcessor proc, | |||
935 | GNUNET_MY_result_spec_uint32 (&repl), | 945 | GNUNET_MY_result_spec_uint32 (&repl), |
936 | GNUNET_MY_result_spec_end | 946 | GNUNET_MY_result_spec_end |
937 | }; | 947 | }; |
938 | 948 | /* | |
939 | /* if (1 != | 949 | if (1 != |
940 | GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->max_repl, 1, &results, NULL, NULL, -1)) | 950 | GNUNET_MYSQL_statement_run_prepared_select (plugin->mc, plugin->max_repl, 1, &results, NULL, NULL, -1)) |
941 | { | 951 | { |
942 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 952 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
@@ -990,14 +1000,15 @@ mysql_plugin_get_keys (void *cls, | |||
990 | 1000 | ||
991 | struct GNUNET_HashCode key; | 1001 | struct GNUNET_HashCode key; |
992 | // MYSQL_BIND cbind[1]; | 1002 | // MYSQL_BIND cbind[1]; |
993 | unsigned long length; | 1003 | // unsigned long length; |
994 | 1004 | ||
995 | statement = GNUNET_MYSQL_statement_get_stmt (plugin->mc, | 1005 | statement = GNUNET_MYSQL_statement_get_stmt (plugin->mc, |
996 | plugin->get_all_keys); | 1006 | plugin->get_all_keys); |
1007 | |||
997 | 1008 | ||
998 | statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc, | 1009 | statements_handle_select = GNUNET_MYSQL_statement_prepare (plugin->mc, |
999 | query); | 1010 | query); |
1000 | 1011 | /* | |
1001 | if (statement == NULL) | 1012 | if (statement == NULL) |
1002 | { | 1013 | { |
1003 | GNUNET_MYSQL_statements_invalidate (plugin->mc); | 1014 | GNUNET_MYSQL_statements_invalidate (plugin->mc); |
@@ -1005,7 +1016,7 @@ mysql_plugin_get_keys (void *cls, | |||
1005 | return; | 1016 | return; |
1006 | } | 1017 | } |
1007 | 1018 | ||
1008 | /* if (mysql_stmt_prepare (statement, query, strlen (query))) | 1019 | if (mysql_stmt_prepare (statement, query, strlen (query))) |
1009 | { | 1020 | { |
1010 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 1021 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", |
1011 | _("Failed to prepare statement `%s'\n"), query); | 1022 | _("Failed to prepare statement `%s'\n"), query); |
@@ -1072,7 +1083,7 @@ mysql_plugin_get_keys (void *cls, | |||
1072 | proc (proc_cls, &key, 1); | 1083 | proc (proc_cls, &key, 1); |
1073 | } | 1084 | } |
1074 | proc (proc_cls, NULL, 0); | 1085 | proc (proc_cls, NULL, 0); |
1075 | */ | 1086 | */ |
1076 | if (ret != MYSQL_NO_DATA) | 1087 | if (ret != MYSQL_NO_DATA) |
1077 | { | 1088 | { |
1078 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1089 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
diff --git a/src/datastore/test_defaults.conf b/src/datastore/test_defaults.conf index 67d782f3a..ba3808985 100644 --- a/src/datastore/test_defaults.conf +++ b/src/datastore/test_defaults.conf | |||
@@ -2,7 +2,7 @@ | |||
2 | @inline@ ../../contrib/no_forcestart.conf | 2 | @inline@ ../../contrib/no_forcestart.conf |
3 | 3 | ||
4 | [datastore] | 4 | [datastore] |
5 | PORT = 22654 | 5 | PORT = 3306 |
6 | QUOTA = 1 MB | 6 | QUOTA = 1 MB |
7 | AUTOSTART = YES | 7 | AUTOSTART = YES |
8 | 8 | ||
diff --git a/src/datastore/test_plugin_datastore_data_mysql.conf b/src/datastore/test_plugin_datastore_data_mysql.conf index 53a188997..ac7a3cde1 100644 --- a/src/datastore/test_plugin_datastore_data_mysql.conf +++ b/src/datastore/test_plugin_datastore_data_mysql.conf | |||
@@ -6,5 +6,5 @@ GNUNET_TEST_HOME = /tmp/test-gnunet-datastore-plugin-mysql/ | |||
6 | DATABASE = mysql | 6 | DATABASE = mysql |
7 | 7 | ||
8 | [datastore-mysql] | 8 | [datastore-mysql] |
9 | DATABASE = gnunetcheck | 9 | DATABASE = gnunet |
10 | 10 | ||