Ticket #178: filepos.patch

File filepos.patch, 6.2 KB (added by human, 18 months ago)

patch to rrd_update

  • rrd_update.c

     
    780780    } 
    781781    /* seek to the beginning of the rra's */ 
    782782    if (*rra_current != rra_begin) { 
    783 #ifndef HAVE_MMAP 
    784783        if (rrd_seek(rrd_file, rra_begin, SEEK_SET) != 0) { 
    785784            rrd_set_error("seek error in rrd"); 
    786785            return -1; 
    787786        } 
    788 #endif 
    789787        *rra_current = rra_begin; 
    790788    } 
    791789    rra_start = rra_begin; 
     
    18681866{ 
    18691867    unsigned long rra_idx; 
    18701868    unsigned long rra_start; 
    1871     unsigned long rra_pos_tmp;  /* temporary byte pointer. */ 
    18721869    time_t    rra_time = 0; /* time of update for a RRA */ 
    18731870 
     1871    unsigned long ds_cnt = rrd->stat_head->ds_cnt; 
     1872     
    18741873    /* Ready to write to disk */ 
    18751874    rra_start = rra_begin; 
     1875 
    18761876    for (rra_idx = 0; rra_idx < rrd->stat_head->rra_cnt; rra_idx++) { 
    1877         /* skip unless there's something to write */ 
    1878         if (rra_step_cnt[rra_idx]) { 
    1879             /* write the first row */ 
     1877        rra_def_t *rra_def = &rrd->rra_def[rra_idx]; 
     1878        rra_ptr_t *rra_ptr = &rrd->rra_ptr[rra_idx]; 
     1879 
     1880        /* for cdp_prep */ 
     1881        unsigned short scratch_idx; 
     1882        unsigned long step_subtract; 
     1883 
     1884        for (scratch_idx = CDP_primary_val, 
     1885                 step_subtract = 1; 
     1886             rra_step_cnt[rra_idx] > 0; 
     1887             rra_step_cnt[rra_idx]--, 
     1888                 scratch_idx = CDP_secondary_val, 
     1889                 step_subtract = 2) { 
     1890 
     1891            unsigned long rra_pos_new; 
    18801892#ifdef DEBUG 
    18811893            fprintf(stderr, "  -- RRA Preseek %ld\n", rrd_file->pos); 
    18821894#endif 
    1883             rrd->rra_ptr[rra_idx].cur_row++; 
    1884             if (rrd->rra_ptr[rra_idx].cur_row >= 
    1885                 rrd->rra_def[rra_idx].row_cnt) 
    1886                 rrd->rra_ptr[rra_idx].cur_row = 0;  /* wrap around */ 
    1887             /* position on the first row */ 
    1888             rra_pos_tmp = rra_start + 
    1889                 (rrd->stat_head->ds_cnt) * (rrd->rra_ptr[rra_idx].cur_row) * 
    1890                 sizeof(rrd_value_t); 
    1891             if (rra_pos_tmp != *rra_current) { 
    1892                 if (rrd_seek(rrd_file, rra_pos_tmp, SEEK_SET) != 0) { 
     1895            /* increment, with wrap-around */ 
     1896            if (++rra_ptr->cur_row >= rra_def->row_cnt) 
     1897              rra_ptr->cur_row = 0; 
     1898 
     1899            /* we know what our position should be */ 
     1900            rra_pos_new = rra_start 
     1901              + ds_cnt * rra_ptr->cur_row * sizeof(rrd_value_t); 
     1902 
     1903            /* re-seek if the position is wrong or we wrapped around */ 
     1904            if (rra_pos_new != *rra_current || rra_ptr->cur_row == 0) { 
     1905                if (rrd_seek(rrd_file, rra_pos_new, SEEK_SET) != 0) { 
    18931906                    rrd_set_error("seek error in rrd"); 
    18941907                    return -1; 
    18951908                } 
    1896                 *rra_current = rra_pos_tmp; 
     1909                *rra_current = rra_pos_new; 
    18971910            } 
    18981911#ifdef DEBUG 
    18991912            fprintf(stderr, "  -- RRA Postseek %ld\n", rrd_file->pos); 
    19001913#endif 
    1901             if (!skip_update[rra_idx]) { 
    1902                 if (*pcdp_summary != NULL) { 
    1903                     rra_time = (current_time - current_time 
    1904                                 % (rrd->rra_def[rra_idx].pdp_cnt * 
    1905                                    rrd->stat_head->pdp_step)) 
    1906                         - 
    1907                         ((rra_step_cnt[rra_idx] - 
    1908                           1) * rrd->rra_def[rra_idx].pdp_cnt * 
    1909                          rrd->stat_head->pdp_step); 
    1910                 } 
    1911                 if (write_RRA_row 
    1912                     (rrd_file, rrd, rra_idx, rra_current, CDP_primary_val, 
    1913                      pcdp_summary, rra_time) == -1) 
    1914                     return -1; 
    1915             } 
    19161914 
    1917             /* write other rows of the bulk update, if any */ 
    1918             for (; rra_step_cnt[rra_idx] > 1; rra_step_cnt[rra_idx]--) { 
    1919                 if (++rrd->rra_ptr[rra_idx].cur_row == 
    1920                     rrd->rra_def[rra_idx].row_cnt) { 
    1921 #ifdef DEBUG 
    1922                     fprintf(stderr, 
    1923                             "Wraparound for RRA %s, %lu updates left\n", 
    1924                             rrd->rra_def[rra_idx].cf_nam, 
    1925                             rra_step_cnt[rra_idx] - 1); 
    1926 #endif 
    1927                     /* wrap */ 
    1928                     rrd->rra_ptr[rra_idx].cur_row = 0; 
    1929                     /* seek back to beginning of current rra */ 
    1930                     if (rrd_seek(rrd_file, rra_start, SEEK_SET) != 0) { 
    1931                         rrd_set_error("seek error in rrd"); 
    1932                         return -1; 
    1933                     } 
    1934 #ifdef DEBUG 
    1935                     fprintf(stderr, "  -- Wraparound Postseek %ld\n", 
    1936                             rrd_file->pos); 
    1937 #endif 
    1938                     *rra_current = rra_start; 
    1939                 } 
    1940                 if (!skip_update[rra_idx]) { 
    1941                     if (*pcdp_summary != NULL) { 
    1942                         rra_time = (current_time - current_time 
    1943                                     % (rrd->rra_def[rra_idx].pdp_cnt * 
    1944                                        rrd->stat_head->pdp_step)) 
    1945                             - 
    1946                             ((rra_step_cnt[rra_idx] - 
    1947                               2) * rrd->rra_def[rra_idx].pdp_cnt * 
    1948                              rrd->stat_head->pdp_step); 
    1949                     } 
    1950                     if (write_RRA_row(rrd_file, rrd, rra_idx, rra_current, 
    1951                                       CDP_secondary_val, pcdp_summary, 
    1952                                       rra_time) == -1) 
    1953                         return -1; 
    1954                 } 
     1915            if (skip_update[rra_idx]) 
     1916                continue; 
     1917 
     1918            if (*pcdp_summary != NULL) { 
     1919                unsigned long step_time = rra_def->pdp_cnt * rrd->stat_head->pdp_step; 
     1920 
     1921                rra_time = (current_time - current_time % step_time) 
     1922                    - ((rra_step_cnt[rra_idx] - step_subtract) * step_time); 
    19551923            } 
     1924 
     1925            if (write_RRA_row 
     1926                (rrd_file, rrd, rra_idx, rra_current, scratch_idx, 
     1927                 pcdp_summary, rra_time) == -1) 
     1928                return -1; 
    19561929        } 
    1957         rra_start += rrd->rra_def[rra_idx].row_cnt * rrd->stat_head->ds_cnt * 
    1958             sizeof(rrd_value_t); 
    1959     }                   /* RRA LOOP */ 
    19601930 
     1931        rra_start += rra_def->row_cnt * ds_cnt * sizeof(rrd_value_t); 
     1932    } /* RRA LOOP */ 
     1933 
    19611934    return 0; 
    19621935} 
    19631936 

NOTE: The content of this website is accessible with any browser. The graphical design though relies completely on CSS2 styles. If you see this text, this means that your browser does not support CSS2. Consider upgrading to a standard conformant browser like Mozilla Firefox or Opera but also Apple's Safari or KDE's Konqueror for example. It may also be that you are looking at a mirror page which did not copy the CSS for this page. Or if some pictu res are missing, then the mirror may not have picked up the contents of the inc directory.