Replace long long timestamp references with more specific mstime_t/ustime_t#3252
Conversation
…ire.c/h, object.c, and server.h Signed-off-by: curious-george-rk <r.ebu@gmail.com>
Signed-off-by: curious-george-rk <r.ebu@gmail.com>
Signed-off-by: curious-george-rk <r.ebu@gmail.com>
Signed-off-by: curious-george-rk <r.ebu@gmail.com>
Signed-off-by: curious-george-rk <r.ebu@gmail.com>
Signed-off-by: curious-george-rk <r.ebu@gmail.com>
7a66cb6 to
91bc01a
Compare
|
thank you @curious-george-rk! It would mean changing more locations, and maybe some of the code will start look more like: but it would ensure future "saftiness". |
|
I think other than the verbosity, it is probably a good idea to go to it long-term for the type enforcement. However, I don't really see a good way to do that incrementally since all the references would need to be updated at once, which would probably be a lot of changes in the short-term. |
Yes. As I wrote "It would mean changing more locations" I probably should have been clear stating "ALL locations" |
|
but @curious-george-rk the work is very technical and not complex. I just think that we need to get some view of how the code would look like and understand what "sacrifices" we will have taking the enforced approach |
@curious-george-rk agree that this will make the code less readable and uglier, which was the reason I "had second thoughts"... (these are the cases I miss C++ :) ) I do agree that going with the wrapped struct method is probably something we would like to do a major decision for. |
This is called nominal types. NASA's Mars Climate Orbiter crashed due to a bug like this: there was a calculation in pound-force seconds for something expected to be in newton-seconds (metric vs non-metric units). Maybe a nominal type system could have prevented it. :) Nominal types can be pushed very far to encode all kinds of semantic differences to make types incompatible with each other. For example, we could encode the difference between an absolute timestamp and delta (duration). Even if both are in microseconds, they can't be used interchangeably. The rules would be something like: delta = abs_time_2 - abs_time_1 // a duration
abs_time_2 = abs_time_1 + delta // e.g. an expiration time in the future
x = abs_time_1 + abs_time_2 // doesn't make any sense; forbid itWe have yet another difference: unix time vs monotonic time. Even if both are in the same unit, their zero don't represent the same point in time and they may drift relative each other, so we can't mix them arbitrarily, for example taking the diff between a ustime (from gettimeofday) and a monotime doesn't make sense. We can add a monotonic delta to a unix timestamp though. In this recent optimization, do just this to avoid calling gettimeofday() too often by instead adding a monotonic delta: Here, Nominal types can probably be pushed very far, but it would also make it cumbersome to read and write code if we go too far in that direction. I don't think we shall introduce the struct variant. I think we should stay fairly close to common C code (e.g. the style used in standard library types and functions). Typedefs for |
@zuiderkwast I read you paper :) but I did not follow the bottom line? Do you think that my suggestion placing a strict type enforcement on time types IS a good thing to have (even if it complicates the code and readability)? |
Paper, hehe. Bottom line: I don't think we shall introduce the struct variant. |
Signed-off-by: curious-george-rk <r.ebu@gmail.com>
ba789a8 to
445ebcb
Compare
zuiderkwast
left a comment
There was a problem hiding this comment.
Yeah, LGTM. Thank you!
ranshid
left a comment
There was a problem hiding this comment.
LGTM.
Small comment, but I approve even without it
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #3252 +/- ##
============================================
- Coverage 75.05% 74.94% -0.12%
============================================
Files 129 129
Lines 71553 71553
============================================
- Hits 53705 53624 -81
- Misses 17848 17929 +81
🚀 New features to boost your workflow:
|
…ver.c Signed-off-by: curious-george-rk <r.ebu@gmail.com>
…time_t (valkey-io#3252) Addresses issue valkey-io#2350 As noted in the issue, much of the expire code uses raw long long for timestamps, which provides no semantic meaning about the unit or purpose of the value. Valkey already defines mstime_t (milliseconds) and ustime_t (microseconds) typedefs — this PR replaces bare long long declarations with the appropriate typedef wherever the value represents an expiration timestamp or time duration. This PR only fixes a small subset in the codebase, but it is an incremental step toward fully replacing the bare long long references. --------- Signed-off-by: curious-george-rk <r.ebu@gmail.com> Co-authored-by: curious-george-rk <r.ebu@gmail.com> Signed-off-by: Daniel Lemire <daniel@lemire.me>
…ime_t/ustime_t (valkey-io#3252)" This reverts commit 3d8a1b5.
…time_t (#3252) Addresses issue #2350 As noted in the issue, much of the expire code uses raw long long for timestamps, which provides no semantic meaning about the unit or purpose of the value. Valkey already defines mstime_t (milliseconds) and ustime_t (microseconds) typedefs — this PR replaces bare long long declarations with the appropriate typedef wherever the value represents an expiration timestamp or time duration. This PR only fixes a small subset in the codebase, but it is an incremental step toward fully replacing the bare long long references. --------- Signed-off-by: curious-george-rk <r.ebu@gmail.com> Co-authored-by: curious-george-rk <r.ebu@gmail.com>




Addresses issue #2350
As noted in the issue, much of the expire code uses raw long long for timestamps, which provides no semantic meaning about the unit or purpose of the value. Valkey already defines mstime_t (milliseconds) and ustime_t (microseconds) typedefs — this PR replaces bare long long declarations with the appropriate typedef wherever the value represents an expiration timestamp or time duration.
This PR only fixes a small subset in the codebase, but it is an incremental step toward fully replacing the bare long long references.