Skip to content

Commit 3eed19e

Browse files
Set the reset timestamp for a wrapped counter 1ms earlier, to avoid start_time==end_time errors. (#189)
1 parent 966290f commit 3eed19e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/write_gcm.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -3848,8 +3848,9 @@ static int wg_rebase_item(
38483848
// element is sufficient.
38493849
int ds_type = payload->values[0].ds_type;
38503850

3851-
// If any of the counters have wrapped, then we need to reset the tracker
3852-
// baseline and start_time.
3851+
// Check to see if any of the counter values have decreased from their last
3852+
// recorded value (indicating an overflow wrap or a reset). If so, reset the
3853+
// tracker baseline and start_time for all values within this payload.
38533854
int some_counter_wrapped = 0;
38543855
for (i = 0; i < payload->num_values; ++i) {
38553856
if (wg_value_less(ds_type, &payload->values[i].val,
@@ -3859,9 +3860,12 @@ static int wg_rebase_item(
38593860
}
38603861
}
38613862

3862-
// If any counter wrapped, everybody resets.
38633863
if (some_counter_wrapped) {
3864-
tracker->start_time = payload->start_time;
3864+
// Set the reset timestamp to be one millisecond before the timestamp of the
3865+
// current point. We don't know the true reset time but this ensures the
3866+
// range is non-zero while unlikely to conflict with any previous point.
3867+
tracker->start_time =
3868+
NS_TO_CDTIME_T(CDTIME_T_TO_NS(payload->start_time) - 1000000);
38653869
for (i = 0; i < payload->num_values; ++i) {
38663870
wg_value_set_zero(ds_type, &tracker->baselines[i]);
38673871
}

0 commit comments

Comments
 (0)