Skip to content

Commit

Permalink
fix: Store.validateArgs wrongfully overwriting start, end unix time (#…
Browse files Browse the repository at this point in the history
…25146) (#25163)

When querying data before 1970-01-01 (UNIX time 0)
validateArgs would set start to -in64 max and end to int64 max.

closes #24669

Co-authored-by: Paul Hegenberg <paul.hegenberg@gmail.com>
(cherry picked from commit c2b3e38)

closes #25148
  • Loading branch information
davidby-influx authored Jul 16, 2024
1 parent 8e0d754 commit 9c8f296
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions v1/services/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ func (s *Store) validateArgs(orgID, bucketID uint64, start, end int64) (string,
return "", "", 0, 0, errors.New("invalid retention policy")
}

if start <= 0 {
if start <= models.MinNanoTime {
start = models.MinNanoTime
}
if end <= 0 {
if end >= models.MaxNanoTime {
end = models.MaxNanoTime
}
return database, rp, start, end, nil
Expand Down
65 changes: 65 additions & 0 deletions v1/services/storage/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,75 @@ import (
"testing"
"time"

"github.com/influxdata/influxdb/v2/internal"
"github.com/influxdata/influxdb/v2/models"
"github.com/influxdata/influxdb/v2/v1/services/meta"
"github.com/stretchr/testify/require"
)

func TestValidateArgs(t *testing.T) {
type inputParams struct {
orgID uint64
bucketID uint64
start int64
end int64
}

type outputParams struct {
database string
rp string
start int64
end int64
err error
}

testCases := []struct {
desc string
store *Store
input inputParams
expected outputParams
}{
{
desc: "start not < models.MinNanoTime and end not > models.MaxNanoTime",
store: NewStore(nil, &internal.MetaClientMock{
DatabaseFn: func(name string) *meta.DatabaseInfo {
return &meta.DatabaseInfo{
Name: name,
RetentionPolicies: []meta.RetentionPolicyInfo{
{
Name: meta.DefaultRetentionPolicyName,
},
},
}
},
}),
input: inputParams{
orgID: 1,
bucketID: 2,
start: models.MinNanoTime - 1,
end: models.MaxNanoTime + 1,
},
expected: outputParams{
database: "0000000000000002",
rp: meta.DefaultRetentionPolicyName,
start: models.MinNanoTime,
end: models.MaxNanoTime,
},
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
database, rp, start, end, err := tC.store.validateArgs(tC.input.orgID, tC.input.bucketID, tC.input.start, tC.input.end)

require.Equal(t, tC.expected.database, database)
require.Equal(t, tC.expected.rp, rp)
require.Equal(t, tC.expected.start, start)
require.Equal(t, tC.expected.end, end)
require.Equal(t, tC.expected.err, err)
})
}
}

func TestGroupShardsByTime(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 9c8f296

Please sign in to comment.