Fix compute_next_snapshot_time().
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 14 Nov 2017 02:19:58 +0000 (03:19 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 19 Nov 2017 01:53:33 +0000 (02:53 +0100)
The function computes the average idle time between snapshots and adds
this value to the completion time of the last snapshot to obtain the
start time for the next snapshot.

However, if the last snapshot happens to be incomplete, its completion
time is set to -1. Hence the computed next snapshot time is going to
be in the past, so we start the next snapshot immediately.

Although this is incorrect, the bug is benign because the correct next
snapshot time should also be in the past since we decided earlier to
create the snapshot which was now found incomplete.

Fix this by using the completion time of the last _complete_ snapshot
instead.

dss.c

diff --git a/dss.c b/dss.c
index ffbf5004505559cb30d8c1deed25a0ab842a8121..9390f48c9f8f16a810680b374050ae45ba6349b0 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -413,7 +413,8 @@ static void dss_get_snapshot_list(struct snapshot_list *sl)
 static int64_t compute_next_snapshot_time(void)
 {
        int64_t x = 0, now = get_current_time(), unit_interval
-               = 24 * 3600 * OPT_UINT32_VAL(DSS, UNIT_INTERVAL), ret;
+               = 24 * 3600 * OPT_UINT32_VAL(DSS, UNIT_INTERVAL), ret,
+               last_completion_time;
        unsigned wanted = desired_number_of_snapshots(0,
                OPT_UINT32_VAL(DSS, NUM_INTERVALS)),
                num_complete = 0;
@@ -427,6 +428,7 @@ static int64_t compute_next_snapshot_time(void)
                        continue;
                num_complete++;
                x += s->completion_time - s->creation_time;
+               last_completion_time = s->completion_time;
        }
        assert(x >= 0);
 
@@ -436,7 +438,7 @@ static int64_t compute_next_snapshot_time(void)
        x /= num_complete; /* avg time to create one snapshot */
        if (unit_interval < x * wanted) /* oops, no sleep at all */
                goto out;
-       ret = s->completion_time + unit_interval / wanted - x;
+       ret = last_completion_time + unit_interval / wanted - x;
 out:
        free_snapshot_list(&sl);
        return ret;