|
|
File filepos.patch, 6.2 KB
(added by human, 18 months ago)
|
|
patch to rrd_update
|
-
|
|
|
|
| 780 | 780 | } |
| 781 | 781 | /* seek to the beginning of the rra's */ |
| 782 | 782 | if (*rra_current != rra_begin) { |
| 783 | | #ifndef HAVE_MMAP |
| 784 | 783 | if (rrd_seek(rrd_file, rra_begin, SEEK_SET) != 0) { |
| 785 | 784 | rrd_set_error("seek error in rrd"); |
| 786 | 785 | return -1; |
| 787 | 786 | } |
| 788 | | #endif |
| 789 | 787 | *rra_current = rra_begin; |
| 790 | 788 | } |
| 791 | 789 | rra_start = rra_begin; |
| … |
… |
|
| 1868 | 1866 | { |
| 1869 | 1867 | unsigned long rra_idx; |
| 1870 | 1868 | unsigned long rra_start; |
| 1871 | | unsigned long rra_pos_tmp; /* temporary byte pointer. */ |
| 1872 | 1869 | time_t rra_time = 0; /* time of update for a RRA */ |
| 1873 | 1870 | |
| | 1871 | unsigned long ds_cnt = rrd->stat_head->ds_cnt; |
| | 1872 | |
| 1874 | 1873 | /* Ready to write to disk */ |
| 1875 | 1874 | rra_start = rra_begin; |
| | 1875 | |
| 1876 | 1876 | 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; |
| 1880 | 1892 | #ifdef DEBUG |
| 1881 | 1893 | fprintf(stderr, " -- RRA Preseek %ld\n", rrd_file->pos); |
| 1882 | 1894 | #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) { |
| 1893 | 1906 | rrd_set_error("seek error in rrd"); |
| 1894 | 1907 | return -1; |
| 1895 | 1908 | } |
| 1896 | | *rra_current = rra_pos_tmp; |
| | 1909 | *rra_current = rra_pos_new; |
| 1897 | 1910 | } |
| 1898 | 1911 | #ifdef DEBUG |
| 1899 | 1912 | fprintf(stderr, " -- RRA Postseek %ld\n", rrd_file->pos); |
| 1900 | 1913 | #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 | | } |
| 1916 | 1914 | |
| 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); |
| 1955 | 1923 | } |
| | 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; |
| 1956 | 1929 | } |
| 1957 | | rra_start += rrd->rra_def[rra_idx].row_cnt * rrd->stat_head->ds_cnt * |
| 1958 | | sizeof(rrd_value_t); |
| 1959 | | } /* RRA LOOP */ |
| 1960 | 1930 | |
| | 1931 | rra_start += rra_def->row_cnt * ds_cnt * sizeof(rrd_value_t); |
| | 1932 | } /* RRA LOOP */ |
| | 1933 | |
| 1961 | 1934 | return 0; |
| 1962 | 1935 | } |
| 1963 | 1936 | |
Download in other formats:
|