aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-08-06 12:13:02 +0000
committerChristian Grothoff <christian@grothoff.org>2010-08-06 12:13:02 +0000
commit18cd28d895f86f6f78107f70c915abd8867198eb (patch)
treeae306bab297c834b8a8e1cc6f90ce93140ad9c40 /src
parent0dd0c280dacaada0ff530d752eff8a7f3a9ccdde (diff)
downloadgnunet-18cd28d895f86f6f78107f70c915abd8867198eb.tar.gz
gnunet-18cd28d895f86f6f78107f70c915abd8867198eb.zip
eliminate size field
Diffstat (limited to 'src')
-rw-r--r--src/datastore/plugin_datastore_mysql.c188
1 files changed, 74 insertions, 114 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 5fc3f6878..dd0e52f40 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -110,7 +110,7 @@
110 * - The tables can be verified/fixed in two ways; 110 * - The tables can be verified/fixed in two ways;
111 * 1) by running mysqlcheck -A, or 111 * 1) by running mysqlcheck -A, or
112 * 2) by executing (inside of mysql using the GNUnet database): 112 * 2) by executing (inside of mysql using the GNUnet database):
113 * mysql> REPAIR TABLE gn080; 113 * mysql> REPAIR TABLE gn090;
114 * mysql> REPAIR TABLE gn072; 114 * mysql> REPAIR TABLE gn072;
115 * 115 *
116 * PROBLEMS? 116 * PROBLEMS?
@@ -121,8 +121,6 @@
121 * to it, create tables, issue queries etc. 121 * to it, create tables, issue queries etc.
122 * 122 *
123 * TODO: 123 * TODO:
124 * - implement GET
125 * - remove 'size' field in gn080.
126 * - use FOREIGN KEY for 'uid/vkey' 124 * - use FOREIGN KEY for 'uid/vkey'
127 * - consistent naming of uid/vkey 125 * - consistent naming of uid/vkey
128 */ 126 */
@@ -162,38 +160,38 @@
162 automatically apply a LIMIT on the outermost clause, so we need to 160 automatically apply a LIMIT on the outermost clause, so we need to
163 repeat ourselves quite a bit. All hail the performance gods (and thanks 161 repeat ourselves quite a bit. All hail the performance gods (and thanks
164 to #mysql on freenode) */ 162 to #mysql on freenode) */
165#define SELECT_IT_LOW_PRIORITY "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(prio) WHERE (prio = ? AND vkey > ?) "\ 163#define SELECT_IT_LOW_PRIORITY "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(prio) WHERE (prio = ? AND vkey > ?) "\
166 "ORDER BY prio ASC,vkey ASC LIMIT 1) "\ 164 "ORDER BY prio ASC,vkey ASC LIMIT 1) " \
167 "UNION "\ 165 "UNION "\
168 "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(prio) WHERE (prio > ? AND vkey != ?)"\ 166 "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(prio) WHERE (prio > ? AND vkey != ?)"\
169 "ORDER BY prio ASC,vkey ASC LIMIT 1)"\ 167 "ORDER BY prio ASC,vkey ASC LIMIT 1)"\
170 "ORDER BY prio ASC,vkey ASC LIMIT 1" 168 "ORDER BY prio ASC,vkey ASC LIMIT 1"
171 169
172#define SELECT_IT_NON_ANONYMOUS "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(prio) WHERE (prio = ? AND vkey < ?)"\ 170#define SELECT_IT_NON_ANONYMOUS "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(prio) WHERE (prio = ? AND vkey < ?)"\
173 " AND anonLevel=0 ORDER BY prio DESC,vkey DESC LIMIT 1) "\ 171 " AND anonLevel=0 ORDER BY prio DESC,vkey DESC LIMIT 1) "\
174 "UNION "\ 172 "UNION "\
175 "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(prio) WHERE (prio < ? AND vkey != ?)"\ 173 "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(prio) WHERE (prio < ? AND vkey != ?)"\
176 " AND anonLevel=0 ORDER BY prio DESC,vkey DESC LIMIT 1) "\ 174 " AND anonLevel=0 ORDER BY prio DESC,vkey DESC LIMIT 1) "\
177 "ORDER BY prio DESC,vkey DESC LIMIT 1" 175 "ORDER BY prio DESC,vkey DESC LIMIT 1"
178 176
179#define SELECT_IT_EXPIRATION_TIME "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(expire) WHERE (expire = ? AND vkey > ?) "\ 177#define SELECT_IT_EXPIRATION_TIME "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(expire) WHERE (expire = ? AND vkey > ?) "\
180 "ORDER BY expire ASC,vkey ASC LIMIT 1) "\ 178 "ORDER BY expire ASC,vkey ASC LIMIT 1) "\
181 "UNION "\ 179 "UNION "\
182 "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(expire) WHERE (expire > ? AND vkey != ?) "\ 180 "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(expire) WHERE (expire > ? AND vkey != ?) "\
183 "ORDER BY expire ASC,vkey ASC LIMIT 1)"\ 181 "ORDER BY expire ASC,vkey ASC LIMIT 1)"\
184 "ORDER BY expire ASC,vkey ASC LIMIT 1" 182 "ORDER BY expire ASC,vkey ASC LIMIT 1"
185 183
186 184
187#define SELECT_IT_MIGRATION_ORDER "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(expire) WHERE (expire = ? AND vkey < ?)"\ 185#define SELECT_IT_MIGRATION_ORDER "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(expire) WHERE (expire = ? AND vkey < ?)"\
188 " AND expire > ? AND type!=3"\ 186 " AND expire > ? AND type!=3"\
189 " ORDER BY expire DESC,vkey DESC LIMIT 1) "\ 187 " ORDER BY expire DESC,vkey DESC LIMIT 1) "\
190 "UNION "\ 188 "UNION "\
191 "(SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX(expire) WHERE (expire < ? AND vkey != ?)"\ 189 "(SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX(expire) WHERE (expire < ? AND vkey != ?)"\
192 " AND expire > ? AND type!=3"\ 190 " AND expire > ? AND type!=3"\
193 " ORDER BY expire DESC,vkey DESC LIMIT 1)"\ 191 " ORDER BY expire DESC,vkey DESC LIMIT 1)"\
194 "ORDER BY expire DESC,vkey DESC LIMIT 1" 192 "ORDER BY expire DESC,vkey DESC LIMIT 1"
195 193
196#define SELECT_SIZE "SELECT sum(size) FROM gn080" 194// #define SELECT_SIZE "SELECT sum(size) FROM gn090"
197 195
198 196
199struct GNUNET_MysqlStatementHandle 197struct GNUNET_MysqlStatementHandle
@@ -247,7 +245,7 @@ struct NextRequestClosure
247 */ 245 */
248 void *prep_cls; 246 void *prep_cls;
249 247
250 MYSQL_BIND rbind[7]; 248 MYSQL_BIND rbind[6];
251 249
252 unsigned int type; 250 unsigned int type;
253 251
@@ -311,45 +309,43 @@ struct Plugin
311 struct GNUNET_MysqlStatementHandle *insert_value; 309 struct GNUNET_MysqlStatementHandle *insert_value;
312 310
313 /** 311 /**
314 * Statements dealing with gn080 table 312 * Statements dealing with gn090 table
315 */ 313 */
316#define INSERT_ENTRY "INSERT INTO gn080 (size,type,prio,anonLevel,expire,hash,vhash,vkey) VALUES (?,?,?,?,?,?,?,?)" 314#define INSERT_ENTRY "INSERT INTO gn090 (type,prio,anonLevel,expire,hash,vhash,vkey) VALUES (?,?,?,?,?,?,?)"
317 struct GNUNET_MysqlStatementHandle *insert_entry; 315 struct GNUNET_MysqlStatementHandle *insert_entry;
318 316
319#define DELETE_ENTRY_BY_VKEY "DELETE FROM gn080 WHERE vkey=?" 317#define DELETE_ENTRY_BY_VKEY "DELETE FROM gn090 WHERE vkey=?"
320 struct GNUNET_MysqlStatementHandle *delete_entry_by_vkey; 318 struct GNUNET_MysqlStatementHandle *delete_entry_by_vkey;
321 319
322#define SELECT_ENTRY_BY_HASH "SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX (hash_vkey) WHERE hash=? AND vkey > ? ORDER BY vkey ASC LIMIT 1 OFFSET ?" 320#define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX (hash_vkey) WHERE hash=? AND vkey > ? ORDER BY vkey ASC LIMIT 1 OFFSET ?"
323 struct GNUNET_MysqlStatementHandle *select_entry_by_hash; 321 struct GNUNET_MysqlStatementHandle *select_entry_by_hash;
324 322
325#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX (hash_vhash_vkey) WHERE hash=? AND vhash=? AND vkey > ? ORDER BY vkey ASC LIMIT 1 OFFSET ?" 323#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX (hash_vhash_vkey) WHERE hash=? AND vhash=? AND vkey > ? ORDER BY vkey ASC LIMIT 1 OFFSET ?"
326 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash; 324 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash;
327 325
328#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX (hash_vkey) WHERE hash=? AND vkey > ? AND type=? ORDER BY vkey ASC LIMIT 1 OFFSET ?" 326#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX (hash_vkey) WHERE hash=? AND vkey > ? AND type=? ORDER BY vkey ASC LIMIT 1 OFFSET ?"
329 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type; 327 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type;
330 328
331#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT size,type,prio,anonLevel,expire,hash,vkey FROM gn080 FORCE INDEX (hash_vhash_vkey) WHERE hash=? AND vhash=? AND vkey > ? AND type=? ORDER BY vkey ASC LIMIT 1 OFFSET ?" 329#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,vkey FROM gn090 FORCE INDEX (hash_vhash_vkey) WHERE hash=? AND vhash=? AND vkey > ? AND type=? ORDER BY vkey ASC LIMIT 1 OFFSET ?"
332 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type; 330 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type;
333 331
334#define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn080 FORCE INDEX (hash) WHERE hash=?" 332#define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn090 FORCE INDEX (hash) WHERE hash=?"
335 struct GNUNET_MysqlStatementHandle *count_entry_by_hash; 333 struct GNUNET_MysqlStatementHandle *count_entry_by_hash;
336 334
337#define COUNT_ENTRY_BY_HASH_AND_VHASH "SELECT count(*) FROM gn080 FORCE INDEX (hash_vhash_vkey) WHERE hash=? AND vhash=?" 335#define COUNT_ENTRY_BY_HASH_AND_VHASH "SELECT count(*) FROM gn090 FORCE INDEX (hash_vhash_vkey) WHERE hash=? AND vhash=?"
338 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_vhash; 336 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_vhash;
339 337
340#define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn080 FORCE INDEX (hash) WHERE hash=? AND type=?" 338#define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (hash) WHERE hash=? AND type=?"
341 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type; 339 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type;
342 340
343#define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn080 FORCE INDEX (hash_vhash) WHERE hash=? AND vhash=? AND type=?" 341#define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (hash_vhash) WHERE hash=? AND vhash=? AND type=?"
344 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type; 342 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type;
345 343
346#define UPDATE_ENTRY "UPDATE gn080 SET prio=prio+?,expire=IF(expire>=?,expire,?) WHERE vkey=?" 344#define UPDATE_ENTRY "UPDATE gn090 SET prio=prio+?,expire=IF(expire>=?,expire,?) WHERE vkey=?"
347 struct GNUNET_MysqlStatementHandle *update_entry; 345 struct GNUNET_MysqlStatementHandle *update_entry;
348 346
349 struct GNUNET_MysqlStatementHandle *iter[4]; 347 struct GNUNET_MysqlStatementHandle *iter[4];
350 348
351 //static unsigned int stat_size;
352
353 /** 349 /**
354 * Size of the mysql database on disk. 350 * Size of the mysql database on disk.
355 */ 351 */
@@ -967,7 +963,7 @@ do_insert_value (struct Plugin *plugin,
967} 963}
968 964
969/** 965/**
970 * Delete an entry from the gn080 table. 966 * Delete an entry from the gn090 table.
971 * 967 *
972 * @param vkey vkey identifying the entry to delete 968 * @param vkey vkey identifying the entry to delete
973 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error 969 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error
@@ -980,7 +976,7 @@ do_delete_entry_by_vkey (struct Plugin *plugin,
980 976
981#if DEBUG_MYSQL 977#if DEBUG_MYSQL
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
983 "Deleting value %llu from gn080 table\n", 979 "Deleting value %llu from gn090 table\n",
984 vkey); 980 vkey);
985#endif 981#endif
986 ret = prepared_statement_run (plugin, 982 ret = prepared_statement_run (plugin,
@@ -995,7 +991,7 @@ do_delete_entry_by_vkey (struct Plugin *plugin,
995 else 991 else
996 { 992 {
997 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 993 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
998 "Deleting value %llu from gn080 table failed\n", 994 "Deleting value %llu from gn090 table failed\n",
999 vkey); 995 vkey);
1000 } 996 }
1001 return ret; 997 return ret;
@@ -1025,7 +1021,7 @@ iterator_helper_prepare (void *cls,
1025 case 1: 1021 case 1:
1026 ret = prepared_statement_run_select (plugin, 1022 ret = prepared_statement_run_select (plugin,
1027 plugin->iter[nrc->iter_select], 1023 plugin->iter[nrc->iter_select],
1028 7, 1024 6,
1029 nrc->rbind, 1025 nrc->rbind,
1030 &return_ok, 1026 &return_ok,
1031 NULL, 1027 NULL,
@@ -1045,7 +1041,7 @@ iterator_helper_prepare (void *cls,
1045 case 2: 1041 case 2:
1046 ret = prepared_statement_run_select (plugin, 1042 ret = prepared_statement_run_select (plugin,
1047 plugin->iter[nrc->iter_select], 1043 plugin->iter[nrc->iter_select],
1048 7, 1044 6,
1049 nrc->rbind, 1045 nrc->rbind,
1050 &return_ok, 1046 &return_ok,
1051 NULL, 1047 NULL,
@@ -1065,7 +1061,7 @@ iterator_helper_prepare (void *cls,
1065 case 3: 1061 case 3:
1066 ret = prepared_statement_run_select (plugin, 1062 ret = prepared_statement_run_select (plugin,
1067 plugin->iter[nrc->iter_select], 1063 plugin->iter[nrc->iter_select],
1068 7, 1064 6,
1069 nrc->rbind, 1065 nrc->rbind,
1070 &return_ok, 1066 &return_ok,
1071 NULL, 1067 NULL,
@@ -1108,7 +1104,6 @@ mysql_next_request_cont (void *next_cls,
1108 struct NextRequestClosure *nrc = next_cls; 1104 struct NextRequestClosure *nrc = next_cls;
1109 struct Plugin *plugin; 1105 struct Plugin *plugin;
1110 int ret; 1106 int ret;
1111 unsigned int size;
1112 unsigned int type; 1107 unsigned int type;
1113 unsigned int priority; 1108 unsigned int priority;
1114 unsigned int anonymity; 1109 unsigned int anonymity;
@@ -1133,74 +1128,52 @@ mysql_next_request_cont (void *next_cls,
1133 memset (nrc->rbind, 0, sizeof (nrc->rbind)); 1128 memset (nrc->rbind, 0, sizeof (nrc->rbind));
1134 rbind = nrc->rbind; 1129 rbind = nrc->rbind;
1135 rbind[0].buffer_type = MYSQL_TYPE_LONG; 1130 rbind[0].buffer_type = MYSQL_TYPE_LONG;
1136 rbind[0].buffer = &size; 1131 rbind[0].buffer = &type;
1137 rbind[0].is_unsigned = 1; 1132 rbind[0].is_unsigned = 1;
1138 rbind[1].buffer_type = MYSQL_TYPE_LONG; 1133 rbind[1].buffer_type = MYSQL_TYPE_LONG;
1139 rbind[1].buffer = &type; 1134 rbind[1].buffer = &priority;
1140 rbind[1].is_unsigned = 1; 1135 rbind[1].is_unsigned = 1;
1141 rbind[2].buffer_type = MYSQL_TYPE_LONG; 1136 rbind[2].buffer_type = MYSQL_TYPE_LONG;
1142 rbind[2].buffer = &priority; 1137 rbind[2].buffer = &anonymity;
1143 rbind[2].is_unsigned = 1; 1138 rbind[2].is_unsigned = 1;
1144 rbind[3].buffer_type = MYSQL_TYPE_LONG; 1139 rbind[3].buffer_type = MYSQL_TYPE_LONGLONG;
1145 rbind[3].buffer = &anonymity; 1140 rbind[3].buffer = &exp;
1146 rbind[3].is_unsigned = 1; 1141 rbind[3].is_unsigned = 1;
1147 rbind[4].buffer_type = MYSQL_TYPE_LONGLONG; 1142 rbind[4].buffer_type = MYSQL_TYPE_BLOB;
1148 rbind[4].buffer = &exp; 1143 rbind[4].buffer = &key;
1149 rbind[4].is_unsigned = 1; 1144 rbind[4].buffer_length = hashSize;
1150 rbind[5].buffer_type = MYSQL_TYPE_BLOB; 1145 rbind[4].length = &hashSize;
1151 rbind[5].buffer = &key; 1146 rbind[5].buffer_type = MYSQL_TYPE_LONGLONG;
1152 rbind[5].buffer_length = hashSize; 1147 rbind[5].buffer = &vkey;
1153 rbind[5].length = &hashSize; 1148 rbind[5].is_unsigned = GNUNET_YES;
1154 rbind[6].buffer_type = MYSQL_TYPE_LONGLONG;
1155 rbind[6].buffer = &vkey;
1156 rbind[6].is_unsigned = GNUNET_YES;
1157 1149
1158 if ( (GNUNET_YES == nrc->end_it) || 1150 if ( (GNUNET_YES == nrc->end_it) ||
1159 (GNUNET_OK != nrc->prep (nrc->prep_cls, 1151 (GNUNET_OK != nrc->prep (nrc->prep_cls,
1160 nrc))) 1152 nrc)))
1161 goto END_SET; 1153 goto END_SET;
1162 GNUNET_assert (nrc->plugin->next_task == GNUNET_SCHEDULER_NO_TASK); 1154 GNUNET_assert (nrc->plugin->next_task == GNUNET_SCHEDULER_NO_TASK);
1163 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1164 {
1165 GNUNET_break (0); /* far too big */
1166 goto END_SET;
1167 }
1168 nrc->last_vkey = vkey; 1155 nrc->last_vkey = vkey;
1169 nrc->last_prio = priority; 1156 nrc->last_prio = priority;
1170 nrc->last_expire = exp; 1157 nrc->last_expire = exp;
1171 if ((rbind[0].buffer_type != MYSQL_TYPE_LONG) || 1158 if ( (rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
1172 (!rbind[0].is_unsigned) || 1159 (hashSize != sizeof (GNUNET_HashCode)) )
1173 (rbind[1].buffer_type != MYSQL_TYPE_LONG) ||
1174 (!rbind[1].is_unsigned) ||
1175 (rbind[2].buffer_type != MYSQL_TYPE_LONG) ||
1176 (!rbind[2].is_unsigned) ||
1177 (rbind[3].buffer_type != MYSQL_TYPE_LONG) ||
1178 (!rbind[3].is_unsigned) ||
1179 (rbind[4].buffer_type != MYSQL_TYPE_LONGLONG) ||
1180 (!rbind[4].is_unsigned) ||
1181 (rbind[5].buffer_type != MYSQL_TYPE_BLOB) ||
1182 (rbind[5].buffer_length != sizeof (GNUNET_HashCode)) ||
1183 (*rbind[5].length != sizeof (GNUNET_HashCode)) ||
1184 (rbind[6].buffer_type != MYSQL_TYPE_LONGLONG) ||
1185 (!rbind[6].is_unsigned))
1186 { 1160 {
1187 GNUNET_break (0); 1161 GNUNET_break (0);
1188 goto END_SET; 1162 goto END_SET;
1189 } 1163 }
1190#if DEBUG_MYSQL 1164#if DEBUG_MYSQL
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1192 "Found value %llu with size %u, prio %u, anon %u, expire %llu selecting from gn080 table\n", 1166 "Found value %llu with prio %u, anon %u, expire %llu selecting from gn090 table\n",
1193 vkey, 1167 vkey,
1194 size,
1195 priority, 1168 priority,
1196 anonymity, 1169 anonymity,
1197 exp); 1170 exp);
1198#endif 1171#endif
1199 /* now do query on gn072 */ 1172 /* now do query on gn072 */
1200 length = size; 1173 length = sizeof (datum);
1201 memset (dbind, 0, sizeof (dbind)); 1174 memset (dbind, 0, sizeof (dbind));
1202 dbind[0].buffer_type = MYSQL_TYPE_BLOB; 1175 dbind[0].buffer_type = MYSQL_TYPE_BLOB;
1203 dbind[0].buffer_length = size; 1176 dbind[0].buffer_length = length;
1204 dbind[0].length = &length; 1177 dbind[0].length = &length;
1205 dbind[0].buffer = datum; 1178 dbind[0].buffer = datum;
1206 ret = prepared_statement_run_select (plugin, 1179 ret = prepared_statement_run_select (plugin,
@@ -1214,29 +1187,22 @@ mysql_next_request_cont (void *next_cls,
1214 GNUNET_break (ret <= 1); /* should only have one rbind! */ 1187 GNUNET_break (ret <= 1); /* should only have one rbind! */
1215 if (ret > 0) 1188 if (ret > 0)
1216 ret = GNUNET_OK; 1189 ret = GNUNET_OK;
1217 if ((ret != GNUNET_OK) || 1190 if (ret != GNUNET_OK)
1218 (dbind[0].buffer_length != size) || (length != size))
1219 { 1191 {
1220 GNUNET_break (ret != 0); /* should have one rbind! */ 1192 GNUNET_break (0);
1221 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1193 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1222 "Failed to obtain %llu from gn072\n", 1194 _("Failed to obtain value %llu from table `%s'\n"),
1223 vkey); 1195 vkey,
1224 GNUNET_break (length == size); /* length should match! */ 1196 "gn072");
1225 GNUNET_break (dbind[0].buffer_length == size); /* length should be internally consistent! */
1226 if (ret != 0)
1227 {
1228 do_delete_value (plugin, vkey);
1229 do_delete_entry_by_vkey (plugin, vkey);
1230 plugin->content_size -= size;
1231 }
1232 goto AGAIN; 1197 goto AGAIN;
1233 } 1198 }
1199 GNUNET_break (length <= sizeof(datum));
1234#if DEBUG_MYSQL 1200#if DEBUG_MYSQL
1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1236 "Calling iterator with value `%s' number %llu of size %u with type %u, priority %u, anonymity %u and expiration %llu\n", 1202 "Calling iterator with value `%s' number %llu of size %u with type %u, priority %u, anonymity %u and expiration %llu\n",
1237 GNUNET_h2s (&key), 1203 GNUNET_h2s (&key),
1238 vkey, 1204 vkey,
1239 size, 1205 length,
1240 type, 1206 type,
1241 priority, 1207 priority,
1242 anonymity, 1208 anonymity,
@@ -1247,7 +1213,7 @@ mysql_next_request_cont (void *next_cls,
1247 ret = nrc->dviter (nrc->dviter_cls, 1213 ret = nrc->dviter (nrc->dviter_cls,
1248 nrc, 1214 nrc,
1249 &key, 1215 &key,
1250 size, 1216 length,
1251 datum, 1217 datum,
1252 type, 1218 type,
1253 priority, 1219 priority,
@@ -1263,7 +1229,7 @@ mysql_next_request_cont (void *next_cls,
1263 { 1229 {
1264 do_delete_value (plugin, vkey); 1230 do_delete_value (plugin, vkey);
1265 do_delete_entry_by_vkey (plugin, vkey); 1231 do_delete_entry_by_vkey (plugin, vkey);
1266 plugin->content_size -= size; 1232 plugin->content_size -= length;
1267 } 1233 }
1268 return; 1234 return;
1269 END_SET: 1235 END_SET:
@@ -1380,18 +1346,17 @@ mysql_plugin_get_size (void *cls)
1380 */ 1346 */
1381static int 1347static int
1382mysql_plugin_put (void *cls, 1348mysql_plugin_put (void *cls,
1383 const GNUNET_HashCode * key, 1349 const GNUNET_HashCode * key,
1384 uint32_t size, 1350 uint32_t size,
1385 const void *data, 1351 const void *data,
1386 enum GNUNET_BLOCK_Type type, 1352 enum GNUNET_BLOCK_Type type,
1387 uint32_t priority, 1353 uint32_t priority,
1388 uint32_t anonymity, 1354 uint32_t anonymity,
1389 struct GNUNET_TIME_Absolute expiration, 1355 struct GNUNET_TIME_Absolute expiration,
1390 char **msg) 1356 char **msg)
1391{ 1357{
1392 struct Plugin *plugin = cls; 1358 struct Plugin *plugin = cls;
1393 unsigned int itype = type; 1359 unsigned int itype = type;
1394 unsigned int isize = size;
1395 unsigned int ipriority = priority; 1360 unsigned int ipriority = priority;
1396 unsigned int ianonymity = anonymity; 1361 unsigned int ianonymity = anonymity;
1397 unsigned long long lexpiration = expiration.value; 1362 unsigned long long lexpiration = expiration.value;
@@ -1416,9 +1381,6 @@ mysql_plugin_put (void *cls,
1416 plugin->insert_entry, 1381 plugin->insert_entry,
1417 NULL, 1382 NULL,
1418 MYSQL_TYPE_LONG, 1383 MYSQL_TYPE_LONG,
1419 &isize,
1420 GNUNET_YES,
1421 MYSQL_TYPE_LONG,
1422 &itype, 1384 &itype,
1423 GNUNET_YES, 1385 GNUNET_YES,
1424 MYSQL_TYPE_LONG, 1386 MYSQL_TYPE_LONG,
@@ -1446,10 +1408,10 @@ mysql_plugin_put (void *cls,
1446 } 1408 }
1447#if DEBUG_MYSQL 1409#if DEBUG_MYSQL
1448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1449 "Inserted value `%s' number %llu with size %u into gn080 table\n", 1411 "Inserted value `%s' number %llu with size %u into gn090 table\n",
1450 GNUNET_h2s (key), 1412 GNUNET_h2s (key),
1451 vkey, 1413 vkey,
1452 isize); 1414 (unsigned int) size);
1453#endif 1415#endif
1454 plugin->content_size += size; 1416 plugin->content_size += size;
1455 return GNUNET_OK; 1417 return GNUNET_OK;
@@ -1492,7 +1454,6 @@ struct GetContext
1492 int off; 1454 int off;
1493 int count; 1455 int count;
1494 int have_vhash; 1456 int have_vhash;
1495 unsigned long size; /* OBSOLETE! */
1496}; 1457};
1497 1458
1498 1459
@@ -1537,7 +1498,7 @@ get_statement_prepare (void *cls,
1537 ret = 1498 ret =
1538 prepared_statement_run_select 1499 prepared_statement_run_select
1539 (plugin, 1500 (plugin,
1540 plugin->select_entry_by_hash_vhash_and_type, 7, nrc->rbind, &return_ok, 1501 plugin->select_entry_by_hash_vhash_and_type, 6, nrc->rbind, &return_ok,
1541 NULL, MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize, 1502 NULL, MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize,
1542 MYSQL_TYPE_BLOB, &gc->vhash, hashSize, &hashSize, 1503 MYSQL_TYPE_BLOB, &gc->vhash, hashSize, &hashSize,
1543 MYSQL_TYPE_LONGLONG, &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG, 1504 MYSQL_TYPE_LONGLONG, &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG,
@@ -1549,7 +1510,7 @@ get_statement_prepare (void *cls,
1549 ret = 1510 ret =
1550 prepared_statement_run_select 1511 prepared_statement_run_select
1551 (plugin, 1512 (plugin,
1552 plugin->select_entry_by_hash_and_type, 7, nrc->rbind, &return_ok, NULL, 1513 plugin->select_entry_by_hash_and_type, 6, nrc->rbind, &return_ok, NULL,
1553 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize, 1514 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize,
1554 MYSQL_TYPE_LONGLONG, &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG, 1515 MYSQL_TYPE_LONGLONG, &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG,
1555 &nrc->type, GNUNET_YES, MYSQL_TYPE_LONG, &limit_off, GNUNET_YES, 1516 &nrc->type, GNUNET_YES, MYSQL_TYPE_LONG, &limit_off, GNUNET_YES,
@@ -1563,7 +1524,7 @@ get_statement_prepare (void *cls,
1563 ret = 1524 ret =
1564 prepared_statement_run_select 1525 prepared_statement_run_select
1565 (plugin, 1526 (plugin,
1566 plugin->select_entry_by_hash_and_vhash, 7, nrc->rbind, &return_ok, NULL, 1527 plugin->select_entry_by_hash_and_vhash, 6, nrc->rbind, &return_ok, NULL,
1567 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize, MYSQL_TYPE_BLOB, 1528 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize, MYSQL_TYPE_BLOB,
1568 &gc->vhash, hashSize, &hashSize, MYSQL_TYPE_LONGLONG, 1529 &gc->vhash, hashSize, &hashSize, MYSQL_TYPE_LONGLONG,
1569 &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG, &limit_off, 1530 &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG, &limit_off,
@@ -1574,7 +1535,7 @@ get_statement_prepare (void *cls,
1574 ret = 1535 ret =
1575 prepared_statement_run_select 1536 prepared_statement_run_select
1576 (plugin, 1537 (plugin,
1577 plugin->select_entry_by_hash, 7, nrc->rbind, &return_ok, NULL, 1538 plugin->select_entry_by_hash, 6, nrc->rbind, &return_ok, NULL,
1578 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize, 1539 MYSQL_TYPE_BLOB, &gc->key, hashSize, &hashSize,
1579 MYSQL_TYPE_LONGLONG, &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG, 1540 MYSQL_TYPE_LONGLONG, &nrc->last_vkey, GNUNET_YES, MYSQL_TYPE_LONG,
1580 &limit_off, GNUNET_YES, -1); 1541 &limit_off, GNUNET_YES, -1);
@@ -1880,7 +1841,7 @@ mysql_plugin_drop (void *cls)
1880 struct Plugin *plugin = cls; 1841 struct Plugin *plugin = cls;
1881 1842
1882 if ((GNUNET_OK != run_statement (plugin, 1843 if ((GNUNET_OK != run_statement (plugin,
1883 "DROP TABLE gn080")) || 1844 "DROP TABLE gn090")) ||
1884 (GNUNET_OK != run_statement (plugin, 1845 (GNUNET_OK != run_statement (plugin,
1885 "DROP TABLE gn072"))) 1846 "DROP TABLE gn072")))
1886 return; /* error */ 1847 return; /* error */
@@ -1913,8 +1874,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1913 } 1874 }
1914#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) 1875#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
1915#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) 1876#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
1916 if (MRUNS ("CREATE TABLE IF NOT EXISTS gn080 (" 1877 if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 ("
1917 " size INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1918 " type INT(11) UNSIGNED NOT NULL DEFAULT 0," 1878 " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1919 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0," 1879 " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
1920 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0," 1880 " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"