2 This file is part of GNUnet
3 (C) 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file datastore/plugin_datastore_sqlite.c
23 * @brief sqlite-based datastore backend
24 * @author Christian Grothoff
28 #include "gnunet_datastore_plugin.h"
31 #define DEBUG_SQLITE GNUNET_NO
35 * Log an error message at log-level 'level' that indicates
36 * a failure of the command 'cmd' on file 'filename'
37 * with the message given by strerror(errno).
39 #define LOG_SQLITE(db, msg, level, cmd) do { GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); if (msg != NULL) GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db->dbh)); } while(0)
41 #define SELECT_IT_LOW_PRIORITY_1 \
42 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio = ? AND hash > ?) "\
43 "ORDER BY hash ASC LIMIT 1"
45 #define SELECT_IT_LOW_PRIORITY_2 \
46 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio > ?) "\
47 "ORDER BY prio ASC, hash ASC LIMIT 1"
49 #define SELECT_IT_NON_ANONYMOUS_1 \
50 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio = ? AND hash < ? AND anonLevel = 0 AND expire > %llu) "\
51 " ORDER BY hash DESC LIMIT 1"
53 #define SELECT_IT_NON_ANONYMOUS_2 \
54 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio < ? AND anonLevel = 0 AND expire > %llu)"\
55 " ORDER BY prio DESC, hash DESC LIMIT 1"
57 #define SELECT_IT_EXPIRATION_TIME_1 \
58 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire = ? AND hash > ?) "\
59 " ORDER BY hash ASC LIMIT 1"
61 #define SELECT_IT_EXPIRATION_TIME_2 \
62 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire > ?) "\
63 " ORDER BY expire ASC, hash ASC LIMIT 1"
65 #define SELECT_IT_MIGRATION_ORDER_1 \
66 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire = ? AND hash < ?) "\
67 " ORDER BY hash DESC LIMIT 1"
69 #define SELECT_IT_MIGRATION_ORDER_2 \
70 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire < ? AND expire > %llu) "\
71 " ORDER BY expire DESC, hash DESC LIMIT 1"
74 * After how many ms "busy" should a DB operation fail for good?
75 * A low value makes sure that we are more responsive to requests
76 * (especially PUTs). A high value guarantees a higher success
77 * rate (SELECTs in iterate can take several seconds despite LIMIT=1).
79 * The default value of 250ms should ensure that users do not experience
80 * huge latencies while at the same time allowing operations to succeed
81 * with reasonable probability.
83 #define BUSY_TIMEOUT_MS 250
88 * Context for all functions in this plugin.
93 * Our execution environment.
95 struct GNUNET_DATASTORE_PluginEnvironment *env;
103 * Native SQLite database handle.
108 * Precompiled SQL for deletion.
110 sqlite3_stmt *delRow;
113 * Precompiled SQL for update.
115 sqlite3_stmt *updPrio;
118 * Precompiled SQL for insertion.
120 sqlite3_stmt *insertContent;
123 * Closure of the 'next_task' (must be freed if 'next_task' is cancelled).
125 struct NextContext *next_task_nc;
128 * Pending task with scheduler for running the next request.
130 GNUNET_SCHEDULER_TaskIdentifier next_task;
133 * Should the database be dropped on shutdown?
135 int drop_on_shutdown;
141 * @brief Prepare a SQL statement
143 * @param dbh handle to the database
144 * @param zSql SQL statement, UTF-8 encoded
145 * @param ppStmt set to the prepared statement
146 * @return 0 on success
149 sq_prepare (sqlite3 * dbh, const char *zSql,
150 sqlite3_stmt ** ppStmt)
154 result = sqlite3_prepare_v2 (dbh,
156 strlen (zSql), ppStmt, (const char **) &dummy);
158 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
160 "Prepared %p: %d\n", *ppStmt, result);
167 * Create our database indices.
169 * @param dbh handle to the database
172 create_indices (sqlite3 * dbh)
176 "CREATE INDEX idx_hash ON gn080 (hash)", NULL, NULL, NULL);
178 "CREATE INDEX idx_hash_vhash ON gn080 (hash,vhash)", NULL,
180 sqlite3_exec (dbh, "CREATE INDEX idx_prio ON gn080 (prio)", NULL, NULL,
182 sqlite3_exec (dbh, "CREATE INDEX idx_expire ON gn080 (expire)", NULL, NULL,
184 sqlite3_exec (dbh, "CREATE INDEX idx_comb3 ON gn080 (prio,anonLevel)", NULL,
186 sqlite3_exec (dbh, "CREATE INDEX idx_comb4 ON gn080 (prio,hash,anonLevel)",
188 sqlite3_exec (dbh, "CREATE INDEX idx_comb7 ON gn080 (expire,hash)", NULL,
195 #define CHECK(a) GNUNET_break(a)
199 #define ENULL_DEFINED 1
200 #define CHECK(a) if (! a) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
207 * Initialize the database connections and associated
208 * data structures (create tables and indices
209 * as needed as well).
211 * @param cfg our configuration
212 * @param plugin the plugin context (state for this module)
213 * @return GNUNET_OK on success
216 database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
217 struct Plugin *plugin)
226 GNUNET_CONFIGURATION_get_value_filename (cfg,
231 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
233 _("Option `%s' in section `%s' missing in configuration!\n"),
236 return GNUNET_SYSERR;
238 if (GNUNET_OK != GNUNET_DISK_file_test (afsdir))
240 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
243 GNUNET_free (afsdir);
244 return GNUNET_SYSERR;
246 /* database is new or got deleted, reset payload to zero! */
247 plugin->env->duc (plugin->env->cls, 0);
250 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir),
251 nl_langinfo (CODESET));
253 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir),
254 "UTF-8"); /* good luck */
256 GNUNET_free (afsdir);
258 /* Open database and precompile statements */
259 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
261 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
263 _("Unable to initialize SQLite: %s.\n"),
264 sqlite3_errmsg (plugin->dbh));
265 return GNUNET_SYSERR;
268 sqlite3_exec (plugin->dbh,
269 "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
271 sqlite3_exec (plugin->dbh,
272 "PRAGMA synchronous=OFF", NULL, NULL, ENULL));
274 sqlite3_exec (plugin->dbh,
275 "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
277 sqlite3_exec (plugin->dbh,
278 "PRAGMA count_changes=OFF", NULL, NULL, ENULL));
280 sqlite3_exec (plugin->dbh,
281 "PRAGMA page_size=4092", NULL, NULL, ENULL));
283 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
286 /* We have to do it here, because otherwise precompiling SQL might fail */
288 sq_prepare (plugin->dbh,
289 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn080'",
291 if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
292 (sqlite3_exec (plugin->dbh,
293 "CREATE TABLE gn080 ("
294 " size INT4 NOT NULL DEFAULT 0,"
295 " type INT4 NOT NULL DEFAULT 0,"
296 " prio INT4 NOT NULL DEFAULT 0,"
297 " anonLevel INT4 NOT NULL DEFAULT 0,"
298 " expire INT8 NOT NULL DEFAULT 0,"
299 " hash TEXT NOT NULL DEFAULT '',"
300 " vhash TEXT NOT NULL DEFAULT '',"
301 " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
302 NULL) != SQLITE_OK) )
304 LOG_SQLITE (plugin, NULL,
305 GNUNET_ERROR_TYPE_ERROR,
307 sqlite3_finalize (stmt);
308 return GNUNET_SYSERR;
310 sqlite3_finalize (stmt);
311 create_indices (plugin->dbh);
314 sq_prepare (plugin->dbh,
315 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn071'",
317 if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
318 (sqlite3_exec (plugin->dbh,
319 "CREATE TABLE gn071 ("
320 " key TEXT NOT NULL DEFAULT '',"
321 " value INTEGER NOT NULL DEFAULT 0)", NULL, NULL,
322 NULL) != SQLITE_OK) )
324 LOG_SQLITE (plugin, NULL,
325 GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
326 sqlite3_finalize (stmt);
327 return GNUNET_SYSERR;
329 sqlite3_finalize (stmt);
331 if ((sq_prepare (plugin->dbh,
332 "UPDATE gn080 SET prio = prio + ?, expire = MAX(expire,?) WHERE "
334 &plugin->updPrio) != SQLITE_OK) ||
335 (sq_prepare (plugin->dbh,
336 "INSERT INTO gn080 (size, type, prio, "
337 "anonLevel, expire, hash, vhash, value) VALUES "
338 "(?, ?, ?, ?, ?, ?, ?, ?)",
339 &plugin->insertContent) != SQLITE_OK) ||
340 (sq_prepare (plugin->dbh,
341 "DELETE FROM gn080 WHERE _ROWID_ = ?",
342 &plugin->delRow) != SQLITE_OK))
344 LOG_SQLITE (plugin, NULL,
345 GNUNET_ERROR_TYPE_ERROR, "precompiling");
346 return GNUNET_SYSERR;
354 * Shutdown database connection and associate data
356 * @param plugin the plugin context (state for this module)
359 database_shutdown (struct Plugin *plugin)
365 if (plugin->delRow != NULL)
366 sqlite3_finalize (plugin->delRow);
367 if (plugin->updPrio != NULL)
368 sqlite3_finalize (plugin->updPrio);
369 if (plugin->insertContent != NULL)
370 sqlite3_finalize (plugin->insertContent);
371 result = sqlite3_close(plugin->dbh);
372 #if SQLITE_VERSION_NUMBER >= 3007000
373 if (result == SQLITE_BUSY)
375 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
377 _("Tried to close sqlite without finalizing all prepared statements.\n"));
378 stmt = sqlite3_next_stmt(plugin->dbh, NULL);
382 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
383 "sqlite", "Closing statement %p\n", stmt);
385 result = sqlite3_finalize(stmt);
387 if (result != SQLITE_OK)
388 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
390 "Failed to close statement %p: %d\n", stmt, result);
392 stmt = sqlite3_next_stmt(plugin->dbh, NULL);
394 result = sqlite3_close(plugin->dbh);
397 if (SQLITE_OK != result)
398 LOG_SQLITE (plugin, NULL,
399 GNUNET_ERROR_TYPE_ERROR,
402 GNUNET_free_non_null (plugin->fn);
407 * Delete the database entry with the given
410 * @param plugin the plugin context (state for this module)
411 * @param rid the ID of the row to delete
414 delete_by_rowid (struct Plugin* plugin,
415 unsigned long long rid)
418 sqlite3_bind_int64 (plugin->delRow, 1, rid);
419 if (SQLITE_DONE != sqlite3_step (plugin->delRow))
421 LOG_SQLITE (plugin, NULL,
422 GNUNET_ERROR_TYPE_ERROR |
423 GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
424 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
425 LOG_SQLITE (plugin, NULL,
426 GNUNET_ERROR_TYPE_ERROR |
427 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
428 return GNUNET_SYSERR;
430 if (SQLITE_OK != sqlite3_reset (plugin->delRow))
431 LOG_SQLITE (plugin, NULL,
432 GNUNET_ERROR_TYPE_ERROR |
433 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
439 * Context for the universal iterator.
444 * Type of a function that will prepare
445 * the next iteration.
448 * @param nc the next context; NULL for the last
449 * call which gives the callback a chance to
450 * clean up the closure
451 * @return GNUNET_OK on success, GNUNET_NO if there are
452 * no more values, GNUNET_SYSERR on error
454 typedef int (*PrepareFunction)(void *cls,
455 struct NextContext *nc);
459 * Context we keep for the "next request" callback.
466 struct Plugin *plugin;
469 * Function to call on the next value.
479 * Function to call to prepare the next
482 PrepareFunction prep;
490 * Statement that the iterator will get the data
491 * from (updated or set by prep).
496 * Row ID of the last result.
498 unsigned long long last_rowid;
501 * Key of the last result.
503 GNUNET_HashCode lastKey;
506 * Expiration time of the last value visited.
508 struct GNUNET_TIME_Absolute lastExpiration;
511 * Priority of the last value visited.
513 unsigned int lastPriority;
516 * Number of results processed so far.
521 * Set to GNUNET_YES if we must stop now.
528 * Continuation of "sqlite_next_request".
530 * @param cls the next context
531 * @param tc the task context (unused)
534 sqlite_next_request_cont (void *cls,
535 const struct GNUNET_SCHEDULER_TaskContext *tc)
537 struct NextContext * nc = cls;
538 struct Plugin *plugin;
539 unsigned long long rowid;
544 unsigned int priority;
545 unsigned int anonymity;
546 struct GNUNET_TIME_Absolute expiration;
547 const GNUNET_HashCode *key;
551 plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
552 plugin->next_task_nc = NULL;
553 if ( (GNUNET_YES == nc->end_it) ||
554 (GNUNET_OK != (nc->prep(nc->prep_cls,
558 nc->iter (nc->iter_cls,
559 NULL, NULL, 0, NULL, 0, 0, 0,
560 GNUNET_TIME_UNIT_ZERO_ABS, 0);
561 nc->prep (nc->prep_cls, NULL);
566 rowid = sqlite3_column_int64 (nc->stmt, 7);
567 nc->last_rowid = rowid;
568 type = sqlite3_column_int (nc->stmt, 1);
569 size = sqlite3_column_bytes (nc->stmt, 6);
570 if (sqlite3_column_bytes (nc->stmt, 5) != sizeof (GNUNET_HashCode))
572 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
574 _("Invalid data in database. Trying to fix (by deletion).\n"));
575 if (SQLITE_OK != sqlite3_reset (nc->stmt))
576 LOG_SQLITE (nc->plugin, NULL,
577 GNUNET_ERROR_TYPE_ERROR |
578 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
581 "DELETE FROM gn080 WHERE NOT LENGTH(hash) = ?",
582 &stmtd) != SQLITE_OK)
584 LOG_SQLITE (nc->plugin, NULL,
585 GNUNET_ERROR_TYPE_ERROR |
586 GNUNET_ERROR_TYPE_BULK,
591 if (SQLITE_OK != sqlite3_bind_int (stmtd, 1, sizeof (GNUNET_HashCode)))
592 LOG_SQLITE (nc->plugin, NULL,
593 GNUNET_ERROR_TYPE_ERROR |
594 GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_int");
595 if (SQLITE_DONE != sqlite3_step (stmtd))
596 LOG_SQLITE (nc->plugin, NULL,
597 GNUNET_ERROR_TYPE_ERROR |
598 GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
599 if (SQLITE_OK != sqlite3_finalize (stmtd))
600 LOG_SQLITE (nc->plugin, NULL,
601 GNUNET_ERROR_TYPE_ERROR |
602 GNUNET_ERROR_TYPE_BULK, "sqlite3_finalize");
606 priority = sqlite3_column_int (nc->stmt, 2);
607 anonymity = sqlite3_column_int (nc->stmt, 3);
608 expiration.abs_value = sqlite3_column_int64 (nc->stmt, 4);
609 key = sqlite3_column_blob (nc->stmt, 5);
610 nc->lastPriority = priority;
611 nc->lastExpiration = expiration;
612 memcpy (&nc->lastKey, key, sizeof(GNUNET_HashCode));
613 data = sqlite3_column_blob (nc->stmt, 6);
615 ret = nc->iter (nc->iter_cls,
625 if (ret == GNUNET_SYSERR)
627 nc->end_it = GNUNET_YES;
631 if (ret == GNUNET_NO)
632 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
634 "Asked to remove entry %llu (%u bytes)\n",
635 (unsigned long long) rowid,
636 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
638 if ( (ret == GNUNET_NO) &&
639 (GNUNET_OK == delete_by_rowid (plugin, rowid)) )
641 plugin->env->duc (plugin->env->cls,
642 - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
644 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
646 "Removed entry %llu (%u bytes)\n",
647 (unsigned long long) rowid,
648 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
655 * Function invoked on behalf of a "PluginIterator"
656 * asking the database plugin to call the iterator
657 * with the next item.
659 * @param next_cls whatever argument was given
660 * to the PluginIterator as "next_cls".
661 * @param end_it set to GNUNET_YES if we
662 * should terminate the iteration early
663 * (iterator should be still called once more
664 * to signal the end of the iteration).
667 sqlite_next_request (void *next_cls,
670 struct NextContext * nc= next_cls;
672 if (GNUNET_YES == end_it)
673 nc->end_it = GNUNET_YES;
674 nc->plugin->next_task_nc = nc;
675 nc->plugin->next_task = GNUNET_SCHEDULER_add_now (&sqlite_next_request_cont,
682 * Store an item in the datastore.
685 * @param key key for the item
686 * @param size number of bytes in data
687 * @param data content stored
688 * @param type type of the content
689 * @param priority priority of the content
690 * @param anonymity anonymity-level for the content
691 * @param expiration expiration time for the content
692 * @param msg set to an error message
693 * @return GNUNET_OK on success
696 sqlite_plugin_put (void *cls,
697 const GNUNET_HashCode * key,
700 enum GNUNET_BLOCK_Type type,
703 struct GNUNET_TIME_Absolute expiration,
706 struct Plugin *plugin = cls;
709 GNUNET_HashCode vhash;
712 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
714 "Storing in database block with type %u/key `%s'/priority %u/expiration %llu (%lld).\n",
718 (unsigned long long) GNUNET_TIME_absolute_get_remaining (expiration).rel_value,
719 (long long) expiration.abs_value);
721 GNUNET_CRYPTO_hash (data, size, &vhash);
722 stmt = plugin->insertContent;
723 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, size)) ||
724 (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) ||
725 (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) ||
726 (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) ||
727 (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, expiration.abs_value)) ||
729 sqlite3_bind_blob (stmt, 6, key, sizeof (GNUNET_HashCode),
730 SQLITE_TRANSIENT)) ||
732 sqlite3_bind_blob (stmt, 7, &vhash, sizeof (GNUNET_HashCode),
735 sqlite3_bind_blob (stmt, 8, data, size,
740 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
741 if (SQLITE_OK != sqlite3_reset (stmt))
742 LOG_SQLITE (plugin, NULL,
743 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
744 return GNUNET_SYSERR;
746 n = sqlite3_step (stmt);
747 if (n != SQLITE_DONE)
749 if (n == SQLITE_BUSY)
751 LOG_SQLITE (plugin, msg,
752 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
753 sqlite3_reset (stmt);
757 LOG_SQLITE (plugin, msg,
758 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
759 sqlite3_reset (stmt);
760 database_shutdown (plugin);
761 database_setup (plugin->env->cfg,
763 return GNUNET_SYSERR;
765 if (SQLITE_OK != sqlite3_reset (stmt))
766 LOG_SQLITE (plugin, NULL,
767 GNUNET_ERROR_TYPE_ERROR |
768 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
769 plugin->env->duc (plugin->env->cls,
770 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
772 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
774 "Stored new entry (%u bytes)\n",
775 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
782 * Update the priority for a particular key in the datastore. If
783 * the expiration time in value is different than the time found in
784 * the datastore, the higher value should be kept. For the
785 * anonymity level, the lower value is to be used. The specified
786 * priority should be added to the existing priority, ignoring the
789 * Note that it is possible for multiple values to match this put.
790 * In that case, all of the respective values are updated.
792 * @param cls the plugin context (state for this module)
793 * @param uid unique identifier of the datum
794 * @param delta by how much should the priority
795 * change? If priority + delta < 0 the
796 * priority should be set to 0 (never go
798 * @param expire new expiration time should be the
799 * MAX of any existing expiration time and
801 * @param msg set to an error message
802 * @return GNUNET_OK on success
805 sqlite_plugin_update (void *cls,
807 int delta, struct GNUNET_TIME_Absolute expire,
810 struct Plugin *plugin = cls;
813 sqlite3_bind_int (plugin->updPrio, 1, delta);
814 sqlite3_bind_int64 (plugin->updPrio, 2, expire.abs_value);
815 sqlite3_bind_int64 (plugin->updPrio, 3, uid);
816 n = sqlite3_step (plugin->updPrio);
817 if (n != SQLITE_DONE)
818 LOG_SQLITE (plugin, msg,
819 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
823 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
827 sqlite3_reset (plugin->updPrio);
829 if (n == SQLITE_BUSY)
831 return n == SQLITE_DONE ? GNUNET_OK : GNUNET_SYSERR;
836 * Internal context for an iteration.
843 sqlite3_stmt *stmt_1;
848 sqlite3_stmt *stmt_2;
868 int limit_nonanonymous;
871 * Desired type for blocks returned by this iterator.
873 enum GNUNET_BLOCK_Type type;
878 * Prepare our SQL query to obtain the next record from the database.
880 * @param cls our "struct IterContext"
881 * @param nc NULL to terminate the iteration, otherwise our context for
882 * getting the next result.
883 * @return GNUNET_OK on success, GNUNET_NO if there are no more results,
884 * GNUNET_SYSERR on error (or end of iteration)
887 iter_next_prepare (void *cls,
888 struct NextContext *nc)
890 struct IterContext *ic = cls;
891 struct Plugin *plugin;
897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
898 "Asked to clean up iterator state.\n");
900 sqlite3_finalize (ic->stmt_1);
901 sqlite3_finalize (ic->stmt_2);
902 return GNUNET_SYSERR;
904 sqlite3_reset (ic->stmt_1);
905 sqlite3_reset (ic->stmt_2);
910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
911 "Restricting to results larger than the last priority %u\n",
914 sqlite3_bind_int (ic->stmt_1, 1, nc->lastPriority);
915 sqlite3_bind_int (ic->stmt_2, 1, nc->lastPriority);
920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 "Restricting to results larger than the last expiration %llu\n",
922 (unsigned long long) nc->lastExpiration.abs_value);
924 sqlite3_bind_int64 (ic->stmt_1, 1, nc->lastExpiration.abs_value);
925 sqlite3_bind_int64 (ic->stmt_2, 1, nc->lastExpiration.abs_value);
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
929 "Restricting to results larger than the last key `%s'\n",
930 GNUNET_h2s(&nc->lastKey));
932 sqlite3_bind_blob (ic->stmt_1, 2,
934 sizeof (GNUNET_HashCode),
936 if (SQLITE_ROW == (ret = sqlite3_step (ic->stmt_1)))
939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
940 "Result found using iterator 1\n");
942 nc->stmt = ic->stmt_1;
945 if (ret != SQLITE_DONE)
947 LOG_SQLITE (plugin, NULL,
948 GNUNET_ERROR_TYPE_ERROR |
949 GNUNET_ERROR_TYPE_BULK,
951 return GNUNET_SYSERR;
953 if (SQLITE_OK != sqlite3_reset (ic->stmt_1))
954 LOG_SQLITE (plugin, NULL,
955 GNUNET_ERROR_TYPE_ERROR |
956 GNUNET_ERROR_TYPE_BULK,
958 if (SQLITE_ROW == (ret = sqlite3_step (ic->stmt_2)))
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "Result found using iterator 2\n");
964 nc->stmt = ic->stmt_2;
967 if (ret != SQLITE_DONE)
969 LOG_SQLITE (plugin, NULL,
970 GNUNET_ERROR_TYPE_ERROR |
971 GNUNET_ERROR_TYPE_BULK,
973 return GNUNET_SYSERR;
975 if (SQLITE_OK != sqlite3_reset (ic->stmt_2))
976 LOG_SQLITE (plugin, NULL,
977 GNUNET_ERROR_TYPE_ERROR |
978 GNUNET_ERROR_TYPE_BULK,
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "No result found using either iterator\n");
989 * Call a method for each key in the database and
990 * call the callback method on it.
992 * @param plugin our plugin context
993 * @param type entries of which type should be considered?
994 * @param is_asc are we iterating in ascending order?
995 * @param is_prio are we iterating by priority (otherwise by expiration)
996 * @param is_migr are we iterating in migration order?
997 * @param limit_nonanonymous are we restricting results to those with anonymity
999 * @param stmt_str_1 first SQL statement to execute
1000 * @param stmt_str_2 SQL statement to execute to get "more" results (inner iteration)
1001 * @param iter function to call on each matching value;
1002 * will be called once with a NULL value at the end
1003 * @param iter_cls closure for iter
1006 basic_iter (struct Plugin *plugin,
1007 enum GNUNET_BLOCK_Type type,
1011 int limit_nonanonymous,
1012 const char *stmt_str_1,
1013 const char *stmt_str_2,
1014 PluginIterator iter,
1017 struct NextContext *nc;
1018 struct IterContext *ic;
1019 sqlite3_stmt *stmt_1;
1020 sqlite3_stmt *stmt_2;
1023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1024 "At %llu, using queries `%s' and `%s'\n",
1025 (unsigned long long) GNUNET_TIME_absolute_get ().abs_value,
1029 if (sq_prepare (plugin->dbh, stmt_str_1, &stmt_1) != SQLITE_OK)
1031 LOG_SQLITE (plugin, NULL,
1032 GNUNET_ERROR_TYPE_ERROR |
1033 GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare_v2");
1034 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1037 if (sq_prepare (plugin->dbh, stmt_str_2, &stmt_2) != SQLITE_OK)
1039 LOG_SQLITE (plugin, NULL,
1040 GNUNET_ERROR_TYPE_ERROR |
1041 GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare_v2");
1042 sqlite3_finalize (stmt_1);
1043 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1046 nc = GNUNET_malloc (sizeof(struct NextContext) +
1047 sizeof(struct IterContext));
1048 nc->plugin = plugin;
1050 nc->iter_cls = iter_cls;
1052 ic = (struct IterContext*) &nc[1];
1053 ic->stmt_1 = stmt_1;
1054 ic->stmt_2 = stmt_2;
1056 ic->is_asc = is_asc;
1057 ic->is_prio = is_prio;
1058 ic->is_migr = is_migr;
1059 ic->limit_nonanonymous = limit_nonanonymous;
1060 nc->prep = &iter_next_prepare;
1064 nc->lastPriority = 0;
1065 nc->lastExpiration.abs_value = 0;
1066 memset (&nc->lastKey, 0, sizeof (GNUNET_HashCode));
1070 nc->lastPriority = 0x7FFFFFFF;
1071 nc->lastExpiration.abs_value = 0x7FFFFFFFFFFFFFFFLL;
1072 memset (&nc->lastKey, 255, sizeof (GNUNET_HashCode));
1074 sqlite_next_request (nc, GNUNET_NO);
1079 * Select a subset of the items in the datastore and call
1080 * the given iterator for each of them.
1082 * @param cls our plugin context
1083 * @param type entries of which type should be considered?
1084 * Use 0 for any type.
1085 * @param iter function to call on each matching value;
1086 * will be called once with a NULL value at the end
1087 * @param iter_cls closure for iter
1090 sqlite_plugin_iter_low_priority (void *cls,
1091 enum GNUNET_BLOCK_Type type,
1092 PluginIterator iter,
1097 GNUNET_YES, GNUNET_YES,
1098 GNUNET_NO, GNUNET_NO,
1099 SELECT_IT_LOW_PRIORITY_1,
1100 SELECT_IT_LOW_PRIORITY_2,
1106 * Select a subset of the items in the datastore and call
1107 * the given iterator for each of them.
1109 * @param cls our plugin context
1110 * @param type entries of which type should be considered?
1111 * Use 0 for any type.
1112 * @param iter function to call on each matching value;
1113 * will be called once with a NULL value at the end
1114 * @param iter_cls closure for iter
1117 sqlite_plugin_iter_zero_anonymity (void *cls,
1118 enum GNUNET_BLOCK_Type type,
1119 PluginIterator iter,
1122 struct GNUNET_TIME_Absolute now;
1126 now = GNUNET_TIME_absolute_get ();
1127 GNUNET_asprintf (&q1, SELECT_IT_NON_ANONYMOUS_1,
1128 (unsigned long long) now.abs_value);
1129 GNUNET_asprintf (&q2, SELECT_IT_NON_ANONYMOUS_2,
1130 (unsigned long long) now.abs_value);
1133 GNUNET_NO, GNUNET_YES,
1134 GNUNET_NO, GNUNET_YES,
1145 * Select a subset of the items in the datastore and call
1146 * the given iterator for each of them.
1148 * @param cls our plugin context
1149 * @param type entries of which type should be considered?
1150 * Use 0 for any type.
1151 * @param iter function to call on each matching value;
1152 * will be called once with a NULL value at the end
1153 * @param iter_cls closure for iter
1156 sqlite_plugin_iter_ascending_expiration (void *cls,
1157 enum GNUNET_BLOCK_Type type,
1158 PluginIterator iter,
1161 struct GNUNET_TIME_Absolute now;
1165 now = GNUNET_TIME_absolute_get ();
1166 GNUNET_asprintf (&q1, SELECT_IT_EXPIRATION_TIME_1,
1167 (unsigned long long) 0*now.abs_value);
1168 GNUNET_asprintf (&q2, SELECT_IT_EXPIRATION_TIME_2,
1169 (unsigned long long) 0*now.abs_value);
1172 GNUNET_YES, GNUNET_NO,
1173 GNUNET_NO, GNUNET_NO,
1182 * Select a subset of the items in the datastore and call
1183 * the given iterator for each of them.
1185 * @param cls our plugin context
1186 * @param type entries of which type should be considered?
1187 * Use 0 for any type.
1188 * @param iter function to call on each matching value;
1189 * will be called once with a NULL value at the end
1190 * @param iter_cls closure for iter
1193 sqlite_plugin_iter_migration_order (void *cls,
1194 enum GNUNET_BLOCK_Type type,
1195 PluginIterator iter,
1198 struct GNUNET_TIME_Absolute now;
1201 now = GNUNET_TIME_absolute_get ();
1202 GNUNET_asprintf (&q, SELECT_IT_MIGRATION_ORDER_2,
1203 (unsigned long long) now.abs_value);
1206 GNUNET_NO, GNUNET_NO,
1207 GNUNET_YES, GNUNET_NO,
1208 SELECT_IT_MIGRATION_ORDER_1,
1216 * Call sqlite using the already prepared query to get
1219 * @param cls context with the prepared query
1220 * @param nc context with the prepared query
1221 * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if
1222 * there are no more results
1225 all_next_prepare (void *cls,
1226 struct NextContext *nc)
1228 struct Plugin *plugin;
1234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1235 "Asked to clean up iterator state.\n");
1237 nc = (struct NextContext *)cls;
1239 sqlite3_finalize (nc->stmt);
1241 return GNUNET_SYSERR;
1243 plugin = nc->plugin;
1244 if (SQLITE_ROW == (ret = sqlite3_step (nc->stmt)))
1248 if (ret != SQLITE_DONE)
1250 LOG_SQLITE (plugin, NULL,
1251 GNUNET_ERROR_TYPE_ERROR |
1252 GNUNET_ERROR_TYPE_BULK,
1254 return GNUNET_SYSERR;
1261 * Select a subset of the items in the datastore and call
1262 * the given iterator for each of them.
1264 * @param cls our plugin context
1265 * @param type entries of which type should be considered?
1266 * Use 0 for any type.
1267 * @param iter function to call on each matching value;
1268 * will be called once with a NULL value at the end
1269 * @param iter_cls closure for iter
1272 sqlite_plugin_iter_all_now (void *cls,
1273 enum GNUNET_BLOCK_Type type,
1274 PluginIterator iter,
1277 struct Plugin *plugin = cls;
1278 struct NextContext *nc;
1281 if (sq_prepare (plugin->dbh,
1282 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080",
1283 &stmt) != SQLITE_OK)
1285 LOG_SQLITE (plugin, NULL,
1286 GNUNET_ERROR_TYPE_ERROR |
1287 GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare_v2");
1288 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1291 nc = GNUNET_malloc (sizeof(struct NextContext));
1292 nc->plugin = plugin;
1294 nc->iter_cls = iter_cls;
1296 nc->prep = &all_next_prepare;
1298 sqlite_next_request (nc, GNUNET_NO);
1305 struct GetNextContext
1336 GNUNET_HashCode key;
1341 GNUNET_HashCode vhash;
1349 * @param cls our "struct GetNextContext*"
1351 * @return GNUNET_YES if there are more results,
1352 * GNUNET_NO if there are no more results,
1353 * GNUNET_SYSERR on internal error
1356 get_next_prepare (void *cls,
1357 struct NextContext *nc)
1359 struct GetNextContext *gnc = cls;
1366 sqlite3_finalize (gnc->stmt);
1367 return GNUNET_SYSERR;
1369 if (nc->count == gnc->total)
1371 if (nc->count + gnc->off == gnc->total)
1374 limit_off = gnc->off;
1378 sqlite3_reset (nc->stmt);
1379 ret = sqlite3_bind_blob (nc->stmt,
1382 sizeof (GNUNET_HashCode),
1384 if ((gnc->have_vhash) && (ret == SQLITE_OK))
1385 ret = sqlite3_bind_blob (nc->stmt,
1388 sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
1389 if ((gnc->type != 0) && (ret == SQLITE_OK))
1390 ret = sqlite3_bind_int (nc->stmt, sqoff++, gnc->type);
1391 if (ret == SQLITE_OK)
1392 ret = sqlite3_bind_int64 (nc->stmt, sqoff++, nc->last_rowid + 1);
1393 if (ret == SQLITE_OK)
1394 ret = sqlite3_bind_int (nc->stmt, sqoff++, limit_off);
1395 if (ret != SQLITE_OK)
1396 return GNUNET_SYSERR;
1397 if (SQLITE_ROW != sqlite3_step (nc->stmt))
1404 * Iterate over the results for a particular key
1407 * @param cls closure
1408 * @param key maybe NULL (to match all entries)
1409 * @param vhash hash of the value, maybe NULL (to
1410 * match all values that have the right key).
1411 * Note that for DBlocks there is no difference
1412 * betwen key and vhash, but for other blocks
1414 * @param type entries of which type are relevant?
1415 * Use 0 for any type.
1416 * @param iter function to call on each matching value;
1417 * will be called once with a NULL value at the end
1418 * @param iter_cls closure for iter
1421 sqlite_plugin_get (void *cls,
1422 const GNUNET_HashCode * key,
1423 const GNUNET_HashCode * vhash,
1424 enum GNUNET_BLOCK_Type type,
1425 PluginIterator iter, void *iter_cls)
1427 struct Plugin *plugin = cls;
1428 struct GetNextContext *gpc;
1429 struct NextContext *nc;
1436 GNUNET_assert (iter != NULL);
1439 sqlite_plugin_iter_low_priority (cls, type, iter, iter_cls);
1442 GNUNET_snprintf (scratch, sizeof (scratch),
1443 "SELECT count(*) FROM gn080 WHERE hash=:1%s%s",
1444 vhash == NULL ? "" : " AND vhash=:2",
1445 type == 0 ? "" : (vhash ==
1446 NULL) ? " AND type=:2" : " AND type=:3");
1447 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
1449 LOG_SQLITE (plugin, NULL,
1450 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
1451 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1455 ret = sqlite3_bind_blob (stmt,
1457 key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
1458 if ((vhash != NULL) && (ret == SQLITE_OK))
1459 ret = sqlite3_bind_blob (stmt,
1462 sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
1463 if ((type != 0) && (ret == SQLITE_OK))
1464 ret = sqlite3_bind_int (stmt, sqoff++, type);
1465 if (SQLITE_OK != ret)
1467 LOG_SQLITE (plugin, NULL,
1468 GNUNET_ERROR_TYPE_ERROR, "sqlite_bind");
1469 sqlite3_reset (stmt);
1470 sqlite3_finalize (stmt);
1471 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1474 ret = sqlite3_step (stmt);
1475 if (ret != SQLITE_ROW)
1477 LOG_SQLITE (plugin, NULL,
1478 GNUNET_ERROR_TYPE_ERROR| GNUNET_ERROR_TYPE_BULK,
1480 sqlite3_reset (stmt);
1481 sqlite3_finalize (stmt);
1482 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1485 total = sqlite3_column_int (stmt, 0);
1486 sqlite3_reset (stmt);
1487 sqlite3_finalize (stmt);
1490 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1494 GNUNET_snprintf (scratch, sizeof (scratch),
1495 "SELECT size, type, prio, anonLevel, expire, hash, value, _ROWID_ "
1496 "FROM gn080 WHERE hash=:1%s%s AND _ROWID_ >= :%d "
1497 "ORDER BY _ROWID_ ASC LIMIT 1 OFFSET :d",
1498 vhash == NULL ? "" : " AND vhash=:2",
1499 type == 0 ? "" : (vhash ==
1500 NULL) ? " AND type=:2" : " AND type=:3",
1502 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
1504 LOG_SQLITE (plugin, NULL,
1505 GNUNET_ERROR_TYPE_ERROR |
1506 GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
1507 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1510 nc = GNUNET_malloc (sizeof(struct NextContext) +
1511 sizeof(struct GetNextContext));
1512 nc->plugin = plugin;
1514 nc->iter_cls = iter_cls;
1516 gpc = (struct GetNextContext*) &nc[1];
1520 gpc->stmt = stmt; /* alias used for freeing at the end! */
1523 gpc->have_vhash = GNUNET_YES;
1524 gpc->vhash = *vhash;
1526 gpc->off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
1527 nc->prep = &get_next_prepare;
1529 sqlite_next_request (nc, GNUNET_NO);
1536 * @param cls our plugin context
1539 sqlite_plugin_drop (void *cls)
1541 struct Plugin *plugin = cls;
1542 plugin->drop_on_shutdown = GNUNET_YES;
1546 static unsigned long long
1547 sqlite_plugin_get_size (void *cls)
1549 struct Plugin *plugin = cls;
1557 if (SQLITE_VERSION_NUMBER < 3006000)
1559 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
1561 _("sqlite version to old to determine size, assuming zero\n"));
1565 sqlite3_exec (plugin->dbh,
1566 "VACUUM", NULL, NULL, ENULL));
1568 sqlite3_exec (plugin->dbh,
1569 "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
1571 sq_prepare (plugin->dbh,
1572 "PRAGMA page_count",
1575 sqlite3_step (stmt))
1576 pages = sqlite3_column_int64 (stmt, 0);
1579 sqlite3_finalize (stmt);
1581 sq_prepare (plugin->dbh,
1584 CHECK (SQLITE_ROW ==
1585 sqlite3_step (stmt));
1586 page_size = sqlite3_column_int64 (stmt, 0);
1587 sqlite3_finalize (stmt);
1588 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1589 _("Using sqlite page utilization to estimate payload (%llu pages of size %llu bytes)\n"),
1590 (unsigned long long) pages,
1591 (unsigned long long) page_size);
1592 return pages * page_size;
1597 * Entry point for the plugin.
1599 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
1600 * @return NULL on error, othrewise the plugin context
1603 libgnunet_plugin_datastore_sqlite_init (void *cls)
1605 static struct Plugin plugin;
1606 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
1607 struct GNUNET_DATASTORE_PluginFunctions *api;
1609 if (plugin.env != NULL)
1610 return NULL; /* can only initialize once! */
1611 memset (&plugin, 0, sizeof(struct Plugin));
1614 database_setup (env->cfg, &plugin))
1616 database_shutdown (&plugin);
1619 api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
1621 api->get_size = &sqlite_plugin_get_size;
1622 api->put = &sqlite_plugin_put;
1623 api->next_request = &sqlite_next_request;
1624 api->get = &sqlite_plugin_get;
1625 api->update = &sqlite_plugin_update;
1626 api->iter_low_priority = &sqlite_plugin_iter_low_priority;
1627 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity;
1628 api->iter_ascending_expiration = &sqlite_plugin_iter_ascending_expiration;
1629 api->iter_migration_order = &sqlite_plugin_iter_migration_order;
1630 api->iter_all_now = &sqlite_plugin_iter_all_now;
1631 api->drop = &sqlite_plugin_drop;
1632 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1633 "sqlite", _("Sqlite database running\n"));
1639 * Exit point from the plugin.
1641 * @param cls the plugin context (as returned by "init")
1642 * @return always NULL
1645 libgnunet_plugin_datastore_sqlite_done (void *cls)
1648 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1649 struct Plugin *plugin = api->cls;
1652 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1654 "sqlite plugin is doneing\n");
1657 if (plugin->next_task != GNUNET_SCHEDULER_NO_TASK)
1660 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1662 "Canceling next task\n");
1664 GNUNET_SCHEDULER_cancel (plugin->next_task);
1665 plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
1667 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1669 "Prep'ing next task\n");
1671 plugin->next_task_nc->prep (plugin->next_task_nc->prep_cls, NULL);
1672 GNUNET_free (plugin->next_task_nc);
1673 plugin->next_task_nc = NULL;
1676 if (plugin->drop_on_shutdown)
1677 fn = GNUNET_strdup (plugin->fn);
1679 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1681 "Shutting down database\n");
1683 database_shutdown (plugin);
1688 if (0 != UNLINK(fn))
1689 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1695 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1697 "sqlite plugin is finished doneing\n");
1702 /* end of plugin_datastore_sqlite.c */