diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2015-03-21 03:38:29 +0000 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2015-03-21 03:38:29 +0000 |
commit | c77d4e5c69ac54ffddf5bd60c18bcb0504389311 (patch) | |
tree | bb40b73db6ed428d6ab44ffee91ca0ed6f16b592 /src/datastore/plugin_datastore_mysql.c | |
parent | ce6f1156a58aafed6563585b3be560ec0b4eabe7 (diff) | |
download | gnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.tar.gz gnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.zip |
Convert datastore plugin API to asynchronous
Diffstat (limited to 'src/datastore/plugin_datastore_mysql.c')
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index 972a51417..5100adc34 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -280,14 +280,15 @@ mysql_plugin_estimate_size (void *cls, unsigned long long *estimate) | |||
280 | * @param anonymity anonymity-level for the content | 280 | * @param anonymity anonymity-level for the content |
281 | * @param replication replication-level for the content | 281 | * @param replication replication-level for the content |
282 | * @param expiration expiration time for the content | 282 | * @param expiration expiration time for the content |
283 | * @param msg set to error message | 283 | * @param cont continuation called with success or failure status |
284 | * @return GNUNET_OK on success | 284 | * @param cont_cls continuation closure |
285 | */ | 285 | */ |
286 | static int | 286 | static void |
287 | mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | 287 | mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, |
288 | const void *data, enum GNUNET_BLOCK_Type type, | 288 | const void *data, enum GNUNET_BLOCK_Type type, |
289 | uint32_t priority, uint32_t anonymity, uint32_t replication, | 289 | uint32_t priority, uint32_t anonymity, uint32_t replication, |
290 | struct GNUNET_TIME_Absolute expiration, char **msg) | 290 | struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, |
291 | void *cont_cls) | ||
291 | { | 292 | { |
292 | struct Plugin *plugin = cls; | 293 | struct Plugin *plugin = cls; |
293 | unsigned int irepl = replication; | 294 | unsigned int irepl = replication; |
@@ -305,7 +306,8 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
305 | if (size > MAX_DATUM_SIZE) | 306 | if (size > MAX_DATUM_SIZE) |
306 | { | 307 | { |
307 | GNUNET_break (0); | 308 | GNUNET_break (0); |
308 | return GNUNET_SYSERR; | 309 | cont (cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); |
310 | return; | ||
309 | } | 311 | } |
310 | hashSize = sizeof (struct GNUNET_HashCode); | 312 | hashSize = sizeof (struct GNUNET_HashCode); |
311 | hashSize2 = sizeof (struct GNUNET_HashCode); | 313 | hashSize2 = sizeof (struct GNUNET_HashCode); |
@@ -322,13 +324,16 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
322 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, | 324 | MYSQL_TYPE_BLOB, key, hashSize, &hashSize, |
323 | MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2, | 325 | MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2, |
324 | MYSQL_TYPE_BLOB, data, lsize, &lsize, -1)) | 326 | MYSQL_TYPE_BLOB, data, lsize, &lsize, -1)) |
325 | return GNUNET_SYSERR; | 327 | { |
328 | cont (cont_cls, key, size, GNUNET_SYSERR, _("MySQL statement run failure")); | ||
329 | return; | ||
330 | } | ||
326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
327 | "Inserted value `%s' with size %u into gn090 table\n", | 332 | "Inserted value `%s' with size %u into gn090 table\n", |
328 | GNUNET_h2s (key), (unsigned int) size); | 333 | GNUNET_h2s (key), (unsigned int) size); |
329 | if (size > 0) | 334 | if (size > 0) |
330 | plugin->env->duc (plugin->env->cls, size); | 335 | plugin->env->duc (plugin->env->cls, size); |
331 | return GNUNET_OK; | 336 | cont (cont_cls, key, size, GNUNET_OK, NULL); |
332 | } | 337 | } |
333 | 338 | ||
334 | 339 | ||
@@ -352,12 +357,13 @@ mysql_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
352 | * @param expire new expiration time should be the | 357 | * @param expire new expiration time should be the |
353 | * MAX of any existing expiration time and | 358 | * MAX of any existing expiration time and |
354 | * this value | 359 | * this value |
355 | * @param msg set to error message | 360 | * @param cont continuation called with success or failure status |
356 | * @return GNUNET_OK on success | 361 | * @param cons_cls continuation closure |
357 | */ | 362 | */ |
358 | static int | 363 | static void |
359 | mysql_plugin_update (void *cls, uint64_t uid, int delta, | 364 | mysql_plugin_update (void *cls, uint64_t uid, int delta, |
360 | struct GNUNET_TIME_Absolute expire, char **msg) | 365 | struct GNUNET_TIME_Absolute expire, |
366 | PluginUpdateCont cont, void *cont_cls) | ||
361 | { | 367 | { |
362 | struct Plugin *plugin = cls; | 368 | struct Plugin *plugin = cls; |
363 | unsigned long long vkey = uid; | 369 | unsigned long long vkey = uid; |
@@ -379,7 +385,7 @@ mysql_plugin_update (void *cls, uint64_t uid, int delta, | |||
379 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n", | 385 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to update value %llu\n", |
380 | vkey); | 386 | vkey); |
381 | } | 387 | } |
382 | return ret; | 388 | cont (cont_cls, ret, NULL); |
383 | } | 389 | } |
384 | 390 | ||
385 | 391 | ||
@@ -778,6 +784,7 @@ mysql_plugin_get_keys (void *cls, | |||
778 | if (statement == NULL) | 784 | if (statement == NULL) |
779 | { | 785 | { |
780 | GNUNET_MYSQL_statements_invalidate (plugin->mc); | 786 | GNUNET_MYSQL_statements_invalidate (plugin->mc); |
787 | proc (proc_cls, NULL, 0); | ||
781 | return; | 788 | return; |
782 | } | 789 | } |
783 | if (mysql_stmt_prepare (statement, query, strlen (query))) | 790 | if (mysql_stmt_prepare (statement, query, strlen (query))) |
@@ -785,6 +792,7 @@ mysql_plugin_get_keys (void *cls, | |||
785 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 792 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", |
786 | _("Failed to prepare statement `%s'\n"), query); | 793 | _("Failed to prepare statement `%s'\n"), query); |
787 | GNUNET_MYSQL_statements_invalidate (plugin->mc); | 794 | GNUNET_MYSQL_statements_invalidate (plugin->mc); |
795 | proc (proc_cls, NULL, 0); | ||
788 | return; | 796 | return; |
789 | } | 797 | } |
790 | GNUNET_assert (proc != NULL); | 798 | GNUNET_assert (proc != NULL); |
@@ -795,6 +803,7 @@ mysql_plugin_get_keys (void *cls, | |||
795 | "mysql_stmt_execute", query, __FILE__, __LINE__, | 803 | "mysql_stmt_execute", query, __FILE__, __LINE__, |
796 | mysql_stmt_error (statement)); | 804 | mysql_stmt_error (statement)); |
797 | GNUNET_MYSQL_statements_invalidate (plugin->mc); | 805 | GNUNET_MYSQL_statements_invalidate (plugin->mc); |
806 | proc (proc_cls, NULL, 0); | ||
798 | return; | 807 | return; |
799 | } | 808 | } |
800 | memset (cbind, 0, sizeof (cbind)); | 809 | memset (cbind, 0, sizeof (cbind)); |
@@ -810,6 +819,7 @@ mysql_plugin_get_keys (void *cls, | |||
810 | "mysql_stmt_bind_result", __FILE__, __LINE__, | 819 | "mysql_stmt_bind_result", __FILE__, __LINE__, |
811 | mysql_stmt_error (statement)); | 820 | mysql_stmt_error (statement)); |
812 | GNUNET_MYSQL_statements_invalidate (plugin->mc); | 821 | GNUNET_MYSQL_statements_invalidate (plugin->mc); |
822 | proc (proc_cls, NULL, 0); | ||
813 | return; | 823 | return; |
814 | } | 824 | } |
815 | while (0 == (ret = mysql_stmt_fetch (statement))) | 825 | while (0 == (ret = mysql_stmt_fetch (statement))) |
@@ -817,6 +827,7 @@ mysql_plugin_get_keys (void *cls, | |||
817 | if (sizeof (struct GNUNET_HashCode) == length) | 827 | if (sizeof (struct GNUNET_HashCode) == length) |
818 | proc (proc_cls, &key, 1); | 828 | proc (proc_cls, &key, 1); |
819 | } | 829 | } |
830 | proc (proc_cls, NULL, 0); | ||
820 | if (ret != MYSQL_NO_DATA) | 831 | if (ret != MYSQL_NO_DATA) |
821 | { | 832 | { |
822 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 833 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |