Go to file
Hui Xiao 74cfe7db60 Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506)
Summary:
Context:
To help cap various memory usage by a single limit of the block cache capacity, we charge the memory usage through inserting/releasing dummy entries in the block cache. CacheReservationManager is such a class (non thread-safe) responsible for  inserting/removing dummy entries to reserve cache space for memory used by the class user.

- Refactored the inner private class CacheRep of WriteBufferManager into public CacheReservationManager class for reusability such as for https://github.com/facebook/rocksdb/pull/8428

- Encapsulated implementation details of cache key generation and dummy entries insertion/release in cache reservation as discussed in https://github.com/facebook/rocksdb/pull/8506#discussion_r666550838

- Consolidated increase/decrease cache reservation into one API - UpdateCacheReservation.

- Adjusted the previous dummy entry release algorithm in decreasing cache reservation to be loop-releasing dummy entries to stay symmetric to dummy entry insertion algorithm

- Made the previous dummy entry release algorithm in delayed decrease mode more aggressive for better decreasing cache reservation when memory used is less likely to increase back.

  Previously, the algorithms only release 1 dummy entries when new_mem_used < 3/4 * cache_allocated_size_ and cache_allocated_size_ - kSizeDummyEntry > new_mem_used.
Now, the algorithms loop-releases as many dummy entries as possible when new_mem_used < 3/4 * cache_allocated_size_.

- Updated WriteBufferManager's test cases to adapt to changes on the release algorithm mentioned above and left comment for some test cases for clarity

- Replaced the previous cache key prefix generation (utilizing object address related to the cache client) with one that utilizes Cache->NewID() to prevent cache-key collision among dummy entry clients sharing the same cache.

  The specific collision we are preventing happens when the object address is reused for a new cache-key prefix while the old cache-key using that same object address in its prefix still exists in the cache. This could happen due to that, under LRU cache policy, there is a possible delay in releasing a cache entry after the cache client object owning that cache entry get deallocated. In this case, the object address related to the cache client object can get reused for other client object to generate a new cache-key prefix.

  This prefix generation can be made obsolete after Peter's unification of all the code generating cache key, mentioned in https://github.com/facebook/rocksdb/pull/8506#discussion_r667265255

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8506

Test Plan:
- Passing the added unit tests cache_reservation_manager_test.cc
- Passing existing and adjusted write_buffer_manager_test.cc

Reviewed By: ajkr

Differential Revision: D29644135

Pulled By: hx235

fbshipit-source-id: 0fc93fbfe4a40bb41be85c314f8f2bafa8b741f7
2021-08-24 12:43:31 -07:00
.circleci Add missing steps for cmake build (#8524) 2021-07-15 13:37:49 -07:00
.github/workflows
buckifier
build_tools Pass extra db_stress args to fbcode crash tests (#8587) 2021-07-27 12:46:47 -07:00
cache Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506) 2021-08-24 12:43:31 -07:00
cmake
coverage
db Deflake write-prepared and write-unprepared tests (#8696) 2021-08-23 23:09:17 -07:00
db_stress_tool Add Bloom/Ribbon hybrid API support (#8679) 2021-08-20 18:00:16 -07:00
docs Bump addressable from 2.7.0 to 2.8.0 in /docs (#8515) 2021-07-12 17:06:07 -07:00
env Make TraceRecord and Replayer public (#8611) 2021-08-11 19:32:46 -07:00
examples
file Add db_test2 to to ASSERT_STATUS_CHECKED (#8640) 2021-08-16 08:10:32 -07:00
fuzz Make EventListener into a Customizable Class (#8473) 2021-07-27 07:47:02 -07:00
hdfs
include/rocksdb Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506) 2021-08-24 12:43:31 -07:00
java Add a stat to count secondary cache hits (#8666) 2021-08-16 21:01:14 -07:00
logging Do not attempt to rename non-existent info log (#8622) 2021-08-04 17:25:00 -07:00
memory
memtable Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506) 2021-08-24 12:43:31 -07:00
microbench
monitoring Add a PerfContext counter for secondary cache hits (#8685) 2021-08-20 15:17:30 -07:00
options Fix LITE build (#8689) 2021-08-23 05:10:13 -07:00
plugin
port Support dynamic sector size in alignment validation for Windows. (#8613) 2021-08-16 07:31:57 -07:00
table Allow intentionally swallowed errors in BlockBasedFilterBlockReader (#8695) 2021-08-23 15:50:27 -07:00
test_util Fix some minor issues in the Customizable infrastructure (#8566) 2021-08-19 10:10:47 -07:00
third-party
tools Refactor TraceAnalyzer to use `TraceRecord::Handler` to avoid casting. (#8678) 2021-08-23 17:18:27 -07:00
trace_replay Refactor TraceAnalyzer to use `TraceRecord::Handler` to avoid casting. (#8678) 2021-08-23 17:18:27 -07:00
util Upgrade xxhash, add Hash128 (#8634) 2021-08-20 18:41:51 -07:00
utilities Refactor TraceAnalyzer to use `TraceRecord::Handler` to avoid casting. (#8678) 2021-08-23 17:18:27 -07:00
.clang-format
.gitignore
.lgtm.yml
.travis.yml
.watchmanconfig
AUTHORS
CMakeLists.txt Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506) 2021-08-24 12:43:31 -07:00
CODE_OF_CONDUCT.md
CONTRIBUTING.md
COPYING
DEFAULT_OPTIONS_HISTORY.md
DUMP_FORMAT.md
HISTORY.md Add extra information to RemoteCompaction APIs (#8680) 2021-08-23 16:27:38 -07:00
INSTALL.md
LANGUAGE-BINDINGS.md
LICENSE.Apache
LICENSE.leveldb
Makefile Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506) 2021-08-24 12:43:31 -07:00
PLUGINS.md
README.md
ROCKSDB_LITE.md
TARGETS Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506) 2021-08-24 12:43:31 -07:00
USERS.md
Vagrantfile
WINDOWS_PORT.md
appveyor.yml
defs.bzl
issue_template.md
src.mk Refactor WriteBufferManager::CacheRep into CacheReservationManager (#8506) 2021-08-24 12:43:31 -07:00
thirdparty.inc

README.md

RocksDB: A Persistent Key-Value Store for Flash and RAM Storage

CircleCI Status TravisCI Status Appveyor Build status PPC64le Build Status

RocksDB is developed and maintained by Facebook Database Engineering Team. It is built on earlier work on LevelDB by Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)

This code is a library that forms the core building block for a fast key-value server, especially suited for storing data on flash drives. It has a Log-Structured-Merge-Database (LSM) design with flexible tradeoffs between Write-Amplification-Factor (WAF), Read-Amplification-Factor (RAF) and Space-Amplification-Factor (SAF). It has multi-threaded compactions, making it especially suitable for storing multiple terabytes of data in a single database.

Start with example usage here: https://github.com/facebook/rocksdb/tree/master/examples

See the github wiki for more explanation.

The public interface is in include/. Callers should not include or rely on the details of any other header files in this package. Those internal APIs may be changed without warning.

Design discussions are conducted in https://www.facebook.com/groups/rocksdb.dev/ and https://rocksdb.slack.com/

License

RocksDB is dual-licensed under both the GPLv2 (found in the COPYING file in the root directory) and Apache 2.0 License (found in the LICENSE.Apache file in the root directory). You may select, at your option, one of the above-listed licenses.