]>
git.proxmox.com Git - ceph.git/blob - 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).
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"
18 namespace ROCKSDB_NAMESPACE
{
20 class WritableFileWriter
;
23 * BlobLogWriter is the blob log stream writer. It provides an append-only
24 * abstraction for writing blob data.
27 * Look at blob_db_format.h to see the details of the record formats.
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);
39 BlobLogWriter(const BlobLogWriter
&) = delete;
40 BlobLogWriter
& operator=(const BlobLogWriter
&) = delete;
44 static void ConstructBlobHeader(std::string
* buf
, const Slice
& key
,
45 const Slice
& val
, uint64_t expiration
);
47 Status
AddRecord(const Slice
& key
, const Slice
& val
, uint64_t* key_offset
,
48 uint64_t* blob_offset
);
50 Status
AddRecord(const Slice
& key
, const Slice
& val
, uint64_t expiration
,
51 uint64_t* key_offset
, uint64_t* blob_offset
);
53 Status
EmitPhysicalRecord(const std::string
& headerbuf
, const Slice
& key
,
54 const Slice
& val
, uint64_t* key_offset
,
55 uint64_t* blob_offset
);
57 Status
AppendFooter(BlobLogFooter
& footer
, std::string
* checksum_method
,
58 std::string
* checksum_value
);
60 Status
WriteHeader(BlobLogHeader
& header
);
62 WritableFileWriter
* file() { return dest_
.get(); }
64 const WritableFileWriter
* file() const { return dest_
.get(); }
66 uint64_t get_log_number() const { return log_number_
; }
71 std::unique_ptr
<WritableFileWriter
> dest_
;
73 Statistics
* statistics_
;
75 uint64_t block_offset_
; // Current offset in block
79 enum ElemType
{ kEtNone
, kEtFileHdr
, kEtRecord
, kEtFileFooter
};
80 ElemType last_elem_type_
;
83 } // namespace ROCKSDB_NAMESPACE