From: Vladimír Čunát Date: Mon, 24 Aug 2020 16:01:59 +0000 (+0200) Subject: utils/cache_gc nitpick: more precise error prints X-Git-Tag: v5.1.3~1^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64b22c321e2dfb2fd23f09a7030f3348f30023e9;p=thirdparty%2Fknot-resolver.git utils/cache_gc nitpick: more precise error prints --- diff --git a/utils/cache_gc/db.c b/utils/cache_gc/db.c index c71fabf60..3a853b430 100644 --- a/utils/cache_gc/db.c +++ b/utils/cache_gc/db.c @@ -179,12 +179,15 @@ int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg, return ret; } - it = api->iter_begin(&txn, KNOT_DB_FIRST); + it = api->iter_begin(&txn, KNOT_DB_NOOP); // _FIRST is split for easier debugging if (it == NULL) { - printf("Error iterating database.\n"); + printf("Error: failed to create an iterator.\n"); api->txn_abort(&txn); return KNOT_ERROR; } + it = api->iter_seek(it, NULL, KNOT_DB_FIRST); + if (it == NULL) + printf("Suspicious: completely empty LMDB at this moment?\n"); int txn_steps = 0; while (it != NULL) { @@ -267,7 +270,7 @@ int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg, } it = api->iter_begin(&txn, KNOT_DB_NOOP); if (it == NULL) { - printf("Error iterating database.\n"); + printf("Error: failed to create an iterator.\n"); api->txn_abort(&txn); return KNOT_ERROR; } diff --git a/utils/cache_gc/db.h b/utils/cache_gc/db.h index 44cfbec29..0e20df19d 100644 --- a/utils/cache_gc/db.h +++ b/utils/cache_gc/db.h @@ -22,3 +22,9 @@ int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg, kr_gc_iter_callback callback, void *ctx); const uint16_t *kr_gc_key_consistent(knot_db_val_t key); + +#ifdef DEBUG +/** Printf a *binary* string in a human-readable way. */ +void debug_printbin(const char *str, unsigned int len); +#endif + diff --git a/utils/cache_gc/kr_cache_gc.c b/utils/cache_gc/kr_cache_gc.c index 1308c75ef..5aae95f04 100644 --- a/utils/cache_gc/kr_cache_gc.c +++ b/utils/cache_gc/kr_cache_gc.c @@ -281,6 +281,13 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg, kr_cache_gc_state_t **state) break; case KNOT_ENOENT: already_gone++; +#ifdef DEBUG + // kresd normally only inserts (or overwrites), + // so it's generally suspicious when a key goes missing. + printf("Record already gone (key len %zu): ", (*i)->len); + debug_printbin((*i)->data, (*i)->len); + printf("\n"); +#endif break; case KNOT_ESPACE: printf("Warning: out of space, bailing out to retry later.\n");