aboutsummaryrefslogtreecommitdiff
path: root/src/datacache
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-24 13:22:40 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-24 13:22:40 +0000
commite2dec2d081a9e2f1a9a19f114efaa974047f26a8 (patch)
tree045fc01ed157096adb5c6094c70b76ad5cb5285b /src/datacache
parent9f55be0f1ed0fe873344ef165bf0b23698749d07 (diff)
downloadgnunet-e2dec2d081a9e2f1a9a19f114efaa974047f26a8.tar.gz
gnunet-e2dec2d081a9e2f1a9a19f114efaa974047f26a8.zip
more logging, cleaning up logging
Diffstat (limited to 'src/datacache')
-rw-r--r--src/datacache/datacache.c2
-rw-r--r--src/datacache/plugin_datacache_sqlite.c130
2 files changed, 80 insertions, 52 deletions
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c
index c83199f09..f79fae95b 100644
--- a/src/datacache/datacache.c
+++ b/src/datacache/datacache.c
@@ -33,6 +33,8 @@
33 33
34#define LOG(kind,...) GNUNET_log_from (kind, "datacache", __VA_ARGS__) 34#define LOG(kind,...) GNUNET_log_from (kind, "datacache", __VA_ARGS__)
35 35
36#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache", op, fn)
37
36/** 38/**
37 * Internal state of the datacache library. 39 * Internal state of the datacache library.
38 */ 40 */
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index b5bc9f5bd..e33758f9b 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -30,6 +30,11 @@
30 30
31#define DEBUG_DATACACHE_SQLITE GNUNET_EXTRA_LOGGING 31#define DEBUG_DATACACHE_SQLITE GNUNET_EXTRA_LOGGING
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "datacache-sqlite", __VA_ARGS__)
34
35#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache-sqlite", op, fn)
36
37
33/** 38/**
34 * How much overhead do we assume per entry in the 39 * How much overhead do we assume per entry in the
35 * datacache? 40 * datacache?
@@ -63,10 +68,10 @@ struct Plugin
63 * a failure of the command 'cmd' on file 'filename' 68 * a failure of the command 'cmd' on file 'filename'
64 * with the message given by strerror(errno). 69 * with the message given by strerror(errno).
65 */ 70 */
66#define LOG_SQLITE(db, level, cmd) do { GNUNET_log_from (level, "datacache-sqlite", _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); } while(0) 71#define LOG_SQLITE(db, level, cmd) do { LOG (level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, sqlite3_errmsg(db)); } while(0)
67 72
68 73
69#define SQLITE3_EXEC(db, cmd) do { emsg = NULL; if (SQLITE_OK != sqlite3_exec(db, cmd, NULL, NULL, &emsg)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "datacache-sqlite", _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_exec", __FILE__, __LINE__, emsg); sqlite3_free(emsg); } } while(0) 74#define SQLITE3_EXEC(db, cmd) do { emsg = NULL; if (SQLITE_OK != sqlite3_exec(db, cmd, NULL, NULL, &emsg)) { LOG (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_exec", __FILE__, __LINE__, emsg); sqlite3_free(emsg); } } while(0)
70 75
71 76
72/** 77/**
@@ -104,11 +109,11 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
104 int64_t dval; 109 int64_t dval;
105 110
106#if DEBUG_DATACACHE_SQLITE 111#if DEBUG_DATACACHE_SQLITE
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 112 LOG (GNUNET_ERROR_TYPE_DEBUG,
108 "Processing `%s' of %u bytes with key `%4s' and expiration %llums\n", 113 "Processing `%s' of %u bytes with key `%4s' and expiration %llums\n",
109 "PUT", (unsigned int) size, GNUNET_h2s (key), 114 "PUT", (unsigned int) size, GNUNET_h2s (key),
110 (unsigned long long) 115 (unsigned long long)
111 GNUNET_TIME_absolute_get_remaining (discard_time).rel_value); 116 GNUNET_TIME_absolute_get_remaining (discard_time).rel_value);
112#endif 117#endif
113 dval = (int64_t) discard_time.abs_value; 118 dval = (int64_t) discard_time.abs_value;
114 if (dval < 0) 119 if (dval < 0)
@@ -118,9 +123,9 @@ sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
118 "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)", 123 "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)",
119 &stmt) != SQLITE_OK) 124 &stmt) != SQLITE_OK)
120 { 125 {
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 126 LOG_SQLITE (plugin->dbh,
122 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", 127 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
123 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 128 "sq_prepare");
124 return 0; 129 return 0;
125 } 130 }
126 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || 131 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
@@ -179,17 +184,17 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
179 184
180 now = GNUNET_TIME_absolute_get (); 185 now = GNUNET_TIME_absolute_get ();
181#if DEBUG_DATACACHE_SQLITE 186#if DEBUG_DATACACHE_SQLITE
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' for key `%4s'\n", "GET", 187 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' for key `%4s'\n", "GET",
183 GNUNET_h2s (key)); 188 GNUNET_h2s (key));
184#endif 189#endif
185 if (sq_prepare 190 if (sq_prepare
186 (plugin->dbh, 191 (plugin->dbh,
187 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", 192 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?",
188 &stmt) != SQLITE_OK) 193 &stmt) != SQLITE_OK)
189 { 194 {
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 195 LOG_SQLITE (plugin->dbh,
191 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", 196 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
192 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 197 "sq_prepare");
193 return 0; 198 return 0;
194 } 199 }
195 ntime = (int64_t) now.abs_value; 200 ntime = (int64_t) now.abs_value;
@@ -211,12 +216,25 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
211 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 216 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
212 "sqlite_step"); 217 "sqlite_step");
213 sqlite3_finalize (stmt); 218 sqlite3_finalize (stmt);
219#if DEBUG_DATACACHE_SQLITE
220 LOG (GNUNET_ERROR_TYPE_DEBUG,
221 "No content found when processing `%s' for key `%4s'\n",
222 "GET", GNUNET_h2s (key));
223#endif
214 return 0; 224 return 0;
215 } 225 }
216 total = sqlite3_column_int (stmt, 0); 226 total = sqlite3_column_int (stmt, 0);
217 sqlite3_finalize (stmt); 227 sqlite3_finalize (stmt);
218 if ((total == 0) || (iter == NULL)) 228 if ((total == 0) || (iter == NULL))
229 {
230#if DEBUG_DATACACHE_SQLITE
231 if (0 == total)
232 LOG (GNUNET_ERROR_TYPE_DEBUG,
233 "No content found when processing `%s' for key `%4s'\n",
234 "GET", GNUNET_h2s (key));
235#endif
219 return total; 236 return total;
237 }
220 238
221 cnt = 0; 239 cnt = 0;
222 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total); 240 off = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, total);
@@ -228,9 +246,9 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
228 off); 246 off);
229 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 247 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
230 { 248 {
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 249 LOG_SQLITE (plugin->dbh,
232 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", 250 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
233 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 251 "sq_prepare");
234 return cnt; 252 return cnt;
235 } 253 }
236 if ((SQLITE_OK != 254 if ((SQLITE_OK !=
@@ -253,6 +271,15 @@ sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
253 if (ntime == INT64_MAX) 271 if (ntime == INT64_MAX)
254 exp = GNUNET_TIME_UNIT_FOREVER_ABS; 272 exp = GNUNET_TIME_UNIT_FOREVER_ABS;
255 cnt++; 273 cnt++;
274#if DEBUG_DATACACHE_SQLITE
275 if (0 == total)
276 LOG (GNUNET_ERROR_TYPE_DEBUG,
277 "Found %u-byte result when processing `%s' for key `%4s'\n",
278 (unsigned int) size,
279 "GET",
280 GNUNET_h2s (key));
281#endif
282
256 if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type)) 283 if (GNUNET_OK != iter (iter_cls, exp, key, size, dat, type))
257 { 284 {
258 sqlite3_finalize (stmt); 285 sqlite3_finalize (stmt);
@@ -282,7 +309,7 @@ sqlite_plugin_del (void *cls)
282 GNUNET_HashCode hc; 309 GNUNET_HashCode hc;
283 310
284#if DEBUG_DATACACHE_SQLITE 311#if DEBUG_DATACACHE_SQLITE
285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s'\n", "DEL"); 312 LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s'\n", "DEL");
286#endif 313#endif
287 stmt = NULL; 314 stmt = NULL;
288 dstmt = NULL; 315 dstmt = NULL;
@@ -291,18 +318,18 @@ sqlite_plugin_del (void *cls)
291 "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1", 318 "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1",
292 &stmt) != SQLITE_OK) 319 &stmt) != SQLITE_OK)
293 { 320 {
294 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 321 LOG_SQLITE (plugin->dbh,
295 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", 322 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
296 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 323 "sq_prepare");
297 if (stmt != NULL) 324 if (stmt != NULL)
298 (void) sqlite3_finalize (stmt); 325 (void) sqlite3_finalize (stmt);
299 return GNUNET_SYSERR; 326 return GNUNET_SYSERR;
300 } 327 }
301 if (SQLITE_ROW != sqlite3_step (stmt)) 328 if (SQLITE_ROW != sqlite3_step (stmt))
302 { 329 {
303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 330 LOG_SQLITE (plugin->dbh,
304 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step", 331 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
305 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 332 "sqlite3_step");
306 (void) sqlite3_finalize (stmt); 333 (void) sqlite3_finalize (stmt);
307 return GNUNET_SYSERR; 334 return GNUNET_SYSERR;
308 } 335 }
@@ -311,42 +338,42 @@ sqlite_plugin_del (void *cls)
311 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); 338 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
312 dsize = sqlite3_column_bytes (stmt, 2); 339 dsize = sqlite3_column_bytes (stmt, 2);
313 if (SQLITE_OK != sqlite3_finalize (stmt)) 340 if (SQLITE_OK != sqlite3_finalize (stmt))
314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 341 LOG_SQLITE (plugin->dbh,
315 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step", 342 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
316 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 343 "sqlite3_step");
317 if (sq_prepare 344 if (sq_prepare
318 (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?", 345 (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?",
319 &dstmt) != SQLITE_OK) 346 &dstmt) != SQLITE_OK)
320 { 347 {
321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 348 LOG_SQLITE (plugin->dbh,
322 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", 349 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
323 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 350 "sq_prepare");
324 if (stmt != NULL) 351 if (stmt != NULL)
325 (void) sqlite3_finalize (stmt); 352 (void) sqlite3_finalize (stmt);
326 return GNUNET_SYSERR; 353 return GNUNET_SYSERR;
327 } 354 }
328 if (SQLITE_OK != 355 if (SQLITE_OK !=
329 sqlite3_bind_int64 (dstmt, 1, rowid)) 356 sqlite3_bind_int64 (dstmt, 1, rowid))
330 { 357 {
331 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 358 LOG_SQLITE (plugin->dbh,
332 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind", 359 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
333 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 360 "sqlite3_bind");
334 (void) sqlite3_finalize (dstmt); 361 (void) sqlite3_finalize (dstmt);
335 return GNUNET_SYSERR; 362 return GNUNET_SYSERR;
336 } 363 }
337 if (sqlite3_step (dstmt) != SQLITE_DONE) 364 if (sqlite3_step (dstmt) != SQLITE_DONE)
338 { 365 {
339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 366 LOG_SQLITE (plugin->dbh,
340 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step", 367 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
341 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 368 "sqlite3_step");
342 (void) sqlite3_finalize (dstmt); 369 (void) sqlite3_finalize (dstmt);
343 return GNUNET_SYSERR; 370 return GNUNET_SYSERR;
344 } 371 }
345 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); 372 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
346 if (SQLITE_OK != sqlite3_finalize (dstmt)) 373 if (SQLITE_OK != sqlite3_finalize (dstmt))
347 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 374 LOG_SQLITE (plugin->dbh,
348 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_finalize", 375 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
349 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 376 "sqlite3_finalize");
350 return GNUNET_OK; 377 return GNUNET_OK;
351} 378}
352 379
@@ -410,8 +437,8 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
410 api->get = &sqlite_plugin_get; 437 api->get = &sqlite_plugin_get;
411 api->put = &sqlite_plugin_put; 438 api->put = &sqlite_plugin_put;
412 api->del = &sqlite_plugin_del; 439 api->del = &sqlite_plugin_del;
413 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "sqlite", 440 LOG (GNUNET_ERROR_TYPE_INFO,
414 _("Sqlite datacache running\n")); 441 _("Sqlite datacache running\n"));
415 return api; 442 return api;
416} 443}
417 444
@@ -435,28 +462,27 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
435 462
436#if !WINDOWS || defined(__CYGWIN__) 463#if !WINDOWS || defined(__CYGWIN__)
437 if (0 != UNLINK (plugin->fn)) 464 if (0 != UNLINK (plugin->fn))
438 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn); 465 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
439 GNUNET_free (plugin->fn); 466 GNUNET_free (plugin->fn);
440#endif 467#endif
441 result = sqlite3_close (plugin->dbh); 468 result = sqlite3_close (plugin->dbh);
442#if SQLITE_VERSION_NUMBER >= 3007000 469#if SQLITE_VERSION_NUMBER >= 3007000
443 if (result == SQLITE_BUSY) 470 if (result == SQLITE_BUSY)
444 { 471 {
445 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", 472 LOG (GNUNET_ERROR_TYPE_WARNING,
446 _ 473 _("Tried to close sqlite without finalizing all prepared statements.\n"));
447 ("Tried to close sqlite without finalizing all prepared statements.\n"));
448 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 474 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
449 while (stmt != NULL) 475 while (stmt != NULL)
450 { 476 {
451#if DEBUG_SQLITE 477#if DEBUG_SQLITE
452 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", 478 LOG (GNUNET_ERROR_TYPE_DEBUG,
453 "Closing statement %p\n", stmt); 479 "Closing statement %p\n", stmt);
454#endif 480#endif
455 result = sqlite3_finalize (stmt); 481 result = sqlite3_finalize (stmt);
456#if DEBUG_SQLITE 482#if DEBUG_SQLITE
457 if (result != SQLITE_OK) 483 if (result != SQLITE_OK)
458 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", 484 LOG (GNUNET_ERROR_TYPE_DEBUG,
459 "Failed to close statement %p: %d\n", stmt, result); 485 "Failed to close statement %p: %d\n", stmt, result);
460#endif 486#endif
461 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 487 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
462 } 488 }
@@ -468,7 +494,7 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
468 494
469#if WINDOWS && !defined(__CYGWIN__) 495#if WINDOWS && !defined(__CYGWIN__)
470 if (0 != UNLINK (plugin->fn)) 496 if (0 != UNLINK (plugin->fn))
471 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn); 497 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", plugin->fn);
472 GNUNET_free (plugin->fn); 498 GNUNET_free (plugin->fn);
473#endif 499#endif
474 GNUNET_free (plugin); 500 GNUNET_free (plugin);