Delete removes Keys but not data
What version of Go are you using (go version)?
go version go1.12.10 linux/amd64
What version of Badger are you using?
v1.5.4
Does this issue reproduce with the latest master?
Not sure
What are the hardware specifications of the machine (RAM, OS, Disk)?
Dell Edge 3001 Gateway 2GB RAM, Ubuntu 18.04, 8GB eMMC
What did you do?
Deleted a list of entries keys
err := ds.Update(func(txn *badger.Txn) error {
for _, key := range keys {
err := txn.Delete(key)
if err != nil {
return count, errors.Wrap(err, "DeleteItemsForKeys error")
}
}
return nil
})
ds.RunValueLogGC(0.7)
What did you expect to see?
Keys and Values removed,
What did you see instead?
No keys, but disk usage keeps increasing ( 000000x.vlog keeps growing)
Hey @RobHumphris, badger has a write-ahead-log called value log (.vlog files). When you perform the delete, the delete is also saved on to the disk. So the disk size is expected to increase on deleted.
Also, RunValueLogGC(..) might not always reclaim space. We perform sampling on value log file before we GC it. If the sampling doesn't find enough stale data, it might not delete it. You can check the error returned by the RunValueGC(..) function.
This is strange because I'd not seen the disk size grow. I'm using your system on an embedded gateway in an IoT project, so I have to free up space.
What would the correct way to deal with the space issue be? If you can give me some pointers I'll write a section on deletion in the README.md file as its an area that may assist others,
You can try by reducing the ValueLogFileSize value. The smaller the size of the value log file, the better are the chances of finding stale data in sampling. https://github.com/dgraph-io/badger/blob/e68feb1d553aab9c5c9d44a47c901c1a934285a8/options.go#L399-L407
You should also reduce the value of discard ratio . RunValueLogGC(0.7) means GC the file only if 70% of the data is stale. Try setting it to a lower value like 0.001.
I have set a smaller Log file size (options.WithValueLogFileSize(1<<28 - 1)), and discard ration of 0.001
data/dir/ looked like
1.1G Nov 8 06:17 000000.vlog
1.1G Nov 8 22:39 000001.vlog
1.8K Nov 14 10:04 000002.sst
1.1G Nov 10 05:45 000003.vlog
1.1G Nov 10 21:40 000004.vlog
1.1G Nov 11 13:18 000005.vlog
1.1G Nov 12 04:54 000006.vlog
1.1G Nov 12 20:26 000007.vlog
1.1G Nov 13 11:54 000008.vlog
364M Nov 14 10:06 000009.vlog
The output from badger showed:
badger 2019/11/14 10:08:00 DEBUG: Storing value log head: {Fid:9 Len:104 Offset:380830025}
badger 2019/11/14 10:08:00 INFO: Got compaction priority: {level:0 score:1.73 dropPrefix:[]}
badger 2019/11/14 10:08:00 INFO: Running for level: 0
badger 2019/11/14 10:08:00 DEBUG: LOG Compact. Added 83 keys. Skipped 140 keys. Iteration took: 1.505725ms
badger 2019/11/14 10:08:00 DEBUG: Discard stats: map[9:3750131]
badger 2019/11/14 10:08:00 INFO: LOG Compact 0->1, del 2 tables, add 1 tables, took 16.018889ms
badger 2019/11/14 10:08:00 INFO: Compaction for level: 0 DONE
badger 2019/11/14 10:08:00 INFO: Force compaction on level 0 done
But we've not reduced the file overhead at all
1.1G Nov 8 06:17 000000.vlog
1.1G Nov 10 05:45 000003.vlog
4.4K Nov 14 10:08 000004.sst
1.1G Nov 10 21:40 000004.vlog
1.1G Nov 11 13:18 000005.vlog
1.1G Nov 12 04:54 000006.vlog
1.1G Nov 12 20:26 000007.vlog
1.1G Nov 13 11:54 000008.vlog
364M Nov 14 10:08 000009.vlog
I must be missing something as other more heavy processing would be filling people's disks.
Hey @RobHumphris, your directory structure shows you don't have a lot of SSTs. We don't remove the data until it is written to SST files on the disk. You have only 4.4KB of data in SST. So you can do two things to force the generation of more SSTs.
-
Set MaxTableSize to a smaller value which would mean you have multiple SSTs and the data would be pushed to the lower levels faster https://github.com/dgraph-io/badger/blob/eef7c122607e5c2cc60e14eb20c883efa3e6855b/options.go#L287-L295
-
Disable the
KeepL0InMemoryoption. By default, it is set totruewhich meansLevel 0will also be in memory and we won't GC the data related to it.
https://github.com/dgraph-io/badger/blob/eef7c122607e5c2cc60e14eb20c883efa3e6855b/options.go#L478-L489
Also, we create traces in GC https://github.com/dgraph-io/badger/blob/master/value.go#L1666.
You can add an HTTP server in your application and look at /debug/requests endpoint. It should have information about which file was garbage collected.
@jarifibrahim You mention that you can add a HTTP server and get more info on what was garbage collected. Any pointers on how to do that?