aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_sqlite.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_sqlite.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_sqlite.c')
-rw-r--r--src/datastore/plugin_datastore_sqlite.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 76f791ad4..1f874e190 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -349,10 +349,14 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
349 sqlite3_finalize (stmt); 349 sqlite3_finalize (stmt);
350 create_indices (plugin->dbh); 350 create_indices (plugin->dbh);
351 351
352#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, _ROWID_"
352 if ( (SQLITE_OK != 353 if ( (SQLITE_OK !=
353 sq_prepare (plugin->dbh, 354 sq_prepare (plugin->dbh,
354 "UPDATE gn090 " 355 "UPDATE gn090 "
355 "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?", 356 "SET prio = prio + ?, "
357 "repl = repl + ?, "
358 "expire = MAX(expire, ?) "
359 "WHERE _ROWID_ = ?",
356 &plugin->updPrio)) || 360 &plugin->updPrio)) ||
357 (SQLITE_OK != 361 (SQLITE_OK !=
358 sq_prepare (plugin->dbh, 362 sq_prepare (plugin->dbh,
@@ -360,7 +364,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
360 &plugin->updRepl)) || 364 &plugin->updRepl)) ||
361 (SQLITE_OK != 365 (SQLITE_OK !=
362 sq_prepare (plugin->dbh, 366 sq_prepare (plugin->dbh,
363 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 " 367 "SELECT " RESULT_COLUMNS " FROM gn090 "
364#if SQLITE_VERSION_NUMBER >= 3007000 368#if SQLITE_VERSION_NUMBER >= 3007000
365 "INDEXED BY idx_repl_rvalue " 369 "INDEXED BY idx_repl_rvalue "
366#endif 370#endif
@@ -382,7 +386,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 &plugin->maxRepl)) || 386 &plugin->maxRepl)) ||
383 (SQLITE_OK != 387 (SQLITE_OK !=
384 sq_prepare (plugin->dbh, 388 sq_prepare (plugin->dbh,
385 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 " 389 "SELECT " RESULT_COLUMNS " FROM gn090 "
386#if SQLITE_VERSION_NUMBER >= 3007000 390#if SQLITE_VERSION_NUMBER >= 3007000
387 "INDEXED BY idx_expire " 391 "INDEXED BY idx_expire "
388#endif 392#endif
@@ -391,7 +395,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
391 &plugin->selExpi)) || 395 &plugin->selExpi)) ||
392 (SQLITE_OK != 396 (SQLITE_OK !=
393 sq_prepare (plugin->dbh, 397 sq_prepare (plugin->dbh,
394 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " "FROM gn090 " 398 "SELECT " RESULT_COLUMNS " FROM gn090 "
395#if SQLITE_VERSION_NUMBER >= 3007000 399#if SQLITE_VERSION_NUMBER >= 3007000
396 "INDEXED BY idx_anon_type_hash " 400 "INDEXED BY idx_anon_type_hash "
397#endif 401#endif
@@ -407,7 +411,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
407 &plugin->insertContent)) || 411 &plugin->insertContent)) ||
408 (SQLITE_OK != 412 (SQLITE_OK !=
409 sq_prepare (plugin->dbh, 413 sq_prepare (plugin->dbh,
410 "SELECT type, prio, anonLevel, expire, hash, value, _ROWID_ FROM gn090 " 414 "SELECT " RESULT_COLUMNS " FROM gn090 "
411 "WHERE _ROWID_ >= ? AND " 415 "WHERE _ROWID_ >= ? AND "
412 "(rvalue >= ? OR 0 = ?) AND " 416 "(rvalue >= ? OR 0 = ?) AND "
413 "(hash = ? OR 0 = ?) AND " 417 "(hash = ? OR 0 = ?) AND "
@@ -642,19 +646,17 @@ sqlite_plugin_put (void *cls,
642 646
643 647
644/** 648/**
645 * Update the priority for a particular key in the datastore. If 649 * Update the priority, replication and expiration for a particular
646 * the expiration time in value is different than the time found in 650 * unique ID in the datastore. If the expiration time in value is
647 * the datastore, the higher value should be kept. For the 651 * different than the time found in the datastore, the higher value
648 * anonymity level, the lower value is to be used. The specified 652 * should be kept. The specified priority and replication is added
649 * priority should be added to the existing priority, ignoring the 653 * to the existing value.
650 * priority in value.
651 *
652 * Note that it is possible for multiple values to match this put.
653 * In that case, all of the respective values are updated.
654 * 654 *
655 * @param cls the plugin context (state for this module) 655 * @param cls the plugin context (state for this module)
656 * @param uid unique identifier of the datum 656 * @param uid unique identifier of the datum
657 * @param delta by how much should the priority 657 * @param priority by how much should the priority
658 * change?
659 * @param replication by how much should the replication
658 * change? 660 * change?
659 * @param expire new expiration time should be the 661 * @param expire new expiration time should be the
660 * MAX of any existing expiration time and 662 * MAX of any existing expiration time and
@@ -665,14 +667,16 @@ sqlite_plugin_put (void *cls,
665static void 667static void
666sqlite_plugin_update (void *cls, 668sqlite_plugin_update (void *cls,
667 uint64_t uid, 669 uint64_t uid,
668 uint32_t delta, 670 uint32_t priority,
671 uint32_t replication,
669 struct GNUNET_TIME_Absolute expire, 672 struct GNUNET_TIME_Absolute expire,
670 PluginUpdateCont cont, 673 PluginUpdateCont cont,
671 void *cont_cls) 674 void *cont_cls)
672{ 675{
673 struct Plugin *plugin = cls; 676 struct Plugin *plugin = cls;
674 struct GNUNET_SQ_QueryParam params[] = { 677 struct GNUNET_SQ_QueryParam params[] = {
675 GNUNET_SQ_query_param_uint32 (&delta), 678 GNUNET_SQ_query_param_uint32 (&priority),
679 GNUNET_SQ_query_param_uint32 (&replication),
676 GNUNET_SQ_query_param_absolute_time (&expire), 680 GNUNET_SQ_query_param_absolute_time (&expire),
677 GNUNET_SQ_query_param_uint64 (&uid), 681 GNUNET_SQ_query_param_uint64 (&uid),
678 GNUNET_SQ_query_param_end 682 GNUNET_SQ_query_param_end
@@ -731,6 +735,7 @@ execute_get (struct Plugin *plugin,
731{ 735{
732 int n; 736 int n;
733 struct GNUNET_TIME_Absolute expiration; 737 struct GNUNET_TIME_Absolute expiration;
738 uint32_t replication;
734 uint32_t type; 739 uint32_t type;
735 uint32_t priority; 740 uint32_t priority;
736 uint32_t anonymity; 741 uint32_t anonymity;
@@ -740,6 +745,7 @@ execute_get (struct Plugin *plugin,
740 struct GNUNET_HashCode key; 745 struct GNUNET_HashCode key;
741 int ret; 746 int ret;
742 struct GNUNET_SQ_ResultSpec rs[] = { 747 struct GNUNET_SQ_ResultSpec rs[] = {
748 GNUNET_SQ_result_spec_uint32 (&replication),
743 GNUNET_SQ_result_spec_uint32 (&type), 749 GNUNET_SQ_result_spec_uint32 (&type),
744 GNUNET_SQ_result_spec_uint32 (&priority), 750 GNUNET_SQ_result_spec_uint32 (&priority),
745 GNUNET_SQ_result_spec_uint32 (&anonymity), 751 GNUNET_SQ_result_spec_uint32 (&anonymity),
@@ -773,6 +779,7 @@ execute_get (struct Plugin *plugin,
773 type, 779 type,
774 priority, 780 priority,
775 anonymity, 781 anonymity,
782 replication,
776 expiration, 783 expiration,
777 rowid); 784 rowid);
778 GNUNET_SQ_cleanup_result (rs); 785 GNUNET_SQ_cleanup_result (rs);
@@ -801,7 +808,7 @@ execute_get (struct Plugin *plugin,
801 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 808 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
802 "sqlite3_reset"); 809 "sqlite3_reset");
803 GNUNET_break (0); 810 GNUNET_break (0);
804 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 811 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
805 database_shutdown (plugin); 812 database_shutdown (plugin);
806 database_setup (plugin->env->cfg, 813 database_setup (plugin->env->cfg,
807 plugin); 814 plugin);
@@ -809,7 +816,7 @@ execute_get (struct Plugin *plugin,
809 } 816 }
810 GNUNET_SQ_reset (plugin->dbh, 817 GNUNET_SQ_reset (plugin->dbh,
811 stmt); 818 stmt);
812 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 819 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
813} 820}
814 821
815 822
@@ -844,7 +851,7 @@ sqlite_plugin_get_zero_anonymity (void *cls,
844 GNUNET_SQ_bind (plugin->selZeroAnon, 851 GNUNET_SQ_bind (plugin->selZeroAnon,
845 params)) 852 params))
846 { 853 {
847 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 854 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
848 return; 855 return;
849 } 856 }
850 execute_get (plugin, plugin->selZeroAnon, proc, proc_cls); 857 execute_get (plugin, plugin->selZeroAnon, proc, proc_cls);
@@ -912,7 +919,7 @@ sqlite_plugin_get_key (void *cls,
912 GNUNET_SQ_bind (plugin->get, 919 GNUNET_SQ_bind (plugin->get,
913 params)) 920 params))
914 { 921 {
915 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 922 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
916 return; 923 return;
917 } 924 }
918 execute_get (plugin, 925 execute_get (plugin,
@@ -962,6 +969,7 @@ struct ReplCtx
962 * @param type type of the content 969 * @param type type of the content
963 * @param priority priority of the content 970 * @param priority priority of the content
964 * @param anonymity anonymity-level for the content 971 * @param anonymity anonymity-level for the content
972 * @param replication replication-level for the content
965 * @param expiration expiration time for the content 973 * @param expiration expiration time for the content
966 * @param uid unique identifier for the datum; 974 * @param uid unique identifier for the datum;
967 * maybe 0 if no unique identifier is available 975 * maybe 0 if no unique identifier is available
@@ -976,6 +984,7 @@ repl_proc (void *cls,
976 enum GNUNET_BLOCK_Type type, 984 enum GNUNET_BLOCK_Type type,
977 uint32_t priority, 985 uint32_t priority,
978 uint32_t anonymity, 986 uint32_t anonymity,
987 uint32_t replication,
979 struct GNUNET_TIME_Absolute expiration, 988 struct GNUNET_TIME_Absolute expiration,
980 uint64_t uid) 989 uint64_t uid)
981{ 990{
@@ -991,6 +1000,7 @@ repl_proc (void *cls,
991 type, 1000 type,
992 priority, 1001 priority,
993 anonymity, 1002 anonymity,
1003 replication,
994 expiration, 1004 expiration,
995 uid); 1005 uid);
996 if (NULL != key) 1006 if (NULL != key)
@@ -1040,7 +1050,7 @@ sqlite_plugin_get_replication (void *cls,
1040 GNUNET_SQ_reset (plugin->dbh, 1050 GNUNET_SQ_reset (plugin->dbh,
1041 plugin->maxRepl); 1051 plugin->maxRepl);
1042 /* DB empty */ 1052 /* DB empty */
1043 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1053 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1044 return; 1054 return;
1045 } 1055 }
1046 repl = sqlite3_column_int (plugin->maxRepl, 1056 repl = sqlite3_column_int (plugin->maxRepl,
@@ -1053,7 +1063,7 @@ sqlite_plugin_get_replication (void *cls,
1053 GNUNET_SQ_bind (plugin->selRepl, 1063 GNUNET_SQ_bind (plugin->selRepl,
1054 params_sel_repl)) 1064 params_sel_repl))
1055 { 1065 {
1056 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1066 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1057 return; 1067 return;
1058 } 1068 }
1059 rc.have_uid = GNUNET_SYSERR; 1069 rc.have_uid = GNUNET_SYSERR;
@@ -1069,7 +1079,7 @@ sqlite_plugin_get_replication (void *cls,
1069 GNUNET_SQ_bind (plugin->updRepl, 1079 GNUNET_SQ_bind (plugin->updRepl,
1070 params_upd_repl)) 1080 params_upd_repl))
1071 { 1081 {
1072 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1082 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1073 return; 1083 return;
1074 } 1084 }
1075 if (SQLITE_DONE != 1085 if (SQLITE_DONE !=
@@ -1083,7 +1093,7 @@ sqlite_plugin_get_replication (void *cls,
1083 if (GNUNET_SYSERR == rc.have_uid) 1093 if (GNUNET_SYSERR == rc.have_uid)
1084 { 1094 {
1085 /* proc was not called at all so far, do it now. */ 1095 /* proc was not called at all so far, do it now. */
1086 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1096 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1087 } 1097 }
1088} 1098}
1089 1099
@@ -1117,7 +1127,7 @@ sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
1117 GNUNET_SQ_bind (stmt, 1127 GNUNET_SQ_bind (stmt,
1118 params)) 1128 params))
1119 { 1129 {
1120 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 1130 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1121 return; 1131 return;
1122 } 1132 }
1123 execute_get (plugin, stmt, proc, proc_cls); 1133 execute_get (plugin, stmt, proc, proc_cls);