/src/rocksdb/db/blob/blob_log_writer.h
Line | Count | Source |
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 | | #pragma once |
6 | | |
7 | | #include <cstdint> |
8 | | #include <memory> |
9 | | #include <string> |
10 | | |
11 | | #include "db/blob/blob_log_format.h" |
12 | | #include "rocksdb/slice.h" |
13 | | #include "rocksdb/statistics.h" |
14 | | #include "rocksdb/status.h" |
15 | | #include "rocksdb/types.h" |
16 | | |
17 | | namespace ROCKSDB_NAMESPACE { |
18 | | |
19 | | class WritableFileWriter; |
20 | | class SystemClock; |
21 | | /** |
22 | | * BlobLogWriter is the blob log stream writer. It provides an append-only |
23 | | * abstraction for writing blob data. |
24 | | * |
25 | | * |
26 | | * Look at blob_db_format.h to see the details of the record formats. |
27 | | */ |
28 | | |
29 | | class BlobLogWriter { |
30 | | public: |
31 | | // Create a writer that will append data to "*dest". |
32 | | // "*dest" must be initially empty. |
33 | | // "*dest" must remain live while this BlobLogWriter is in use. |
34 | | BlobLogWriter(std::unique_ptr<WritableFileWriter>&& dest, SystemClock* clock, |
35 | | Statistics* statistics, uint64_t log_number, bool use_fsync, |
36 | | bool do_flush, uint64_t boffset = 0); |
37 | | // No copying allowed |
38 | | BlobLogWriter(const BlobLogWriter&) = delete; |
39 | | BlobLogWriter& operator=(const BlobLogWriter&) = delete; |
40 | | |
41 | | ~BlobLogWriter(); |
42 | | |
43 | | static void ConstructBlobHeader(std::string* buf, const Slice& key, |
44 | | const Slice& val, uint64_t expiration); |
45 | | |
46 | | Status AddRecord(const WriteOptions& write_options, const Slice& key, |
47 | | const Slice& val, uint64_t* key_offset, |
48 | | uint64_t* blob_offset); |
49 | | |
50 | | Status AddRecord(const WriteOptions& write_options, const Slice& key, |
51 | | const Slice& val, uint64_t expiration, uint64_t* key_offset, |
52 | | uint64_t* blob_offset); |
53 | | |
54 | | Status EmitPhysicalRecord(const WriteOptions& write_options, |
55 | | const std::string& headerbuf, const Slice& key, |
56 | | const Slice& val, uint64_t* key_offset, |
57 | | uint64_t* blob_offset); |
58 | | |
59 | | Status AppendFooter(const WriteOptions& write_options, BlobLogFooter& footer, |
60 | | std::string* checksum_method, |
61 | | std::string* checksum_value); |
62 | | |
63 | | Status WriteHeader(const WriteOptions& write_options, BlobLogHeader& header); |
64 | | |
65 | 0 | WritableFileWriter* file() { return dest_.get(); } |
66 | | |
67 | 0 | const WritableFileWriter* file() const { return dest_.get(); } |
68 | | |
69 | 0 | uint64_t get_log_number() const { return log_number_; } |
70 | | |
71 | | Status Sync(const WriteOptions& write_options); |
72 | | |
73 | | private: |
74 | | std::unique_ptr<WritableFileWriter> dest_; |
75 | | SystemClock* clock_; |
76 | | Statistics* statistics_; |
77 | | uint64_t log_number_; |
78 | | uint64_t block_offset_; // Current offset in block |
79 | | bool use_fsync_; |
80 | | bool do_flush_; |
81 | | |
82 | | public: |
83 | | enum ElemType { kEtNone, kEtFileHdr, kEtRecord, kEtFileFooter }; |
84 | | ElemType last_elem_type_; |
85 | | }; |
86 | | |
87 | | } // namespace ROCKSDB_NAMESPACE |