]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
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 | ||
6 | #pragma once | |
7 | ||
8 | #include <memory> | |
9 | ||
10 | #include "memory/memory_allocator.h" | |
11 | #include "rocksdb/cache.h" | |
12 | #include "rocksdb/rocksdb_namespace.h" | |
13 | #include "rocksdb/slice.h" | |
14 | #include "rocksdb/status.h" | |
15 | ||
16 | namespace ROCKSDB_NAMESPACE { | |
17 | ||
18 | // A class representing a single uncompressed value read from a blob file. | |
19 | class BlobContents { | |
20 | public: | |
21 | static std::unique_ptr<BlobContents> Create(CacheAllocationPtr&& allocation, | |
22 | size_t size); | |
23 | ||
24 | BlobContents(const BlobContents&) = delete; | |
25 | BlobContents& operator=(const BlobContents&) = delete; | |
26 | ||
27 | BlobContents(BlobContents&&) = default; | |
28 | BlobContents& operator=(BlobContents&&) = default; | |
29 | ||
30 | ~BlobContents() = default; | |
31 | ||
32 | const Slice& data() const { return data_; } | |
33 | size_t size() const { return data_.size(); } | |
34 | ||
35 | size_t ApproximateMemoryUsage() const; | |
36 | ||
37 | // Callbacks for secondary cache | |
38 | static size_t SizeCallback(void* obj); | |
39 | ||
40 | static Status SaveToCallback(void* from_obj, size_t from_offset, | |
41 | size_t length, void* out); | |
42 | ||
43 | static Cache::CacheItemHelper* GetCacheItemHelper(); | |
44 | ||
45 | static Status CreateCallback(CacheAllocationPtr&& allocation, const void* buf, | |
46 | size_t size, void** out_obj, size_t* charge); | |
47 | ||
48 | private: | |
49 | BlobContents(CacheAllocationPtr&& allocation, size_t size) | |
50 | : allocation_(std::move(allocation)), data_(allocation_.get(), size) {} | |
51 | ||
52 | CacheAllocationPtr allocation_; | |
53 | Slice data_; | |
54 | }; | |
55 | ||
56 | } // namespace ROCKSDB_NAMESPACE |