From: Peter Stamfest Date: Thu, 27 Feb 2014 10:01:33 +0000 (+0100) Subject: Allow RRA resize to absolutely specified row_count X-Git-Tag: v1.5.0-rc1~131^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f45d83101b25553a4415d557aa5ab79c3e9fa99;p=thirdparty%2Frrdtool-1.x.git Allow RRA resize to absolutely specified row_count --- diff --git a/src/rrd_modify.c b/src/rrd_modify.c index f56899ed..992ad27b 100644 --- a/src/rrd_modify.c +++ b/src/rrd_modify.c @@ -464,16 +464,35 @@ static int rrd_modify_r(const char *infilename, */ if (rra_op) { - switch (rra_op->op) { + char op = rra_op->op; + unsigned int row_count = rra_op->row_count; + + // rewrite '=' ops into '-' or '+' for better code-reuse... + if (op == '=') { + if (row_count < in.rra_def[i].row_cnt) { + row_count = in.rra_def[i].row_cnt - row_count; + op = '-'; + } else if (row_count > in.rra_def[i].row_cnt) { + row_count = row_count - in.rra_def[i].row_cnt; + op = '+'; + } else { + // equal - special case: nothing to do... + } + } + + switch (op) { + case '=': + // no op + break; case '-': // remove rows: just skip the first couple of rows! - ii = rra_op->row_count; + ii = row_count; break; case '+': // add rows: insert the requested number of rows! // currently, just add the all as NaN values... - for ( ; oi < rra_op->row_count ; oi++) { + for ( ; oi < row_count ; oi++) { for (j = 0 ; j < out.stat_head->ds_cnt ; j++) { out.rrd_value[total_cnt_out + oi * out.stat_head->ds_cnt +