-
Notifications
You must be signed in to change notification settings - Fork 14
Change janus_messages::Duration and Time to be in units of TimePrecision #4219
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
base: main
Are you sure you want to change the base?
Conversation
…regation_artifacts test to use fold/merged_with
… ref two more issues to follow-ups
…k test - Fix the time_bucket_start_opt for add_report, which I had broken. - Then also ensure that we ask for buckets, not timestamps
…TIME_PRECISION) to from_time_precision_units(0)
FromSql: PostgreSQL empty range is decoded as Interval::EMPTY, which is good. However, ToSql: Interval::EMPTY encodes to [1970-01-01 00:00:00, 1970-01-01 00:00:00), which bit me while I was fixing the rest of this. We shouldn't ever hit this! But we might as well fix it while we're here. Also, these timestamps in PostgreSQL are microseconds, not millis.
| let now_time = clock.now().to_time(&time_precision); | ||
|
|
||
| let report_time_2 = now_time.sub_duration(&batch_time_window_size).unwrap(); | ||
| let report_time_1 = report_time_2.sub_duration(&batch_time_window_size).unwrap(); | ||
|
|
||
| // Compute the bucketed time bucket starts for querying outstanding batches | ||
| let batch_window_units = batch_time_window_size.as_time_precision_units(); | ||
| let bucket_time_1 = Time::from_time_precision_units( | ||
| (report_time_1.as_time_precision_units() / batch_window_units) * batch_window_units, | ||
| ); | ||
| let bucket_time_2 = Time::from_time_precision_units( | ||
| (report_time_2.as_time_precision_units() / batch_window_units) * batch_window_units, | ||
| ); |
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.
This is just not ergonomic. I did it this way because to_batch_interval_start() is just odd to reason through hanging off of DateTimeExt -- for this purpose anyway. It's also a bit weird to hang off Time because then we need basically two time_precision arguments.
I'm going to open a follow-on to tackle this better. For now, this may be dumb but it works.
tgeoghegan
left a comment
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.
I still need to look at the stuff in janus_aggregator_core::datastore but I'm going a little cross eyed and it's getting dark outside, so here's a first set of comments.
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.
The other day I observed to Chris Patton that I'm no longer sure exactly which draft of taskprov we implement. Since you've been looking at this closely and are up to speed on related changes to taskprov itself, do you think you could document the implemented taskprov draft version in the "Draft versions and release branches" table in the top-level README.md? I think it's OK if many of the rows of the taskprov draft columns are "?" so long as we start tracking what version we implement in main / release/0.9 onward.
| (report.client_timestamp().as_time_precision_units() / batch_window_units) | ||
| * batch_window_units, |
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.
It really looks like / batch_window_units * batch_window_units should cancel out, and then Time::from_time_precision_units(report.client_timestamp().as_time_precision_units()) is just report.client_timestamp(). But I think what's happening is that report.client_timestamp() is in terms of the task's time precision but batch_time_window_size is in terms of a different time precision used by the batch creator? Would a method on Time akin to Interval::to_time_precision help make it clear that we're doing a conversion here?
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.
Yeah, that's the issue exactly, the possibility for them being a factor of each other. I'm going to rework that in #4225.
Co-authored-by: Tim Geoghegan <timg@divviup.org>
tgeoghegan
left a comment
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.
More comments on the datastore stuff. Please re-request review when you're done addressing things and I will do another pass.
| pub fn remaining_lease_duration(&self, current_time: &Time, skew_seconds: u64) -> StdDuration { | ||
| pub fn remaining_lease_duration( | ||
| &self, | ||
| current_time: &DateTime<Utc>, |
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.
Lease::lease_expiry_time is NaiveDateTime. Is there a reason current_time can't be the same type? Would that simplify the arithmetic here?
| } | ||
|
|
||
| /// Convert an interval from task time precision to SQL time precision. | ||
| pub fn from_task_interval( |
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.
task_interval doesn't sound right. from_dap_time_interval?
| let start_sql_usec = time_to_sql_timestamp(*self.0.start(), &SQL_UNIT_TIME_PRECISION) | ||
| .map_err(|_| "microsecond timestamp of Interval start overflowed")?; | ||
| let end_sql_usec = time_to_sql_timestamp(self.0.end(), &SQL_UNIT_TIME_PRECISION) |
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.
Hmm. I dislike that we have start() -> &Time end() -> Time, especially since Time is Copy and it's just a u64, so we shouldn't bother with references anyway. Ah well, that's not a new issue.
Will do, but at this point, I'm out! I've resolved everything that I've ... resolved with commits. The unresolved comments will be there for me when we return! See you in 2026! |
Resolves #4019
The rest of the owl:
This small change consists of a few commits which refactor
janus_messages::Timeand::Durationto be injanus_messages::TimePrecisionunits. After the change to thejanus_messagesmodule, the first series of commits were done with regexes to get everything to compile. Then I progressively fixed tests, until they all passed. Then I've been performing cleanup, resolving issues from self-review and otherwise.I have filed follow-on issues for things that seemed bigger but not intrinsic to this change:
I did include two other notable fixes/refactors in this PR which arguably could have gone into separate ones, and still could:
client_timestamp_intervalone place usingfoldandIntervalExt::merged_withwhich didn't produce zero-width intervals, and then we had the other way that needed explicitadd_duration(Duration::from_seconds(1), &time_precision). This seemed worthwhile to take here.