Skip to content

Commit

Permalink
Fix files stat under Postgres.
Browse files Browse the repository at this point in the history
  • Loading branch information
robbat2 authored and dormando committed Dec 10, 2010
1 parent 6572670 commit a6e108b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fix files stat under Postgres (Robin H. Johnson)

2.18 -- 2010-09-28

* Add rebalance commands
Expand Down
9 changes: 8 additions & 1 deletion mogstats
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,21 @@ sub stats_for_devices {
return $devs;
}

sub stats_for_files_sql {
my $sql = 'SELECT dmid, classid, COUNT(classid), sum(length), sum(length::int4 * devcount::int4) FROM file GROUP BY 1, 2';
return $sql if ($DB_TYPE eq 'Postgres');
$sql =~ s/::int4//g;
return $sql;
}

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

verbose("... files stats...");
my $stats = $dbh->selectall_arrayref('SELECT dmid, classid, COUNT(classid), sum(length), sum(length * devcount) FROM file GROUP BY 1, 2');
my $stats = $dbh->selectall_arrayref(stats_for_files_sql());
my $files = {};
for my $stat (@$stats) {
my $domain = $classes{$stat->[0]}->{name};
Expand Down

0 comments on commit a6e108b

Please sign in to comment.