[memcached] plindner, r502: add new experimental dump mode

commits at code.sixapart.com commits at code.sixapart.com
Thu Apr 12 22:17:24 UTC 2007


add new experimental dump mode

U   trunk/server/scripts/memcached-tool


Modified: trunk/server/scripts/memcached-tool
===================================================================
--- trunk/server/scripts/memcached-tool	2007-04-12 20:03:15 UTC (rev 501)
+++ trunk/server/scripts/memcached-tool	2007-04-12 22:17:24 UTC (rev 502)
@@ -26,6 +26,8 @@
     undef $mode if $from < 6 || $from > 17;
     undef $mode if $to   < 6 || $to   > 17;
     print STDERR "ERROR: parameters out of range\n\n" unless $mode;
+} elsif ($mode eq 'dump') {
+    ;
 } else {
     undef $mode;
 }
@@ -78,6 +80,53 @@
     exit;
 }
 
+if ($mode eq 'dump') {
+    my %items;
+    my $totalitems;
+
+    print $sock "stats items\r\n";
+
+    while (<$sock>) {
+        last if /^END/;
+        if (/^STAT items:(\d*):number (\d*)/) {
+            $items{$1} = $2;
+            $totalitems += $2;
+        }
+    }
+    print STDERR "Dumping memcache contents\n";
+    print STDERR "  Number of buckets: " . scalar(keys(%items)) . "\n";
+    print STDERR "  Number of items  : $totalitems\n";
+
+    foreach my $bucket (sort(keys(%items))) {
+        print STDERR "Dumping bucket $bucket - " . $items{$bucket} . " total items\n";
+        print $sock "stats cachedump $bucket $items{$bucket} 1\r\n";
+        my %keyexp;
+        while (<$sock>) {
+            last if /^END/;
+            # return format looks like this
+            # ITEM foo [6 b; 1176415152 s]
+            if (/^ITEM (\w+) \[.* (\d+) s\]/) {
+                $keyexp{$1} = $2;
+            }
+        }
+
+        foreach my $k (keys(%keyexp)) {
+            my $val;
+            print $sock "get $k\r\n";
+            my $response = <$sock>;
+            $response =~ /VALUE (\w+) (\d+) (\d+)/;
+            my $flags = $2;
+            my $len = $3;
+            read $sock, $val , $len;
+            # get the END
+            $_ = <$sock>;
+            $_ = <$sock>;
+            print "add $k $flags $keyexp{$k} $len\r\n$val\r\n";
+        }
+    }
+    exit;
+}
+
 # display mode:
 
 my %items;  # class -> { number, age, chunk_size, chunks_per_page,




More information about the memcached-commits mailing list