Commit c9604fac authored by anb's avatar anb Committed by Anbang Wen

Restore visibility for cache stats

Add the missing stats for cache module.
parent d71db413
......@@ -64,6 +64,23 @@ static inline int cache_clear(struct kr_cache *cache)
return cache_op(cache, clear);
}
/** @internal Wrap cache operation with stats counter */
static inline int cache_op_read(struct kr_cache *cache,
const knot_db_val_t *key,
knot_db_val_t *val, int maxcount) {
int ret = cache_op(cache, read, key, val, maxcount);
if (!ret) {
cache->stats.hit += 1;
return ret;
}
if (ret == -abs(ENOENT)) {
cache->stats.miss += 1;
}
return ret;
}
/** @internal Open cache db transaction and check internal data version. */
static int assert_right_version(struct kr_cache *cache)
{
......@@ -71,7 +88,7 @@ static int assert_right_version(struct kr_cache *cache)
uint8_t key_str[] = "\x00\x00V"; /* CACHE_KEY_DEF; zero-term. but we don't care */
knot_db_val_t key = { .data = key_str, .len = sizeof(key_str) };
knot_db_val_t val = { NULL, 0 };
int ret = cache_op(cache, read, &key, &val, 1);
int ret = cache_op_read(cache, &key, &val, 1);
if (ret == 0 && val.len == sizeof(CACHE_VERSION)
&& memcmp(val.data, &CACHE_VERSION, sizeof(CACHE_VERSION)) == 0) {
ret = kr_error(EEXIST);
......@@ -356,7 +373,7 @@ static int cache_peek_real(kr_layer_t *ctx, knot_pkt_t *pkt)
*/
knot_db_val_t key = key_exact_type_maypkt(k, qry->stype);
knot_db_val_t val = { NULL, 0 };
ret = cache_op(cache, read, &key, &val, 1);
ret = cache_op_read(cache, &key, &val, 1);
if (!ret) {
/* found an entry: test conditions, materialize into pkt, etc. */
ret = found_exact_hit(ctx, pkt, val, lowest_rank);
......@@ -528,7 +545,7 @@ static int cache_peek_real(kr_layer_t *ctx, knot_pkt_t *pkt)
}
/** 4. add SOA iff needed
/** 4. add SOA if needed
*/
do_soa:
if (ans.rcode != PKT_NOERROR) {
......@@ -537,7 +554,7 @@ do_soa:
k->buf[0] = k->zlf_len;
key = key_exact_type(k, KNOT_RRTYPE_SOA);
knot_db_val_t val = { NULL, 0 };
ret = cache_op(cache, read, &key, &val, 1);
ret = cache_op_read(cache, &key, &val, 1);
const struct entry_h *eh;
if (ret || !(eh = entry_h_consistent(val, KNOT_RRTYPE_SOA))) {
assert(ret); /* only want to catch `eh` failures */
......@@ -904,7 +921,7 @@ static int try_wild(struct key *k, struct answer *ans, const knot_dname_t *clenc
knot_db_val_t key = key_exact_type(k, type);
/* Find the record. */
knot_db_val_t val = { NULL, 0 };
int ret = cache_op(cache, read, &key, &val, 1);
int ret = cache_op_read(cache, &key, &val, 1);
if (!ret) {
ret = entry_h_seek(&val, type);
}
......@@ -958,7 +975,7 @@ static int peek_exact_real(struct kr_cache *cache, const knot_dname_t *name, uin
knot_db_val_t key = key_exact_type(k, type);
knot_db_val_t val = { NULL, 0 };
ret = cache_op(cache, read, &key, &val, 1);
ret = cache_op_read(cache, &key, &val, 1);
if (!ret) ret = entry_h_seek(&val, type);
if (ret) return kr_error(ret);
......@@ -1016,7 +1033,7 @@ static knot_db_val_t closest_NS(kr_layer_t *ctx, struct key *k)
k->buf[0] = zlf_len;
knot_db_val_t key = key_exact_type(k, KNOT_RRTYPE_NS);
knot_db_val_t val = VAL_EMPTY;
int ret = cache_op(cache, read, &key, &val, 1);
int ret = cache_op_read(cache, &key, &val, 1);
if (ret == -abs(ENOENT)) goto next_label;
if (ret) {
assert(!ret);
......
Markdown is supported
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