diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-29 08:06:54 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-29 08:06:54 +0000 |
commit | f4d2a974968ab6a3e83815a68dc6b98588105277 (patch) | |
tree | 3af1b060ee55c28a4262e4c0a95f7d06eb8e6384 /src/datacache | |
parent | b0a50c0e1fd6e5434c7e53e4b55748368247e839 (diff) | |
download | gnunet-f4d2a974968ab6a3e83815a68dc6b98588105277.tar.gz gnunet-f4d2a974968ab6a3e83815a68dc6b98588105277.zip |
-doxygen
Diffstat (limited to 'src/datacache')
-rw-r--r-- | src/datacache/plugin_datacache_postgres.c | 126 | ||||
-rw-r--r-- | src/datacache/plugin_datacache_sqlite.c | 26 |
2 files changed, 98 insertions, 54 deletions
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index 9f3d6beec..836a24251 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c | |||
@@ -61,7 +61,7 @@ struct Plugin | |||
61 | * @brief Get a database handle | 61 | * @brief Get a database handle |
62 | * | 62 | * |
63 | * @param plugin global context | 63 | * @param plugin global context |
64 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 64 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
65 | */ | 65 | */ |
66 | static int | 66 | static int |
67 | init_connection (struct Plugin *plugin) | 67 | init_connection (struct Plugin *plugin) |
@@ -89,7 +89,8 @@ init_connection (struct Plugin *plugin) | |||
89 | PG_DIAG_SQLSTATE))))) | 89 | PG_DIAG_SQLSTATE))))) |
90 | { | 90 | { |
91 | (void) GNUNET_POSTGRES_check_result (plugin->dbh, ret, | 91 | (void) GNUNET_POSTGRES_check_result (plugin->dbh, ret, |
92 | PGRES_COMMAND_OK, "CREATE TABLE", | 92 | PGRES_COMMAND_OK, |
93 | "CREATE TABLE", | ||
93 | "gn090dc"); | 94 | "gn090dc"); |
94 | PQfinish (plugin->dbh); | 95 | PQfinish (plugin->dbh); |
95 | plugin->dbh = NULL; | 96 | plugin->dbh = NULL; |
@@ -98,9 +99,11 @@ init_connection (struct Plugin *plugin) | |||
98 | if (PQresultStatus (ret) == PGRES_COMMAND_OK) | 99 | if (PQresultStatus (ret) == PGRES_COMMAND_OK) |
99 | { | 100 | { |
100 | if ((GNUNET_OK != | 101 | if ((GNUNET_OK != |
101 | GNUNET_POSTGRES_exec (plugin->dbh, "CREATE INDEX idx_key ON gn090dc (key)")) || | 102 | GNUNET_POSTGRES_exec (plugin->dbh, |
103 | "CREATE INDEX idx_key ON gn090dc (key)")) || | ||
102 | (GNUNET_OK != | 104 | (GNUNET_OK != |
103 | GNUNET_POSTGRES_exec (plugin->dbh, "CREATE INDEX idx_dt ON gn090dc (discard_time)"))) | 105 | GNUNET_POSTGRES_exec (plugin->dbh, |
106 | "CREATE INDEX idx_dt ON gn090dc (discard_time)"))) | ||
104 | { | 107 | { |
105 | PQclear (ret); | 108 | PQclear (ret); |
106 | PQfinish (plugin->dbh); | 109 | PQfinish (plugin->dbh); |
@@ -113,16 +116,25 @@ init_connection (struct Plugin *plugin) | |||
113 | PQexec (plugin->dbh, | 116 | PQexec (plugin->dbh, |
114 | "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL"); | 117 | "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL"); |
115 | if (GNUNET_OK != | 118 | if (GNUNET_OK != |
116 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc")) | 119 | GNUNET_POSTGRES_check_result (plugin->dbh, |
120 | ret, | ||
121 | PGRES_COMMAND_OK, | ||
122 | "ALTER TABLE", | ||
123 | "gn090dc")) | ||
117 | { | 124 | { |
118 | PQfinish (plugin->dbh); | 125 | PQfinish (plugin->dbh); |
119 | plugin->dbh = NULL; | 126 | plugin->dbh = NULL; |
120 | return GNUNET_SYSERR; | 127 | return GNUNET_SYSERR; |
121 | } | 128 | } |
122 | PQclear (ret); | 129 | PQclear (ret); |
123 | ret = PQexec (plugin->dbh, "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN"); | 130 | ret = PQexec (plugin->dbh, |
131 | "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN"); | ||
124 | if (GNUNET_OK != | 132 | if (GNUNET_OK != |
125 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc")) | 133 | GNUNET_POSTGRES_check_result (plugin->dbh, |
134 | ret, | ||
135 | PGRES_COMMAND_OK, | ||
136 | "ALTER TABLE", | ||
137 | "gn090dc")) | ||
126 | { | 138 | { |
127 | PQfinish (plugin->dbh); | 139 | PQfinish (plugin->dbh); |
128 | plugin->dbh = NULL; | 140 | plugin->dbh = NULL; |
@@ -130,23 +142,29 @@ init_connection (struct Plugin *plugin) | |||
130 | } | 142 | } |
131 | PQclear (ret); | 143 | PQclear (ret); |
132 | if ((GNUNET_OK != | 144 | if ((GNUNET_OK != |
133 | GNUNET_POSTGRES_prepare (plugin->dbh, "getkt", | 145 | GNUNET_POSTGRES_prepare (plugin->dbh, |
134 | "SELECT discard_time,type,value,path FROM gn090dc " | 146 | "getkt", |
135 | "WHERE key=$1 AND type=$2 ", 2)) || | 147 | "SELECT discard_time,type,value,path FROM gn090dc " |
148 | "WHERE key=$1 AND type=$2 ", 2)) || | ||
136 | (GNUNET_OK != | 149 | (GNUNET_OK != |
137 | GNUNET_POSTGRES_prepare (plugin->dbh, "getk", | 150 | GNUNET_POSTGRES_prepare (plugin->dbh, |
138 | "SELECT discard_time,type,value,path FROM gn090dc " | 151 | "getk", |
139 | "WHERE key=$1", 1)) || | 152 | "SELECT discard_time,type,value,path FROM gn090dc " |
153 | "WHERE key=$1", 1)) || | ||
140 | (GNUNET_OK != | 154 | (GNUNET_OK != |
141 | GNUNET_POSTGRES_prepare (plugin->dbh, "getm", | 155 | GNUNET_POSTGRES_prepare (plugin->dbh, |
142 | "SELECT length(value),oid,key FROM gn090dc " | 156 | "getm", |
143 | "ORDER BY discard_time ASC LIMIT 1", 0)) || | 157 | "SELECT length(value),oid,key FROM gn090dc " |
158 | "ORDER BY discard_time ASC LIMIT 1", 0)) || | ||
144 | (GNUNET_OK != | 159 | (GNUNET_OK != |
145 | GNUNET_POSTGRES_prepare (plugin->dbh, "delrow", "DELETE FROM gn090dc WHERE oid=$1", 1)) || | 160 | GNUNET_POSTGRES_prepare (plugin->dbh, |
161 | "delrow", | ||
162 | "DELETE FROM gn090dc WHERE oid=$1", 1)) || | ||
146 | (GNUNET_OK != | 163 | (GNUNET_OK != |
147 | GNUNET_POSTGRES_prepare (plugin->dbh, "put", | 164 | GNUNET_POSTGRES_prepare (plugin->dbh, |
148 | "INSERT INTO gn090dc (type, discard_time, key, value, path) " | 165 | "put", |
149 | "VALUES ($1, $2, $3, $4, $5)", 5))) | 166 | "INSERT INTO gn090dc (type, discard_time, key, value, path) " |
167 | "VALUES ($1, $2, $3, $4, $5)", 5))) | ||
150 | { | 168 | { |
151 | PQfinish (plugin->dbh); | 169 | PQfinish (plugin->dbh); |
152 | plugin->dbh = NULL; | 170 | plugin->dbh = NULL; |
@@ -159,19 +177,22 @@ init_connection (struct Plugin *plugin) | |||
159 | /** | 177 | /** |
160 | * Store an item in the datastore. | 178 | * Store an item in the datastore. |
161 | * | 179 | * |
162 | * @param cls closure (our "struct Plugin") | 180 | * @param cls closure (our `struct Plugin`) |
163 | * @param key key to store data under | 181 | * @param key key to store @a data under |
164 | * @param size number of bytes in data | 182 | * @param size number of bytes in @a data |
165 | * @param data data to store | 183 | * @param data data to store |
166 | * @param type type of the value | 184 | * @param type type of the value |
167 | * @param discard_time when to discard the value in any case | 185 | * @param discard_time when to discard the value in any case |
168 | * @param path_info_len number of entries in 'path_info' | 186 | * @param path_info_len number of entries in @a path_info |
169 | * @param path_info a path through the network | 187 | * @param path_info a path through the network |
170 | * @return 0 if duplicate, -1 on error, number of bytes used otherwise | 188 | * @return 0 if duplicate, -1 on error, number of bytes used otherwise |
171 | */ | 189 | */ |
172 | static ssize_t | 190 | static ssize_t |
173 | postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, size_t size, | 191 | postgres_plugin_put (void *cls, |
174 | const char *data, enum GNUNET_BLOCK_Type type, | 192 | const struct GNUNET_HashCode *key, |
193 | size_t size, | ||
194 | const char *data, | ||
195 | enum GNUNET_BLOCK_Type type, | ||
175 | struct GNUNET_TIME_Absolute discard_time, | 196 | struct GNUNET_TIME_Absolute discard_time, |
176 | unsigned int path_info_len, | 197 | unsigned int path_info_len, |
177 | const struct GNUNET_PeerIdentity *path_info) | 198 | const struct GNUNET_PeerIdentity *path_info) |
@@ -214,17 +235,19 @@ postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, size_t size, | |||
214 | * Iterate over the results for a particular key | 235 | * Iterate over the results for a particular key |
215 | * in the datastore. | 236 | * in the datastore. |
216 | * | 237 | * |
217 | * @param cls closure (our "struct Plugin") | 238 | * @param cls closure (our `struct Plugin`) |
218 | * @param key | 239 | * @param key key to look for |
219 | * @param type entries of which type are relevant? | 240 | * @param type entries of which type are relevant? |
220 | * @param iter maybe NULL (to just count) | 241 | * @param iter maybe NULL (to just count) |
221 | * @param iter_cls closure for iter | 242 | * @param iter_cls closure for @a iter |
222 | * @return the number of results found | 243 | * @return the number of results found |
223 | */ | 244 | */ |
224 | static unsigned int | 245 | static unsigned int |
225 | postgres_plugin_get (void *cls, const struct GNUNET_HashCode * key, | 246 | postgres_plugin_get (void *cls, |
247 | const struct GNUNET_HashCode *key, | ||
226 | enum GNUNET_BLOCK_Type type, | 248 | enum GNUNET_BLOCK_Type type, |
227 | GNUNET_DATACACHE_Iterator iter, void *iter_cls) | 249 | GNUNET_DATACACHE_Iterator iter, |
250 | void *iter_cls) | ||
228 | { | 251 | { |
229 | struct Plugin *plugin = cls; | 252 | struct Plugin *plugin = cls; |
230 | uint32_t btype = htonl (type); | 253 | uint32_t btype = htonl (type); |
@@ -251,7 +274,10 @@ postgres_plugin_get (void *cls, const struct GNUNET_HashCode * key, | |||
251 | (type == 0) ? 1 : 2, paramValues, paramLengths, | 274 | (type == 0) ? 1 : 2, paramValues, paramLengths, |
252 | paramFormats, 1); | 275 | paramFormats, 1); |
253 | if (GNUNET_OK != | 276 | if (GNUNET_OK != |
254 | GNUNET_POSTGRES_check_result (plugin->dbh, res, PGRES_TUPLES_OK, "PQexecPrepared", | 277 | GNUNET_POSTGRES_check_result (plugin->dbh, |
278 | res, | ||
279 | PGRES_TUPLES_OK, | ||
280 | "PQexecPrepared", | ||
255 | (type == 0) ? "getk" : "getkt")) | 281 | (type == 0) ? "getk" : "getkt")) |
256 | { | 282 | { |
257 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 283 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -272,8 +298,9 @@ postgres_plugin_get (void *cls, const struct GNUNET_HashCode * key, | |||
272 | PQclear (res); | 298 | PQclear (res); |
273 | return cnt; | 299 | return cnt; |
274 | } | 300 | } |
275 | if ((4 != PQnfields (res)) || (sizeof (uint64_t) != PQfsize (res, 0)) || | 301 | if ( (4 != PQnfields (res)) || |
276 | (sizeof (uint32_t) != PQfsize (res, 1))) | 302 | (sizeof (uint64_t) != PQfsize (res, 0)) || |
303 | (sizeof (uint32_t) != PQfsize (res, 1))) | ||
277 | { | 304 | { |
278 | GNUNET_break (0); | 305 | GNUNET_break (0); |
279 | PQclear (res); | 306 | PQclear (res); |
@@ -318,8 +345,8 @@ postgres_plugin_get (void *cls, const struct GNUNET_HashCode * key, | |||
318 | * Delete the entry with the lowest expiration value | 345 | * Delete the entry with the lowest expiration value |
319 | * from the datacache right now. | 346 | * from the datacache right now. |
320 | * | 347 | * |
321 | * @param cls closure (our "struct Plugin") | 348 | * @param cls closure (our `struct Plugin`) |
322 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 349 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
323 | */ | 350 | */ |
324 | static int | 351 | static int |
325 | postgres_plugin_del (void *cls) | 352 | postgres_plugin_del (void *cls) |
@@ -330,9 +357,15 @@ postgres_plugin_del (void *cls) | |||
330 | struct GNUNET_HashCode key; | 357 | struct GNUNET_HashCode key; |
331 | PGresult *res; | 358 | PGresult *res; |
332 | 359 | ||
333 | res = PQexecPrepared (plugin->dbh, "getm", 0, NULL, NULL, NULL, 1); | 360 | res = PQexecPrepared (plugin->dbh, |
361 | "getm", | ||
362 | 0, NULL, NULL, NULL, 1); | ||
334 | if (GNUNET_OK != | 363 | if (GNUNET_OK != |
335 | GNUNET_POSTGRES_check_result (plugin->dbh, res, PGRES_TUPLES_OK, "PQexecPrepared", "getm")) | 364 | GNUNET_POSTGRES_check_result (plugin->dbh, |
365 | res, | ||
366 | PGRES_TUPLES_OK, | ||
367 | "PQexecPrepared", | ||
368 | "getm")) | ||
336 | { | 369 | { |
337 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 370 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
338 | "Ending iteration (postgres error)\n"); | 371 | "Ending iteration (postgres error)\n"); |
@@ -358,10 +391,15 @@ postgres_plugin_del (void *cls) | |||
358 | oid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1)); | 391 | oid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1)); |
359 | memcpy (&key, PQgetvalue (res, 0, 2), sizeof (struct GNUNET_HashCode)); | 392 | memcpy (&key, PQgetvalue (res, 0, 2), sizeof (struct GNUNET_HashCode)); |
360 | PQclear (res); | 393 | PQclear (res); |
361 | if (GNUNET_OK != GNUNET_POSTGRES_delete_by_rowid (plugin->dbh, "delrow", oid)) | 394 | if (GNUNET_OK != |
395 | GNUNET_POSTGRES_delete_by_rowid (plugin->dbh, | ||
396 | "delrow", | ||
397 | oid)) | ||
362 | return GNUNET_SYSERR; | 398 | return GNUNET_SYSERR; |
363 | plugin->num_items--; | 399 | plugin->num_items--; |
364 | plugin->env->delete_notify (plugin->env->cls, &key, size + OVERHEAD); | 400 | plugin->env->delete_notify (plugin->env->cls, |
401 | &key, | ||
402 | size + OVERHEAD); | ||
365 | return GNUNET_OK; | 403 | return GNUNET_OK; |
366 | } | 404 | } |
367 | 405 | ||
@@ -369,8 +407,8 @@ postgres_plugin_del (void *cls) | |||
369 | /** | 407 | /** |
370 | * Entry point for the plugin. | 408 | * Entry point for the plugin. |
371 | * | 409 | * |
372 | * @param cls closure (the "struct GNUNET_DATACACHE_PluginEnvironmnet") | 410 | * @param cls closure (the `struct GNUNET_DATACACHE_PluginEnvironmnet`) |
373 | * @return the plugin's closure (our "struct Plugin") | 411 | * @return the plugin's closure (our `struct Plugin`) |
374 | */ | 412 | */ |
375 | void * | 413 | void * |
376 | libgnunet_plugin_datacache_postgres_init (void *cls) | 414 | libgnunet_plugin_datacache_postgres_init (void *cls) |
@@ -394,7 +432,7 @@ libgnunet_plugin_datacache_postgres_init (void *cls) | |||
394 | api->put = &postgres_plugin_put; | 432 | api->put = &postgres_plugin_put; |
395 | api->del = &postgres_plugin_del; | 433 | api->del = &postgres_plugin_del; |
396 | LOG (GNUNET_ERROR_TYPE_INFO, | 434 | LOG (GNUNET_ERROR_TYPE_INFO, |
397 | _("Postgres datacache running\n")); | 435 | "Postgres datacache running\n"); |
398 | return api; | 436 | return api; |
399 | } | 437 | } |
400 | 438 | ||
@@ -402,7 +440,7 @@ libgnunet_plugin_datacache_postgres_init (void *cls) | |||
402 | /** | 440 | /** |
403 | * Exit point from the plugin. | 441 | * Exit point from the plugin. |
404 | * | 442 | * |
405 | * @param cls closure (our "struct Plugin") | 443 | * @param cls closure (our `struct Plugin`) |
406 | * @return NULL | 444 | * @return NULL |
407 | */ | 445 | */ |
408 | void * | 446 | void * |
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 3d21df5a9..d28233772 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c | |||
@@ -621,36 +621,42 @@ libgnunet_plugin_datacache_sqlite_done (void *cls) | |||
621 | #if !WINDOWS || defined(__CYGWIN__) | 621 | #if !WINDOWS || defined(__CYGWIN__) |
622 | if ( (NULL != plugin->fn) && | 622 | if ( (NULL != plugin->fn) && |
623 | (0 != UNLINK (plugin->fn)) ) | 623 | (0 != UNLINK (plugin->fn)) ) |
624 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn); | 624 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, |
625 | "unlink", | ||
626 | plugin->fn); | ||
625 | GNUNET_free_non_null (plugin->fn); | 627 | GNUNET_free_non_null (plugin->fn); |
626 | #endif | 628 | #endif |
627 | result = sqlite3_close (plugin->dbh); | 629 | result = sqlite3_close (plugin->dbh); |
628 | #if SQLITE_VERSION_NUMBER >= 3007000 | 630 | #if SQLITE_VERSION_NUMBER >= 3007000 |
629 | if (result == SQLITE_BUSY) | 631 | if (SQLITE_BUSY == result) |
630 | { | 632 | { |
631 | LOG (GNUNET_ERROR_TYPE_WARNING, | 633 | LOG (GNUNET_ERROR_TYPE_WARNING, |
632 | _ | 634 | _("Tried to close sqlite without finalizing all prepared statements.\n")); |
633 | ("Tried to close sqlite without finalizing all prepared statements.\n")); | ||
634 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 635 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); |
635 | while (stmt != NULL) | 636 | while (NULL != stmt) |
636 | { | 637 | { |
637 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing statement %p\n", stmt); | ||
638 | result = sqlite3_finalize (stmt); | 638 | result = sqlite3_finalize (stmt); |
639 | if (result != SQLITE_OK) | 639 | if (result != SQLITE_OK) |
640 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to close statement %p: %d\n"), | 640 | LOG (GNUNET_ERROR_TYPE_WARNING, |
641 | stmt, result); | 641 | "Failed to close statement %p: %d\n", |
642 | stmt, | ||
643 | result); | ||
642 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 644 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); |
643 | } | 645 | } |
644 | result = sqlite3_close (plugin->dbh); | 646 | result = sqlite3_close (plugin->dbh); |
645 | } | 647 | } |
646 | #endif | 648 | #endif |
647 | if (SQLITE_OK != result) | 649 | if (SQLITE_OK != result) |
648 | LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); | 650 | LOG_SQLITE (plugin->dbh, |
651 | GNUNET_ERROR_TYPE_ERROR, | ||
652 | "sqlite3_close"); | ||
649 | 653 | ||
650 | #if WINDOWS && !defined(__CYGWIN__) | 654 | #if WINDOWS && !defined(__CYGWIN__) |
651 | if ( (NULL != plugin->fn) && | 655 | if ( (NULL != plugin->fn) && |
652 | (0 != UNLINK (plugin->fn)) ) | 656 | (0 != UNLINK (plugin->fn)) ) |
653 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn); | 657 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, |
658 | "unlink", | ||
659 | plugin->fn); | ||
654 | GNUNET_free_non_null (plugin->fn); | 660 | GNUNET_free_non_null (plugin->fn); |
655 | #endif | 661 | #endif |
656 | GNUNET_free (plugin); | 662 | GNUNET_free (plugin); |