mogtool patch to list all files matching a given key prefix

Arthur Bebak abebak at fabrikinc.com
Thu Oct 19 19:32:40 UTC 2006


This patch adds a new command "listkey" to mogtool. It will
list all files in MogileFS which match the given prefix.

Example: List all files in MogileFS whose keys start with the characters "abc1".

mogtool listkey abc1

To apply the patch to the current mogtool copy everything
between the patch begins/patch ends lines below, put it
in a file called "mogpatch" and run the patch tool like so:

patch mogtool mogpatch

Hopefully Mark or Brad can just check this into subversion.

Would be nice if we could list all keys which match a given
regexp, but I think that would require a change to MogileFS
to give us a REGEXP SQL query on the keys.


--------------- patch begins ---------------
1a2,4
 >
 > eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
 >     if 0; # not running under some shell
35a39
 >     $ mogtool listkey
92a97,102
 > =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"
 >
395a406,411
 > =head2 Listing Files Matching a Key
 >
 >     $ mogtool listkey abc1
 >
 > Lists all files in MogileFS whose keys start with the characters "abc1".
 >
533c549
< eval "use MogileFS::Client;";
---
 > eval "use MogileFS;";
547a564
 > listkey() if $cmd eq 'lsk' || $cmd eq "listkey";
568c585
<     my $mogfs = MogileFS::Client->new(
---
 >     my $mogfs = MogileFS->new(
1195a1213,1234
 > 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;
 > }
 >
---------------------- patch ends --------------------
-- 
Arthur Bebak
abebak at fabrikinc.com


More information about the mogilefs mailing list