Skip to content

Commit

Permalink
Add 'domains' to mogstats for faster fetch
Browse files Browse the repository at this point in the history
Last release of mogstats upped verbosity of --stats files, which no longer
could satisfy the summation using the index. If you need a faster/lighter view
this mode is provided for compatibility.

(by pyhhak)

git-svn-id: http://code.sixapart.com/svn/mogilefs/trunk@1461 f67b2e87-0811-0410-a7e0-dd94e48410d6
  • Loading branch information
dormando committed Aug 2, 2010
1 parent d1bb31c commit 28ed4bb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Add 'domains' argument to mogstats for faster queries on basic by-domain
and class stats. (pyhhak)

2.16 -- 2010-04-02

* Add --replpolicy option for configuring a replication policy string.
Expand Down
39 changes: 38 additions & 1 deletion mogstats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Getopt::Long;
# FIXME: decide how to share constants between utils and server.
use constant ENDOFTIME => 2147483647;
my %QUEUES = ( 1 => 'FSCK_QUEUE' );
my %valid_stats = map { $_ => 1 } qw/devices fids files replication replication-queue delete-queue general-queues all/;
my %valid_stats = map { $_ => 1 } qw/devices fids files domains replication replication-queue delete-queue general-queues all/;

my $DBH_CACHE = '';
my $DB_TYPE = '';
Expand Down Expand Up @@ -112,6 +112,20 @@ sub cmd_stats {
printf " -------------------- ----------- ---------- ----------- -------------\n";
}

if ($args{domains} && !($args{files} || $args{all})) {
print "\nStatistics for domains...\n";
printf " %-20s %-10s %10s\n", 'domain', 'class', 'files';
printf " -------------------- ----------- ----------\n";
foreach my $domain (sort keys %{$stats->{domains}}) {
my $classes = $stats->{domains}->{$domain};
foreach my $class (sort keys %$classes) {
my $files = $classes->{$class};
printf " %-20s %-10s %10s\n", $domain, $class, $files;
}
}
printf " -------------------- ----------- ----------\n";
}

if ($args{replication} || $args{all}) {
print "\nStatistics for replication...\n";
printf " %-20s %-10s %10s %10s\n", 'domain', 'class', 'devcount', 'files';
Expand Down Expand Up @@ -241,6 +255,11 @@ sub stats_from_db {
$ret->{files} = stats_for_files(\%globals);
}

# domain statistics (how many files per domain, faster than file stats)
if ($args->{domains} && !($args->{files} || $args->{all})) {
$ret->{domains} = stats_for_domains(\%globals);
}

# device statistics (how many files are on each device)
if ($args->{devices} || $args->{all}) {
$ret->{devices} = stats_for_devices(\%globals);
Expand Down Expand Up @@ -301,6 +320,24 @@ sub stats_for_files {
return $files;
}

sub stats_for_domains {
my $globals = shift;
my %classes = %{$globals->{classes}};
my %devices = %{$globals->{devices}};
my $dbh = get_dbh() or die "Could not get database handle";

verbose("... domains stats...");
my $stats = $dbh->selectall_arrayref('SELECT dmid, classid, COUNT(classid) FROM file GROUP BY 1, 2');
my $files = {};
for my $stat (@$stats) {
my $domain = $classes{$stat->[0]}->{name};
my $class = $classes{$stat->[0]}->{classes}->{$stat->[1]};
$files->{$domain}->{$class} = $stat->[2];
}
verbose("... done");
return $files;
}

sub stats_for_replication {
my $globals = shift;
my %classes = %{$globals->{classes}};
Expand Down

0 comments on commit 28ed4bb

Please sign in to comment.