line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## -*- Mode: CPerl -*- |
2
|
|
|
|
|
|
|
## |
3
|
|
|
|
|
|
|
## File: DiaColloDB::Upgrade::v0_04_dlimits.pm |
4
|
|
|
|
|
|
|
## Author: Bryan Jurish <moocow@cpan.org> |
5
|
|
|
|
|
|
|
## Description: DiaColloDB utilities: auto-magic upgrade: v0.04: date-limits @$coldb{qw(xdmin xdmax)} |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package DiaColloDB::Upgrade::v0_04_dlimits; |
8
|
1
|
|
|
1
|
|
7
|
use DiaColloDB::Upgrade::Base; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
9
|
1
|
|
|
1
|
|
6
|
use DiaColloDB::Utils qw(:pack); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
10
|
1
|
|
|
1
|
|
250
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
549
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(DiaColloDB::Upgrade::Base); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
##============================================================================== |
14
|
|
|
|
|
|
|
## API |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
## $version = $up->toversion() |
17
|
|
|
|
|
|
|
## + returns default target version; default just returns $DiaColloDB::VERSION |
18
|
|
|
|
|
|
|
sub toversion { |
19
|
0
|
|
|
0
|
1
|
|
return '0.04.000'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
## $bool = $up->needed() |
23
|
|
|
|
|
|
|
## + returns true iff local index in $dbdir needs upgrade |
24
|
|
|
|
|
|
|
sub needed { |
25
|
0
|
|
|
0
|
1
|
|
my $up = shift; |
26
|
0
|
|
0
|
|
|
|
return !defined($up->{hdr}{xdmin}) || !defined($up->{hdr}{xdmax}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
## $bool = $up->upgrade() |
30
|
|
|
|
|
|
|
## + performs upgrade |
31
|
|
|
|
|
|
|
sub upgrade { |
32
|
0
|
|
|
0
|
1
|
|
my $up = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
##-- backup |
35
|
0
|
0
|
|
|
|
|
$up->backup() or return undef; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
##-- xdmin, xdmax: from xenum |
38
|
0
|
|
|
|
|
|
my $dbdir = $up->{dbdir}; |
39
|
0
|
|
|
|
|
|
my $hdr = $up->dbheader; |
40
|
0
|
0
|
|
|
|
|
my $xenum = $DiaColloDB::XECLASS->new(base=>"$dbdir/xenum") |
41
|
|
|
|
|
|
|
or $up->logconfess("failed to open (tuple+date) enum $dbdir/xenum.*: $!"); |
42
|
0
|
|
|
|
|
|
my $pack_xdate = '@'.(packsize($hdr->{pack_id}) * scalar(@{$hdr->{attrs}})).$hdr->{pack_date}; |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my ($dmin,$dmax) = (undef,undef); |
44
|
0
|
|
|
|
|
|
my ($d); |
45
|
0
|
|
|
|
|
|
foreach (@{$xenum->toArray}) { |
|
0
|
|
|
|
|
|
|
46
|
0
|
0
|
0
|
|
|
|
next if (!$_ || !($d=unpack($pack_xdate,$_))); ##-- ignore null keys and dates |
47
|
0
|
0
|
0
|
|
|
|
$dmin = $d if (!defined($dmin) || $d < $dmin); |
48
|
0
|
0
|
0
|
|
|
|
$dmax = $d if (!defined($dmax) || $d > $dmax); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
0
|
|
|
|
$dmin //= 0; |
51
|
0
|
|
0
|
|
|
|
$dmax //= 0; |
52
|
0
|
|
|
|
|
|
$up->vlog('info', "extracted date-range \"xdmin\":$dmin, \"xdmax\":$dmax"); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
##-- update header |
55
|
0
|
|
|
|
|
|
@$hdr{qw(xdmin xdmax)} = ($dmin,$dmax); |
56
|
0
|
|
|
|
|
|
return $up->updateHeader(); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
##============================================================================== |
60
|
|
|
|
|
|
|
## Backups & Rollback |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
## @files = $up->revert_created() |
63
|
|
|
|
|
|
|
## + returns list of files created by this upgrade, for use with default rollback() implementation |
64
|
|
|
|
|
|
|
sub revert_created { |
65
|
0
|
|
|
0
|
1
|
|
return qw(); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
## @files = $up->revert_updated() |
69
|
|
|
|
|
|
|
## + returns list of files updated by this upgrade, for use with default rollback() implementation |
70
|
|
|
|
|
|
|
sub revert_updated { |
71
|
0
|
|
|
0
|
1
|
|
return qw(header.json); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
##============================================================================== |
76
|
|
|
|
|
|
|
## Footer |
77
|
|
|
|
|
|
|
1; ##-- be happy |