/* SPDX-License-Identifier: GPL-3.0-or-later */
-// #define DEBUG 1
#include "db.h"
#include "lib/cache/cdb_lmdb.h"
#include "lib/cache/impl.h"
-//#include <lib/defines.h>
-#include <ctype.h> //DEBUG
+#include <ctype.h>
#include <time.h>
#include <sys/stat.h>
return lab;
}
-#ifdef DEBUG
void debug_printbin(const char *str, unsigned int len)
{
putchar('"');
}
putchar('"');
}
-#endif
/** Return one entry_h reference from a cache DB value. NULL if not consistent/suitable. */
static const struct entry_h *val2entry(const knot_db_val_t val, uint16_t ktype)
int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg,
kr_gc_iter_callback callback, void *ctx)
{
-#ifdef DEBUG
unsigned int counter_iter = 0;
unsigned int counter_gc_consistent = 0;
unsigned int counter_kr_consistent = 0;
-#endif
knot_db_txn_t txn = { 0 };
knot_db_iter_t *it = NULL;
ret == KNOT_EOK ? kr_gc_key_consistent(key) : NULL;
const struct entry_h *entry = NULL;
if (entry_type != NULL) {
-#ifdef DEBUG
counter_gc_consistent++;
-#endif
entry = val2entry(val, *entry_type);
}
/* TODO: perhaps improve some details around here:
info.expires_in = entry->time + entry->ttl - now;
info.no_labels = entry_labels(&key, *entry_type);
}
-#ifdef DEBUG
counter_iter++;
counter_kr_consistent += info.valid;
- if (!entry_type || !entry) { // don't log fully consistent entries
- printf
- ("GC %sconsistent, KR %sconsistent, size %zu, key len %zu: ",
- entry_type ? "" : "in", entry ? "" : "IN",
- (key.len + val.len), key.len);
- debug_printbin(key.data, key.len);
- printf("\n");
+ if (VERBOSE_STATUS) {
+ if (!entry_type || !entry) { // don't log fully consistent entries
+ printf
+ ("GC %sconsistent, KR %sconsistent, size %zu, key len %zu: ",
+ entry_type ? "" : "in", entry ? "" : "IN",
+ (key.len + val.len), key.len);
+ debug_printbin(key.data, key.len);
+ printf("\n");
+ }
}
-#endif
ret = callback(&key, &info, ctx);
if (ret != KNOT_EOK) {
}
api->txn_abort(&txn);
-#ifdef DEBUG
- printf("DEBUG: iterated %u items, gc consistent %u, kr consistent %u\n",
- counter_iter, counter_gc_consistent, counter_kr_consistent);
-#endif
+
+ kr_log_verbose("DEBUG: iterated %u items, gc consistent %u, kr consistent %u\n",
+ counter_iter, counter_gc_consistent, counter_kr_consistent);
return KNOT_EOK;
}
#include <lib/cache/impl.h>
#include <lib/defines.h>
#include "lib/cache/cdb_lmdb.h"
+#include "lib/utils.h"
#include "kr_cache_gc.h"
/* use less precise variant to avoid 32-bit overflow */
ssize_t amount_tofree = cats_sumsize / 100 * cfg->cache_to_be_freed;
-#ifdef DEBUG
- printf("tofree: %zd / %zd\n", amount_tofree, cats_sumsize);
- for (int i = 0; i < CATEGORIES; i++) {
- if (cats.categories_sizes[i] > 0) {
- printf("category %.2d size %zu\n", i,
- cats.categories_sizes[i]);
+ kr_log_verbose("tofree: %zd / %zd\n", amount_tofree, cats_sumsize);
+ if (VERBOSE_STATUS) {
+ for (int i = 0; i < CATEGORIES; i++) {
+ if (cats.categories_sizes[i] > 0) {
+ printf("category %.2d size %zu\n", i,
+ cats.categories_sizes[i]);
+ }
}
}
-#endif
category_t limit_category = CATEGORIES;
while (limit_category > 0 && amount_tofree > 0) {
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
+ if (VERBOSE_STATUS) {
+ // 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");
+ }
break;
case KNOT_ESPACE:
printf("Warning: out of space, bailing out to retry later.\n");