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

Fix panic: runtime error: slice bounds out of range #9117

Merged
merged 2 commits into from
Nov 15, 2017
Merged

Conversation

jwilder
Copy link
Contributor

@jwilder jwilder commented Nov 15, 2017

This fixes a regression in 1.4 introduced in ca40c1a where a delete with an invalid time range could end up either causing a panic or duplicate data in the blocks. I discovered this trying to reproduce #9116, which I have not been able to reproduce yet. This fix may fix that as well. This does not occur in 1.3.

For both of these, star the server with INFLUXDB_DATA_CACHE_SNAPSHOT_WRITE_COLD_DURATION=1s influxd

To reproduce the panic:

A delete where the min and max times are backwards causes a panic in Exclude.

#!/bin/bash

influx -execute "drop database test; create database test"

curl -v "http://localhost:8086/write?db=test" --data-binary 'cpu value=1 0
cpu value=1 1
cpu value=1 2
cpu value=1 3
cpu value=1 4
cpu value=1 5
cpu value=1 6
cpu value=1 7
cpu value=1 8
cpu value=1 9
cpu value=1 10
cpu value=1 11
mem value=1 1
zzz value=1 2
aaa value=1 3'

echo "Waiting 2 seconds for snapshot"
sleep 2

echo "All data is there"
influx -database test -execute "select * from /.*/"

echo "Delete cpu series by exact times"
influx -database test -execute "delete from cpu where time >= 10 and time <= 1;"


echo "Waiting for compaction"
sleep 2
echo "All series lexicographically after aaa are gone"

influx -database test -execute "select * from /.*/"

The server crashes with:

panic: runtime error: slice bounds out of range

goroutine 4248 [running]:
github.com/influxdata/influxdb/tsdb/engine/tsm1.FloatValues.Exclude(0xc42031e000, 0xc, 0xc, 0xa, 0x1, 0xc42031e000, 0xc, 0xc)
	/Users/jason/go/src/github.com/influxdata/influxdb/tsdb/engine/tsm1/encoding.gen.go:317 +0x1c8
github.com/influxdata/influxdb/tsdb/engine/tsm1.(*tsmKeyIterator).combineFloat(0xc4204d31e0, 0xc4202ba101, 0x8, 0xc4207457d0, 0x10452d4)
	/Users/jason/go/src/github.com/influxdata/influxdb/tsdb/engine/tsm1/compact.gen.go:87 +0x430
github.com/influxdata/influxdb/tsdb/engine/tsm1.(*tsmKeyIterator).mergeFloat(0xc4204d31e0)
	/Users/jason/go/src/github.com/influxdata/influxdb/tsdb/engine/tsm1/compact.gen.go:31 +0x14e

To reproduce the duplicate data:

#!/bin/bash

influx -execute "drop database test; create database test"

curl -v "http://localhost:8086/write?db=test" --data-binary 'cpu value=1 0
cpu value=1 1
cpu value=1 2
cpu value=1 3
cpu value=1 4
cpu value=1 5
cpu value=1 6
cpu value=1 7
cpu value=1 8
cpu value=1 9
cpu value=1 10
cpu value=1 11
mem value=1 1
zzz value=1 2
aaa value=1 3'

echo "Waiting 2 seconds for snapshot"
sleep 2

echo "All data is there"
influx -database test -execute "select * from /.*/"

echo "Delete cpu series by exact times"
influx -database test -execute "delete from cpu where time >= 0 and time <= 0; delete from cpu where time >= 2 and time <= 4; delete from cpu where time >= 6 and time <= 8; delete from cpu where time >= 10 and time <= 1;"

echo "Waiting for compaction"
sleep 2
echo "All series lexicographically after aaa are gone"

influx -database test -execute "select * from /.*/"

This causes the CPU series to have duplicate data after a compaction:

name: cpu
time value
---- -----
1    1
5    1
9    1
5    1
9    1
10   1
11   1
Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated
  • Sign CLA (if not already signed)

A panic could occur if an invalid time range was passed to
Exclude/Include, etc.
@jwilder jwilder requested a review from stuartcarnie November 15, 2017 15:32
@ghost ghost assigned jwilder Nov 15, 2017
@ghost ghost added the review label Nov 15, 2017
Copy link
Contributor

@e-dard e-dard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

[ci skip]
Copy link
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jwilder jwilder merged commit c3c4fd5 into master Nov 15, 2017
@jwilder jwilder deleted the jw-exclude-panic branch November 15, 2017 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants