From 63aea2bf80befd6fdde3a232597f8693c39e3447 Mon Sep 17 00:00:00 2001 From: Carl Smith Date: Wed, 9 Oct 2024 07:52:11 +1300 Subject: [PATCH] Return DB timestamp for refreshed paths Previously we alway returned "now" if there was a chance of a path being refreshed. That was because refreshed paths always had their timestamps updated to "now" even if the refresher decided not to update anything so that we did not call the refresher again for stale child nodes. Now that we do not use the DB timestamps to decide whether to call the refreshers anymore we can fix this odd behaviour. The change in behaviour is; 1. A call to a refresher does not result in all children of the path having their timestamps set to "now" even if they were not modified. 2. A call to get a timestamp for a path will call refreshers to make sure the timestamp is up to date. --- apteryxd.c | 3 ++- test.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/apteryxd.c b/apteryxd.c index 2ca3cdb..18b1c20 100644 --- a/apteryxd.c +++ b/apteryxd.c @@ -2287,12 +2287,13 @@ handle_timestamp (rpc_message msg) if ((value = proxy_timestamp (path)) == 0) { /* Lookup value */ - if (call_refreshers (path, true) || config_tree_has_providers (path)) + if (config_tree_has_providers (path)) { value = get_time_us (); } else { + call_refreshers (path, false); value = db_timestamp (path); } } diff --git a/test.c b/test.c index 06bc9d2..a1e0943 100644 --- a/test.c +++ b/test.c @@ -8833,20 +8833,24 @@ test_timestamp_refreshed () uint64_t ts, ts1; char *value; - _cb_timeout = 1000000; + _cb_timeout = 5000; apteryx_refresh(path, test_refresh_callback); + /* Getting the timestamp should call the refresher */ ts = apteryx_timestamp (path); CU_ASSERT (ts != 0); + /* Refresher should not be called again and hence + the timestamp should not change */ value = apteryx_get(path); ts1 = apteryx_timestamp (path); + CU_ASSERT(ts1 == ts); - CU_ASSERT(ts1 != 0); - CU_ASSERT(ts != ts1); - + /* Getting the timestamp should call the refresher + as we have waited _cb_timeout */ + usleep (_cb_timeout); ts = apteryx_timestamp (path); - CU_ASSERT(ts == ts1); + CU_ASSERT(ts != ts1); free (value); apteryx_unrefresh(path, test_refresh_callback);