-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Timestamp
a special SATS type
#1836
Conversation
- Add timestamp as a new "special" `AlgebraicType`. - Impl STT, Ser, De for `SystemTime`. This requires moving `Timestamp` into the SATS crate. - Change most references to `Timestamp` in Rust code to be `SystemTime` instead, incl. in the WebSocket message schema. - Update Rust bindings, SDK and codegen to use `SystemTime` where appropriate. Currently having a problem with modules and clients using `std::time::SystemTime`: we are giving micros precision, but on my machine `SystemTime` has nanos precision, so test which round-trip `SystemTime` through SATS lose information. Possible solutions are: - Say this is fine. Rewrite failing tests to accept the loss of precision. - Revise the SATS `Timestamp` type to be more precise, likely by copying the Linux-x64 `SystemTime` definition. Hope that Rust on MacOS or Windows don't use a meaningfully different repr, and that C#'s `DateTimeOffset` is similarly compatible. - Continue having modules and clients use `Timestamp`, which is always u64 micros, but add methods for converting to and from `SystemTime`/`DateTimeOffset`.
Having discussed this more with the team, there's an additional wrinkle: while C#'s My disposition is to avoid these tough questions by retaining I'm also interested in providing a special SATS type analogous to Rust |
Per PR discussion, restore `Timestamp` to user-facing status, and offer methods for potentially lossy conversions to and from `SystemTime`. Also give `Timestamp` nanosecond precision and allow it to represent negative values. I'm not entirely confident about allowing negative values, since pre-1970 timestamps seem unlikely to be useful, and allowing negatives complicates the API somewhat in its interactions with `Duration`.
Also, don't clamp negative durations to zero in `ScheduleAt::Interval`, instead use their magnitude.
Fix compile errors Tests pass
TODO: Switch back to EDIT: |
Timestamp and TimeDuration store `micros: i64`, not `nanos: i64`. This means that old commitlogs and snapshots should still be compatible, assuming they don't include timestamps greater than `i64::MAX`, as previously we used `micros: u64`. This seems unlikely. The C# changes included here are untested, and the C# SDK has not been updated.
Timestamp
a special SATS typeTimestamp
a special SATS type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving as code owner of websocket.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving RE: Timestamp
, core
, and schema
.
TODO: test |
Turns out we don't even define |
Co-authored-by: Zeke Foppa <[email protected]> Signed-off-by: Phoebe Goldman <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My codeowned files look good given the time-sensitivity.
crates/cli/src/tasks/csharp.rs
## Description of Changes C# part of clockworklabs/SpacetimeDB#1836 Needs to be rebased onto #220 once that is merged. ## API - [x] This is an API breaking change to the SDK ScheduleAt is now constructed in slightly different ways. ## Requires SpacetimeDB PRs *List any PRs here that are required for this SDK change to work* ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: phoebe/timestamp-special-type ## Testing Will need an update to blackholio as well.
Description of Changes
AlgebraicType
.Timestamp
to the SATS crate, where previously it was in bothbindings
andclient-api-messages
.lib
, which seems wrong to me.Timestamp
rather thanu64
.Timestamp
storemicros_since_unix_epoch: i64
, where previously it hadmicros_since_unix_epoch: u64
.SystemTime
and C#DateTime(Offset)
can do.TimeDuration
, analogous toDuration
andTimeSpan
, as another new "special"AlgebraicType
.TimeDuration
ismicros: i64
, to matchTimestamp
.TimeSpan
but Rust has unsignedDuration
.ScheduleAt
storesTimestamp
orTimeDuration
in its two variants.ScheduleAt::Interval
means arguably we want unsignedTimeDuration
, as a negative interval seems meaningless.ScheduleAt::Interval(-10 minutes)
is the same asScheduleAt::Interval(10 minutes)
.ScheduleAt
s viaDuration::into
, I hope.u64
s.Companion PRs:
Still TODO:
API and ABI breaking changes
Timestamp
type (e.g. inReducerContext
) is now defined in the SATS crate, re-exported from lib and bindings, and has slightly different methods.Timestamp::now
is deprecated and stubbed in the WASM target.Timestamp
is changed fromU64
toProduct { __timestamp_micros_since_unix_epoch__: I64 }
. This is layout-equivalent in BSATN and I think BFLATN, but changes the JSON format. It will also make oldModuleDef
s / system tables detect a migration.Expected complexity level and risk
2 - Changing the SATS definitions of types has been shown recently to be potentially scary. On the other hand, this redefinition is layout-compatible, so should be much less breaking than when we redefined
Identity
.Testing
Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!
Timestamp
is well-behaved and compatible withSystemTime
.