Does dropPrefix remove !badger!move keys?
What version of Go are you using (go version)?
$ go version go version go1.13.6
What version of Badger are you using?
2.0.2
Does this issue reproduce with the latest master?
yes
What are the hardware specifications of the machine (RAM, OS, Disk)?
16 GB, Mac OS, 2TB
What did you do?
- Inserted 1M of keys in badgerDB with two common prefixes say prefix1, prefix2
- Called dropPrefix for prefix1 which resulted in removing 500K keys.
- ValueLogGC discard ratio is set to 0.3 and frequency of calling ValueLogGC is 1min.
- There were no badger!move keys till this point. When ValueLogGC got triggered, it cleaned up some of the value log files.
- After the clean up !badger!move keys showed up in keys histogram.
- Called dropPrefix on prefix2 as well.
- There are no keys in DB but only !badger!move keys are still there.
- So ValueLog files are not cleaned up entirely.
What did you expect to see?
All ValueLog files except one would be cleaned up and there are no internal move keys.
What did you see instead?
!badger!move keys are not cleaned up.
Hey @sana-jawad, we do not clean up the badger!move! keys. This is a known issue. One of the challenges here is to figure out which !badger!move keys are actually invalid and which ones are valid.
We could perform lookups for all !move! keys but this would severely affect the write performance as the compactions would become very expensive. This is a fairly tough task and we're working on finding a solution for it.
Thanks @jarifibrahim for the reply. It makes sense. I have a suggestion for dropPrefix method:
When dropPrefix is called for a "prefix", the dropPrefix should also drop keys with !badger!move+prefix. For drop prefix the choice is much more easy to make. Right now as a work around I am calling dropPrefix two times: dropPrefix(prefix) dropPrefix(!badger!move+prefix)
Also an observation, lower the value of discardRatio the higher the number of !badger!move keys. And thus more the number of !badger!move keys, the size on disk keeps on increasing over time. It may be added in the comments for discardRatio.
Thanks @sana-jawad. The dropPrefix(!badger!move+prefix) seems like a decent idea. Feel free to send a PR for it and the documentation changes. :)
This has been fixed via https://github.com/dgraph-io/badger/pull/1331.