badger icon indicating copy to clipboard operation
badger copied to clipboard

Does dropPrefix remove !badger!move keys?

Open sana-jawad opened this issue 6 years ago • 4 comments

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?

  1. Inserted 1M of keys in badgerDB with two common prefixes say prefix1, prefix2
  2. Called dropPrefix for prefix1 which resulted in removing 500K keys.
  3. ValueLogGC discard ratio is set to 0.3 and frequency of calling ValueLogGC is 1min.
  4. There were no badger!move keys till this point. When ValueLogGC got triggered, it cleaned up some of the value log files.
  5. After the clean up !badger!move keys showed up in keys histogram.
  6. Called dropPrefix on prefix2 as well.
  7. There are no keys in DB but only !badger!move keys are still there.
  8. 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.

sana-jawad avatar Apr 04 '20 07:04 sana-jawad

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.

jarifibrahim avatar Apr 06 '20 13:04 jarifibrahim

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.

sana-jawad avatar Apr 06 '20 19:04 sana-jawad

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. :)

jarifibrahim avatar Apr 08 '20 10:04 jarifibrahim

This has been fixed via https://github.com/dgraph-io/badger/pull/1331.

jarifibrahim avatar May 22 '20 16:05 jarifibrahim