]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/cache/secondary_cache.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / cache / secondary_cache.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
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
6 #include "rocksdb/secondary_cache.h"
7
8 #include "cache/cache_entry_roles.h"
9
10 namespace ROCKSDB_NAMESPACE {
11
12 namespace {
13
14 size_t SliceSize(void* obj) { return static_cast<Slice*>(obj)->size(); }
15
16 Status SliceSaveTo(void* from_obj, size_t from_offset, size_t length,
17 void* out) {
18 const Slice& slice = *static_cast<Slice*>(from_obj);
19 std::memcpy(out, slice.data() + from_offset, length);
20 return Status::OK();
21 }
22
23 } // namespace
24
25 Status SecondaryCache::InsertSaved(const Slice& key, const Slice& saved) {
26 static Cache::CacheItemHelper helper{
27 &SliceSize, &SliceSaveTo, GetNoopDeleterForRole<CacheEntryRole::kMisc>()};
28 // NOTE: depends on Insert() being synchronous, not keeping pointer `&saved`
29 return Insert(key, const_cast<Slice*>(&saved), &helper);
30 }
31
32 } // namespace ROCKSDB_NAMESPACE