From 54fb2a8975502024b8f27d366cb1036d51798605 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Thu, 17 Feb 2022 21:08:59 -0800 Subject: [PATCH] Change type of cache buffer passed to `Cache::CreateCallback()` to `const void*` (#9595) Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9595 Reviewed By: riversand963 Differential Revision: D34329906 Pulled By: ajkr fbshipit-source-id: 508601856fa9bee4d40f4a68d14d333ef2143d40 --- HISTORY.md | 1 + cache/cache_bench_tool.cc | 5 +++-- cache/lru_cache_test.cc | 5 +++-- include/rocksdb/cache.h | 2 +- table/block_based/block_like_traits.h | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 57bc4f5d9..52c2f9c0c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -32,6 +32,7 @@ * Remove DBOptions::preserved_deletes and DB::SetPreserveDeletesSequenceNumber(). * Remove deprecated API AdvancedColumnFamilyOptions::rate_limit_delay_max_milliseconds. * Removed timestamp from WriteOptions. Accordingly, added to DB APIs Put, Delete, SingleDelete, etc. accepting an additional argument 'timestamp'. Added Put, Delete, SingleDelete, etc to WriteBatch accepting an additional argument 'timestamp'. Removed WriteBatch::AssignTimestamps(vector) API. Renamed WriteBatch::AssignTimestamp() to WriteBatch::UpdateTimestamps() with clarified comments. +* Changed type of cache buffer passed to `Cache::CreateCallback` from `void*` to `const void*`. * Significant updates to FilterPolicy-related APIs and configuration: * Remove public API support for deprecated, inefficient block-based filter (use_block_based_builder=true). * Old code and configuration strings that would enable it now quietly enable full filters instead, though any built-in FilterPolicy can still read block-based filters. This includes changing the longstanding default behavior of the Java API. diff --git a/cache/cache_bench_tool.cc b/cache/cache_bench_tool.cc index b63afc1e0..cd9fac3d9 100644 --- a/cache/cache_bench_tool.cc +++ b/cache/cache_bench_tool.cc @@ -510,8 +510,9 @@ class CacheBench { timer.Start(); Slice key = gen.GetRand(thread->rnd, max_key_, max_log_); uint64_t random_op = thread->rnd.Next(); - Cache::CreateCallback create_cb = - [](void* buf, size_t size, void** out_obj, size_t* charge) -> Status { + Cache::CreateCallback create_cb = [](const void* buf, size_t size, + void** out_obj, + size_t* charge) -> Status { *out_obj = reinterpret_cast(new char[size]); memcpy(*out_obj, buf, size); *charge = size; diff --git a/cache/lru_cache_test.cc b/cache/lru_cache_test.cc index e8eb63826..865a03751 100644 --- a/cache/lru_cache_test.cc +++ b/cache/lru_cache_test.cc @@ -432,8 +432,9 @@ class LRUSecondaryCacheTest : public LRUCacheTest { static Cache::CacheItemHelper helper_fail_; - Cache::CreateCallback test_item_creator = - [&](void* buf, size_t size, void** out_obj, size_t* charge) -> Status { + Cache::CreateCallback test_item_creator = [&](const void* buf, size_t size, + void** out_obj, + size_t* charge) -> Status { if (fail_create_) { return Status::NotSupported(); } diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index 772977df3..75fbea0e8 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -206,7 +206,7 @@ class Cache { // takes in a buffer from the NVM cache and constructs an object using // it. The callback doesn't have ownership of the buffer and should // copy the contents into its own buffer. - using CreateCallback = std::function; Cache(std::shared_ptr allocator = nullptr) diff --git a/table/block_based/block_like_traits.h b/table/block_based/block_like_traits.h index ccfa8bc56..de9e8a440 100644 --- a/table/block_based/block_like_traits.h +++ b/table/block_based/block_like_traits.h @@ -25,7 +25,8 @@ Cache::CreateCallback GetCreateCallback(size_t read_amp_bytes_per_bit, Statistics* statistics, bool using_zstd, const FilterPolicy* filter_policy) { return [read_amp_bytes_per_bit, statistics, using_zstd, filter_policy]( - void* buf, size_t size, void** out_obj, size_t* charge) -> Status { + const void* buf, size_t size, void** out_obj, + size_t* charge) -> Status { assert(buf != nullptr); std::unique_ptr buf_data(new char[size]()); memcpy(buf_data.get(), buf, size);