Avoid panic in filltables() (#1365)
Avoid panic in filltables() (#1365)

Fixes: DGRAPH-1673

We are seeing below panic in sentry:

panic: runtime error: makeslice: len out of range

goroutine 21775506 [running]:
github.com/dgraph-io/badger/v2.(*levelsController).fillTables(0xc0001c5180, 0xc1ea6d3b40, 0x0)
	/go/pkg/mod/github.com/dgraph-io/badger/v2@v2.0.1-rc1.0.20200528205344-e7b6e76f96e8/levels.go:829 +0x3bd
github.com/dgraph-io/badger/v2.(*levelsController).doCompact(0xc0001c5180, 0x1, 0x3ff04f5543000000, 0x0, 0x0, 0x0, 0x0, 0x0)
	/go/pkg/mod/github.com/dgraph-io/badger/v2@v2.0.1-rc1.0.20200528205344-e7b6e76f96e8/levels.go:923 +0x91b
github.com/dgraph-io/badger/v2.(*levelsController).runWorker(0xc0001c5180, 0xc13b7156a0)
	/go/pkg/mod/github.com/dgraph-io/badger/v2@v2.0.1-rc1.0.20200528205344-e7b6e76f96e8/levels.go:368 +0x2fd
created by github.com/dgraph-io/badger/v2.(*levelsController).startCompact
	/go/pkg/mod/github.com/dgraph-io/badger/v2@v2.0.1-rc1.0.20200528205344-e7b6e76f96e8/levels.go:343 +0x88
Above panic is occuring in fillTables(), which is called to pick right tables for compaction from any
level(L) and its next level(L+1). When we pick any table from level L, we pick all table from level
L+1, who are overlapping with level L's table key range. To achieve above task we call
overlappingTables(), which returns the range of index (left, right). After this we create a slice
of size (right-left) to copy tables from index left to right using make().

Ideally this right should be >= left. But in some case we have seeing above panic and this might be
when right < left. We are not able to reproduce this.
This PR just logs the error when right < left and continues the loop. Once we see this information
in logs we can get more context around cases when right < left.
dgraph-io/badger,dgraph-io/badger