summaryrefslogtreecommitdiff
path: root/t/watcher.t
diff options
context:
space:
mode:
authorHemal Shah <hemal@stripe.com>2022-10-19 19:17:13 -0700
committerdormando <dormando@rydia.net>2023-03-15 17:16:36 -0700
commit9b3c946f485309cdf50f7fb1622707b5373e33f3 (patch)
tree50442521e1d2912caddfe0266f5223b0f4b48fb3 /t/watcher.t
parentc04701654413719d4abd7645c6d7b3fba4255e85 (diff)
downloadmemcached-9b3c946f485309cdf50f7fb1622707b5373e33f3.tar.gz
log: Add a new watcher to watch for deletions.
`watch deletions`: would log all keys which are deleted using either `delete` or `md` command. The log line would contain the command used, the key, the clsid and size of the deleted item. Items which result in delete miss or are marked as stale wouldn't show up in the logs
Diffstat (limited to 't/watcher.t')
-rwxr-xr-xt/watcher.t49
1 files changed, 48 insertions, 1 deletions
diff --git a/t/watcher.t b/t/watcher.t
index f977c2a..09800a9 100755
--- a/t/watcher.t
+++ b/t/watcher.t
@@ -10,7 +10,7 @@ use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
-plan tests => 30;
+plan tests => 43;
my $server = new_memcached('-m 60 -o watcher_logbuf_size=8');
my $client = $server->sock;
@@ -235,3 +235,50 @@ SKIP: {
is($watchresult, "CLIENT_ERROR watch commands not allowed\r\n", "attempted watch gave client error with no_watch option set");
}
+
+
+# test delete/meta-delete with value sizes
+{
+ my $watcher = $server->new_sock;
+ print $watcher "watch deletions\n";
+ is(<$watcher>, "OK\r\n", "deletions watcher enabled");
+
+ print $client "set vfoo 0 0 4\r\nvbar\r\n";
+ is(<$client>, "STORED\r\n", "stored the key");
+
+ # wouldn't be logged to watcher
+ print $client "md non-existing-key\r\n";
+ is(<$client>, "NF\r\n", "non-existing key can't be deleted");
+
+ print $client "delete vfoo\r\n";
+ is(<$client>, "DELETED\r\n", "key was deleted");
+
+ like(<$watcher>, qr/ts=\d+\.\d+\ gid=\d+ type=deleted key=vfoo cmd=delete .+ size=4/,
+ "delete command logged with correct size");
+
+ print $client "set vfoo 0 0 4\r\nvbar\r\n";
+ is(<$client>, "STORED\r\n", "stored the key");
+
+ print $client "md vfoo\r\n";
+ is(<$client>, "HD\r\n", "key was deleted");
+
+ like(<$watcher>, qr/ts=\d+\.\d+\ gid=\d+ type=deleted key=vfoo cmd=md .+ size=4/,
+ "meta-delete command logged with correct size");
+
+ print $client "set vfoo 0 0 4\r\nvbar\r\n";
+ is(<$client>, "STORED\r\n", "stored the key");
+
+ # shouldn't result in log line
+ print $client "md vfoo I\r\n";
+ is(<$client>, "HD\r\n", "key was marked stale");
+
+ print $client "mg vfoo\r\n";
+ is(<$client>, "HD X W\r\n", "mg shows key is stale and won recache");
+
+ # now do a delete and it will show up in the log, explicitly use delete instead of md to check the cmd= pair in log
+ print $client "delete vfoo\r\n";
+ is(<$client>, "DELETED\r\n", "key was deleted");
+
+ like(<$watcher>, qr/ts=\d+\.\d+\ gid=\d+ type=deleted key=vfoo cmd=delete .+ size=4/,
+ "delete command logged with correct size");
+}