-
Notifications
You must be signed in to change notification settings - Fork 21
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
Avoid timestamptz subtraction for span and event start offsets #1047
Conversation
c9a9f50
to
9f0371d
Compare
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.
General question with this PR: Are we trying to avoid using days and micros for an Aerie reason? The PR mentions accuracy concerns at the start, but based on how the math is done those accuracy concerns don't seem like they'd appear (since it tries to fill the days
part of the tuple, not the months
part)
) throws SQLException { | ||
for (final var eventPoint : eventPoints.entrySet()) { | ||
final var time = eventPoint.getKey(); | ||
final var transactions = eventPoint.getValue(); | ||
for (int transactionIndex = 0; transactionIndex < transactions.size(); transactionIndex++) { | ||
final var eventGraph = transactions.get(transactionIndex); | ||
final var flattenedEventGraph = EventGraphFlattener.flatten(eventGraph); | ||
batchInsertEventGraph(datasetId, time, transactionIndex, simulationStart, flattenedEventGraph, this.statement); | ||
batchInsertEventGraph(datasetId, time, transactionIndex, flattenedEventGraph, this.statement); |
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.
Why was this done via a static method rather than inlined in the apply
like our other batch inserts?
for (final Pair<String, Pair<Integer, SerializedValue>> entry : flattenedEventGraph) { | ||
for (final var entry : flattenedEventGraph) { | ||
final var causalTime = entry.getLeft(); | ||
final Pair<Integer, SerializedValue> event = entry.getRight(); | ||
final var event = entry.getRight(); |
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.
Idle question: why are these getting converted from their specific types to var
s?
@@ -338,7 +338,7 @@ private static void postActivities( | |||
final Timestamp simulationStart | |||
) throws SQLException { | |||
try ( | |||
final var postActivitiesAction = new PostSpansAction(connection); | |||
final var insertSpansAction = new InsertSpansAction(connection); |
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.
Minor: Looking at this with the rename, I wonder if something like InsertActivitySpansAction
rather than just InsertSpansAction
(or renaming the function from postActivities
to postActivitySpans
) would help with clarity, since Aerie does have the concept of non-Activity Spans
The original driver for this PR was to have consistency in time representation. Spans inserted by the scheduler have the form If we were to choose one of these representations to standardize on, I would prefer the former. It is true that under controlled circumstances, we shouldn't see issues with precision, but the former form has a different semantic meaning from the latter form, one that conforms better to our notion of duration in Aerie.
|
Ah, yeah, the consistency argument makes sense to me 👍. Was that implied by the line |
Thought about this PR: is it possible to encode this conversion from (months, days, microseconds) -> (microseconds) via DB triggers? I'm thinking of this bug in the UI, which wouldn't have occurred if the DB enforced the standardization |
Closing to reduce clutter - we can revisit this if the need arises |
Description
Postgres stores intervals in tuples of (months, days, microseconds) (docs)
The first two are primarily needed for calendrical durations. For example, January 1st -> February 1st -> March 1st is 2 months. Noon on Sunday + 1 day is Noon on Monday, even if that crosses a daylight savings boundary (so a day can be 23, 24, or 25 hours, depending on when it is)
On Aerie, to the extent possible, we want to use the microseconds part of that tuple. This is primarily to canonicalize the representation of intervals in Aerie, to avoid the multiple representations
24:00:00.000
vs24 days
.This PR updates the
PostSpansAction
(renamed toInsertSpansAction
to mirror database parlance) to write durations usingPreparedStatements.setDuration
rather than by doing subtraction between two timestamps. The primary purpose of this change is to avoidstart_offsets
that mix the days and microseconds portions of theinterval
type.Verification
I built Aerie on
develop
, ran simulation and saw that it inserted mixed days/microseconds intervals into thespan.start_offset
column. I then switched to this branch, rebuilt, and saw that it inserted only microsecond-based intervals.Documentation
We definitely need a document on "Time in Aerie", since this is a topic that comes up often. I'll make a documentation ticket.
NASA-AMMOS/aerie-docs#66
Future work
interval
type. Perhaps a domain type, or check constraints could help here, or moving to a different representation of offsets altogether.