/src/rocksdb/db/blob/blob_file_reader.h
Line | Count | Source (jump to first uncovered line) |
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 | | #pragma once |
7 | | |
8 | | #include <cinttypes> |
9 | | #include <memory> |
10 | | |
11 | | #include "db/blob/blob_read_request.h" |
12 | | #include "file/random_access_file_reader.h" |
13 | | #include "rocksdb/compression_type.h" |
14 | | #include "rocksdb/rocksdb_namespace.h" |
15 | | #include "util/autovector.h" |
16 | | |
17 | | namespace ROCKSDB_NAMESPACE { |
18 | | |
19 | | class Status; |
20 | | struct ImmutableOptions; |
21 | | struct FileOptions; |
22 | | class HistogramImpl; |
23 | | struct ReadOptions; |
24 | | class Slice; |
25 | | class FilePrefetchBuffer; |
26 | | class BlobContents; |
27 | | class Statistics; |
28 | | |
29 | | class BlobFileReader { |
30 | | public: |
31 | | static Status Create(const ImmutableOptions& immutable_options, |
32 | | const ReadOptions& read_options, |
33 | | const FileOptions& file_options, |
34 | | uint32_t column_family_id, |
35 | | HistogramImpl* blob_file_read_hist, |
36 | | uint64_t blob_file_number, |
37 | | const std::shared_ptr<IOTracer>& io_tracer, |
38 | | std::unique_ptr<BlobFileReader>* reader); |
39 | | |
40 | | BlobFileReader(const BlobFileReader&) = delete; |
41 | | BlobFileReader& operator=(const BlobFileReader&) = delete; |
42 | | |
43 | | ~BlobFileReader(); |
44 | | |
45 | | Status GetBlob(const ReadOptions& read_options, const Slice& user_key, |
46 | | uint64_t offset, uint64_t value_size, |
47 | | CompressionType compression_type, |
48 | | FilePrefetchBuffer* prefetch_buffer, |
49 | | MemoryAllocator* allocator, |
50 | | std::unique_ptr<BlobContents>* result, |
51 | | uint64_t* bytes_read) const; |
52 | | |
53 | | // offsets must be sorted in ascending order by caller. |
54 | | void MultiGetBlob( |
55 | | const ReadOptions& read_options, MemoryAllocator* allocator, |
56 | | autovector<std::pair<BlobReadRequest*, std::unique_ptr<BlobContents>>>& |
57 | | blob_reqs, |
58 | | uint64_t* bytes_read) const; |
59 | | |
60 | 0 | CompressionType GetCompressionType() const { return compression_type_; } |
61 | | |
62 | 0 | uint64_t GetFileSize() const { return file_size_; } |
63 | | |
64 | | private: |
65 | | BlobFileReader(std::unique_ptr<RandomAccessFileReader>&& file_reader, |
66 | | uint64_t file_size, CompressionType compression_type, |
67 | | SystemClock* clock, Statistics* statistics); |
68 | | |
69 | | static Status OpenFile(const ImmutableOptions& immutable_options, |
70 | | const FileOptions& file_opts, |
71 | | HistogramImpl* blob_file_read_hist, |
72 | | uint64_t blob_file_number, |
73 | | const std::shared_ptr<IOTracer>& io_tracer, |
74 | | uint64_t* file_size, |
75 | | std::unique_ptr<RandomAccessFileReader>* file_reader); |
76 | | |
77 | | static Status ReadHeader(const RandomAccessFileReader* file_reader, |
78 | | const ReadOptions& read_options, |
79 | | uint32_t column_family_id, Statistics* statistics, |
80 | | CompressionType* compression_type); |
81 | | |
82 | | static Status ReadFooter(const RandomAccessFileReader* file_reader, |
83 | | const ReadOptions& read_options, uint64_t file_size, |
84 | | Statistics* statistics); |
85 | | |
86 | | using Buffer = std::unique_ptr<char[]>; |
87 | | |
88 | | static Status ReadFromFile(const RandomAccessFileReader* file_reader, |
89 | | const ReadOptions& read_options, |
90 | | uint64_t read_offset, size_t read_size, |
91 | | Statistics* statistics, Slice* slice, Buffer* buf, |
92 | | AlignedBuf* aligned_buf); |
93 | | |
94 | | static Status VerifyBlob(const Slice& record_slice, const Slice& user_key, |
95 | | uint64_t value_size); |
96 | | |
97 | | static Status UncompressBlobIfNeeded(const Slice& value_slice, |
98 | | CompressionType compression_type, |
99 | | MemoryAllocator* allocator, |
100 | | SystemClock* clock, |
101 | | Statistics* statistics, |
102 | | std::unique_ptr<BlobContents>* result); |
103 | | |
104 | | std::unique_ptr<RandomAccessFileReader> file_reader_; |
105 | | uint64_t file_size_; |
106 | | CompressionType compression_type_; |
107 | | SystemClock* clock_; |
108 | | Statistics* statistics_; |
109 | | }; |
110 | | |
111 | | } // namespace ROCKSDB_NAMESPACE |