Skip to content
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

Fix time zone shifts when the shift happens on a time zone boundary #8610

Merged
merged 1 commit into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [#8569](https://github.com/influxdata/influxdb/issues/8569): Fix the cq start and end times to use unix timestamps.
- [#8601](https://github.com/influxdata/influxdb/pull/8601): Fixed time boundaries for continuous queries with time zones.
- [#8097](https://github.com/influxdata/influxdb/pull/8097): Return query parsing errors in CSV formats.
- [#8607](https://github.com/influxdata/influxdb/issues/8607): Fix time zone shifts when the shift happens on a time zone boundary.

## v1.3.1 [unreleased]

Expand Down
10 changes: 5 additions & 5 deletions influxql/iterator.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ func (itr *floatFillIterator) Next() (*FloatPoint, error) {
// Check to see if we have passed over an offset change and adjust the time
// to account for this new offset.
if itr.opt.Location != nil {
if _, offset := itr.opt.Zone(itr.window.time); offset != itr.window.offset {
if _, offset := itr.opt.Zone(itr.window.time - 1); offset != itr.window.offset {
diff := itr.window.offset - offset
if abs(diff) < int64(itr.opt.Interval.Duration) {
itr.window.time += diff
Expand Down Expand Up @@ -4073,7 +4073,7 @@ func (itr *integerFillIterator) Next() (*IntegerPoint, error) {
// Check to see if we have passed over an offset change and adjust the time
// to account for this new offset.
if itr.opt.Location != nil {
if _, offset := itr.opt.Zone(itr.window.time); offset != itr.window.offset {
if _, offset := itr.opt.Zone(itr.window.time - 1); offset != itr.window.offset {
diff := itr.window.offset - offset
if abs(diff) < int64(itr.opt.Interval.Duration) {
itr.window.time += diff
Expand Down Expand Up @@ -7403,7 +7403,7 @@ func (itr *unsignedFillIterator) Next() (*UnsignedPoint, error) {
// Check to see if we have passed over an offset change and adjust the time
// to account for this new offset.
if itr.opt.Location != nil {
if _, offset := itr.opt.Zone(itr.window.time); offset != itr.window.offset {
if _, offset := itr.opt.Zone(itr.window.time - 1); offset != itr.window.offset {
diff := itr.window.offset - offset
if abs(diff) < int64(itr.opt.Interval.Duration) {
itr.window.time += diff
Expand Down Expand Up @@ -10733,7 +10733,7 @@ func (itr *stringFillIterator) Next() (*StringPoint, error) {
// Check to see if we have passed over an offset change and adjust the time
// to account for this new offset.
if itr.opt.Location != nil {
if _, offset := itr.opt.Zone(itr.window.time); offset != itr.window.offset {
if _, offset := itr.opt.Zone(itr.window.time - 1); offset != itr.window.offset {
diff := itr.window.offset - offset
if abs(diff) < int64(itr.opt.Interval.Duration) {
itr.window.time += diff
Expand Down Expand Up @@ -14063,7 +14063,7 @@ func (itr *booleanFillIterator) Next() (*BooleanPoint, error) {
// Check to see if we have passed over an offset change and adjust the time
// to account for this new offset.
if itr.opt.Location != nil {
if _, offset := itr.opt.Zone(itr.window.time); offset != itr.window.offset {
if _, offset := itr.opt.Zone(itr.window.time - 1); offset != itr.window.offset {
diff := itr.window.offset - offset
if abs(diff) < int64(itr.opt.Interval.Duration) {
itr.window.time += diff
Expand Down
2 changes: 1 addition & 1 deletion influxql/iterator.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ func (itr *{{$k.name}}FillIterator) Next() (*{{$k.Name}}Point, error) {
// Check to see if we have passed over an offset change and adjust the time
// to account for this new offset.
if itr.opt.Location != nil {
if _, offset := itr.opt.Zone(itr.window.time); offset != itr.window.offset {
if _, offset := itr.opt.Zone(itr.window.time - 1); offset != itr.window.offset {
diff := itr.window.offset - offset
if abs(diff) < int64(itr.opt.Interval.Duration) {
itr.window.time += diff
Expand Down
43 changes: 26 additions & 17 deletions influxql/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,14 +849,13 @@ func (opt IteratorOptions) Window(t int64) (start, end int64) {
t -= int64(opt.Interval.Offset)

// Retrieve the zone offset for the start time.
var startOffset int64
var zone int64
if opt.Location != nil {
_, startOffset = opt.Zone(t)
t += startOffset
_, zone = opt.Zone(t)
}

// Truncate time by duration.
dt := t % int64(opt.Interval.Duration)
dt := (t + zone) % int64(opt.Interval.Duration)
if dt < 0 {
// Negative modulo rounds up instead of down, so offset
// with the duration.
Expand All @@ -874,38 +873,48 @@ func (opt IteratorOptions) Window(t int64) (start, end int64) {
// after the offset switch. Now that we are at midnight in UTC, we can
// lookup the zone offset again to get the real starting offset.
if opt.Location != nil {
_, adjustedOffset := opt.Zone(start)
_, startOffset := opt.Zone(start)
// Do not adjust the offset if the offset change is greater than or
// equal to the duration.
if o := startOffset - adjustedOffset; o != 0 && abs(o) < int64(opt.Interval.Duration) {
startOffset = adjustedOffset
if o := zone - startOffset; o != 0 && abs(o) < int64(opt.Interval.Duration) {
start += o
}
}
start += int64(opt.Interval.Offset) - startOffset
start += int64(opt.Interval.Offset)

// Find the end time.
if dt := int64(opt.Interval.Duration) - dt; MaxTime-dt <= t {
end = MaxTime
} else {
end = t + dt
}
end += int64(opt.Interval.Offset) - startOffset

// Retrieve the zone offset for the end time.
if opt.Location != nil {
_, endOffset := opt.Zone(end)
// Adjust the end time if the offset is different from the start offset.
if startOffset != endOffset {
offset := startOffset - endOffset

// Only apply the offset if it is smaller than the duration.
// This prevents going back in time and creating time windows
// that don't make any sense.
if abs(offset) < int64(opt.Interval.Duration) {
end += offset
// Only apply the offset if it is smaller than the duration.
// This prevents going back in time and creating time windows
// that don't make any sense.
if o := zone - endOffset; o != 0 && abs(o) < int64(opt.Interval.Duration) {
// If the offset is greater than 0, that means we are adding time.
// Added time goes into the previous interval because the clocks
// move backwards. If the offset is less than 0, then we are skipping
// time. Skipped time comes after the switch so if we have a time
// interval that lands on the switch, it comes from the next
// interval and not the current one. For this reason, we need to know
// when the actual switch happens by seeing if the time switch is within
// the current interval. We calculate the zone offset with the offset
// and see if the value is the same. If it is, we apply the
// offset.
if o > 0 {
end += o
} else if _, z := opt.Zone(end + o); z == endOffset {
end += o
}
}
}
end += int64(opt.Interval.Offset)
return
}

Expand Down
Loading