peterbourgon / diskv

A disk-backed key-value store.
http://godoc.org/github.com/peterbourgon/diskv
MIT License
1.41k stars 102 forks source link

ensureCacheSpaceWithLock panics with variable sized keys #40

Closed WinstonPrivacy closed 4 years ago

WinstonPrivacy commented 6 years ago

If variable sized keys are being used, then ensureCacheSpaceWithLock() can panic during the cache cleanup routine which loops through safe(). This occurs if the key being inserted is larger than the last key removed.

It would be better if either this key were inserted anyway (and thus exceeding the cache threshold) or the routine was modified so that it cleared some percent of the total cache size before proceeding.

WinstonPrivacy commented 6 years ago

I've fixed or improved a number of things related to this in my fork:

peterbourgon commented 6 years ago

Nice! Would love to see a PR with these fixes (in isolation).

akarmarkar commented 6 years ago

@WinstonPrivacy I am seeing this same issue. Can you please point me to your fork or raise a PR ? Thanks !

WinstonPrivacy commented 6 years ago

Here you go:

https://github.com/WinstonPrivacyInc/diskv

akarmarkar commented 6 years ago

Thanks !

floren commented 4 years ago

I got bitten by a panic in ensureCacheSpaceWithLock over the weekend, although I'm not clear what I did to trigger it. Any thoughts on building a PR? I look at look at WinstonPrivacy's fork but I'm afraid I can't be sure exactly which commits are relevant to this issue and which are for other things.

floren commented 4 years ago

Edit: I've written a test to check it.