From 7ab700ccb35f94c10ee58a92474fa2141151b415 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 6 Apr 2014 13:46:37 +0200 Subject: [PATCH] store: Don't change the interval if the new interval is zero. If the interval is zero, multiple updates happened at the same time. This does not affect the interval at which the object is updated in the backend, though. --- src/core/store.c | 12 +++++++----- t/core/store_test.c | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/core/store.c b/src/core/store.c index fd08de9..dace58f 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -295,11 +295,13 @@ store_obj(int parent_type, const char *parent_name, else { sdb_time_t interval = last_update - old->last_update; old->last_update = last_update; - if (old->interval) - old->interval = (sdb_time_t)((0.9 * (double)old->interval) - + (0.1 * (double)interval)); - else - old->interval = interval; + if (interval) { + if (old->interval) + old->interval = (sdb_time_t)((0.9 * (double)old->interval) + + (0.1 * (double)interval)); + else + old->interval = interval; + } } if (updated_obj) diff --git a/t/core/store_test.c b/t/core/store_test.c index d57747f..29c5b1b 100644 --- a/t/core/store_test.c +++ b/t/core/store_test.c @@ -385,6 +385,28 @@ START_TEST(test_interval) "sdb_store_host() did not calculate interval correctly: " "got: %"PRIscTIME"; expected: %"PRIscTIME, host->interval, 10); + /* multiple updates for the same timestamp don't modify the interval */ + sdb_store_host("host", 40); + sdb_store_host("host", 40); + sdb_store_host("host", 40); + sdb_store_host("host", 40); + + fail_unless(host->interval == 10, + "sdb_store_host() changed interval when doing multiple updates " + "using the same timestamp; got: %"PRIscTIME"; " + "expected: %"PRIscTIME, host->interval, 10); + + /* multiple updates using an timestamp don't modify the interval */ + sdb_store_host("host", 20); + sdb_store_host("host", 20); + sdb_store_host("host", 20); + sdb_store_host("host", 20); + + fail_unless(host->interval == 10, + "sdb_store_host() changed interval when doing multiple updates " + "using an old timestamp; got: %"PRIscTIME"; expected: %"PRIscTIME, + host->interval, 10); + /* new interval: 20 us */ sdb_store_host("host", 60); fail_unless(host->interval == 11, -- 2.30.2