Change max time for SHOW meta queries

If all points in a series are timestamped in the future, the SHOW
queries will not return anything from these series.

This commit changes the to time used when querying shards for the SHOW
queries to the maximum time, in order to ensure future points are
considered in the results for these queries.

Fixes #6599.
pull/6675/head
Edd Robinson 2016-05-19 16:03:13 +01:00
parent 6f25d97de4
commit bc6e1e84af
2 changed files with 81 additions and 1 deletions

View File

@ -5225,6 +5225,78 @@ func TestServer_Query_DropAndRecreateMeasurement(t *testing.T) {
}
}
func TestServer_Query_ShowQueries_Future(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig())
defer s.Close()
if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicyInfo("rp0", 1, 0)); err != nil {
t.Fatal(err)
}
if err := s.MetaClient.SetDefaultRetentionPolicy("db0", "rp0"); err != nil {
t.Fatal(err)
}
writes := []string{
fmt.Sprintf(`cpu,host=server01 value=100 %d`, models.MaxNanoTime.UnixNano()),
}
test := NewTest("db0", "rp0")
test.writes = Writes{
&Write{data: strings.Join(writes, "\n")},
}
test.addQueries([]*Query{
&Query{
name: `show measurements`,
command: "SHOW MEASUREMENTS",
exp: `{"results":[{"series":[{"name":"measurements","columns":["name"],"values":[["cpu"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: `show series`,
command: "SHOW SERIES",
exp: `{"results":[{"series":[{"columns":["key"],"values":[["cpu,host=server01"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: `show tag keys`,
command: "SHOW TAG KEYS FROM cpu",
exp: `{"results":[{"series":[{"name":"cpu","columns":["tagKey"],"values":[["host"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: `show tag values`,
command: "SHOW TAG VALUES WITH KEY = \"host\"",
exp: `{"results":[{"series":[{"name":"cpu","columns":["key","value"],"values":[["host","server01"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: `show field keys`,
command: "SHOW FIELD KEYS",
exp: `{"results":[{"series":[{"name":"cpu","columns":["fieldKey","fieldType"],"values":[["value","float"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
}...)
for i, query := range test.queries {
if i == 0 {
if err := test.init(s); err != nil {
t.Fatalf("test init failed: %s", err)
}
}
if query.skip {
t.Logf("SKIP:: %s", query.name)
continue
}
if err := query.Execute(s); err != nil {
t.Error(query.Error(err))
} else if !query.success() {
t.Error(query.failureMessage())
}
}
}
func TestServer_Query_ShowSeries(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig())

View File

@ -420,7 +420,15 @@ func (e *StatementExecutor) executeSelectStatement(stmt *influxql.SelectStatemen
}
if opt.MaxTime.IsZero() {
opt.MaxTime = now
// In the case that we're executing a meta query where the user cannot
// specify a time condition, then we expand the default max time
// to the maximum possible value, to ensure that data where all points
// are in the future are returned.
if influxql.Sources(stmt.Sources).HasSystemSource() {
opt.MaxTime = time.Unix(0, models.MaxNanoTime.UnixNano())
} else {
opt.MaxTime = now
}
}
if opt.MinTime.IsZero() {
opt.MinTime = time.Unix(0, 0)