From 2d080fe23a2c1768f51a97ab375820e4978fca6d Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Thu, 19 May 2016 16:03:13 +0100 Subject: [PATCH] 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. --- cmd/influxd/run/server_test.go | 72 +++++++++++++++++++++++++++++++ coordinator/statement_executor.go | 10 ++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 0ddb454e314..7d17a6ab372 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -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()) diff --git a/coordinator/statement_executor.go b/coordinator/statement_executor.go index 7e9af86671e..e836676b664 100644 --- a/coordinator/statement_executor.go +++ b/coordinator/statement_executor.go @@ -388,7 +388,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)