aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_mysql.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amat.us>2017-04-16 20:46:21 -0500
committerDavid Barksdale <amatus@amat.us>2017-04-16 20:49:27 -0500
commita58d36b8da7afa42410bac54f57d5f3b6b6c4391 (patch)
tree87b00f07dda6a5c28a9d65ef9c05044cab2336fd /src/datastore/plugin_datastore_mysql.c
parent4907330f51ffd48af1f7bac6f43c7c7f78c37818 (diff)
downloadgnunet-a58d36b8da7afa42410bac54f57d5f3b6b6c4391.tar.gz
gnunet-a58d36b8da7afa42410bac54f57d5f3b6b6c4391.zip
[datastore] Create remove plugin API call
The only use of vhash in the get_key call was for removing, split that out into its own function. This simplifies the get_key call and removes the need for some indexes, speeding up insertion into the database.
Diffstat (limited to 'src/datastore/plugin_datastore_mysql.c')
-rw-r--r--src/datastore/plugin_datastore_mysql.c209
1 files changed, 104 insertions, 105 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index edc459272..708e35860 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -150,6 +150,12 @@ 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 DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 "\
154 "WHERE hash = ? AND "\
155 "value = ? "\
156 "LIMIT 1"
157 struct GNUNET_MYSQL_StatementHandle *delete_entry_by_hash_value;
158
153#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid" 159#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid"
154 160
155#define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 "\ 161#define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 "\
@@ -159,22 +165,13 @@ struct Plugin
159 struct GNUNET_MYSQL_StatementHandle *select_entry; 165 struct GNUNET_MYSQL_StatementHandle *select_entry;
160 166
161#define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 "\ 167#define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 "\
162 "FORCE INDEX (idx_hash) "\ 168 "FORCE INDEX (idx_hash_type_uid) "\
163 "WHERE hash=? AND "\ 169 "WHERE hash=? AND "\
164 "uid >= ? AND "\ 170 "uid >= ? AND "\
165 "(rvalue >= ? OR 0 = ?) "\ 171 "(rvalue >= ? OR 0 = ?) "\
166 "ORDER BY uid LIMIT 1" 172 "ORDER BY uid LIMIT 1"
167 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash; 173 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash;
168 174
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"
176 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_vhash;
177
178#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 "\ 175#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 "\
179 "FORCE INDEX (idx_hash_type_uid) "\ 176 "FORCE INDEX (idx_hash_type_uid) "\
180 "WHERE hash = ? AND "\ 177 "WHERE hash = ? AND "\
@@ -184,17 +181,6 @@ struct Plugin
184 "ORDER BY uid LIMIT 1" 181 "ORDER BY uid LIMIT 1"
185 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type; 182 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type;
186 183
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"
196 struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_vhash_and_type;
197
198#define UPDATE_ENTRY "UPDATE gn090 SET "\ 184#define UPDATE_ENTRY "UPDATE gn090 SET "\
199 "prio = prio + ?, "\ 185 "prio = prio + ?, "\
200 "repl = repl + ?, "\ 186 "repl = repl + ?, "\
@@ -552,11 +538,6 @@ execute_select (struct Plugin *plugin,
552 * @param next_uid return the result with lowest uid >= next_uid 538 * @param next_uid return the result with lowest uid >= next_uid
553 * @param random if true, return a random result instead of using next_uid 539 * @param random if true, return a random result instead of using next_uid
554 * @param key key to match, never NULL 540 * @param key key to match, never NULL
555 * @param vhash hash of the value, maybe NULL (to
556 * match all values that have the right key).
557 * Note that for DBlocks there is no difference
558 * betwen key and vhash, but for other blocks
559 * there may be!
560 * @param type entries of which type are relevant? 541 * @param type entries of which type are relevant?
561 * Use 0 for any type. 542 * Use 0 for any type.
562 * @param proc function to call on the matching value, 543 * @param proc function to call on the matching value,
@@ -568,7 +549,6 @@ mysql_plugin_get_key (void *cls,
568 uint64_t next_uid, 549 uint64_t next_uid,
569 bool random, 550 bool random,
570 const struct GNUNET_HashCode *key, 551 const struct GNUNET_HashCode *key,
571 const struct GNUNET_HashCode *vhash,
572 enum GNUNET_BLOCK_Type type, 552 enum GNUNET_BLOCK_Type type,
573 PluginDatumProcessor proc, 553 PluginDatumProcessor proc,
574 void *proc_cls) 554 void *proc_cls)
@@ -602,79 +582,37 @@ mysql_plugin_get_key (void *cls,
602 } 582 }
603 else if (type != GNUNET_BLOCK_TYPE_ANY) 583 else if (type != GNUNET_BLOCK_TYPE_ANY)
604 { 584 {
605 if (NULL != vhash) 585 struct GNUNET_MY_QueryParam params_select[] = {
606 { 586 GNUNET_MY_query_param_auto_from_type (key),
607 struct GNUNET_MY_QueryParam params_select[] = { 587 GNUNET_MY_query_param_uint32 (&type),
608 GNUNET_MY_query_param_auto_from_type (key), 588 GNUNET_MY_query_param_uint64 (&next_uid),
609 GNUNET_MY_query_param_auto_from_type (vhash), 589 GNUNET_MY_query_param_uint64 (&rvalue),
610 GNUNET_MY_query_param_uint32 (&type), 590 GNUNET_MY_query_param_uint64 (&rvalue),
611 GNUNET_MY_query_param_uint64 (&next_uid), 591 GNUNET_MY_query_param_end
612 GNUNET_MY_query_param_uint64 (&rvalue), 592 };
613 GNUNET_MY_query_param_uint64 (&rvalue), 593
614 GNUNET_MY_query_param_end 594 execute_select (plugin,
615 }; 595 plugin->select_entry_by_hash_and_type,
616 596 proc,
617 execute_select (plugin, 597 proc_cls,
618 plugin->select_entry_by_hash_vhash_and_type, 598 params_select);
619 proc,
620 proc_cls,
621 params_select);
622 }
623 else
624 {
625 struct GNUNET_MY_QueryParam params_select[] = {
626 GNUNET_MY_query_param_auto_from_type (key),
627 GNUNET_MY_query_param_uint32 (&type),
628 GNUNET_MY_query_param_uint64 (&next_uid),
629 GNUNET_MY_query_param_uint64 (&rvalue),
630 GNUNET_MY_query_param_uint64 (&rvalue),
631 GNUNET_MY_query_param_end
632 };
633
634 execute_select (plugin,
635 plugin->select_entry_by_hash_and_type,
636 proc,
637 proc_cls,
638 params_select);
639 }
640 } 599 }
641 else 600 else
642 { 601 {
643 if (NULL != vhash) 602 struct GNUNET_MY_QueryParam params_select[] = {
644 { 603 GNUNET_MY_query_param_auto_from_type (key),
645 struct GNUNET_MY_QueryParam params_select[] = { 604 GNUNET_MY_query_param_uint64 (&next_uid),
646 GNUNET_MY_query_param_auto_from_type (key), 605 GNUNET_MY_query_param_uint64 (&rvalue),
647 GNUNET_MY_query_param_auto_from_type (vhash), 606 GNUNET_MY_query_param_uint64 (&rvalue),
648 GNUNET_MY_query_param_uint64 (&next_uid), 607 GNUNET_MY_query_param_end
649 GNUNET_MY_query_param_uint64 (&rvalue), 608 };
650 GNUNET_MY_query_param_uint64 (&rvalue),
651 GNUNET_MY_query_param_end
652 };
653
654 execute_select (plugin,
655 plugin->select_entry_by_hash_and_vhash,
656 proc,
657 proc_cls,
658 params_select);
659 }
660 else
661 {
662 struct GNUNET_MY_QueryParam params_select[] = {
663 GNUNET_MY_query_param_auto_from_type (key),
664 GNUNET_MY_query_param_uint64 (&next_uid),
665 GNUNET_MY_query_param_uint64 (&rvalue),
666 GNUNET_MY_query_param_uint64 (&rvalue),
667 GNUNET_MY_query_param_end
668 };
669
670 execute_select (plugin,
671 plugin->select_entry_by_hash,
672 proc,
673 proc_cls,
674 params_select);
675 }
676 }
677 609
610 execute_select (plugin,
611 plugin->select_entry_by_hash,
612 proc,
613 proc_cls,
614 params_select);
615 }
678} 616}
679 617
680 618
@@ -1098,6 +1036,69 @@ mysql_plugin_drop (void *cls)
1098 1036
1099 1037
1100/** 1038/**
1039 * Remove a particular key in the datastore.
1040 *
1041 * @param cls closure
1042 * @param key key for the content
1043 * @param size number of bytes in data
1044 * @param data content stored
1045 * @param cont continuation called with success or failure status
1046 * @param cont_cls continuation closure for @a cont
1047 */
1048static void
1049mysql_plugin_remove_key (void *cls,
1050 const struct GNUNET_HashCode *key,
1051 uint32_t size,
1052 const void *data,
1053 PluginRemoveCont cont,
1054 void *cont_cls)
1055{
1056 struct Plugin *plugin = cls;
1057 struct GNUNET_MY_QueryParam params_delete[] = {
1058 GNUNET_MY_query_param_auto_from_type (key),
1059 GNUNET_MY_query_param_fixed_size (data, size),
1060 GNUNET_MY_query_param_end
1061 };
1062
1063 if (GNUNET_OK !=
1064 GNUNET_MY_exec_prepared (plugin->mc,
1065 plugin->delete_entry_by_hash_value,
1066 params_delete))
1067 {
1068 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1069 "Removing key `%s' from gn090 table failed\n",
1070 GNUNET_h2s (key));
1071 cont (cont_cls,
1072 key,
1073 size,
1074 GNUNET_SYSERR,
1075 _("MySQL statement run failure"));
1076 return;
1077 }
1078
1079 MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->delete_entry_by_hash_value);
1080 my_ulonglong rows = mysql_stmt_affected_rows (stmt);
1081
1082 if (0 == rows)
1083 {
1084 cont (cont_cls,
1085 key,
1086 size,
1087 GNUNET_NO,
1088 NULL);
1089 return;
1090 }
1091 plugin->env->duc (plugin->env->cls,
1092 -size);
1093 cont (cont_cls,
1094 key,
1095 size,
1096 GNUNET_OK,
1097 NULL);
1098}
1099
1100
1101/**
1101 * Entry point for the plugin. 1102 * Entry point for the plugin.
1102 * 1103 *
1103 * @param cls the `struct GNUNET_DATASTORE_PluginEnvironment *` 1104 * @param cls the `struct GNUNET_DATASTORE_PluginEnvironment *`
@@ -1132,24 +1133,20 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1132 " hash BINARY(64) NOT NULL DEFAULT ''," 1133 " hash BINARY(64) NOT NULL DEFAULT '',"
1133 " vhash BINARY(64) NOT NULL DEFAULT ''," 1134 " vhash BINARY(64) NOT NULL DEFAULT '',"
1134 " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT," 1135 " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT,"
1135 " PRIMARY KEY (uid)," " INDEX idx_hash (hash(64))," 1136 " PRIMARY KEY (uid),"
1136 " INDEX idx_hash_uid (hash(64),uid),"
1137 " INDEX idx_hash_vhash (hash(64),vhash(64)),"
1138 " INDEX idx_hash_type_uid (hash(64),type,rvalue)," 1137 " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
1139 " INDEX idx_prio (prio)," " INDEX idx_repl_rvalue (repl,rvalue)," 1138 " INDEX idx_prio (prio),"
1139 " INDEX idx_repl_rvalue (repl,rvalue),"
1140 " INDEX idx_expire (expire)," 1140 " INDEX idx_expire (expire),"
1141 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" 1141 " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
1142 ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") || 1142 ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") ||
1143 PINIT (plugin->insert_entry, INSERT_ENTRY) || 1143 PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1144 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || 1144 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
1145 PINIT (plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) ||
1145 PINIT (plugin->select_entry, SELECT_ENTRY) || 1146 PINIT (plugin->select_entry, SELECT_ENTRY) ||
1146 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || 1147 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
1147 PINIT (plugin->select_entry_by_hash_and_vhash,
1148 SELECT_ENTRY_BY_HASH_AND_VHASH) ||
1149 PINIT (plugin->select_entry_by_hash_and_type, 1148 PINIT (plugin->select_entry_by_hash_and_type,
1150 SELECT_ENTRY_BY_HASH_AND_TYPE) || 1149 SELECT_ENTRY_BY_HASH_AND_TYPE) ||
1151 PINIT (plugin->select_entry_by_hash_vhash_and_type,
1152 SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
1153 PINIT (plugin->get_size, SELECT_SIZE) || 1150 PINIT (plugin->get_size, SELECT_SIZE) ||
1154 PINIT (plugin->update_entry, UPDATE_ENTRY) || 1151 PINIT (plugin->update_entry, UPDATE_ENTRY) ||
1155 PINIT (plugin->dec_repl, DEC_REPL) || 1152 PINIT (plugin->dec_repl, DEC_REPL) ||
@@ -1158,7 +1155,8 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1158 PINIT (plugin->select_priority, SELECT_IT_PRIORITY) || 1155 PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
1159 PINIT (plugin->max_repl, SELECT_MAX_REPL) || 1156 PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
1160 PINIT (plugin->get_all_keys, GET_ALL_KEYS) || 1157 PINIT (plugin->get_all_keys, GET_ALL_KEYS) ||
1161 PINIT (plugin->select_replication, SELECT_IT_REPLICATION)) 1158 PINIT (plugin->select_replication, SELECT_IT_REPLICATION) ||
1159 false)
1162 { 1160 {
1163 GNUNET_MYSQL_context_destroy (plugin->mc); 1161 GNUNET_MYSQL_context_destroy (plugin->mc);
1164 GNUNET_free (plugin); 1162 GNUNET_free (plugin);
@@ -1177,6 +1175,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1177 api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity; 1175 api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity;
1178 api->get_keys = &mysql_plugin_get_keys; 1176 api->get_keys = &mysql_plugin_get_keys;
1179 api->drop = &mysql_plugin_drop; 1177 api->drop = &mysql_plugin_drop;
1178 api->remove_key = &mysql_plugin_remove_key;
1180 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", 1179 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
1181 _("Mysql database running\n")); 1180 _("Mysql database running\n"));
1182 return api; 1181 return api;