Skip to content

Commit

Permalink
Modify the max nanosecond time to be one nanosecond less
Browse files Browse the repository at this point in the history
The highest time represented by a nanosecond needs to be used for an
exclusive range, so the maximum time needs to be one less than the
possible maximum number of nanoseconds representable by an int64 so that
we don't lose a point at that one time.

Previously worked in the open source version because the timestamp used
for finding a shard would be truncated by the retention policy so the
lookup time didn't run into this edge case because it didn't rest on the
truncation boundary. Since that point didn't really belong in that shard
group and was placed there by mistake, it's best to fix this bug since
the timestamp used to create the shard group should be capable of
retrieving it.
  • Loading branch information
jsternberg committed Jun 16, 2016
1 parent 3b400a2 commit 8e1b036
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
- [#6771](https://github.com/influxdata/influxdb/issues/6771): Fix the point validation parser to identify and sort tags correctly.
- [#6835](https://github.com/influxdata/influxdb/pull/6835): Include sysvinit-tools as an rpm dependency.
- [#6834](https://github.com/influxdata/influxdb/pull/6834): Add port to all graphite log output to help with debugging multiple endpoints
- [#6850](https://github.com/influxdata/influxdb/pull/6850): Modify the max nanosecond time to be one nanosecond less.

## v0.13.0 [2016-05-12]

Expand Down
2 changes: 1 addition & 1 deletion influxql/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

// MaxTime is used as the maximum time value when computing an unbounded range.
// This time is 2262-04-11 23:47:16.854775806 +0000 UTC
MaxTime = models.MaxNanoTime - 1
MaxTime = models.MaxNanoTime
)

// Iterator represents a generic interface for all Iterators.
Expand Down
2 changes: 1 addition & 1 deletion models/points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ func TestParsePointNegativeTimestamp(t *testing.T) {
}

func TestParsePointMaxTimestamp(t *testing.T) {
test(t, `cpu value=1 9223372036854775807`,
test(t, fmt.Sprintf(`cpu value=1 %d`, models.MaxNanoTime),
NewTestPoint(
"cpu",
models.Tags{},
Expand Down
4 changes: 2 additions & 2 deletions models/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const (

// MaxNanoTime is the maximum time that can be represented.
//
// 2262-04-11 23:47:16.854775807 +0000 UTC
// 2262-04-11 23:47:16.854775806 +0000 UTC
//
MaxNanoTime = int64(math.MaxInt64)
MaxNanoTime = int64(math.MaxInt64) - 1
)

var (
Expand Down
3 changes: 2 additions & 1 deletion services/meta/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ func (data *Data) CreateShardGroup(database, policy string, timestamp time.Time)
sgi.StartTime = timestamp.Truncate(rpi.ShardGroupDuration).UTC()
sgi.EndTime = sgi.StartTime.Add(rpi.ShardGroupDuration).UTC()
if sgi.EndTime.After(time.Unix(0, models.MaxNanoTime)) {
sgi.EndTime = time.Unix(0, models.MaxNanoTime)
// Shard group range is [start, end) so add one to the max time.
sgi.EndTime = time.Unix(0, models.MaxNanoTime+1)
}

data.MaxShardID++
Expand Down

0 comments on commit 8e1b036

Please sign in to comment.