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