File Coverage

blib/lib/MogileFS/DeviceState.pm
Criterion Covered Total %
statement 8 16 50.0
branch 1 2 50.0
condition 0 3 0.0
subroutine 5 12 41.6
pod 0 11 0.0
total 14 44 31.8


line stmt bran cond sub pod time code
1             package MogileFS::DeviceState;
2 22     22   94 use strict;
  22         27  
  22         6132  
3              
4             # properties are:
5             # read: can it serve traffic?
6             # drain: should its file_on be drained?
7             # new_files: does it get new files
8             # write: is it writable? (for instance, for deletes)
9             # dead: permanently dead, files lost, not coming back to service
10             my $singleton = {
11             'alive' => bless({
12             read => 1,
13             write => 1,
14             monitor => 1,
15             new_files => 1,
16             }),
17             'dead' => bless({
18             # Note that 'dead' doesn't include 'drain', since that's
19             # handled (specially) by the reap job.
20             dead => 1,
21             }),
22             'down' => bless({
23             }),
24             'readonly' => bless({
25             read => 1,
26             monitor => 1,
27             }),
28             'drain' => bless({
29             read => 1,
30             write => 1,
31             drain => 1,
32             monitor => 1,
33             }),
34             };
35              
36             # returns undef if unknown state
37             sub of_string {
38 290     290 0 505 my ($class, $state) = @_;
39 290 50       626 return $state ? $singleton->{$state} : undef;
40             }
41              
42 0     0 0 0 sub should_drain { $_[0]->{drain} }
43 0     0 0 0 sub can_delete_from { $_[0]->{write} }
44 0     0 0 0 sub can_read_from { $_[0]->{read} }
45 54     54 0 127 sub should_get_new_files { $_[0]->{new_files} }
46 125     125 0 325 sub should_get_repl_files { $_[0]->{new_files} }
47 219     219 0 517 sub should_have_files { ! $_[0]->{dead} }
48 0     0 0   sub should_monitor { $_[0]->{monitor} }
49              
50             # named inconveniently so it's not taken to mean equalling string
51             # "dead"
52 0     0 0   sub is_perm_dead { $_[0]->{dead} }
53              
54 0     0 0   sub should_wake_reaper { $_[0]->{dead} }
55              
56             sub should_fsck_search_on {
57 0     0 0   my $ds = shift;
58 0   0       return $ds->can_read_from || $ds->should_have_files;
59             }
60              
61             1;
62