Patch for the latest mogtool to add the "listkey" command

Arthur Bebak abebak at fabrikinc.com
Wed Nov 15 21:29:16 UTC 2006


Attached is a a patch to mogtool which will add a "listkey" command.
The patch works against mogtool checked into subversion at revision 483.

listkey will list all files which match the given key. Key is just a prefix,
and this will list all keys which match the prefix. So if you specify key as
"ABC1" then you'll get all keys which start with the characters "ABC1"

So for example:

mogtool listkey ABC1

This will list all keys which start with the characters "ABC1".

Obviously it would be nice if the given key could be a regexp, but
we'd need support on the server side to do regexp matching against
keys in the database to implement this.

This patch is a followup to an earlier one I submitted on the list,
but it never got incorporated into subversion, so here it is again
after mogtool has been slightly updated.

To apply:

patch mogtool <mogtool_patch-483

Enjoy,
-- 
Arthur Bebak
abebak at fabrikinc.com
-------------- next part --------------
--- ./mogtool	2006-10-19 23:26:34.000000000 -0700
+++ /root/mogtool	2006-11-15 20:05:18.000000000 -0800
@@ -1,4 +1,7 @@
 #!/usr/bin/perl
+
+eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
+    if 0; # not running under some shell
 ############################################################################
 
 =head1 NAME
@@ -33,6 +36,7 @@
     $ mogtool delete thekey
 
     $ mogtool list
+    $ mogtool listkey
 
 =head1 GENERAL OPTIONS
 
@@ -90,6 +94,12 @@
 
 List all big files contained in MogileFS.  No options, no arguments.
 
+=item listkey|lsk key
+
+List all files which match the key. Key is just a prefix, and this will list
+all keys which match the prefix. So if you specify key as "ABC1" then you'll 
+get all keys which start with the characters "ABC1" 
+
 =back
 
 =head1 INJECT OPTIONS
@@ -393,6 +403,12 @@
 Lists all large files stored in MogileFS.  It is not possible to list all normal files
 at this time.
 
+=head2 Listing Files Matching a Key
+
+    $ mogtool listkey abc1
+
+Lists all files in MogileFS whose keys start with the characters "abc1".
+
 =head1 CONFIGURATION FILE
 
 Instead of adding a ton of options to the command line every time, mogtool enables
@@ -545,6 +561,7 @@
 inject() if $cmd eq 'i' || $cmd eq "inject";
 extract() if $cmd eq 'x' || $cmd eq "extract";
 list() if $cmd eq 'ls' || $cmd eq "list";
+listkey() if $cmd eq 'lsk' || $cmd eq "listkey";
 mdelete() if $cmd eq 'rm' || $cmd eq "delete";
 
 # fail if we get this far
@@ -1193,6 +1210,28 @@
     exit 0;
 }
 
+sub listkey {
+
+    my $key_pattern = shift(@ARGV);
+    abortWithUsage() unless $key_pattern;
+
+    # list all files matchine a key
+    my ($ct, $after, $list);
+    while (($after, $list) = $mogfs->list_keys("$key_pattern", $after)) {
+        last unless $list && @$list;
+
+        # now extract the key and dump it
+        foreach my $key (@$list) {
+
+            $ct++;
+
+            print "$key\n";
+        }
+    }
+    print "#$ct files found\n";
+    exit 0;
+}
+
 sub mdelete {
     my $key = shift(@ARGV);
     abortWithUsage() unless $key;


More information about the mogilefs mailing list