Skip to content
Snippets Groups Projects
Verified Commit 6e927fc7 authored by Petr Špaček's avatar Petr Špaček
Browse files

gc: verbose mode is now runtime option

parent 64b22c32
Branches
Tags
1 merge request!1042cache-forking fixes
/* 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>
......@@ -124,7 +122,6 @@ static uint8_t entry_labels(knot_db_val_t * key, uint16_t rrtype)
return lab;
}
#ifdef DEBUG
void debug_printbin(const char *str, unsigned int len)
{
putchar('"');
......@@ -137,7 +134,6 @@ void debug_printbin(const char *str, unsigned int len)
}
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)
......@@ -161,11 +157,9 @@ 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;
......@@ -210,9 +204,7 @@ int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg,
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:
......@@ -226,18 +218,18 @@ int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg,
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) {
......@@ -280,9 +272,8 @@ int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg,
}
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;
}
......@@ -23,8 +23,6 @@ int kr_gc_cache_iter(knot_db_t * knot_db, const kr_cache_gc_cfg_t *cfg,
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
......@@ -14,6 +14,7 @@
#include <lib/cache/impl.h>
#include <lib/defines.h>
#include "lib/cache/cdb_lmdb.h"
#include "lib/utils.h"
#include "kr_cache_gc.h"
......@@ -218,15 +219,15 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg, kr_cache_gc_state_t **state)
/* 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) {
......@@ -281,13 +282,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
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");
......
......@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
};
int o;
while ((o = getopt(argc, argv, "hnc:d:l:L:m:u:f:w:t:")) != -1) {
while ((o = getopt(argc, argv, "hnvc:d:l:L:m:u:f:w:t:")) != -1) {
switch (o) {
case 'c':
cfg.cache_path = optarg;
......@@ -114,6 +114,9 @@ int main(int argc, char *argv[])
case 'n':
cfg.dry_run = true;
break;
case 'v':
kr_verbose_set(true);
break;
case ':':
case '?':
case 'h':
......@@ -129,10 +132,6 @@ int main(int argc, char *argv[])
return 1;
}
#ifdef DEBUG
kr_verbose_set(true); // used inside cache operations
#endif
int exit_code = 0;
kr_cache_gc_state_t *gc_state = NULL;
bool last_espace = false;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment