BUG/MINOR: cache: do not display expired entries in "show cache"
authorWilly Tarreau <w@1wt.eu>
Wed, 13 Apr 2022 09:21:39 +0000 (11:21 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 29 Apr 2022 13:49:18 +0000 (15:49 +0200)
It was mentioned in issue #12 that expired entries would appear with a
negative expire delay in "show cache". Instead of listing them, let's
just evict them.

This could be backported to all versions since this was reported on
1.8 already.

(cherry picked from commit f1de1b51cab49f654938524a515cf26ac2db0bf5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit d3a85582c8f58539e9d084db8bb8ce5659f9d866)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit dcce27fda1bc548b5d6fdafaf3a34359e1ac05ba)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/cache.c

index 4c34377..0568abe 100644 (file)
@@ -1723,9 +1723,19 @@ static int cli_io_handler_show_cache(struct appctx *appctx)
                        }
 
                        entry = container_of(node, struct cache_entry, eb);
-                       chunk_printf(&trash, "%p hash:%u size:%u (%u blocks), refcount:%u, expire:%d\n", entry, read_u32(entry->hash), block_ptr(entry)->len, block_ptr(entry)->block_count, block_ptr(entry)->refcount, entry->expire - (int)now.tv_sec);
-
                        next_key = node->key + 1;
+
+                       if (entry->expire > now.tv_sec) {
+                               chunk_printf(&trash, "%p hash:%u size:%u (%u blocks), refcount:%u, expire:%d\n",
+                                            entry, read_u32(entry->hash),
+                                            block_ptr(entry)->len, block_ptr(entry)->block_count,
+                                            block_ptr(entry)->refcount, entry->expire - (int)now.tv_sec);
+                       } else {
+                               /* time to remove that one */
+                               eb32_delete(&entry->eb);
+                               entry->eb.key = 0;
+                       }
+
                        appctx->ctx.cli.i0 = next_key;
 
                        shctx_unlock(shctx_ptr(cache));