Rebased/squashed version of #12825. Upstream discussion at https://github.com/google/leveldb/issues/561.
When snappy compression is disabled, LevelDB does not use a block cache. This PR avoids wasting memory reserved for the block cache in that situation, and gives it to the write buffer instead.
Unfortunately this behavior is not documented (I have filed a bug upstream already). You can see here that PosixMmapReadableFile
takes a scratch
argument that is unused. This isn’t by accident; the return value of the method is compared against the supplied buffer here to determine whether the block cache should be used.
Giving more memory to the write buffer is good for a number of reasons. Among them: LevelDB checks reads against the mem table holding current writes, so the write buffer acts as an LRU within LevelDB.