aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_sqlite.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/plugin_datastore_sqlite.c')
-rw-r--r--src/datastore/plugin_datastore_sqlite.c429
1 files changed, 188 insertions, 241 deletions
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 075d31623..46486d933 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -144,12 +144,12 @@ sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt)
144 char *dummy; 144 char *dummy;
145 int result; 145 int result;
146 146
147 result = sqlite3_prepare_v2 (dbh, 147 result =
148 zSql, 148 sqlite3_prepare_v2 (dbh, zSql, strlen (zSql), ppStmt,
149 strlen (zSql), ppStmt, (const char **) &dummy); 149 (const char **) &dummy);
150#if DEBUG_SQLITE && 0 150#if DEBUG_SQLITE && 0
151 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
152 "sqlite", "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result); 152 "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result);
153#endif 153#endif
154 return result; 154 return result;
155} 155}
@@ -165,8 +165,7 @@ create_indices (sqlite3 * dbh)
165{ 165{
166 /* create indices */ 166 /* create indices */
167 if ((SQLITE_OK != 167 if ((SQLITE_OK !=
168 sqlite3_exec (dbh, 168 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)",
169 "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)",
170 NULL, NULL, NULL)) || 169 NULL, NULL, NULL)) ||
171 (SQLITE_OK != 170 (SQLITE_OK !=
172 sqlite3_exec (dbh, 171 sqlite3_exec (dbh,
@@ -232,12 +231,10 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
232#endif 231#endif
233 232
234 if (GNUNET_OK != 233 if (GNUNET_OK !=
235 GNUNET_CONFIGURATION_get_value_filename (cfg, 234 GNUNET_CONFIGURATION_get_value_filename (cfg, "datastore-sqlite",
236 "datastore-sqlite",
237 "FILENAME", &afsdir)) 235 "FILENAME", &afsdir))
238 { 236 {
239 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 237 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
240 "sqlite",
241 _ 238 _
242 ("Option `%s' in section `%s' missing in configuration!\n"), 239 ("Option `%s' in section `%s' missing in configuration!\n"),
243 "FILENAME", "datastore-sqlite"); 240 "FILENAME", "datastore-sqlite");
@@ -255,8 +252,8 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
255 plugin->env->duc (plugin->env->cls, 0); 252 plugin->env->duc (plugin->env->cls, 0);
256 } 253 }
257#ifdef ENABLE_NLS 254#ifdef ENABLE_NLS
258 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), 255 plugin->fn =
259 nl_langinfo (CODESET)); 256 GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), nl_langinfo (CODESET));
260#else 257#else
261 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */ 258 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir), "UTF-8"); /* good luck */
262#endif 259#endif
@@ -265,33 +262,32 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
265 /* Open database and precompile statements */ 262 /* Open database and precompile statements */
266 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK) 263 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
267 { 264 {
268 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 265 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "sqlite",
269 "sqlite",
270 _("Unable to initialize SQLite: %s.\n"), 266 _("Unable to initialize SQLite: %s.\n"),
271 sqlite3_errmsg (plugin->dbh)); 267 sqlite3_errmsg (plugin->dbh));
272 return GNUNET_SYSERR; 268 return GNUNET_SYSERR;
273 } 269 }
274 CHECK (SQLITE_OK == 270 CHECK (SQLITE_OK ==
275 sqlite3_exec (plugin->dbh, 271 sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL,
276 "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); 272 ENULL));
277 CHECK (SQLITE_OK == 273 CHECK (SQLITE_OK ==
278 sqlite3_exec (plugin->dbh, 274 sqlite3_exec (plugin->dbh, "PRAGMA synchronous=OFF", NULL, NULL,
279 "PRAGMA synchronous=OFF", NULL, NULL, ENULL)); 275 ENULL));
280 CHECK (SQLITE_OK == 276 CHECK (SQLITE_OK ==
281 sqlite3_exec (plugin->dbh, 277 sqlite3_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF", NULL, NULL,
282 "PRAGMA legacy_file_format=OFF", NULL, NULL, ENULL)); 278 ENULL));
283 CHECK (SQLITE_OK == 279 CHECK (SQLITE_OK ==
284 sqlite3_exec (plugin->dbh, 280 sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL,
285 "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL)); 281 NULL, ENULL));
286 CHECK (SQLITE_OK == 282 CHECK (SQLITE_OK ==
287 sqlite3_exec (plugin->dbh, 283 sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
288 "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, ENULL)); 284 ENULL));
289 CHECK (SQLITE_OK == 285 CHECK (SQLITE_OK ==
290 sqlite3_exec (plugin->dbh, 286 sqlite3_exec (plugin->dbh, "PRAGMA count_changes=OFF", NULL, NULL,
291 "PRAGMA count_changes=OFF", NULL, NULL, ENULL)); 287 ENULL));
292 CHECK (SQLITE_OK == 288 CHECK (SQLITE_OK ==
293 sqlite3_exec (plugin->dbh, 289 sqlite3_exec (plugin->dbh, "PRAGMA page_size=4092", NULL, NULL,
294 "PRAGMA page_size=4092", NULL, NULL, ENULL)); 290 ENULL));
295 291
296 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); 292 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
297 293
@@ -302,18 +298,14 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
302 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'", 298 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn090'",
303 &stmt)); 299 &stmt));
304 if ((sqlite3_step (stmt) == SQLITE_DONE) && 300 if ((sqlite3_step (stmt) == SQLITE_DONE) &&
305 (sqlite3_exec (plugin->dbh, 301 (sqlite3_exec
306 "CREATE TABLE gn090 (" 302 (plugin->dbh,
307 " repl INT4 NOT NULL DEFAULT 0," 303 "CREATE TABLE gn090 (" " repl INT4 NOT NULL DEFAULT 0,"
308 " type INT4 NOT NULL DEFAULT 0," 304 " type INT4 NOT NULL DEFAULT 0," " prio INT4 NOT NULL DEFAULT 0,"
309 " prio INT4 NOT NULL DEFAULT 0," 305 " anonLevel INT4 NOT NULL DEFAULT 0,"
310 " anonLevel INT4 NOT NULL DEFAULT 0," 306 " expire INT8 NOT NULL DEFAULT 0," " rvalue INT8 NOT NULL,"
311 " expire INT8 NOT NULL DEFAULT 0," 307 " hash TEXT NOT NULL DEFAULT ''," " vhash TEXT NOT NULL DEFAULT '',"
312 " rvalue INT8 NOT NULL," 308 " value BLOB NOT NULL DEFAULT '')", NULL, NULL, NULL) != SQLITE_OK))
313 " hash TEXT NOT NULL DEFAULT '',"
314 " vhash TEXT NOT NULL DEFAULT '',"
315 " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
316 NULL) != SQLITE_OK))
317 { 309 {
318 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); 310 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
319 sqlite3_finalize (stmt); 311 sqlite3_finalize (stmt);
@@ -322,47 +314,49 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
322 sqlite3_finalize (stmt); 314 sqlite3_finalize (stmt);
323 create_indices (plugin->dbh); 315 create_indices (plugin->dbh);
324 316
325 if ((sq_prepare (plugin->dbh, 317 if ((sq_prepare
326 "UPDATE gn090 " 318 (plugin->dbh,
327 "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?", 319 "UPDATE gn090 "
328 &plugin->updPrio) != SQLITE_OK) || 320 "SET prio = prio + ?, expire = MAX(expire,?) WHERE _ROWID_ = ?",
329 (sq_prepare (plugin->dbh, 321 &plugin->updPrio) != SQLITE_OK) ||
330 "UPDATE gn090 " 322 (sq_prepare
331 "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?", 323 (plugin->dbh,
332 &plugin->updRepl) != SQLITE_OK) || 324 "UPDATE gn090 " "SET repl = MAX (0, repl - 1) WHERE _ROWID_ = ?",
333 (sq_prepare (plugin->dbh, 325 &plugin->updRepl) != SQLITE_OK) ||
334 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 326 (sq_prepare
335 "FROM gn090 INDEXED BY idx_repl_rvalue " 327 (plugin->dbh,
336 "WHERE repl=?2 AND" 328 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
337 " (rvalue>=?1 OR" 329 "FROM gn090 INDEXED BY idx_repl_rvalue " "WHERE repl=?2 AND"
338 " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))" 330 " (rvalue>=?1 OR"
339 " ORDER BY rvalue ASC" 331 " NOT EXISTS (SELECT 1 FROM gn090 INDEXED BY idx_repl_rvalue WHERE repl=?2 AND rvalue>=?1 LIMIT 1))"
340 " LIMIT 1", 332 " ORDER BY rvalue ASC" " LIMIT 1",
341 &plugin->selRepl) != SQLITE_OK) || 333 &plugin->selRepl) != SQLITE_OK) ||
342 (sq_prepare (plugin->dbh, 334 (sq_prepare
343 "SELECT MAX(repl) " 335 (plugin->dbh,
344 "FROM gn090 INDEXED BY idx_repl_rvalue", 336 "SELECT MAX(repl) " "FROM gn090 INDEXED BY idx_repl_rvalue",
345 &plugin->maxRepl) != SQLITE_OK) || 337 &plugin->maxRepl) != SQLITE_OK) ||
346 (sq_prepare (plugin->dbh, 338 (sq_prepare
347 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 339 (plugin->dbh,
348 "FROM gn090 INDEXED BY idx_expire" 340 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
349 " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " 341 "FROM gn090 INDEXED BY idx_expire"
350 " ORDER BY expire ASC LIMIT 1", 342 " WHERE NOT EXISTS (SELECT 1 FROM gn090 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) "
351 &plugin->selExpi) != SQLITE_OK) || 343 " ORDER BY expire ASC LIMIT 1", &plugin->selExpi) != SQLITE_OK) ||
352 (sq_prepare (plugin->dbh, 344 (sq_prepare
353 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ " 345 (plugin->dbh,
354 "FROM gn090 INDEXED BY idx_anon_type_hash " 346 "SELECT type,prio,anonLevel,expire,hash,value,_ROWID_ "
355 "WHERE (anonLevel = 0 AND type=?1) " 347 "FROM gn090 INDEXED BY idx_anon_type_hash "
356 "ORDER BY hash DESC LIMIT 1 OFFSET ?2", 348 "WHERE (anonLevel = 0 AND type=?1) "
357 &plugin->selZeroAnon) != SQLITE_OK) || 349 "ORDER BY hash DESC LIMIT 1 OFFSET ?2",
358 (sq_prepare (plugin->dbh, 350 &plugin->selZeroAnon) != SQLITE_OK) ||
359 "INSERT INTO gn090 (repl, type, prio, " 351 (sq_prepare
360 "anonLevel, expire, rvalue, hash, vhash, value) " 352 (plugin->dbh,
361 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", 353 "INSERT INTO gn090 (repl, type, prio, "
362 &plugin->insertContent) != SQLITE_OK) || 354 "anonLevel, expire, rvalue, hash, vhash, value) "
363 (sq_prepare (plugin->dbh, 355 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
364 "DELETE FROM gn090 WHERE _ROWID_ = ?", 356 &plugin->insertContent) != SQLITE_OK) ||
365 &plugin->delRow) != SQLITE_OK)) 357 (sq_prepare
358 (plugin->dbh, "DELETE FROM gn090 WHERE _ROWID_ = ?",
359 &plugin->delRow) != SQLITE_OK))
366 { 360 {
367 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling"); 361 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR, "precompiling");
368 return GNUNET_SYSERR; 362 return GNUNET_SYSERR;
@@ -406,22 +400,20 @@ database_shutdown (struct Plugin *plugin)
406#if SQLITE_VERSION_NUMBER >= 3007000 400#if SQLITE_VERSION_NUMBER >= 3007000
407 if (result == SQLITE_BUSY) 401 if (result == SQLITE_BUSY)
408 { 402 {
409 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 403 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite",
410 "sqlite",
411 _ 404 _
412 ("Tried to close sqlite without finalizing all prepared statements.\n")); 405 ("Tried to close sqlite without finalizing all prepared statements.\n"));
413 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 406 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
414 while (stmt != NULL) 407 while (stmt != NULL)
415 { 408 {
416#if DEBUG_SQLITE 409#if DEBUG_SQLITE
417 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
418 "sqlite", "Closing statement %p\n", stmt); 411 "Closing statement %p\n", stmt);
419#endif 412#endif
420 result = sqlite3_finalize (stmt); 413 result = sqlite3_finalize (stmt);
421#if DEBUG_SQLITE 414#if DEBUG_SQLITE
422 if (result != SQLITE_OK) 415 if (result != SQLITE_OK)
423 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
424 "sqlite",
425 "Failed to close statement %p: %d\n", stmt, result); 417 "Failed to close statement %p: %d\n", stmt, result);
426#endif 418#endif
427 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 419 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
@@ -448,8 +440,7 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
448{ 440{
449 if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid)) 441 if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid))
450 { 442 {
451 LOG_SQLITE (plugin, NULL, 443 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
452 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
453 "sqlite3_bind_XXXX"); 444 "sqlite3_bind_XXXX");
454 if (SQLITE_OK != sqlite3_reset (plugin->delRow)) 445 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
455 LOG_SQLITE (plugin, NULL, 446 LOG_SQLITE (plugin, NULL,
@@ -459,19 +450,17 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
459 } 450 }
460 if (SQLITE_DONE != sqlite3_step (plugin->delRow)) 451 if (SQLITE_DONE != sqlite3_step (plugin->delRow))
461 { 452 {
462 LOG_SQLITE (plugin, NULL, 453 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
463 GNUNET_ERROR_TYPE_ERROR | 454 "sqlite3_step");
464 GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
465 if (SQLITE_OK != sqlite3_reset (plugin->delRow)) 455 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
466 LOG_SQLITE (plugin, NULL, 456 LOG_SQLITE (plugin, NULL,
467 GNUNET_ERROR_TYPE_ERROR | 457 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
468 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 458 "sqlite3_reset");
469 return GNUNET_SYSERR; 459 return GNUNET_SYSERR;
470 } 460 }
471 if (SQLITE_OK != sqlite3_reset (plugin->delRow)) 461 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
472 LOG_SQLITE (plugin, NULL, 462 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
473 GNUNET_ERROR_TYPE_ERROR | 463 "sqlite3_reset");
474 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
475 return GNUNET_OK; 464 return GNUNET_OK;
476} 465}
477 466
@@ -492,14 +481,9 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid)
492 * @return GNUNET_OK on success 481 * @return GNUNET_OK on success
493 */ 482 */
494static int 483static int
495sqlite_plugin_put (void *cls, 484sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, uint32_t size,
496 const GNUNET_HashCode * key, 485 const void *data, enum GNUNET_BLOCK_Type type,
497 uint32_t size, 486 uint32_t priority, uint32_t anonymity, uint32_t replication,
498 const void *data,
499 enum GNUNET_BLOCK_Type type,
500 uint32_t priority,
501 uint32_t anonymity,
502 uint32_t replication,
503 struct GNUNET_TIME_Absolute expiration, char **msg) 487 struct GNUNET_TIME_Absolute expiration, char **msg)
504{ 488{
505 struct Plugin *plugin = cls; 489 struct Plugin *plugin = cls;
@@ -512,12 +496,9 @@ sqlite_plugin_put (void *cls,
512 if (size > MAX_ITEM_SIZE) 496 if (size > MAX_ITEM_SIZE)
513 return GNUNET_SYSERR; 497 return GNUNET_SYSERR;
514#if DEBUG_SQLITE 498#if DEBUG_SQLITE
515 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 499 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
516 "sqlite",
517 "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n", 500 "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n",
518 type, 501 type, GNUNET_h2s (key), priority,
519 GNUNET_h2s (key),
520 priority,
521 (unsigned long long) 502 (unsigned long long)
522 GNUNET_TIME_absolute_get_remaining (expiration).rel_value, 503 GNUNET_TIME_absolute_get_remaining (expiration).rel_value,
523 (long long) expiration.abs_value); 504 (long long) expiration.abs_value);
@@ -536,13 +517,10 @@ sqlite_plugin_put (void *cls,
536 SQLITE_TRANSIENT)) || 517 SQLITE_TRANSIENT)) ||
537 (SQLITE_OK != 518 (SQLITE_OK !=
538 sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode), 519 sqlite3_bind_blob (stmt, 8, &vhash, sizeof (GNUNET_HashCode),
539 SQLITE_TRANSIENT)) 520 SQLITE_TRANSIENT)) ||
540 || (SQLITE_OK != 521 (SQLITE_OK != sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT)))
541 sqlite3_bind_blob (stmt, 9, data, size, SQLITE_TRANSIENT)))
542 { 522 {
543 LOG_SQLITE (plugin, 523 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
544 msg,
545 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
546 "sqlite3_bind_XXXX"); 524 "sqlite3_bind_XXXX");
547 if (SQLITE_OK != sqlite3_reset (stmt)) 525 if (SQLITE_OK != sqlite3_reset (stmt))
548 LOG_SQLITE (plugin, NULL, 526 LOG_SQLITE (plugin, NULL,
@@ -556,8 +534,7 @@ sqlite_plugin_put (void *cls,
556 case SQLITE_DONE: 534 case SQLITE_DONE:
557 plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 535 plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
558#if DEBUG_SQLITE 536#if DEBUG_SQLITE
559 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 537 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
560 "sqlite",
561 "Stored new entry (%u bytes)\n", 538 "Stored new entry (%u bytes)\n",
562 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 539 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
563#endif 540#endif
@@ -565,27 +542,24 @@ sqlite_plugin_put (void *cls,
565 break; 542 break;
566 case SQLITE_BUSY: 543 case SQLITE_BUSY:
567 GNUNET_break (0); 544 GNUNET_break (0);
568 LOG_SQLITE (plugin, msg, 545 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
569 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
570 "sqlite3_step"); 546 "sqlite3_step");
571 ret = GNUNET_SYSERR; 547 ret = GNUNET_SYSERR;
572 break; 548 break;
573 default: 549 default:
574 LOG_SQLITE (plugin, msg, 550 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
575 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
576 "sqlite3_step"); 551 "sqlite3_step");
577 if (SQLITE_OK != sqlite3_reset (stmt)) 552 if (SQLITE_OK != sqlite3_reset (stmt))
578 LOG_SQLITE (plugin, NULL, 553 LOG_SQLITE (plugin, NULL,
579 GNUNET_ERROR_TYPE_ERROR | 554 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
580 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 555 "sqlite3_reset");
581 database_shutdown (plugin); 556 database_shutdown (plugin);
582 database_setup (plugin->env->cfg, plugin); 557 database_setup (plugin->env->cfg, plugin);
583 return GNUNET_SYSERR; 558 return GNUNET_SYSERR;
584 } 559 }
585 if (SQLITE_OK != sqlite3_reset (stmt)) 560 if (SQLITE_OK != sqlite3_reset (stmt))
586 LOG_SQLITE (plugin, NULL, 561 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
587 GNUNET_ERROR_TYPE_ERROR | 562 "sqlite3_reset");
588 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
589 return ret; 563 return ret;
590} 564}
591 565
@@ -614,21 +588,17 @@ sqlite_plugin_put (void *cls,
614 * @return GNUNET_OK on success 588 * @return GNUNET_OK on success
615 */ 589 */
616static int 590static int
617sqlite_plugin_update (void *cls, 591sqlite_plugin_update (void *cls, uint64_t uid, int delta,
618 uint64_t uid, 592 struct GNUNET_TIME_Absolute expire, char **msg)
619 int delta, struct GNUNET_TIME_Absolute expire, char **msg)
620{ 593{
621 struct Plugin *plugin = cls; 594 struct Plugin *plugin = cls;
622 int n; 595 int n;
623 596
624 if ((SQLITE_OK != 597 if ((SQLITE_OK != sqlite3_bind_int (plugin->updPrio, 1, delta)) ||
625 sqlite3_bind_int (plugin->updPrio, 1, delta)) || 598 (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value))
626 (SQLITE_OK != 599 || (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid)))
627 sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value)) ||
628 (SQLITE_OK != sqlite3_bind_int64 (plugin->updPrio, 3, uid)))
629 { 600 {
630 LOG_SQLITE (plugin, msg, 601 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
631 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
632 "sqlite3_bind_XXXX"); 602 "sqlite3_bind_XXXX");
633 if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) 603 if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
634 LOG_SQLITE (plugin, NULL, 604 LOG_SQLITE (plugin, NULL,
@@ -639,8 +609,7 @@ sqlite_plugin_update (void *cls,
639 } 609 }
640 n = sqlite3_step (plugin->updPrio); 610 n = sqlite3_step (plugin->updPrio);
641 if (SQLITE_OK != sqlite3_reset (plugin->updPrio)) 611 if (SQLITE_OK != sqlite3_reset (plugin->updPrio))
642 LOG_SQLITE (plugin, NULL, 612 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
643 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
644 "sqlite3_reset"); 613 "sqlite3_reset");
645 switch (n) 614 switch (n)
646 { 615 {
@@ -650,13 +619,11 @@ sqlite_plugin_update (void *cls,
650#endif 619#endif
651 return GNUNET_OK; 620 return GNUNET_OK;
652 case SQLITE_BUSY: 621 case SQLITE_BUSY:
653 LOG_SQLITE (plugin, msg, 622 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
654 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
655 "sqlite3_step"); 623 "sqlite3_step");
656 return GNUNET_NO; 624 return GNUNET_NO;
657 default: 625 default:
658 LOG_SQLITE (plugin, msg, 626 LOG_SQLITE (plugin, msg, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
659 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
660 "sqlite3_step"); 627 "sqlite3_step");
661 return GNUNET_SYSERR; 628 return GNUNET_SYSERR;
662 } 629 }
@@ -673,8 +640,8 @@ sqlite_plugin_update (void *cls,
673 * @param proc_cls closure for 'proc' 640 * @param proc_cls closure for 'proc'
674 */ 641 */
675static void 642static void
676execute_get (struct Plugin *plugin, 643execute_get (struct Plugin *plugin, sqlite3_stmt * stmt,
677 sqlite3_stmt * stmt, PluginDatumProcessor proc, void *proc_cls) 644 PluginDatumProcessor proc, void *proc_cls)
678{ 645{
679 int n; 646 int n;
680 struct GNUNET_TIME_Absolute expiration; 647 struct GNUNET_TIME_Absolute expiration;
@@ -690,14 +657,13 @@ execute_get (struct Plugin *plugin,
690 rowid = sqlite3_column_int64 (stmt, 6); 657 rowid = sqlite3_column_int64 (stmt, 6);
691 if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode)) 658 if (sqlite3_column_bytes (stmt, 4) != sizeof (GNUNET_HashCode))
692 { 659 {
693 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 660 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite",
694 "sqlite",
695 _ 661 _
696 ("Invalid data in database. Trying to fix (by deletion).\n")); 662 ("Invalid data in database. Trying to fix (by deletion).\n"));
697 if (SQLITE_OK != sqlite3_reset (stmt)) 663 if (SQLITE_OK != sqlite3_reset (stmt))
698 LOG_SQLITE (plugin, NULL, 664 LOG_SQLITE (plugin, NULL,
699 GNUNET_ERROR_TYPE_ERROR | 665 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
700 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 666 "sqlite3_reset");
701 if (GNUNET_OK == delete_by_rowid (plugin, rowid)) 667 if (GNUNET_OK == delete_by_rowid (plugin, rowid))
702 plugin->env->duc (plugin->env->cls, 668 plugin->env->duc (plugin->env->cls,
703 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 669 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
@@ -705,8 +671,7 @@ execute_get (struct Plugin *plugin,
705 } 671 }
706 expiration.abs_value = sqlite3_column_int64 (stmt, 3); 672 expiration.abs_value = sqlite3_column_int64 (stmt, 3);
707#if DEBUG_SQLITE 673#if DEBUG_SQLITE
708 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 674 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
709 "sqlite",
710 "Found reply in database with expiration %llu\n", 675 "Found reply in database with expiration %llu\n",
711 (unsigned long long) expiration.abs_value); 676 (unsigned long long) expiration.abs_value);
712#endif 677#endif
@@ -718,8 +683,8 @@ execute_get (struct Plugin *plugin,
718 expiration, rowid); 683 expiration, rowid);
719 if (SQLITE_OK != sqlite3_reset (stmt)) 684 if (SQLITE_OK != sqlite3_reset (stmt))
720 LOG_SQLITE (plugin, NULL, 685 LOG_SQLITE (plugin, NULL,
721 GNUNET_ERROR_TYPE_ERROR | 686 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
722 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 687 "sqlite3_reset");
723 if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid))) 688 if ((GNUNET_NO == ret) && (GNUNET_OK == delete_by_rowid (plugin, rowid)))
724 plugin->env->duc (plugin->env->cls, 689 plugin->env->duc (plugin->env->cls,
725 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 690 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
@@ -728,29 +693,27 @@ execute_get (struct Plugin *plugin,
728 /* database must be empty */ 693 /* database must be empty */
729 if (SQLITE_OK != sqlite3_reset (stmt)) 694 if (SQLITE_OK != sqlite3_reset (stmt))
730 LOG_SQLITE (plugin, NULL, 695 LOG_SQLITE (plugin, NULL,
731 GNUNET_ERROR_TYPE_ERROR | 696 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
732 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 697 "sqlite3_reset");
733 break; 698 break;
734 case SQLITE_BUSY: 699 case SQLITE_BUSY:
735 case SQLITE_ERROR: 700 case SQLITE_ERROR:
736 case SQLITE_MISUSE: 701 case SQLITE_MISUSE:
737 default: 702 default:
738 LOG_SQLITE (plugin, NULL, 703 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
739 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
740 "sqlite3_step"); 704 "sqlite3_step");
741 if (SQLITE_OK != sqlite3_reset (stmt)) 705 if (SQLITE_OK != sqlite3_reset (stmt))
742 LOG_SQLITE (plugin, NULL, 706 LOG_SQLITE (plugin, NULL,
743 GNUNET_ERROR_TYPE_ERROR | 707 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
744 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 708 "sqlite3_reset");
745 GNUNET_break (0); 709 GNUNET_break (0);
746 database_shutdown (plugin); 710 database_shutdown (plugin);
747 database_setup (plugin->env->cfg, plugin); 711 database_setup (plugin->env->cfg, plugin);
748 break; 712 break;
749 } 713 }
750 if (SQLITE_OK != sqlite3_reset (stmt)) 714 if (SQLITE_OK != sqlite3_reset (stmt))
751 LOG_SQLITE (plugin, NULL, 715 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
752 GNUNET_ERROR_TYPE_ERROR | 716 "sqlite3_reset");
753 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
754 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 717 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
755} 718}
756 719
@@ -770,8 +733,7 @@ execute_get (struct Plugin *plugin,
770 * @param proc_cls closure for proc 733 * @param proc_cls closure for proc
771 */ 734 */
772static void 735static void
773sqlite_plugin_get_zero_anonymity (void *cls, 736sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset,
774 uint64_t offset,
775 enum GNUNET_BLOCK_Type type, 737 enum GNUNET_BLOCK_Type type,
776 PluginDatumProcessor proc, void *proc_cls) 738 PluginDatumProcessor proc, void *proc_cls)
777{ 739{
@@ -783,13 +745,12 @@ sqlite_plugin_get_zero_anonymity (void *cls,
783 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || 745 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
784 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset))) 746 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, offset)))
785 { 747 {
786 LOG_SQLITE (plugin, NULL, 748 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
787 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
788 "sqlite3_bind_XXXX"); 749 "sqlite3_bind_XXXX");
789 if (SQLITE_OK != sqlite3_reset (stmt)) 750 if (SQLITE_OK != sqlite3_reset (stmt))
790 LOG_SQLITE (plugin, NULL, 751 LOG_SQLITE (plugin, NULL,
791 GNUNET_ERROR_TYPE_ERROR | 752 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
792 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 753 "sqlite3_reset");
793 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 754 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
794 return; 755 return;
795 } 756 }
@@ -816,12 +777,10 @@ sqlite_plugin_get_zero_anonymity (void *cls,
816 * @param proc_cls closure for proc 777 * @param proc_cls closure for proc
817 */ 778 */
818static void 779static void
819sqlite_plugin_get_key (void *cls, 780sqlite_plugin_get_key (void *cls, uint64_t offset, const GNUNET_HashCode * key,
820 uint64_t offset,
821 const GNUNET_HashCode * key,
822 const GNUNET_HashCode * vhash, 781 const GNUNET_HashCode * vhash,
823 enum GNUNET_BLOCK_Type type, 782 enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc,
824 PluginDatumProcessor proc, void *proc_cls) 783 void *proc_cls)
825{ 784{
826 struct Plugin *plugin = cls; 785 struct Plugin *plugin = cls;
827 int ret; 786 int ret;
@@ -839,18 +798,19 @@ sqlite_plugin_get_key (void *cls,
839 type == 0 ? "" : " AND type=?"); 798 type == 0 ? "" : " AND type=?");
840 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 799 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
841 { 800 {
842 LOG_SQLITE (plugin, NULL, 801 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
843 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
844 "sqlite_prepare"); 802 "sqlite_prepare");
845 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 803 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
846 return; 804 return;
847 } 805 }
848 sqoff = 1; 806 sqoff = 1;
849 ret = sqlite3_bind_blob (stmt, sqoff++, 807 ret =
850 key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 808 sqlite3_bind_blob (stmt, sqoff++, key, sizeof (GNUNET_HashCode),
809 SQLITE_TRANSIENT);
851 if ((vhash != NULL) && (ret == SQLITE_OK)) 810 if ((vhash != NULL) && (ret == SQLITE_OK))
852 ret = sqlite3_bind_blob (stmt, sqoff++, 811 ret =
853 vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 812 sqlite3_bind_blob (stmt, sqoff++, vhash, sizeof (GNUNET_HashCode),
813 SQLITE_TRANSIENT);
854 if ((type != 0) && (ret == SQLITE_OK)) 814 if ((type != 0) && (ret == SQLITE_OK))
855 ret = sqlite3_bind_int (stmt, sqoff++, type); 815 ret = sqlite3_bind_int (stmt, sqoff++, type);
856 if (SQLITE_OK != ret) 816 if (SQLITE_OK != ret)
@@ -863,8 +823,7 @@ sqlite_plugin_get_key (void *cls,
863 ret = sqlite3_step (stmt); 823 ret = sqlite3_step (stmt);
864 if (ret != SQLITE_ROW) 824 if (ret != SQLITE_ROW)
865 { 825 {
866 LOG_SQLITE (plugin, NULL, 826 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
867 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
868 "sqlite_step"); 827 "sqlite_step");
869 sqlite3_finalize (stmt); 828 sqlite3_finalize (stmt);
870 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 829 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
@@ -888,29 +847,27 @@ sqlite_plugin_get_key (void *cls,
888 type == 0 ? "" : " AND type=?"); 847 type == 0 ? "" : " AND type=?");
889 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 848 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
890 { 849 {
891 LOG_SQLITE (plugin, NULL, 850 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
892 GNUNET_ERROR_TYPE_ERROR | 851 "sqlite_prepare");
893 GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
894 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 852 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
895 return; 853 return;
896 } 854 }
897 sqoff = 1; 855 sqoff = 1;
898 ret = sqlite3_bind_blob (stmt, 856 ret =
899 sqoff++, 857 sqlite3_bind_blob (stmt, sqoff++, key, sizeof (GNUNET_HashCode),
900 key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 858 SQLITE_TRANSIENT);
901 if ((vhash != NULL) && (ret == SQLITE_OK)) 859 if ((vhash != NULL) && (ret == SQLITE_OK))
902 ret = sqlite3_bind_blob (stmt, 860 ret =
903 sqoff++, 861 sqlite3_bind_blob (stmt, sqoff++, vhash, sizeof (GNUNET_HashCode),
904 vhash, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT); 862 SQLITE_TRANSIENT);
905 if ((type != 0) && (ret == SQLITE_OK)) 863 if ((type != 0) && (ret == SQLITE_OK))
906 ret = sqlite3_bind_int (stmt, sqoff++, type); 864 ret = sqlite3_bind_int (stmt, sqoff++, type);
907 if (ret == SQLITE_OK) 865 if (ret == SQLITE_OK)
908 ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off); 866 ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off);
909 if (ret != SQLITE_OK) 867 if (ret != SQLITE_OK)
910 { 868 {
911 LOG_SQLITE (plugin, NULL, 869 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
912 GNUNET_ERROR_TYPE_ERROR | 870 "sqlite_bind");
913 GNUNET_ERROR_TYPE_BULK, "sqlite_bind");
914 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 871 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
915 return; 872 return;
916 } 873 }
@@ -968,20 +925,17 @@ struct ReplCtx
968 * GNUNET_NO to delete the item 925 * GNUNET_NO to delete the item
969 */ 926 */
970static int 927static int
971repl_proc (void *cls, 928repl_proc (void *cls, const GNUNET_HashCode * key, uint32_t size,
972 const GNUNET_HashCode * key, 929 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
973 uint32_t size, 930 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
974 const void *data, 931 uint64_t uid)
975 enum GNUNET_BLOCK_Type type,
976 uint32_t priority,
977 uint32_t anonymity,
978 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
979{ 932{
980 struct ReplCtx *rc = cls; 933 struct ReplCtx *rc = cls;
981 int ret; 934 int ret;
982 935
983 ret = rc->proc (rc->proc_cls, 936 ret =
984 key, size, data, type, priority, anonymity, expiration, uid); 937 rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity,
938 expiration, uid);
985 if (key != NULL) 939 if (key != NULL)
986 { 940 {
987 rc->uid = uid; 941 rc->uid = uid;
@@ -1002,8 +956,8 @@ repl_proc (void *cls,
1002 * @param proc_cls closure for proc 956 * @param proc_cls closure for proc
1003 */ 957 */
1004static void 958static void
1005sqlite_plugin_get_replication (void *cls, 959sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc,
1006 PluginDatumProcessor proc, void *proc_cls) 960 void *proc_cls)
1007{ 961{
1008 struct Plugin *plugin = cls; 962 struct Plugin *plugin = cls;
1009 struct ReplCtx rc; 963 struct ReplCtx rc;
@@ -1012,8 +966,7 @@ sqlite_plugin_get_replication (void *cls,
1012 sqlite3_stmt *stmt; 966 sqlite3_stmt *stmt;
1013 967
1014#if DEBUG_SQLITE 968#if DEBUG_SQLITE
1015 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 969 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1016 "sqlite",
1017 "Getting random block based on replication order.\n"); 970 "Getting random block based on replication order.\n");
1018#endif 971#endif
1019 rc.have_uid = GNUNET_NO; 972 rc.have_uid = GNUNET_NO;
@@ -1024,23 +977,21 @@ sqlite_plugin_get_replication (void *cls,
1024 { 977 {
1025 if (SQLITE_OK != sqlite3_reset (stmt)) 978 if (SQLITE_OK != sqlite3_reset (stmt))
1026 LOG_SQLITE (plugin, NULL, 979 LOG_SQLITE (plugin, NULL,
1027 GNUNET_ERROR_TYPE_ERROR | 980 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1028 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 981 "sqlite3_reset");
1029 /* DB empty */ 982 /* DB empty */
1030 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 983 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1031 return; 984 return;
1032 } 985 }
1033 repl = sqlite3_column_int (stmt, 0); 986 repl = sqlite3_column_int (stmt, 0);
1034 if (SQLITE_OK != sqlite3_reset (stmt)) 987 if (SQLITE_OK != sqlite3_reset (stmt))
1035 LOG_SQLITE (plugin, NULL, 988 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1036 GNUNET_ERROR_TYPE_ERROR | 989 "sqlite3_reset");
1037 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
1038 stmt = plugin->selRepl; 990 stmt = plugin->selRepl;
1039 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 991 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
1040 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue)) 992 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, rvalue))
1041 { 993 {
1042 LOG_SQLITE (plugin, NULL, 994 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1043 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1044 "sqlite3_bind_XXXX"); 995 "sqlite3_bind_XXXX");
1045 if (SQLITE_OK != sqlite3_reset (stmt)) 996 if (SQLITE_OK != sqlite3_reset (stmt))
1046 LOG_SQLITE (plugin, NULL, 997 LOG_SQLITE (plugin, NULL,
@@ -1051,8 +1002,7 @@ sqlite_plugin_get_replication (void *cls,
1051 } 1002 }
1052 if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl)) 1003 if (SQLITE_OK != sqlite3_bind_int (stmt, 2, repl))
1053 { 1004 {
1054 LOG_SQLITE (plugin, NULL, 1005 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1055 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1056 "sqlite3_bind_XXXX"); 1006 "sqlite3_bind_XXXX");
1057 if (SQLITE_OK != sqlite3_reset (stmt)) 1007 if (SQLITE_OK != sqlite3_reset (stmt))
1058 LOG_SQLITE (plugin, NULL, 1008 LOG_SQLITE (plugin, NULL,
@@ -1071,18 +1021,18 @@ sqlite_plugin_get_replication (void *cls,
1071 "sqlite3_bind_XXXX"); 1021 "sqlite3_bind_XXXX");
1072 if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) 1022 if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
1073 LOG_SQLITE (plugin, NULL, 1023 LOG_SQLITE (plugin, NULL,
1074 GNUNET_ERROR_TYPE_ERROR | 1024 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1075 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 1025 "sqlite3_reset");
1076 return; 1026 return;
1077 } 1027 }
1078 if (SQLITE_DONE != sqlite3_step (plugin->updRepl)) 1028 if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
1079 LOG_SQLITE (plugin, NULL, 1029 LOG_SQLITE (plugin, NULL,
1080 GNUNET_ERROR_TYPE_ERROR | 1030 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1081 GNUNET_ERROR_TYPE_BULK, "sqlite3_step"); 1031 "sqlite3_step");
1082 if (SQLITE_OK != sqlite3_reset (plugin->updRepl)) 1032 if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
1083 LOG_SQLITE (plugin, NULL, 1033 LOG_SQLITE (plugin, NULL,
1084 GNUNET_ERROR_TYPE_ERROR | 1034 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1085 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); 1035 "sqlite3_reset");
1086 } 1036 }
1087} 1037}
1088 1038
@@ -1097,24 +1047,22 @@ sqlite_plugin_get_replication (void *cls,
1097 * @param proc_cls closure for proc 1047 * @param proc_cls closure for proc
1098 */ 1048 */
1099static void 1049static void
1100sqlite_plugin_get_expiration (void *cls, 1050sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
1101 PluginDatumProcessor proc, void *proc_cls) 1051 void *proc_cls)
1102{ 1052{
1103 struct Plugin *plugin = cls; 1053 struct Plugin *plugin = cls;
1104 sqlite3_stmt *stmt; 1054 sqlite3_stmt *stmt;
1105 struct GNUNET_TIME_Absolute now; 1055 struct GNUNET_TIME_Absolute now;
1106 1056
1107#if DEBUG_SQLITE 1057#if DEBUG_SQLITE
1108 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1058 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1109 "sqlite",
1110 "Getting random block based on expiration and priority order.\n"); 1059 "Getting random block based on expiration and priority order.\n");
1111#endif 1060#endif
1112 now = GNUNET_TIME_absolute_get (); 1061 now = GNUNET_TIME_absolute_get ();
1113 stmt = plugin->selExpi; 1062 stmt = plugin->selExpi;
1114 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value)) 1063 if (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, now.abs_value))
1115 { 1064 {
1116 LOG_SQLITE (plugin, NULL, 1065 LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1117 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1118 "sqlite3_bind_XXXX"); 1066 "sqlite3_bind_XXXX");
1119 if (SQLITE_OK != sqlite3_reset (stmt)) 1067 if (SQLITE_OK != sqlite3_reset (stmt))
1120 LOG_SQLITE (plugin, NULL, 1068 LOG_SQLITE (plugin, NULL,
@@ -1162,16 +1110,15 @@ sqlite_plugin_estimate_size (void *cls)
1162 1110
1163 if (SQLITE_VERSION_NUMBER < 3006000) 1111 if (SQLITE_VERSION_NUMBER < 3006000)
1164 { 1112 {
1165 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 1113 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "datastore-sqlite",
1166 "datastore-sqlite",
1167 _ 1114 _
1168 ("sqlite version to old to determine size, assuming zero\n")); 1115 ("sqlite version to old to determine size, assuming zero\n"));
1169 return 0; 1116 return 0;
1170 } 1117 }
1171 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL)); 1118 CHECK (SQLITE_OK == sqlite3_exec (plugin->dbh, "VACUUM", NULL, NULL, ENULL));
1172 CHECK (SQLITE_OK == 1119 CHECK (SQLITE_OK ==
1173 sqlite3_exec (plugin->dbh, 1120 sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL,
1174 "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL)); 1121 NULL, ENULL));
1175 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt)); 1122 CHECK (SQLITE_OK == sq_prepare (plugin->dbh, "PRAGMA page_count", &stmt));
1176 if (SQLITE_ROW == sqlite3_step (stmt)) 1123 if (SQLITE_ROW == sqlite3_step (stmt))
1177 pages = sqlite3_column_int64 (stmt, 0); 1124 pages = sqlite3_column_int64 (stmt, 0);
@@ -1222,8 +1169,8 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
1222 api->get_expiration = &sqlite_plugin_get_expiration; 1169 api->get_expiration = &sqlite_plugin_get_expiration;
1223 api->get_zero_anonymity = &sqlite_plugin_get_zero_anonymity; 1170 api->get_zero_anonymity = &sqlite_plugin_get_zero_anonymity;
1224 api->drop = &sqlite_plugin_drop; 1171 api->drop = &sqlite_plugin_drop;
1225 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 1172 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "sqlite",
1226 "sqlite", _("Sqlite database running\n")); 1173 _("Sqlite database running\n"));
1227 return api; 1174 return api;
1228} 1175}
1229 1176
@@ -1242,16 +1189,16 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1242 struct Plugin *plugin = api->cls; 1189 struct Plugin *plugin = api->cls;
1243 1190
1244#if DEBUG_SQLITE 1191#if DEBUG_SQLITE
1245 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1192 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1246 "sqlite", "sqlite plugin is done\n"); 1193 "sqlite plugin is done\n");
1247#endif 1194#endif
1248 1195
1249 fn = NULL; 1196 fn = NULL;
1250 if (plugin->drop_on_shutdown) 1197 if (plugin->drop_on_shutdown)
1251 fn = GNUNET_strdup (plugin->fn); 1198 fn = GNUNET_strdup (plugin->fn);
1252#if DEBUG_SQLITE 1199#if DEBUG_SQLITE
1253 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1200 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1254 "sqlite", "Shutting down database\n"); 1201 "Shutting down database\n");
1255#endif 1202#endif
1256 database_shutdown (plugin); 1203 database_shutdown (plugin);
1257 plugin->env = NULL; 1204 plugin->env = NULL;
@@ -1263,8 +1210,8 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1263 GNUNET_free (fn); 1210 GNUNET_free (fn);
1264 } 1211 }
1265#if DEBUG_SQLITE 1212#if DEBUG_SQLITE
1266 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1213 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
1267 "sqlite", "sqlite plugin is finished\n"); 1214 "sqlite plugin is finished\n");
1268#endif 1215#endif
1269 return NULL; 1216 return NULL;
1270} 1217}