From f16f4b66391749342444e21c4a1eac5888669e4c Mon Sep 17 00:00:00 2001 From: Todd Persen Date: Sat, 11 Oct 2014 21:36:05 -0400 Subject: [PATCH] Querying for data outside of existing shards should return an empty response. Fix #1004. Close #1023 --- CHANGELOG.md | 2 ++ coordinator/coordinator.go | 2 +- integration/single_server_test.go | 34 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2c7b0a15e2..63925fd5eaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - [Issue #1007](https://github.com/influxdb/influxdb/issues/1007). Return the right content type in the response when compression is enabled +- [Issue #1004](https://github.com/influxdb/influxdb/issues/1004). Don't throw an + exception when querying for non existent data - [Issue #722](https://github.com/influxdb/influxdb/issues/722). Add an install target to the Makefile - [Issue #916](https://github.com/influxdb/influxdb/issues/916). Set diff --git a/coordinator/coordinator.go b/coordinator/coordinator.go index 7cb7c53fd31..a92ea93b960 100644 --- a/coordinator/coordinator.go +++ b/coordinator/coordinator.go @@ -275,7 +275,7 @@ func (self *Coordinator) runQuerySpec(querySpec *parser.QuerySpec, p engine.Proc } if len(shards) == 0 { - return fmt.Errorf("Couldn't look up columns") + return processor.Close() } shardConcurrentLimit := self.config.ConcurrentShardQueryLimit diff --git a/integration/single_server_test.go b/integration/single_server_test.go index c4c5b7f8bdd..b01411cf14e 100644 --- a/integration/single_server_test.go +++ b/integration/single_server_test.go @@ -587,6 +587,40 @@ func (self *SingleServerSuite) TestDataResurrectionAfterRestart(c *C) { c.Assert(series[0].Points, HasLen, 0) } +func (self *SingleServerSuite) TestEmptyResponseWhenNoShardsMatchQuery(c *C) { + rootUser := self.server.GetClient("", c) + + rootUser.CreateDatabase("db") + + c.Assert(rootUser.CreateDatabaseUser("db", "user", "pass"), IsNil) + + config := &influxdb.ClientConfig{ + Username: "user", + Password: "pass", + Database: "db", + } + + user, _ := influxdb.NewClient(config) + + data := ` + [ + { + "points": [ + [1] + ], + "name": "test_should_write", + "columns": ["value"] + } + ]` + + series := []*influxdb.Series{} + c.Assert(json.Unmarshal([]byte(data), &series), IsNil) + c.Assert(user.WriteSeries(series), IsNil) + + failing_content := self.server.RunQueryAsRoot("select * from test_should_write where time > '1990-12-01' and time < '1990-12-12'", "m", c) + c.Assert(failing_content, HasLen, 0) +} + // issue https://github.com/influxdb/influxdb/issues/702. Dropping shards can cause server crash // Two cases here. First is they try to drop the same shard multiple times. Second is that // they drop a shard and the server gets restarted so the raft log replays and tries to drop it again.