Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

querying a range that includes the past and the future causes a panic #2268

Closed
neonstalwart opened this issue Apr 13, 2015 · 8 comments
Closed
Assignees
Milestone

Comments

@neonstalwart
Copy link
Contributor

the following script will cause a panic. the script is similar to the one added in #2159 with an extra time > now() - 2d in the where clause of the last query.

now=$(date '+%FT%T.000Z')
tomorrow=$(date -v +1d '+%FT%T.000Z')

echo "creating database"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "q=CREATE DATABASE foo"

echo "creating retention policy"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "q=CREATE RETENTION POLICY bar ON foo DURATION INF REPLICATION 1 DEFAULT"

echo "inserting data"
curl -d "{\"database\" : \"foo\", \"retentionPolicy\" : \"bar\", \"points\": [{\"name\": \"cpu\", \"tags\": {\"region\":\"uswest\",\"host\": \"server01\"},\"timestamp\": \"$now\",\"fields\": {\"value\": 100}}]}" -H "Content-Type: application/json" -ipv4 http://localhost:8086/write

echo "inserting data"
curl -d "{\"database\" : \"foo\", \"retentionPolicy\" : \"bar\", \"points\": [{\"name\": \"cpu\", \"tags\": {\"region\":\"uswest\",\"host\": \"server01\"},\"timestamp\": \"$tomorrow\",\"fields\": {\"value\": 200}}]}" -H "Content-Type: application/json" -ipv4 http://localhost:8086/write

sleep 1

echo "querying data"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT count(value) FROM \"foo\".\"bar\".cpu"

echo "querying data"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT count(value) FROM \"foo\".\"bar\".cpu where time > now() - 2d and time < now() + 10d"
@neonstalwart neonstalwart changed the title querying a range that includes the future causes a panic querying a range that includes the past and the future causes a panic Apr 13, 2015
@otoolep
Copy link
Contributor

otoolep commented Apr 13, 2015

Thanks for the bug report @neonstalwart -- does it also occur if the future time is specified in absolute terms?

@dgnorton
Copy link
Contributor

I was able to reproduce with @neonstalwart 's script...

[http] 2015/04/13 15:44:26 127.0.0.1 - - [13/Apr/2015:15:44:26 -0400] GET /query?db=foo&q=SELECT%20count%28value%29%20FROM%20%22foo%22.%22bar%22.cpu HTTP/1.1 200 110 - curl/7.35.0 7dfaa3c5-e215-11e4-8024-000000000000 32.623578ms
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4dabea]

goroutine 284398 [running]:
github.com/influxdb/influxdb.(*Measurement).idsForExpr(0xc20860d560, 0xc208c9af00, 0x0, 0x0, 0x0, 0xc208ec1300, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/database.go:365 +0x91a
github.com/influxdb/influxdb.(*Measurement).walkWhereForSeriesIds(0xc20860d560, 0x7ff708325340, 0xc208c9af00, 0xc208c9b140, 0x0, 0x0, 0x0, 0xc208ec1300, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/database.go:498 +0xcdb
github.com/influxdb/influxdb.(*Measurement).walkWhereForSeriesIds(0xc20860d560, 0x7ff708325340, 0xc208c9b020, 0xc208c9b140, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/database.go:436 +0x1f6
github.com/influxdb/influxdb.(*Measurement).filters(0xc20860d560, 0xc209db60c0, 0xc208ec1540)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/database.go:292 +0xac
github.com/influxdb/influxdb.(*Measurement).tagSets(0xc20860d560, 0xc209db60c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/database.go:313 +0x67
github.com/influxdb/influxdb.(*tx).CreateMapReduceJobs(0xc20c203c80, 0xc209db60c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/tx.go:125 +0x1009
github.com/influxdb/influxdb/influxql.(*Planner).Plan(0xc209de37a0, 0xc209db60c0, 0x2710, 0x1, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/influxql/engine.go:710 +0x319
github.com/influxdb/influxdb.(*Server).planSelectStatement(0xc208062200, 0xc209db60c0, 0x2710, 0x0, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/server.go:2418 +0x14a
github.com/influxdb/influxdb.(*Server).executeSelectStatement(0xc208062200, 0x0, 0xc209db60c0, 0xc20a0cea5e, 0x3, 0x0, 0xc2086dd7a0, 0x2710, 0x0, 0x0)
    /home/dgnorton/go/src/github.com/influxdb/influxdb/server.go:2245 +0xba
github.com/influxdb/influxdb.func·039()
    /home/dgnorton/go/src/github.com/influxdb/influxdb/server.go:2150 +0xab4
created by github.com/influxdb/influxdb.(*Server).ExecuteQuery
    /home/dgnorton/go/src/github.com/influxdb/influxdb/server.go:2231 +0x314

@neonstalwart
Copy link
Contributor Author

@otoolep what does an absolute time need to look like? i tried to use date -v +10d '+%FT%T.000Z' but that doesn't seem to be it.

@dgnorton
Copy link
Contributor

@otoolep no panic if absolute time is used...

> select count(value) from cpu where time > now() - 10d and time < '2015-04-22T19:00:00.000000000Z'
name: cpu
---------
time                count
2015-03-21T23:33:46.006871148Z  1

@toddboom
Copy link
Contributor

I think this might be a dupe of #2184.

@neonstalwart
Copy link
Contributor Author

confirmed that absolute time is ok

now=$(date '+%FT%T.000Z')
tomorrow=$(date -v +1d '+%FT%T.000Z')
tendays=$(date -v +10d '+%F')

echo "creating database"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "q=CREATE DATABASE foo"

echo "creating retention policy"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "q=CREATE RETENTION POLICY bar ON foo DURATION INF REPLICATION 1 DEFAULT"

echo "inserting data"
curl -d "{\"database\" : \"foo\", \"retentionPolicy\" : \"bar\", \"points\": [{\"name\": \"cpu\", \"tags\": {\"region\":\"uswest\",\"host\": \"server01\"},\"timestamp\": \"$now\",\"fields\": {\"value\": 100}}]}" -H "Content-Type: application/json" -ipv4 http://localhost:8086/write

echo "inserting data"
curl -d "{\"database\" : \"foo\", \"retentionPolicy\" : \"bar\", \"points\": [{\"name\": \"cpu\", \"tags\": {\"region\":\"uswest\",\"host\": \"server01\"},\"timestamp\": \"$tomorrow\",\"fields\": {\"value\": 200}}]}" -H "Content-Type: application/json" -ipv4 http://localhost:8086/write

sleep 1

echo "querying data"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT count(value) FROM \"foo\".\"bar\".cpu"

echo "querying data"
curl -G -ipv4 http://localhost:8086/query --data-urlencode "db=foo" --data-urlencode "q=SELECT count(value) FROM \"foo\".\"bar\".cpu where time > now() - 2d and time < '$tendays'"

it may be a dupe of #2184 - if it is then it seems we've narrowed it down to using and and now() (not just and)

@dgnorton dgnorton self-assigned this Apr 13, 2015
@neonstalwart
Copy link
Contributor Author

it seems we've narrowed it down to using and and now() (not just and)

that's an oversimplification because time > now() - 2d and time <= now() works

@dgnorton
Copy link
Contributor

There's a bug in the way it creates the AST for time > now() - 2d and time < now() + 10d. The RHS of the and is being grouped / evaluated as (time < now()) - 5d. The bug doesn't show up when we just have and time < now(). We'll get it fixed.

@beckettsean beckettsean added this to the 0.9.0 milestone Apr 14, 2015
dgnorton added a commit that referenced this issue Apr 15, 2015
Parsing:

WHERE time > now() - 2d AND time < now() + 10d

generated an expression tree that evaluated as:

... AND (time < now()) + 10d

instead of:

... AND time < (now() + 10d)
dgnorton added a commit that referenced this issue Apr 15, 2015
dgnorton added a commit that referenced this issue Apr 15, 2015
dgnorton added a commit that referenced this issue Apr 15, 2015
fix #2268: fix expression parsing bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants