]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
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 <memory> | |
9 | ||
10 | #include "db/blob/blob_log_format.h" | |
11 | #include "rocksdb/slice.h" | |
12 | ||
13 | namespace ROCKSDB_NAMESPACE { | |
14 | ||
15 | class RandomAccessFileReader; | |
16 | class Env; | |
17 | class Statistics; | |
18 | class Status; | |
19 | ||
20 | /** | |
21 | * BlobLogSequentialReader is a general purpose log stream reader | |
22 | * implementation. The actual job of reading from the device is implemented by | |
23 | * the RandomAccessFileReader interface. | |
24 | * | |
25 | * Please see BlobLogWriter for details on the file and record layout. | |
26 | */ | |
27 | ||
28 | class BlobLogSequentialReader { | |
29 | public: | |
30 | enum ReadLevel { | |
31 | kReadHeader, | |
32 | kReadHeaderKey, | |
33 | kReadHeaderKeyBlob, | |
34 | }; | |
35 | ||
36 | // Create a reader that will return log records from "*file_reader". | |
37 | BlobLogSequentialReader(std::unique_ptr<RandomAccessFileReader>&& file_reader, | |
38 | Env* env, Statistics* statistics); | |
39 | ||
40 | // No copying allowed | |
41 | BlobLogSequentialReader(const BlobLogSequentialReader&) = delete; | |
42 | BlobLogSequentialReader& operator=(const BlobLogSequentialReader&) = delete; | |
43 | ||
44 | ~BlobLogSequentialReader(); | |
45 | ||
46 | Status ReadHeader(BlobLogHeader* header); | |
47 | ||
48 | // Read the next record into *record. Returns true if read | |
49 | // successfully, false if we hit end of the input. The contents filled in | |
50 | // *record will only be valid until the next mutating operation on this | |
51 | // reader. | |
52 | // If blob_offset is non-null, return offset of the blob through it. | |
53 | Status ReadRecord(BlobLogRecord* record, ReadLevel level = kReadHeader, | |
54 | uint64_t* blob_offset = nullptr); | |
55 | ||
56 | Status ReadFooter(BlobLogFooter* footer); | |
57 | ||
58 | void ResetNextByte() { next_byte_ = 0; } | |
59 | ||
60 | uint64_t GetNextByte() const { return next_byte_; } | |
61 | ||
62 | private: | |
63 | Status ReadSlice(uint64_t size, Slice* slice, char* buf); | |
64 | ||
65 | const std::unique_ptr<RandomAccessFileReader> file_; | |
66 | Env* env_; | |
67 | Statistics* statistics_; | |
68 | ||
69 | Slice buffer_; | |
70 | char header_buf_[BlobLogRecord::kHeaderSize]; | |
71 | ||
72 | // which byte to read next | |
73 | uint64_t next_byte_; | |
74 | }; | |
75 | ||
76 | } // namespace ROCKSDB_NAMESPACE |