aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/datastore/perf_datastore_api.c8
-rw-r--r--src/datastore/perf_plugin_datastore.c8
-rw-r--r--src/datastore/plugin_datastore_sqlite.c108
-rw-r--r--src/datastore/test_datastore_api.c8
-rw-r--r--src/datastore/test_datastore_api_management.c8
-rw-r--r--src/util/crypto_hash.c2
6 files changed, 117 insertions, 25 deletions
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 1f7c828e0..e5dc67b44 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -407,13 +407,17 @@ int
407main (int argc, char *argv[]) 407main (int argc, char *argv[])
408{ 408{
409 int ret; 409 int ret;
410 const char *pos; 410 char *pos;
411 char dir_name[128]; 411 char dir_name[128];
412 412
413 /* determine name of plugin to use */ 413 /* determine name of plugin to use */
414 plugin_name = argv[0]; 414 plugin_name = argv[0];
415 while (NULL != (pos = strstr(plugin_name, "_"))) 415 while (NULL != (pos = strstr(plugin_name, "_")))
416 plugin_name = pos+1; 416 plugin_name = pos+1;
417 if (NULL != (pos = strstr(plugin_name, ".")))
418 pos[0] = 0;
419 else
420 pos = (char *) plugin_name;
417 421
418 GNUNET_snprintf (dir_name, 422 GNUNET_snprintf (dir_name,
419 sizeof (dir_name), 423 sizeof (dir_name),
@@ -428,6 +432,8 @@ main (int argc, char *argv[])
428#endif 432#endif
429 NULL); 433 NULL);
430 ret = check (); 434 ret = check ();
435 if (pos != plugin_name)
436 pos[0] = '.';
431#if REPORT_ID 437#if REPORT_ID
432 fprintf (stderr, "\n"); 438 fprintf (stderr, "\n");
433#endif 439#endif
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index c55fb6258..facf7be67 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -415,13 +415,17 @@ int
415main (int argc, char *argv[]) 415main (int argc, char *argv[])
416{ 416{
417 int ret; 417 int ret;
418 const char *pos; 418 char *pos;
419 char dir_name[128]; 419 char dir_name[128];
420 420
421 /* determine name of plugin to use */ 421 /* determine name of plugin to use */
422 plugin_name = argv[0]; 422 plugin_name = argv[0];
423 while (NULL != (pos = strstr(plugin_name, "_"))) 423 while (NULL != (pos = strstr(plugin_name, "_")))
424 plugin_name = pos+1; 424 plugin_name = pos+1;
425 if (NULL != (pos = strstr(plugin_name, ".")))
426 pos[0] = 0;
427 else
428 pos = (char *) plugin_name;
425 429
426 GNUNET_snprintf (dir_name, 430 GNUNET_snprintf (dir_name,
427 sizeof (dir_name), 431 sizeof (dir_name),
@@ -436,6 +440,8 @@ main (int argc, char *argv[])
436#endif 440#endif
437 NULL); 441 NULL);
438 ret = check (); 442 ret = check ();
443 if (pos != plugin_name)
444 pos[0] = '.';
439 GNUNET_DISK_directory_remove (dir_name); 445 GNUNET_DISK_directory_remove (dir_name);
440 446
441 return ret; 447 return ret;
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 457f75c45..1b8382537 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -28,7 +28,7 @@
28#include "gnunet_datastore_plugin.h" 28#include "gnunet_datastore_plugin.h"
29#include <sqlite3.h> 29#include <sqlite3.h>
30 30
31#define DEBUG_SQLITE GNUNET_YES 31#define DEBUG_SQLITE GNUNET_NO
32 32
33 33
34/** 34/**
@@ -105,6 +105,11 @@ struct Plugin
105 sqlite3 *dbh; 105 sqlite3 *dbh;
106 106
107 /** 107 /**
108 * Precompiled SQL for deletion.
109 */
110 sqlite3_stmt *delRow;
111
112 /**
108 * Precompiled SQL for update. 113 * Precompiled SQL for update.
109 */ 114 */
110 sqlite3_stmt *updPrio; 115 sqlite3_stmt *updPrio;
@@ -145,9 +150,16 @@ sq_prepare (sqlite3 * dbh, const char *zSql,
145 sqlite3_stmt ** ppStmt) 150 sqlite3_stmt ** ppStmt)
146{ 151{
147 char *dummy; 152 char *dummy;
148 return sqlite3_prepare_v2 (dbh, 153 int result;
149 zSql, 154 result = sqlite3_prepare_v2 (dbh,
150 strlen (zSql), ppStmt, (const char **) &dummy); 155 zSql,
156 strlen (zSql), ppStmt, (const char **) &dummy);
157#if DEBUG_SQLITE
158 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
159 "sqlite",
160 "Prepared %p: %d\n", *ppStmt, result);
161#endif
162 return result;
151} 163}
152 164
153 165
@@ -324,12 +336,16 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
324 "INSERT INTO gn080 (size, type, prio, " 336 "INSERT INTO gn080 (size, type, prio, "
325 "anonLevel, expire, hash, vhash, value) VALUES " 337 "anonLevel, expire, hash, vhash, value) VALUES "
326 "(?, ?, ?, ?, ?, ?, ?, ?)", 338 "(?, ?, ?, ?, ?, ?, ?, ?)",
327 &plugin->insertContent) != SQLITE_OK)) 339 &plugin->insertContent) != SQLITE_OK) ||
340 (sq_prepare (plugin->dbh,
341 "DELETE FROM gn080 WHERE _ROWID_ = ?",
342 &plugin->delRow) != SQLITE_OK))
328 { 343 {
329 LOG_SQLITE (plugin, NULL, 344 LOG_SQLITE (plugin, NULL,
330 GNUNET_ERROR_TYPE_ERROR, "precompiling"); 345 GNUNET_ERROR_TYPE_ERROR, "precompiling");
331 return GNUNET_SYSERR; 346 return GNUNET_SYSERR;
332 } 347 }
348
333 return GNUNET_OK; 349 return GNUNET_OK;
334} 350}
335 351
@@ -342,11 +358,36 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
342static void 358static void
343database_shutdown (struct Plugin *plugin) 359database_shutdown (struct Plugin *plugin)
344{ 360{
361 int result;
362 if (plugin->delRow != NULL)
363 sqlite3_finalize (plugin->delRow);
345 if (plugin->updPrio != NULL) 364 if (plugin->updPrio != NULL)
346 sqlite3_finalize (plugin->updPrio); 365 sqlite3_finalize (plugin->updPrio);
347 if (plugin->insertContent != NULL) 366 if (plugin->insertContent != NULL)
348 sqlite3_finalize (plugin->insertContent); 367 sqlite3_finalize (plugin->insertContent);
349 sqlite3_close (plugin->dbh); 368 result = sqlite3_close(plugin->dbh);
369 while (result == SQLITE_BUSY)
370 {
371 sqlite3_stmt *stmt;
372 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
373 "sqlite",
374 _("Tried to close sqlite without finalizing all prepared statements.\n"));
375 for (stmt = sqlite3_next_stmt(plugin->dbh, NULL); stmt != NULL; stmt = sqlite3_next_stmt(plugin->dbh, NULL))
376 {
377#if DEBUG_SQLITE
378 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
379 "sqlite", "Closing statement %p\n", stmt);
380#endif
381 result = sqlite3_finalize(stmt);
382#if DEBUG_SQLITE
383 if (result != SQLITE_OK)
384 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
385 "sqlite",
386 "Failed to close statement %p: %d\n", stmt, result);
387#endif
388 }
389 result = sqlite3_close(plugin->dbh);
390 }
350 GNUNET_free_non_null (plugin->fn); 391 GNUNET_free_non_null (plugin->fn);
351} 392}
352 393
@@ -362,26 +403,23 @@ static int
362delete_by_rowid (struct Plugin* plugin, 403delete_by_rowid (struct Plugin* plugin,
363 unsigned long long rid) 404 unsigned long long rid)
364{ 405{
365 sqlite3_stmt *stmt;
366 406
367 if (sq_prepare (plugin->dbh, 407 sqlite3_bind_int64 (plugin->delRow, 1, rid);
368 "DELETE FROM gn080 WHERE _ROWID_ = ?", &stmt) != SQLITE_OK) 408 if (SQLITE_DONE != sqlite3_step (plugin->delRow))
369 { 409 {
370 LOG_SQLITE (plugin, NULL, 410 LOG_SQLITE (plugin, NULL,
371 GNUNET_ERROR_TYPE_ERROR | 411 GNUNET_ERROR_TYPE_ERROR |
372 GNUNET_ERROR_TYPE_BULK, "sq_prepare"); 412 GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
413 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
414 LOG_SQLITE (plugin, NULL,
415 GNUNET_ERROR_TYPE_ERROR |
416 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
373 return GNUNET_SYSERR; 417 return GNUNET_SYSERR;
374 } 418 }
375 sqlite3_bind_int64 (stmt, 1, rid); 419 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
376 if (SQLITE_DONE != sqlite3_step (stmt))
377 {
378 LOG_SQLITE (plugin, NULL, 420 LOG_SQLITE (plugin, NULL,
379 GNUNET_ERROR_TYPE_ERROR | 421 GNUNET_ERROR_TYPE_ERROR |
380 GNUNET_ERROR_TYPE_BULK, "sqlite3_step"); 422 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
381 sqlite3_finalize (stmt);
382 return GNUNET_SYSERR;
383 }
384 sqlite3_finalize (stmt);
385 return GNUNET_OK; 423 return GNUNET_OK;
386} 424}
387 425
@@ -1167,7 +1205,7 @@ sqlite_plugin_iter_migration_order (void *cls,
1167 * Call sqlite using the already prepared query to get 1205 * Call sqlite using the already prepared query to get
1168 * the next result. 1206 * the next result.
1169 * 1207 *
1170 * @param cls not used 1208 * @param cls context with the prepared query
1171 * @param nc context with the prepared query 1209 * @param nc context with the prepared query
1172 * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if 1210 * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if
1173 * there are no more results 1211 * there are no more results
@@ -1185,6 +1223,10 @@ all_next_prepare (void *cls,
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1186 "Asked to clean up iterator state.\n"); 1224 "Asked to clean up iterator state.\n");
1187#endif 1225#endif
1226 nc = (struct NextContext *)cls;
1227 if (nc->stmt)
1228 sqlite3_finalize (nc->stmt);
1229 nc->stmt = NULL;
1188 return GNUNET_SYSERR; 1230 return GNUNET_SYSERR;
1189 } 1231 }
1190 plugin = nc->plugin; 1232 plugin = nc->plugin;
@@ -1241,7 +1283,7 @@ sqlite_plugin_iter_all_now (void *cls,
1241 nc->iter_cls = iter_cls; 1283 nc->iter_cls = iter_cls;
1242 nc->stmt = stmt; 1284 nc->stmt = stmt;
1243 nc->prep = &all_next_prepare; 1285 nc->prep = &all_next_prepare;
1244 nc->prep_cls = NULL; 1286 nc->prep_cls = nc;
1245 sqlite_next_request (nc, GNUNET_NO); 1287 sqlite_next_request (nc, GNUNET_NO);
1246} 1288}
1247 1289
@@ -1595,10 +1637,26 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1595 struct GNUNET_DATASTORE_PluginFunctions *api = cls; 1637 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1596 struct Plugin *plugin = api->cls; 1638 struct Plugin *plugin = api->cls;
1597 1639
1640#if DEBUG_SQLITE
1641 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1642 "sqlite",
1643 "sqlite plugin is doneing\n");
1644#endif
1645
1598 if (plugin->next_task != GNUNET_SCHEDULER_NO_TASK) 1646 if (plugin->next_task != GNUNET_SCHEDULER_NO_TASK)
1599 { 1647 {
1648#if DEBUG_SQLITE
1649 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1650 "sqlite",
1651 "Canceling next task\n");
1652#endif
1600 GNUNET_SCHEDULER_cancel (plugin->next_task); 1653 GNUNET_SCHEDULER_cancel (plugin->next_task);
1601 plugin->next_task = GNUNET_SCHEDULER_NO_TASK; 1654 plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
1655#if DEBUG_SQLITE
1656 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1657 "sqlite",
1658 "Prep'ing next task\n");
1659#endif
1602 plugin->next_task_nc->prep (plugin->next_task_nc->prep_cls, NULL); 1660 plugin->next_task_nc->prep (plugin->next_task_nc->prep_cls, NULL);
1603 GNUNET_free (plugin->next_task_nc); 1661 GNUNET_free (plugin->next_task_nc);
1604 plugin->next_task_nc = NULL; 1662 plugin->next_task_nc = NULL;
@@ -1606,6 +1664,11 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1606 fn = NULL; 1664 fn = NULL;
1607 if (plugin->drop_on_shutdown) 1665 if (plugin->drop_on_shutdown)
1608 fn = GNUNET_strdup (plugin->fn); 1666 fn = GNUNET_strdup (plugin->fn);
1667#if DEBUG_SQLITE
1668 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1669 "sqlite",
1670 "Shutting down database\n");
1671#endif
1609 database_shutdown (plugin); 1672 database_shutdown (plugin);
1610 plugin->env = NULL; 1673 plugin->env = NULL;
1611 GNUNET_free (api); 1674 GNUNET_free (api);
@@ -1617,6 +1680,11 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
1617 fn); 1680 fn);
1618 GNUNET_free (fn); 1681 GNUNET_free (fn);
1619 } 1682 }
1683#if DEBUG_SQLITE
1684 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1685 "sqlite",
1686 "sqlite plugin is finished doneing\n");
1687#endif
1620 return NULL; 1688 return NULL;
1621} 1689}
1622 1690
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index 06abc0c0f..2edc9a6ec 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -678,13 +678,17 @@ int
678main (int argc, char *argv[]) 678main (int argc, char *argv[])
679{ 679{
680 int ret; 680 int ret;
681 const char *pos; 681 char *pos;
682 char dir_name[128]; 682 char dir_name[128];
683 683
684 /* determine name of plugin to use */ 684 /* determine name of plugin to use */
685 plugin_name = argv[0]; 685 plugin_name = argv[0];
686 while (NULL != (pos = strstr(plugin_name, "_"))) 686 while (NULL != (pos = strstr(plugin_name, "_")))
687 plugin_name = pos+1; 687 plugin_name = pos+1;
688 if (NULL != (pos = strstr(plugin_name, ".")))
689 pos[0] = 0;
690 else
691 pos = (char *) plugin_name;
688 692
689 GNUNET_snprintf (dir_name, 693 GNUNET_snprintf (dir_name,
690 sizeof (dir_name), 694 sizeof (dir_name),
@@ -699,6 +703,8 @@ main (int argc, char *argv[])
699#endif 703#endif
700 NULL); 704 NULL);
701 ret = check (); 705 ret = check ();
706 if (pos != plugin_name)
707 pos[0] = '.';
702 GNUNET_DISK_directory_remove (dir_name); 708 GNUNET_DISK_directory_remove (dir_name);
703 return ret; 709 return ret;
704} 710}
diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c
index d17d8fbc8..8d71fed90 100644
--- a/src/datastore/test_datastore_api_management.c
+++ b/src/datastore/test_datastore_api_management.c
@@ -388,13 +388,17 @@ main (int argc, char *argv[])
388{ 388{
389 int ret; 389 int ret;
390 390
391 const char *pos; 391 char *pos;
392 char dir_name[128]; 392 char dir_name[128];
393 393
394 /* determine name of plugin to use */ 394 /* determine name of plugin to use */
395 plugin_name = argv[0]; 395 plugin_name = argv[0];
396 while (NULL != (pos = strstr(plugin_name, "_"))) 396 while (NULL != (pos = strstr(plugin_name, "_")))
397 plugin_name = pos+1; 397 plugin_name = pos+1;
398 if (NULL != (pos = strstr(plugin_name, ".")))
399 pos[0] = 0;
400 else
401 pos = (char *) plugin_name;
398 402
399 GNUNET_snprintf (dir_name, 403 GNUNET_snprintf (dir_name,
400 sizeof (dir_name), 404 sizeof (dir_name),
@@ -409,6 +413,8 @@ main (int argc, char *argv[])
409#endif 413#endif
410 NULL); 414 NULL);
411 ret = check (); 415 ret = check ();
416 if (pos != plugin_name)
417 pos[0] = '.';
412 GNUNET_DISK_directory_remove (dir_name); 418 GNUNET_DISK_directory_remove (dir_name);
413 return ret; 419 return ret;
414} 420}
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 9e5af4ab5..0cbc4289c 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -141,7 +141,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
141 size_t delta; 141 size_t delta;
142 142
143 fhc->task = GNUNET_SCHEDULER_NO_TASK; 143 fhc->task = GNUNET_SCHEDULER_NO_TASK;
144 GNUNET_assert (fhc->offset < fhc->fsize); 144 GNUNET_assert (fhc->offset <= fhc->fsize);
145 delta = fhc->bsize; 145 delta = fhc->bsize;
146 if (fhc->fsize - fhc->offset < delta) 146 if (fhc->fsize - fhc->offset < delta)
147 delta = fhc->fsize - fhc->offset; 147 delta = fhc->fsize - fhc->offset;