cache_helpers.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #include "cache/cache_helpers.h"
  6. namespace ROCKSDB_NAMESPACE {
  7. void ReleaseCacheHandleCleanup(void* arg1, void* arg2) {
  8. Cache* const cache = static_cast<Cache*>(arg1);
  9. assert(cache);
  10. Cache::Handle* const cache_handle = static_cast<Cache::Handle*>(arg2);
  11. assert(cache_handle);
  12. cache->Release(cache_handle);
  13. }
  14. Status WarmInCache(Cache* cache, const Slice& key, const Slice& saved,
  15. Cache::CreateContext* create_context,
  16. const Cache::CacheItemHelper* helper,
  17. Cache::Priority priority, size_t* out_charge) {
  18. assert(helper);
  19. assert(helper->create_cb);
  20. Cache::ObjectPtr value;
  21. size_t charge;
  22. Status st = helper->create_cb(saved, CompressionType::kNoCompression,
  23. CacheTier::kVolatileTier, create_context,
  24. cache->memory_allocator(), &value, &charge);
  25. if (st.ok()) {
  26. st =
  27. cache->Insert(key, value, helper, charge, /*handle*/ nullptr, priority);
  28. if (out_charge) {
  29. *out_charge = charge;
  30. }
  31. }
  32. return st;
  33. }
  34. } // namespace ROCKSDB_NAMESPACE