Subject: | resize_RRA does not rely to ptr leading to datashift which broke RRA data |
resize_RRA must rely to ptr when increasing/decreasing size.
Suggested fix:
sub resize_RRA {
my ($self, $idx, $size) = @_; my $rrd=$self->{rrd};
if ($idx > $rrd->{rra_cnt} || $idx<0) {croak("RRA index out of range\n");}
if ($size < 0) {$size=0;}
# load RRA data, if not already loaded
if (!defined($rrd->{dataloaded})) {$self->_loadRRAdata;}
# update data
my $row_cnt = $rrd->{rra}[$idx]->{row_cnt};
my $ptr = $rrd->{rra}[$idx]->{ptr};
my $empty = $self->_packd([(NAN)x$rrd->{ds_cnt}]);
if ($size > $row_cnt) {
# Expand
splice( @{$rrd->{rra}[$idx]->{data}}, $ptr+1, 0, ( ($empty)x($size-$row_cnt) ) );
} elsif ($size < $row_cnt) {
# Shrink; removing tail
my $cnt_strip = $row_cnt-$size;
my $tail = ($ptr+1 + $cnt_strip > $size ? $row_cnt - $ptr-1 : $cnt_strip);
splice(@{$rrd->{rra}[$idx]->{data}}, $ptr+1, $tail);
# then removing head if remainder
splice(@{$rrd->{rra}[$idx]->{data}}, 0, $cnt_strip-$tail) if $tail < $cnt_strip;
}
$rrd->{rra}[$idx]->{row_cnt} = $size;
return 1;
}