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 2, 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_statistics_service.h"
29 #include "plugin_datastore.h"
32 #define DEBUG_SQLITE GNUNET_YES
35 * After how many payload-changing operations
36 * do we sync our statistics?
38 #define MAX_STAT_SYNC_LAG 50
40 #define QUOTA_STAT_NAME gettext_noop ("# bytes used in file-sharing datastore")
43 * Log an error message at log-level 'level' that indicates
44 * a failure of the command 'cmd' on file 'filename'
45 * with the message given by strerror(errno).
47 #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 with error: %s"), cmd, sqlite3_errmsg(db->dbh)); } while(0)
49 #define SELECT_IT_LOW_PRIORITY_1 \
50 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio = ? AND hash > ?) "\
51 "ORDER BY hash ASC LIMIT 1"
53 #define SELECT_IT_LOW_PRIORITY_2 \
54 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio > ?) "\
55 "ORDER BY prio ASC, hash ASC LIMIT 1"
57 #define SELECT_IT_NON_ANONYMOUS_1 \
58 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio = ? AND hash < ? AND anonLevel = 0 AND expire > %llu) "\
59 " ORDER BY hash DESC LIMIT 1"
61 #define SELECT_IT_NON_ANONYMOUS_2 \
62 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (prio < ? AND anonLevel = 0 AND expire > %llu)"\
63 " ORDER BY prio DESC, hash DESC LIMIT 1"
65 #define SELECT_IT_EXPIRATION_TIME_1 \
66 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire = ? AND hash > ?) "\
67 " ORDER BY hash ASC LIMIT 1"
69 #define SELECT_IT_EXPIRATION_TIME_2 \
70 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire > ?) "\
71 " ORDER BY expire ASC, hash ASC LIMIT 1"
73 #define SELECT_IT_MIGRATION_ORDER_1 \
74 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire = ? AND hash < ?) "\
75 " ORDER BY hash DESC LIMIT 1"
77 #define SELECT_IT_MIGRATION_ORDER_2 \
78 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080 WHERE (expire < ? AND expire > %llu) "\
79 " ORDER BY expire DESC, hash DESC LIMIT 1"
82 * After how many ms "busy" should a DB operation fail for good?
83 * A low value makes sure that we are more responsive to requests
84 * (especially PUTs). A high value guarantees a higher success
85 * rate (SELECTs in iterate can take several seconds despite LIMIT=1).
87 * The default value of 250ms should ensure that users do not experience
88 * huge latencies while at the same time allowing operations to succeed
89 * with reasonable probability.
91 #define BUSY_TIMEOUT_MS 250
96 * Context for all functions in this plugin.
101 * Our execution environment.
103 struct GNUNET_DATASTORE_PluginEnvironment *env;
111 * Native SQLite database handle.
116 * Precompiled SQL for update.
118 sqlite3_stmt *updPrio;
121 * Precompiled SQL for insertion.
123 sqlite3_stmt *insertContent;
126 * Handle to the statistics service.
128 struct GNUNET_STATISTICS_Handle *statistics;
131 * Handle for pending get request.
133 struct GNUNET_STATISTICS_GetHandle *stat_get;
136 * Closure of the 'next_task' (must be freed if 'next_task' is cancelled).
138 struct NextContext *next_task_nc;
141 * Pending task with scheduler for running the next request.
143 GNUNET_SCHEDULER_TaskIdentifier next_task;
146 * How much data are we currently storing
149 unsigned long long payload;
152 * Number of updates that were made to the
153 * payload value since we last synchronized
154 * it with the statistics service.
156 unsigned int lastSync;
159 * Should the database be dropped on shutdown?
161 int drop_on_shutdown;
164 * Did we get an answer from statistics?
171 * @brief Prepare a SQL statement
173 * @param dbh handle to the database
174 * @param zSql SQL statement, UTF-8 encoded
175 * @param ppStmt set to the prepared statement
176 * @return 0 on success
179 sq_prepare (sqlite3 * dbh, const char *zSql,
180 sqlite3_stmt ** ppStmt)
183 return sqlite3_prepare (dbh,
185 strlen (zSql), ppStmt, (const char **) &dummy);
190 * Create our database indices.
192 * @param dbh handle to the database
195 create_indices (sqlite3 * dbh)
199 "CREATE INDEX idx_hash ON gn080 (hash)", NULL, NULL, NULL);
201 "CREATE INDEX idx_hash_vhash ON gn080 (hash,vhash)", NULL,
203 sqlite3_exec (dbh, "CREATE INDEX idx_prio ON gn080 (prio)", NULL, NULL,
205 sqlite3_exec (dbh, "CREATE INDEX idx_expire ON gn080 (expire)", NULL, NULL,
207 sqlite3_exec (dbh, "CREATE INDEX idx_comb3 ON gn080 (prio,anonLevel)", NULL,
209 sqlite3_exec (dbh, "CREATE INDEX idx_comb4 ON gn080 (prio,hash,anonLevel)",
211 sqlite3_exec (dbh, "CREATE INDEX idx_comb7 ON gn080 (expire,hash)", NULL,
218 #define CHECK(a) GNUNET_break(a)
222 #define ENULL_DEFINED 1
223 #define CHECK(a) if (! a) { GNUNET_log(GNUNET_ERROR_TYPE_ERRROR, "%s\n", e); sqlite3_free(e); }
230 * Initialize the database connections and associated
231 * data structures (create tables and indices
232 * as needed as well).
234 * @param cfg our configuration
235 * @param plugin the plugin context (state for this module)
236 * @return GNUNET_OK on success
239 database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg,
240 struct Plugin *plugin)
249 GNUNET_CONFIGURATION_get_value_filename (cfg,
254 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
256 _("Option `%s' in section `%s' missing in configuration!\n"),
259 return GNUNET_SYSERR;
261 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir))
264 GNUNET_free (afsdir);
265 return GNUNET_SYSERR;
267 plugin->fn = GNUNET_STRINGS_to_utf8 (afsdir, strlen (afsdir),
269 nl_langinfo (CODESET)
271 "UTF-8" /* good luck */
274 GNUNET_free (afsdir);
276 /* Open database and precompile statements */
277 if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
279 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
281 _("Unable to initialize SQLite: %s.\n"),
282 sqlite3_errmsg (plugin->dbh));
283 return GNUNET_SYSERR;
286 sqlite3_exec (plugin->dbh,
287 "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL));
289 sqlite3_exec (plugin->dbh,
290 "PRAGMA synchronous=OFF", NULL, NULL, ENULL));
292 sqlite3_exec (plugin->dbh,
293 "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL));
295 sqlite3_exec (plugin->dbh,
296 "PRAGMA count_changes=OFF", NULL, NULL, ENULL));
298 sqlite3_exec (plugin->dbh,
299 "PRAGMA page_size=4092", NULL, NULL, ENULL));
301 CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS));
304 /* We have to do it here, because otherwise precompiling SQL might fail */
306 sq_prepare (plugin->dbh,
307 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn080'",
309 if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
310 (sqlite3_exec (plugin->dbh,
311 "CREATE TABLE gn080 ("
312 " size INT4 NOT NULL DEFAULT 0,"
313 " type INT4 NOT NULL DEFAULT 0,"
314 " prio INT4 NOT NULL DEFAULT 0,"
315 " anonLevel INT4 NOT NULL DEFAULT 0,"
316 " expire INT8 NOT NULL DEFAULT 0,"
317 " hash TEXT NOT NULL DEFAULT '',"
318 " vhash TEXT NOT NULL DEFAULT '',"
319 " value BLOB NOT NULL DEFAULT '')", NULL, NULL,
320 NULL) != SQLITE_OK) )
322 LOG_SQLITE (plugin, NULL,
323 GNUNET_ERROR_TYPE_ERROR,
325 sqlite3_finalize (stmt);
326 return GNUNET_SYSERR;
328 sqlite3_finalize (stmt);
329 create_indices (plugin->dbh);
332 sq_prepare (plugin->dbh,
333 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'gn071'",
335 if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
336 (sqlite3_exec (plugin->dbh,
337 "CREATE TABLE gn071 ("
338 " key TEXT NOT NULL DEFAULT '',"
339 " value INTEGER NOT NULL DEFAULT 0)", NULL, NULL,
340 NULL) != SQLITE_OK) )
342 LOG_SQLITE (plugin, NULL,
343 GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
344 sqlite3_finalize (stmt);
345 return GNUNET_SYSERR;
347 sqlite3_finalize (stmt);
349 if ((sq_prepare (plugin->dbh,
350 "UPDATE gn080 SET prio = prio + ?, expire = MAX(expire,?) WHERE "
352 &plugin->updPrio) != SQLITE_OK) ||
353 (sq_prepare (plugin->dbh,
354 "INSERT INTO gn080 (size, type, prio, "
355 "anonLevel, expire, hash, vhash, value) VALUES "
356 "(?, ?, ?, ?, ?, ?, ?, ?)",
357 &plugin->insertContent) != SQLITE_OK))
359 LOG_SQLITE (plugin, NULL,
360 GNUNET_ERROR_TYPE_ERROR, "precompiling");
361 return GNUNET_SYSERR;
368 * Synchronize our utilization statistics with the
369 * statistics service.
370 * @param plugin the plugin context (state for this module)
373 sync_stats (struct Plugin *plugin)
375 GNUNET_STATISTICS_set (plugin->statistics,
379 plugin->lastSync = 0;
384 * Shutdown database connection and associate data
386 * @param plugin the plugin context (state for this module)
389 database_shutdown (struct Plugin *plugin)
391 if (plugin->lastSync > 0)
393 if (plugin->updPrio != NULL)
394 sqlite3_finalize (plugin->updPrio);
395 if (plugin->insertContent != NULL)
396 sqlite3_finalize (plugin->insertContent);
397 sqlite3_close (plugin->dbh);
398 GNUNET_free_non_null (plugin->fn);
403 * Get an estimate of how much space the database is
406 * @param cls our plugin context
407 * @return number of bytes used on disk
409 static unsigned long long sqlite_plugin_get_size (void *cls)
411 struct Plugin *plugin = cls;
412 return plugin->payload;
417 * Delete the database entry with the given
420 * @param plugin the plugin context (state for this module)
421 * @param rid the ID of the row to delete
424 delete_by_rowid (struct Plugin* plugin,
425 unsigned long long rid)
429 if (sq_prepare (plugin->dbh,
430 "DELETE FROM gn080 WHERE _ROWID_ = ?", &stmt) != SQLITE_OK)
432 LOG_SQLITE (plugin, NULL,
433 GNUNET_ERROR_TYPE_ERROR |
434 GNUNET_ERROR_TYPE_BULK, "sq_prepare");
435 return GNUNET_SYSERR;
437 sqlite3_bind_int64 (stmt, 1, rid);
438 if (SQLITE_DONE != sqlite3_step (stmt))
440 LOG_SQLITE (plugin, NULL,
441 GNUNET_ERROR_TYPE_ERROR |
442 GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
443 sqlite3_finalize (stmt);
444 return GNUNET_SYSERR;
446 sqlite3_finalize (stmt);
452 * Context for the universal iterator.
457 * Type of a function that will prepare
458 * the next iteration.
461 * @param nc the next context; NULL for the last
462 * call which gives the callback a chance to
463 * clean up the closure
464 * @return GNUNET_OK on success, GNUNET_NO if there are
465 * no more values, GNUNET_SYSERR on error
467 typedef int (*PrepareFunction)(void *cls,
468 struct NextContext *nc);
472 * Context we keep for the "next request" callback.
479 struct Plugin *plugin;
482 * Function to call on the next value.
492 * Function to call to prepare the next
495 PrepareFunction prep;
503 * Statement that the iterator will get the data
504 * from (updated or set by prep).
509 * Row ID of the last result.
511 unsigned long long last_rowid;
514 * Key of the last result.
516 GNUNET_HashCode lastKey;
519 * Expiration time of the last value visited.
521 struct GNUNET_TIME_Absolute lastExpiration;
524 * Priority of the last value visited.
526 unsigned int lastPriority;
529 * Number of results processed so far.
534 * Set to GNUNET_YES if we must stop now.
541 * Continuation of "sqlite_next_request".
543 * @param cls the next context
544 * @param tc the task context (unused)
547 sqlite_next_request_cont (void *cls,
548 const struct GNUNET_SCHEDULER_TaskContext *tc)
550 struct NextContext * nc = cls;
551 struct Plugin *plugin;
552 unsigned long long rowid;
557 unsigned int priority;
558 unsigned int anonymity;
559 struct GNUNET_TIME_Absolute expiration;
560 const GNUNET_HashCode *key;
564 plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
565 plugin->next_task_nc = NULL;
566 if ( (GNUNET_YES == nc->end_it) ||
567 (GNUNET_OK != (nc->prep(nc->prep_cls,
571 nc->iter (nc->iter_cls,
572 NULL, NULL, 0, NULL, 0, 0, 0,
573 GNUNET_TIME_UNIT_ZERO_ABS, 0);
574 nc->prep (nc->prep_cls, NULL);
579 rowid = sqlite3_column_int64 (nc->stmt, 7);
580 nc->last_rowid = rowid;
581 type = sqlite3_column_int (nc->stmt, 1);
582 size = sqlite3_column_bytes (nc->stmt, 6);
583 if (sqlite3_column_bytes (nc->stmt, 5) != sizeof (GNUNET_HashCode))
585 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
587 _("Invalid data in database. Trying to fix (by deletion).\n"));
588 if (SQLITE_OK != sqlite3_reset (nc->stmt))
589 LOG_SQLITE (nc->plugin, NULL,
590 GNUNET_ERROR_TYPE_ERROR |
591 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
594 "DELETE FROM gn080 WHERE NOT LENGTH(hash) = ?",
595 &stmtd) != SQLITE_OK)
597 LOG_SQLITE (nc->plugin, NULL,
598 GNUNET_ERROR_TYPE_ERROR |
599 GNUNET_ERROR_TYPE_BULK,
604 if (SQLITE_OK != sqlite3_bind_int (stmtd, 1, sizeof (GNUNET_HashCode)))
605 LOG_SQLITE (nc->plugin, NULL,
606 GNUNET_ERROR_TYPE_ERROR |
607 GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_int");
608 if (SQLITE_DONE != sqlite3_step (stmtd))
609 LOG_SQLITE (nc->plugin, NULL,
610 GNUNET_ERROR_TYPE_ERROR |
611 GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
612 if (SQLITE_OK != sqlite3_finalize (stmtd))
613 LOG_SQLITE (nc->plugin, NULL,
614 GNUNET_ERROR_TYPE_ERROR |
615 GNUNET_ERROR_TYPE_BULK, "sqlite3_finalize");
619 priority = sqlite3_column_int (nc->stmt, 2);
620 anonymity = sqlite3_column_int (nc->stmt, 3);
621 expiration.value = sqlite3_column_int64 (nc->stmt, 4);
622 key = sqlite3_column_blob (nc->stmt, 5);
623 nc->lastPriority = priority;
624 nc->lastExpiration = expiration;
625 memcpy (&nc->lastKey, key, sizeof(GNUNET_HashCode));
626 data = sqlite3_column_blob (nc->stmt, 6);
628 ret = nc->iter (nc->iter_cls,
638 if (ret == GNUNET_SYSERR)
640 nc->end_it = GNUNET_YES;
644 if (ret == GNUNET_NO)
645 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
647 "Asked to remove entry %llu (%u bytes)\n",
648 (unsigned long long) rowid,
649 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
651 if ( (ret == GNUNET_NO) &&
652 (GNUNET_OK == delete_by_rowid (plugin, rowid)) )
654 if (plugin->payload >= size + GNUNET_DATASTORE_ENTRY_OVERHEAD)
655 plugin->payload -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
657 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
658 _("Datastore payload inaccurate, please fix and restart!\n"));
661 if (ret == GNUNET_NO)
662 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
664 "Removed entry %llu (%u bytes), new payload is %llu\n",
665 (unsigned long long) rowid,
666 size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
669 if (plugin->lastSync >= MAX_STAT_SYNC_LAG)
676 * Function invoked on behalf of a "PluginIterator"
677 * asking the database plugin to call the iterator
678 * with the next item.
680 * @param next_cls whatever argument was given
681 * to the PluginIterator as "next_cls".
682 * @param end_it set to GNUNET_YES if we
683 * should terminate the iteration early
684 * (iterator should be still called once more
685 * to signal the end of the iteration).
688 sqlite_next_request (void *next_cls,
691 struct NextContext * nc= next_cls;
693 if (GNUNET_YES == end_it)
694 nc->end_it = GNUNET_YES;
695 nc->plugin->next_task_nc = nc;
696 nc->plugin->next_task = GNUNET_SCHEDULER_add_now (nc->plugin->env->sched,
697 &sqlite_next_request_cont,
704 * Store an item in the datastore.
707 * @param key key for the item
708 * @param size number of bytes in data
709 * @param data content stored
710 * @param type type of the content
711 * @param priority priority of the content
712 * @param anonymity anonymity-level for the content
713 * @param expiration expiration time for the content
714 * @param msg set to an error message
715 * @return GNUNET_OK on success
718 sqlite_plugin_put (void *cls,
719 const GNUNET_HashCode * key,
722 enum GNUNET_BLOCK_Type type,
725 struct GNUNET_TIME_Absolute expiration,
728 struct Plugin *plugin = cls;
731 GNUNET_HashCode vhash;
734 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
736 "Storing in database block with type %u/key `%s'/priority %u/expiration %llu (%lld).\n",
740 (unsigned long long) GNUNET_TIME_absolute_get_remaining (expiration).value,
741 (long long) expiration.value);
743 GNUNET_CRYPTO_hash (data, size, &vhash);
744 stmt = plugin->insertContent;
745 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, size)) ||
746 (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) ||
747 (SQLITE_OK != sqlite3_bind_int (stmt, 3, priority)) ||
748 (SQLITE_OK != sqlite3_bind_int (stmt, 4, anonymity)) ||
749 (SQLITE_OK != sqlite3_bind_int64 (stmt, 5, (sqlite3_int64) expiration.value)) ||
751 sqlite3_bind_blob (stmt, 6, key, sizeof (GNUNET_HashCode),
752 SQLITE_TRANSIENT)) ||
754 sqlite3_bind_blob (stmt, 7, &vhash, sizeof (GNUNET_HashCode),
757 sqlite3_bind_blob (stmt, 8, data, size,
762 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_XXXX");
763 if (SQLITE_OK != sqlite3_reset (stmt))
764 LOG_SQLITE (plugin, NULL,
765 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
766 return GNUNET_SYSERR;
768 n = sqlite3_step (stmt);
769 if (n != SQLITE_DONE)
771 if (n == SQLITE_BUSY)
773 LOG_SQLITE (plugin, msg,
774 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
775 sqlite3_reset (stmt);
779 LOG_SQLITE (plugin, msg,
780 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
781 sqlite3_reset (stmt);
782 return GNUNET_SYSERR;
784 if (SQLITE_OK != sqlite3_reset (stmt))
785 LOG_SQLITE (plugin, NULL,
786 GNUNET_ERROR_TYPE_ERROR |
787 GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
789 plugin->payload += size + GNUNET_DATASTORE_ENTRY_OVERHEAD;
791 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
793 "Stored new entry (%u bytes), new payload is %llu\n",
794 size + GNUNET_DATASTORE_ENTRY_OVERHEAD,
797 if (plugin->lastSync >= MAX_STAT_SYNC_LAG)
804 * Update the priority for a particular key in the datastore. If
805 * the expiration time in value is different than the time found in
806 * the datastore, the higher value should be kept. For the
807 * anonymity level, the lower value is to be used. The specified
808 * priority should be added to the existing priority, ignoring the
811 * Note that it is possible for multiple values to match this put.
812 * In that case, all of the respective values are updated.
814 * @param cls the plugin context (state for this module)
815 * @param uid unique identifier of the datum
816 * @param delta by how much should the priority
817 * change? If priority + delta < 0 the
818 * priority should be set to 0 (never go
820 * @param expire new expiration time should be the
821 * MAX of any existing expiration time and
823 * @param msg set to an error message
824 * @return GNUNET_OK on success
827 sqlite_plugin_update (void *cls,
829 int delta, struct GNUNET_TIME_Absolute expire,
832 struct Plugin *plugin = cls;
835 sqlite3_bind_int (plugin->updPrio, 1, delta);
836 sqlite3_bind_int64 (plugin->updPrio, 2, expire.value);
837 sqlite3_bind_int64 (plugin->updPrio, 3, uid);
838 n = sqlite3_step (plugin->updPrio);
839 if (n != SQLITE_DONE)
840 LOG_SQLITE (plugin, msg,
841 GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
845 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
849 sqlite3_reset (plugin->updPrio);
851 if (n == SQLITE_BUSY)
853 return n == SQLITE_DONE ? GNUNET_OK : GNUNET_SYSERR;
858 * Internal context for an iteration.
865 sqlite3_stmt *stmt_1;
870 sqlite3_stmt *stmt_2;
890 int limit_nonanonymous;
893 * Desired type for blocks returned by this iterator.
895 enum GNUNET_BLOCK_Type type;
900 * Prepare our SQL query to obtain the next record from the database.
902 * @param cls our "struct IterContext"
903 * @param nc NULL to terminate the iteration, otherwise our context for
904 * getting the next result.
905 * @return GNUNET_OK on success, GNUNET_NO if there are no more results,
906 * GNUNET_SYSERR on error (or end of iteration)
909 iter_next_prepare (void *cls,
910 struct NextContext *nc)
912 struct IterContext *ic = cls;
913 struct Plugin *plugin;
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
920 "Asked to clean up iterator state.\n");
922 sqlite3_finalize (ic->stmt_1);
923 sqlite3_finalize (ic->stmt_2);
924 return GNUNET_SYSERR;
926 sqlite3_reset (ic->stmt_1);
927 sqlite3_reset (ic->stmt_2);
932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
933 "Restricting to results larger than the last priority %u\n",
936 sqlite3_bind_int (ic->stmt_1, 1, nc->lastPriority);
937 sqlite3_bind_int (ic->stmt_2, 1, nc->lastPriority);
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 "Restricting to results larger than the last expiration %llu\n",
944 (unsigned long long) nc->lastExpiration.value);
946 sqlite3_bind_int64 (ic->stmt_1, 1, nc->lastExpiration.value);
947 sqlite3_bind_int64 (ic->stmt_2, 1, nc->lastExpiration.value);
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
951 "Restricting to results larger than the last key `%s'\n",
952 GNUNET_h2s(&nc->lastKey));
954 sqlite3_bind_blob (ic->stmt_1, 2,
956 sizeof (GNUNET_HashCode),
958 if (SQLITE_ROW == (ret = sqlite3_step (ic->stmt_1)))
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "Result found using iterator 1\n");
964 nc->stmt = ic->stmt_1;
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_1))
976 LOG_SQLITE (plugin, NULL,
977 GNUNET_ERROR_TYPE_ERROR |
978 GNUNET_ERROR_TYPE_BULK,
980 if (SQLITE_ROW == (ret = sqlite3_step (ic->stmt_2)))
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
984 "Result found using iterator 2\n");
986 nc->stmt = ic->stmt_2;
989 if (ret != SQLITE_DONE)
991 LOG_SQLITE (plugin, NULL,
992 GNUNET_ERROR_TYPE_ERROR |
993 GNUNET_ERROR_TYPE_BULK,
995 return GNUNET_SYSERR;
997 if (SQLITE_OK != sqlite3_reset (ic->stmt_2))
998 LOG_SQLITE (plugin, NULL,
999 GNUNET_ERROR_TYPE_ERROR |
1000 GNUNET_ERROR_TYPE_BULK,
1003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1004 "No result found using either iterator\n");
1011 * Call a method for each key in the database and
1012 * call the callback method on it.
1014 * @param plugin our plugin context
1015 * @param type entries of which type should be considered?
1016 * @param is_asc are we iterating in ascending order?
1017 * @param is_prio are we iterating by priority (otherwise by expiration)
1018 * @param is_migr are we iterating in migration order?
1019 * @param limit_nonanonymous are we restricting results to those with anonymity
1021 * @param stmt_str_1 first SQL statement to execute
1022 * @param stmt_str_2 SQL statement to execute to get "more" results (inner iteration)
1023 * @param iter function to call on each matching value;
1024 * will be called once with a NULL value at the end
1025 * @param iter_cls closure for iter
1028 basic_iter (struct Plugin *plugin,
1029 enum GNUNET_BLOCK_Type type,
1033 int limit_nonanonymous,
1034 const char *stmt_str_1,
1035 const char *stmt_str_2,
1036 PluginIterator iter,
1039 struct NextContext *nc;
1040 struct IterContext *ic;
1041 sqlite3_stmt *stmt_1;
1042 sqlite3_stmt *stmt_2;
1045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1046 "At %llu, using queries `%s' and `%s'\n",
1047 (unsigned long long) GNUNET_TIME_absolute_get ().value,
1051 if (sq_prepare (plugin->dbh, stmt_str_1, &stmt_1) != SQLITE_OK)
1053 LOG_SQLITE (plugin, NULL,
1054 GNUNET_ERROR_TYPE_ERROR |
1055 GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare");
1056 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1059 if (sq_prepare (plugin->dbh, stmt_str_2, &stmt_2) != SQLITE_OK)
1061 LOG_SQLITE (plugin, NULL,
1062 GNUNET_ERROR_TYPE_ERROR |
1063 GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare");
1064 sqlite3_finalize (stmt_1);
1065 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1068 nc = GNUNET_malloc (sizeof(struct NextContext) +
1069 sizeof(struct IterContext));
1070 nc->plugin = plugin;
1072 nc->iter_cls = iter_cls;
1074 ic = (struct IterContext*) &nc[1];
1075 ic->stmt_1 = stmt_1;
1076 ic->stmt_2 = stmt_2;
1078 ic->is_asc = is_asc;
1079 ic->is_prio = is_prio;
1080 ic->is_migr = is_migr;
1081 ic->limit_nonanonymous = limit_nonanonymous;
1082 nc->prep = &iter_next_prepare;
1086 nc->lastPriority = 0;
1087 nc->lastExpiration.value = 0;
1088 memset (&nc->lastKey, 0, sizeof (GNUNET_HashCode));
1092 nc->lastPriority = 0x7FFFFFFF;
1093 nc->lastExpiration.value = 0x7FFFFFFFFFFFFFFFLL;
1094 memset (&nc->lastKey, 255, sizeof (GNUNET_HashCode));
1096 sqlite_next_request (nc, GNUNET_NO);
1101 * Select a subset of the items in the datastore and call
1102 * the given iterator for each of them.
1104 * @param cls our plugin context
1105 * @param type entries of which type should be considered?
1106 * Use 0 for any type.
1107 * @param iter function to call on each matching value;
1108 * will be called once with a NULL value at the end
1109 * @param iter_cls closure for iter
1112 sqlite_plugin_iter_low_priority (void *cls,
1113 enum GNUNET_BLOCK_Type type,
1114 PluginIterator iter,
1119 GNUNET_YES, GNUNET_YES,
1120 GNUNET_NO, GNUNET_NO,
1121 SELECT_IT_LOW_PRIORITY_1,
1122 SELECT_IT_LOW_PRIORITY_2,
1128 * Select a subset of the items in the datastore and call
1129 * the given iterator for each of them.
1131 * @param cls our plugin context
1132 * @param type entries of which type should be considered?
1133 * Use 0 for any type.
1134 * @param iter function to call on each matching value;
1135 * will be called once with a NULL value at the end
1136 * @param iter_cls closure for iter
1139 sqlite_plugin_iter_zero_anonymity (void *cls,
1140 enum GNUNET_BLOCK_Type type,
1141 PluginIterator iter,
1144 struct GNUNET_TIME_Absolute now;
1148 now = GNUNET_TIME_absolute_get ();
1149 GNUNET_asprintf (&q1, SELECT_IT_NON_ANONYMOUS_1,
1150 (unsigned long long) now.value);
1151 GNUNET_asprintf (&q2, SELECT_IT_NON_ANONYMOUS_2,
1152 (unsigned long long) now.value);
1155 GNUNET_NO, GNUNET_YES,
1156 GNUNET_NO, GNUNET_YES,
1167 * Select a subset of the items in the datastore and call
1168 * the given iterator for each of them.
1170 * @param cls our plugin context
1171 * @param type entries of which type should be considered?
1172 * Use 0 for any type.
1173 * @param iter function to call on each matching value;
1174 * will be called once with a NULL value at the end
1175 * @param iter_cls closure for iter
1178 sqlite_plugin_iter_ascending_expiration (void *cls,
1179 enum GNUNET_BLOCK_Type type,
1180 PluginIterator iter,
1183 struct GNUNET_TIME_Absolute now;
1187 now = GNUNET_TIME_absolute_get ();
1188 GNUNET_asprintf (&q1, SELECT_IT_EXPIRATION_TIME_1,
1189 (unsigned long long) 0*now.value);
1190 GNUNET_asprintf (&q2, SELECT_IT_EXPIRATION_TIME_2,
1191 (unsigned long long) 0*now.value);
1194 GNUNET_YES, GNUNET_NO,
1195 GNUNET_NO, GNUNET_NO,
1204 * Select a subset of the items in the datastore and call
1205 * the given iterator for each of them.
1207 * @param cls our plugin context
1208 * @param type entries of which type should be considered?
1209 * Use 0 for any type.
1210 * @param iter function to call on each matching value;
1211 * will be called once with a NULL value at the end
1212 * @param iter_cls closure for iter
1215 sqlite_plugin_iter_migration_order (void *cls,
1216 enum GNUNET_BLOCK_Type type,
1217 PluginIterator iter,
1220 struct GNUNET_TIME_Absolute now;
1223 now = GNUNET_TIME_absolute_get ();
1224 GNUNET_asprintf (&q, SELECT_IT_MIGRATION_ORDER_2,
1225 (unsigned long long) now.value);
1228 GNUNET_NO, GNUNET_NO,
1229 GNUNET_YES, GNUNET_NO,
1230 SELECT_IT_MIGRATION_ORDER_1,
1238 * Call sqlite using the already prepared query to get
1241 * @param cls not used
1242 * @param nc context with the prepared query
1243 * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if
1244 * there are no more results
1247 all_next_prepare (void *cls,
1248 struct NextContext *nc)
1250 struct Plugin *plugin;
1256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1257 "Asked to clean up iterator state.\n");
1259 return GNUNET_SYSERR;
1261 plugin = nc->plugin;
1262 if (SQLITE_ROW == (ret = sqlite3_step (nc->stmt)))
1266 if (ret != SQLITE_DONE)
1268 LOG_SQLITE (plugin, NULL,
1269 GNUNET_ERROR_TYPE_ERROR |
1270 GNUNET_ERROR_TYPE_BULK,
1272 return GNUNET_SYSERR;
1279 * Select a subset of the items in the datastore and call
1280 * the given iterator for each of them.
1282 * @param cls our plugin context
1283 * @param type entries of which type should be considered?
1284 * Use 0 for any type.
1285 * @param iter function to call on each matching value;
1286 * will be called once with a NULL value at the end
1287 * @param iter_cls closure for iter
1290 sqlite_plugin_iter_all_now (void *cls,
1291 enum GNUNET_BLOCK_Type type,
1292 PluginIterator iter,
1295 struct Plugin *plugin = cls;
1296 struct NextContext *nc;
1299 if (sq_prepare (plugin->dbh,
1300 "SELECT size,type,prio,anonLevel,expire,hash,value,_ROWID_ FROM gn080",
1301 &stmt) != SQLITE_OK)
1303 LOG_SQLITE (plugin, NULL,
1304 GNUNET_ERROR_TYPE_ERROR |
1305 GNUNET_ERROR_TYPE_BULK, "sqlite3_prepare");
1306 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1309 nc = GNUNET_malloc (sizeof(struct NextContext));
1310 nc->plugin = plugin;
1312 nc->iter_cls = iter_cls;
1314 nc->prep = &all_next_prepare;
1315 nc->prep_cls = NULL;
1316 sqlite_next_request (nc, GNUNET_NO);
1323 struct GetNextContext
1354 GNUNET_HashCode key;
1359 GNUNET_HashCode vhash;
1367 * @param cls our "struct GetNextContext*"
1369 * @return GNUNET_YES if there are more results,
1370 * GNUNET_NO if there are no more results,
1371 * GNUNET_SYSERR on internal error
1374 get_next_prepare (void *cls,
1375 struct NextContext *nc)
1377 struct GetNextContext *gnc = cls;
1384 sqlite3_finalize (gnc->stmt);
1385 return GNUNET_SYSERR;
1387 if (nc->count == gnc->total)
1389 if (nc->count + gnc->off == gnc->total)
1392 limit_off = gnc->off;
1396 sqlite3_reset (nc->stmt);
1397 ret = sqlite3_bind_blob (nc->stmt,
1400 sizeof (GNUNET_HashCode),
1402 if ((gnc->have_vhash) && (ret == SQLITE_OK))
1403 ret = sqlite3_bind_blob (nc->stmt,
1406 sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
1407 if ((gnc->type != 0) && (ret == SQLITE_OK))
1408 ret = sqlite3_bind_int (nc->stmt, sqoff++, gnc->type);
1409 if (ret == SQLITE_OK)
1410 ret = sqlite3_bind_int64 (nc->stmt, sqoff++, nc->last_rowid + 1);
1411 if (ret == SQLITE_OK)
1412 ret = sqlite3_bind_int (nc->stmt, sqoff++, limit_off);
1413 if (ret != SQLITE_OK)
1414 return GNUNET_SYSERR;
1415 if (SQLITE_ROW != sqlite3_step (nc->stmt))
1422 * Iterate over the results for a particular key
1425 * @param cls closure
1426 * @param key maybe NULL (to match all entries)
1427 * @param vhash hash of the value, maybe NULL (to
1428 * match all values that have the right key).
1429 * Note that for DBlocks there is no difference
1430 * betwen key and vhash, but for other blocks
1432 * @param type entries of which type are relevant?
1433 * Use 0 for any type.
1434 * @param iter function to call on each matching value;
1435 * will be called once with a NULL value at the end
1436 * @param iter_cls closure for iter
1439 sqlite_plugin_get (void *cls,
1440 const GNUNET_HashCode * key,
1441 const GNUNET_HashCode * vhash,
1442 enum GNUNET_BLOCK_Type type,
1443 PluginIterator iter, void *iter_cls)
1445 struct Plugin *plugin = cls;
1446 struct GetNextContext *gpc;
1447 struct NextContext *nc;
1454 GNUNET_assert (iter != NULL);
1457 sqlite_plugin_iter_low_priority (cls, type, iter, iter_cls);
1460 GNUNET_snprintf (scratch, sizeof (scratch),
1461 "SELECT count(*) FROM gn080 WHERE hash=:1%s%s",
1462 vhash == NULL ? "" : " AND vhash=:2",
1463 type == 0 ? "" : (vhash ==
1464 NULL) ? " AND type=:2" : " AND type=:3");
1465 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
1467 LOG_SQLITE (plugin, NULL,
1468 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
1469 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1473 ret = sqlite3_bind_blob (stmt,
1475 key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
1476 if ((vhash != NULL) && (ret == SQLITE_OK))
1477 ret = sqlite3_bind_blob (stmt,
1480 sizeof (GNUNET_HashCode), SQLITE_TRANSIENT);
1481 if ((type != 0) && (ret == SQLITE_OK))
1482 ret = sqlite3_bind_int (stmt, sqoff++, type);
1483 if (SQLITE_OK != ret)
1485 LOG_SQLITE (plugin, NULL,
1486 GNUNET_ERROR_TYPE_ERROR, "sqlite_bind");
1487 sqlite3_reset (stmt);
1488 sqlite3_finalize (stmt);
1489 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1492 ret = sqlite3_step (stmt);
1493 if (ret != SQLITE_ROW)
1495 LOG_SQLITE (plugin, NULL,
1496 GNUNET_ERROR_TYPE_ERROR| GNUNET_ERROR_TYPE_BULK,
1498 sqlite3_reset (stmt);
1499 sqlite3_finalize (stmt);
1500 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1503 total = sqlite3_column_int (stmt, 0);
1504 sqlite3_reset (stmt);
1505 sqlite3_finalize (stmt);
1508 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1512 GNUNET_snprintf (scratch, sizeof (scratch),
1513 "SELECT size, type, prio, anonLevel, expire, hash, value, _ROWID_ "
1514 "FROM gn080 WHERE hash=:1%s%s AND _ROWID_ >= :%d "
1515 "ORDER BY _ROWID_ ASC LIMIT 1 OFFSET :d",
1516 vhash == NULL ? "" : " AND vhash=:2",
1517 type == 0 ? "" : (vhash ==
1518 NULL) ? " AND type=:2" : " AND type=:3",
1520 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
1522 LOG_SQLITE (plugin, NULL,
1523 GNUNET_ERROR_TYPE_ERROR |
1524 GNUNET_ERROR_TYPE_BULK, "sqlite_prepare");
1525 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1528 nc = GNUNET_malloc (sizeof(struct NextContext) +
1529 sizeof(struct GetNextContext));
1530 nc->plugin = plugin;
1532 nc->iter_cls = iter_cls;
1534 gpc = (struct GetNextContext*) &nc[1];
1538 gpc->stmt = stmt; /* alias used for freeing at the end! */
1541 gpc->have_vhash = GNUNET_YES;
1542 gpc->vhash = *vhash;
1544 gpc->off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
1545 nc->prep = &get_next_prepare;
1547 sqlite_next_request (nc, GNUNET_NO);
1554 * @param cls our plugin context
1557 sqlite_plugin_drop (void *cls)
1559 struct Plugin *plugin = cls;
1560 plugin->drop_on_shutdown = GNUNET_YES;
1565 * Callback function to process statistic values.
1567 * @param cls closure
1568 * @param subsystem name of subsystem that created the statistic
1569 * @param name the name of the datum
1570 * @param value the current value
1571 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1572 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1575 process_stat_in (void *cls,
1576 const char *subsystem,
1581 struct Plugin *plugin = cls;
1583 plugin->stats_worked = GNUNET_YES;
1584 plugin->payload += value;
1586 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1588 "Notification from statistics about existing payload (%llu), new payload is %llu\n",
1597 process_stat_done (void *cls,
1600 struct Plugin *plugin = cls;
1603 uint64_t free_pages;
1605 plugin->stat_get = NULL;
1606 if (plugin->stats_worked == GNUNET_NO)
1609 sq_prepare (plugin->dbh,
1610 "PRAGMA page_count",
1613 sqlite3_step (stmt))
1614 pages = sqlite3_column_int64 (stmt, 0);
1617 sqlite3_finalize (stmt);
1619 sq_prepare (plugin->dbh,
1620 "PRAGMA freelist_count",
1622 CHECK (SQLITE_ROW ==
1623 sqlite3_step (stmt));
1624 free_pages = sqlite3_column_int64 (stmt, 0);
1625 sqlite3_finalize (stmt);
1626 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1627 _("Using sqlite page utilization to estimate payload (%llu pages total, %llu free)\n"),
1628 (unsigned long long) pages,
1629 (unsigned long long) free_pages);
1630 plugin->payload = (pages - free_pages) * 4092LL;
1636 * Entry point for the plugin.
1638 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*"
1639 * @return NULL on error, othrewise the plugin context
1642 libgnunet_plugin_datastore_sqlite_init (void *cls)
1644 static struct Plugin plugin;
1645 struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
1646 struct GNUNET_DATASTORE_PluginFunctions *api;
1648 if (plugin.env != NULL)
1649 return NULL; /* can only initialize once! */
1650 memset (&plugin, 0, sizeof(struct Plugin));
1652 plugin.statistics = GNUNET_STATISTICS_create (env->sched,
1655 plugin.stat_get = GNUNET_STATISTICS_get (plugin.statistics,
1658 GNUNET_TIME_UNIT_SECONDS,
1663 database_setup (env->cfg, &plugin))
1665 database_shutdown (&plugin);
1668 api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
1670 api->get_size = &sqlite_plugin_get_size;
1671 api->put = &sqlite_plugin_put;
1672 api->next_request = &sqlite_next_request;
1673 api->get = &sqlite_plugin_get;
1674 api->update = &sqlite_plugin_update;
1675 api->iter_low_priority = &sqlite_plugin_iter_low_priority;
1676 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity;
1677 api->iter_ascending_expiration = &sqlite_plugin_iter_ascending_expiration;
1678 api->iter_migration_order = &sqlite_plugin_iter_migration_order;
1679 api->iter_all_now = &sqlite_plugin_iter_all_now;
1680 api->drop = &sqlite_plugin_drop;
1681 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1682 "sqlite", _("Sqlite database running\n"));
1688 * Exit point from the plugin.
1690 * @param cls the plugin context (as returned by "init")
1691 * @return always NULL
1694 libgnunet_plugin_datastore_sqlite_done (void *cls)
1697 struct GNUNET_DATASTORE_PluginFunctions *api = cls;
1698 struct Plugin *plugin = api->cls;
1700 if (plugin->stat_get != NULL)
1702 GNUNET_STATISTICS_get_cancel (plugin->stat_get);
1703 plugin->stat_get = NULL;
1705 if (plugin->next_task != GNUNET_SCHEDULER_NO_TASK)
1707 GNUNET_SCHEDULER_cancel (plugin->env->sched,
1709 plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
1710 plugin->next_task_nc->prep (plugin->next_task_nc->prep_cls, NULL);
1711 GNUNET_free (plugin->next_task_nc);
1712 plugin->next_task_nc = NULL;
1715 if (plugin->drop_on_shutdown)
1716 fn = GNUNET_strdup (plugin->fn);
1717 database_shutdown (plugin);
1718 GNUNET_STATISTICS_destroy (plugin->statistics,
1721 plugin->payload = 0;
1725 if (0 != UNLINK(fn))
1726 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
1734 /* end of plugin_datastore_sqlite.c */