Changeset 356

Show
Ignore:
Timestamp:
08/17/06 19:18:38 (2 years ago)
Author:
marksmith
Message:

* add 'replicate_now' command which makes due all deferred replications
* add stats to replication output for new style file_to_replicate table

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/server-newrepl/lib/MogileFS/Worker/Query.pm

    r342 r356  
    158158 
    159159    # figure out what classid this file is for 
    160     my $class = $args->{class}
     160    my $class = $args->{class} || ""
    161161    my $classid = 0; 
    162162    if (length($class)) { 
     
    10321032        } 
    10331033        $ret->{"replicationcount"} = $count; 
     1034 
     1035        # now we want to do the "new" replication stats 
     1036        my $db_time = $dbh->selectrow_array('SELECT UNIX_TIMESTAMP()'); 
     1037        $stats = $dbh->selectall_arrayref('SELECT nexttry, COUNT(*) FROM file_to_replicate GROUP BY 1'); 
     1038        foreach my $stat (@$stats) { 
     1039            if ($stat->[0] < 1000) { 
     1040                # anything under 1000 is a specific state, so let's define those.  here's the list 
     1041                # of short names to describe them. 
     1042                my $name = { 
     1043                    0 => 'newfile', # new files that need to be replicated 
     1044                    1 => 'redo',    # files that need to go through replication again 
     1045                }->{$stat->[0]} || "unknown"; 
     1046 
     1047                # now put it in the output hashref.  note that we do += because we might 
     1048                # have more than one group of unknowns. 
     1049                $ret->{"to_replicate_$name"} += $stat->[1]; 
     1050 
     1051            } elsif ($stat->[0] == MogileFS::Worker::Replicate::end_of_time()) { 
     1052                $ret->{"to_replicate_manually"} = $stat->[1]; 
     1053 
     1054            } elsif ($stat->[0] < $db_time) { 
     1055                $ret->{"to_replicate_overdue"} += $stat->[1]; 
     1056 
     1057            } else { 
     1058                $ret->{"to_replicate_deferred"} += $stat->[1]; 
     1059            } 
     1060        } 
    10341061    } 
    10351062 
     
    10751102    my MogileFS::Worker::Query $self = shift; 
    10761103    my $args = shift; 
     1104    return $self->ok_line; 
     1105} 
     1106 
     1107sub cmd_replicate_now { 
     1108    my MogileFS::Worker::Query $self = shift; 
     1109 
     1110    my $dbh = Mgd::get_dbh() 
     1111        or return $self->err_line('nodb'); 
     1112    $dbh->do("UPDATE file_to_replicate SET nexttry = UNIX_TIMESTAMP() WHERE nexttry > UNIX_TIMESTAMP()"); 
     1113 
    10771114    return $self->ok_line; 
    10781115}