aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_mysql.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amat.us>2017-03-22 22:17:05 -0500
committerDavid Barksdale <amatus@amat.us>2017-03-22 22:19:13 -0500
commit78ecfccd774a77ae3d7a51e3f5c7c7c86cf7985b (patch)
tree1dc23a2f6d78c8026e69181ac90055929d79bba8 /src/datastore/plugin_datastore_mysql.c
parentaa98f144e6db0da5a0a4cad83fe64a80bbab6692 (diff)
downloadgnunet-78ecfccd774a77ae3d7a51e3f5c7c7c86cf7985b.tar.gz
gnunet-78ecfccd774a77ae3d7a51e3f5c7c7c86cf7985b.zip
[datastore] Return and update replication
This fixes a couple FIXMEs in the datastore code. The replication value is now returned from the datastore and the update function can increase the replication.
Diffstat (limited to 'src/datastore/plugin_datastore_mysql.c')
-rw-r--r--src/datastore/plugin_datastore_mysql.c117
1 files changed, 84 insertions, 33 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 5ae4485cb..6f2a76499 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -150,22 +150,56 @@ struct Plugin
150#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" 150#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
151 struct GNUNET_MYSQL_StatementHandle *delete_entry_by_uid; 151 struct GNUNET_MYSQL_StatementHandle *delete_entry_by_uid;
152 152
153#define SELECT_ENTRY "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 WHERE uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1" 153#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid"
154
155#define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 "\
156 "WHERE uid >= ? AND "\
157 "(rvalue >= ? OR 0 = ?) "\
158 "ORDER BY uid LIMIT 1"
154 struct GNUNET_MYSQL_StatementHandle *select_entry; 159 struct GNUNET_MYSQL_StatementHandle *select_entry;
155 160
156#define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash) WHERE hash=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1" 161#define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 "\
162 "FORCE INDEX (idx_hash) "\
163 "WHERE hash=? AND "\
164 "uid >= ? AND "\
165 "(rvalue >= ? OR 0 = ?) "\
166 "ORDER BY uid LIMIT 1"
157 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash; 167 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash;
158 168
159#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1" 169#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT " RESULT_COLUMNS " FROM gn090 "\
170 "FORCE INDEX (idx_hash_vhash) "\
171 "WHERE hash = ? AND "\
172 "vhash = ? AND "\
173 "uid >= ? AND "\
174 "(rvalue >= ? OR 0 = ?) "\
175 "ORDER BY uid LIMIT 1"
160 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_vhash; 176 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_vhash;
161 177
162#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1" 178#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 "\
179 "FORCE INDEX (idx_hash_type_uid) "\
180 "WHERE hash = ? AND "\
181 "type = ? AND "\
182 "uid >= ? AND "\
183 "(rvalue >= ? OR 0 = ?) "\
184 "ORDER BY uid LIMIT 1"
163 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type; 185 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type;
164 186
165#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=? AND uid >= ? AND (rvalue >= ? OR 0 = ?) ORDER BY uid LIMIT 1" 187#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT " RESULT_COLUMNS " "\
188 "FROM gn090 "\
189 "FORCE INDEX (idx_hash_vhash) "\
190 "WHERE hash = ? AND "\
191 "vhash = ? AND "\
192 "type = ? AND "\
193 "uid >= ? AND "\
194 "(rvalue >= ? OR 0 = ?) "\
195 "ORDER BY uid LIMIT 1"
166 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_vhash_and_type; 196 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_vhash_and_type;
167 197
168#define UPDATE_ENTRY "UPDATE gn090 SET prio=prio+?,expire=IF(expire>=?,expire,?) WHERE uid=?" 198#define UPDATE_ENTRY "UPDATE gn090 SET "\
199 "prio = prio + ?, "\
200 "repl = repl + ?, "\
201 "expire = IF(expire >= ?, expire, ?) "\
202 "WHERE uid = ?"
169 struct GNUNET_MYSQL_StatementHandle *update_entry; 203 struct GNUNET_MYSQL_StatementHandle *update_entry;
170 204
171#define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?" 205#define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"
@@ -174,20 +208,27 @@ struct Plugin
174#define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090" 208#define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090"
175 struct GNUNET_MYSQL_StatementHandle *get_size; 209 struct GNUNET_MYSQL_StatementHandle *get_size;
176 210
177#define SELECT_IT_NON_ANONYMOUS "SELECT type,prio,anonLevel,expire,hash,value,uid "\ 211#define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 "\
178 "FROM gn090 FORCE INDEX (idx_anonLevel_type_rvalue) "\ 212 "FORCE INDEX (idx_anonLevel_type_rvalue) "\
179 "WHERE anonLevel=0 AND type=? AND uid >= ? "\ 213 "WHERE anonLevel=0 AND "\
180 "ORDER BY uid LIMIT 1" 214 "type=? AND "\
215 "uid >= ? "\
216 "ORDER BY uid LIMIT 1"
181 struct GNUNET_MYSQL_StatementHandle *zero_iter; 217 struct GNUNET_MYSQL_StatementHandle *zero_iter;
182 218
183#define SELECT_IT_EXPIRATION "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_expire) WHERE expire < ? ORDER BY expire ASC LIMIT 1" 219#define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 "\
220 "FORCE INDEX (idx_expire) "\
221 "WHERE expire < ? "\
222 "ORDER BY expire ASC LIMIT 1"
184 struct GNUNET_MYSQL_StatementHandle *select_expiration; 223 struct GNUNET_MYSQL_StatementHandle *select_expiration;
185 224
186#define SELECT_IT_PRIORITY "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_prio) ORDER BY prio ASC LIMIT 1" 225#define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 "\
226 "FORCE INDEX (idx_prio) "\
227 "ORDER BY prio ASC LIMIT 1"
187 struct GNUNET_MYSQL_StatementHandle *select_priority; 228 struct GNUNET_MYSQL_StatementHandle *select_priority;
188 229
189#define SELECT_IT_REPLICATION "SELECT type,prio,anonLevel,expire,hash,value,uid "\ 230#define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 "\
190 "FROM gn090 FORCE INDEX (idx_repl_rvalue) "\ 231 "FORCE INDEX (idx_repl_rvalue) "\
191 "WHERE repl=? AND "\ 232 "WHERE repl=? AND "\
192 " (rvalue>=? OR"\ 233 " (rvalue>=? OR"\
193 " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) "\ 234 " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE repl=? AND rvalue>=?)) "\
@@ -371,19 +412,17 @@ mysql_plugin_put (void *cls,
371 412
372 413
373/** 414/**
374 * Update the priority for a particular key in the datastore. If 415 * Update the priority, replication and expiration for a particular
375 * the expiration time in value is different than the time found in 416 * unique ID in the datastore. If the expiration time in value is
376 * the datastore, the higher value should be kept. For the 417 * different than the time found in the datastore, the higher value
377 * anonymity level, the lower value is to be used. The specified 418 * should be kept. The specified priority and replication is added
378 * priority should be added to the existing priority, ignoring the 419 * to the existing value.
379 * priority in value.
380 *
381 * Note that it is possible for multiple values to match this put.
382 * In that case, all of the respective values are updated.
383 * 420 *
384 * @param cls our "struct Plugin*" 421 * @param cls our "struct Plugin*"
385 * @param uid unique identifier of the datum 422 * @param uid unique identifier of the datum
386 * @param delta by how much should the priority 423 * @param priority by how much should the priority
424 * change?
425 * @param replication by how much should the replication
387 * change? 426 * change?
388 * @param expire new expiration time should be the 427 * @param expire new expiration time should be the
389 * MAX of any existing expiration time and 428 * MAX of any existing expiration time and
@@ -394,7 +433,8 @@ mysql_plugin_put (void *cls,
394static void 433static void
395mysql_plugin_update (void *cls, 434mysql_plugin_update (void *cls,
396 uint64_t uid, 435 uint64_t uid,
397 uint32_t delta, 436 uint32_t priority,
437 uint32_t replication,
398 struct GNUNET_TIME_Absolute expire, 438 struct GNUNET_TIME_Absolute expire,
399 PluginUpdateCont cont, 439 PluginUpdateCont cont,
400 void *cont_cls) 440 void *cont_cls)
@@ -404,13 +444,15 @@ mysql_plugin_update (void *cls,
404 int ret; 444 int ret;
405 445
406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
407 "Updating value %llu adding %d to priority and maxing exp at %s\n", 447 "Updating value %llu adding %d to priority %d to replication and maxing exp at %s\n",
408 (unsigned long long) uid, 448 (unsigned long long) uid,
409 delta, 449 priority,
410 GNUNET_STRINGS_absolute_time_to_string (expire)); 450 replication,
451 GNUNET_STRINGS_absolute_time_to_string (expire));
411 452
412 struct GNUNET_MY_QueryParam params_update[] = { 453 struct GNUNET_MY_QueryParam params_update[] = {
413 GNUNET_MY_query_param_uint32 (&delta), 454 GNUNET_MY_query_param_uint32 (&priority),
455 GNUNET_MY_query_param_uint32 (&replication),
414 GNUNET_MY_query_param_uint64 (&lexpire), 456 GNUNET_MY_query_param_uint64 (&lexpire),
415 GNUNET_MY_query_param_uint64 (&lexpire), 457 GNUNET_MY_query_param_uint64 (&lexpire),
416 GNUNET_MY_query_param_uint64 (&uid), 458 GNUNET_MY_query_param_uint64 (&uid),
@@ -457,6 +499,7 @@ execute_select (struct Plugin *plugin,
457 struct GNUNET_MY_QueryParam *params_select) 499 struct GNUNET_MY_QueryParam *params_select)
458{ 500{
459 int ret; 501 int ret;
502 uint32_t replication;
460 uint32_t type; 503 uint32_t type;
461 uint32_t priority; 504 uint32_t priority;
462 uint32_t anonymity; 505 uint32_t anonymity;
@@ -466,6 +509,7 @@ execute_select (struct Plugin *plugin,
466 struct GNUNET_HashCode key; 509 struct GNUNET_HashCode key;
467 struct GNUNET_TIME_Absolute expiration; 510 struct GNUNET_TIME_Absolute expiration;
468 struct GNUNET_MY_ResultSpec results_select[] = { 511 struct GNUNET_MY_ResultSpec results_select[] = {
512 GNUNET_MY_result_spec_uint32 (&replication),
469 GNUNET_MY_result_spec_uint32 (&type), 513 GNUNET_MY_result_spec_uint32 (&type),
470 GNUNET_MY_result_spec_uint32 (&priority), 514 GNUNET_MY_result_spec_uint32 (&priority),
471 GNUNET_MY_result_spec_uint32 (&anonymity), 515 GNUNET_MY_result_spec_uint32 (&anonymity),
@@ -482,7 +526,7 @@ execute_select (struct Plugin *plugin,
482 if (GNUNET_OK != ret) 526 if (GNUNET_OK != ret)
483 { 527 {
484 proc (proc_cls, 528 proc (proc_cls,
485 NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 529 NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
486 return; 530 return;
487 } 531 }
488 532
@@ -491,7 +535,7 @@ execute_select (struct Plugin *plugin,
491 if (GNUNET_OK != ret) 535 if (GNUNET_OK != ret)
492 { 536 {
493 proc (proc_cls, 537 proc (proc_cls,
494 NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 538 NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
495 return; 539 return;
496 } 540 }
497 541
@@ -513,6 +557,7 @@ execute_select (struct Plugin *plugin,
513 type, 557 type,
514 priority, 558 priority,
515 anonymity, 559 anonymity,
560 replication,
516 expiration, 561 expiration,
517 uid); 562 uid);
518 GNUNET_MY_cleanup_result (results_select); 563 GNUNET_MY_cleanup_result (results_select);
@@ -729,6 +774,7 @@ struct ReplCtx
729 * @param type type of the content 774 * @param type type of the content
730 * @param priority priority of the content 775 * @param priority priority of the content
731 * @param anonymity anonymity-level for the content 776 * @param anonymity anonymity-level for the content
777 * @param replication replication-level for the content
732 * @param expiration expiration time for the content 778 * @param expiration expiration time for the content
733 * @param uid unique identifier for the datum; 779 * @param uid unique identifier for the datum;
734 * maybe 0 if no unique identifier is available 780 * maybe 0 if no unique identifier is available
@@ -744,6 +790,7 @@ repl_proc (void *cls,
744 enum GNUNET_BLOCK_Type type, 790 enum GNUNET_BLOCK_Type type,
745 uint32_t priority, 791 uint32_t priority,
746 uint32_t anonymity, 792 uint32_t anonymity,
793 uint32_t replication,
747 struct GNUNET_TIME_Absolute expiration, 794 struct GNUNET_TIME_Absolute expiration,
748 uint64_t uid) 795 uint64_t uid)
749{ 796{
@@ -759,6 +806,7 @@ repl_proc (void *cls,
759 type, 806 type,
760 priority, 807 priority,
761 anonymity, 808 anonymity,
809 replication,
762 expiration, 810 expiration,
763 uid); 811 uid);
764 if (NULL != key) 812 if (NULL != key)
@@ -826,7 +874,7 @@ mysql_plugin_get_replication (void *cls,
826 plugin->max_repl, 874 plugin->max_repl,
827 params_get)) 875 params_get))
828 { 876 {
829 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 877 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
830 return; 878 return;
831 } 879 }
832 880
@@ -834,7 +882,7 @@ mysql_plugin_get_replication (void *cls,
834 GNUNET_MY_extract_result (plugin->max_repl, 882 GNUNET_MY_extract_result (plugin->max_repl,
835 results_get)) 883 results_get))
836 { 884 {
837 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 885 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
838 return; 886 return;
839 } 887 }
840 GNUNET_break (GNUNET_NO == 888 GNUNET_break (GNUNET_NO ==
@@ -976,6 +1024,7 @@ struct ExpiCtx
976 * @param type type of the content 1024 * @param type type of the content
977 * @param priority priority of the content 1025 * @param priority priority of the content
978 * @param anonymity anonymity-level for the content 1026 * @param anonymity anonymity-level for the content
1027 * @param replication replication-level for the content
979 * @param expiration expiration time for the content 1028 * @param expiration expiration time for the content
980 * @param uid unique identifier for the datum; 1029 * @param uid unique identifier for the datum;
981 * maybe 0 if no unique identifier is available 1030 * maybe 0 if no unique identifier is available
@@ -991,6 +1040,7 @@ expi_proc (void *cls,
991 enum GNUNET_BLOCK_Type type, 1040 enum GNUNET_BLOCK_Type type,
992 uint32_t priority, 1041 uint32_t priority,
993 uint32_t anonymity, 1042 uint32_t anonymity,
1043 uint32_t replication,
994 struct GNUNET_TIME_Absolute expiration, 1044 struct GNUNET_TIME_Absolute expiration,
995 uint64_t uid) 1045 uint64_t uid)
996{ 1046{
@@ -1016,6 +1066,7 @@ expi_proc (void *cls,
1016 type, 1066 type,
1017 priority, 1067 priority,
1018 anonymity, 1068 anonymity,
1069 replication,
1019 expiration, 1070 expiration,
1020 uid); 1071 uid);
1021} 1072}