diff --git a/utils/cache_gc/db.c b/utils/cache_gc/db.c index c71fabf60e152909d5b35fc1010fe7552a0f7db0..3a853b430b57ebecbd39925da6a26f6431dd1897 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 44cfbec2955c3658caf9594b685934e1127bc257..0e20df19d43afdfdb9a106284f0f169cf1667fe2 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 1308c75efebdabcfb941bb211ae3083d480ff2c8..5aae95f047af42a8a1d36b7d77102a9f82d7d665 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");