]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/blob_db/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).
13 #include "rocksdb/env.h"
14 #include "rocksdb/slice.h"
15 #include "rocksdb/statistics.h"
16 #include "rocksdb/status.h"
17 #include "rocksdb/types.h"
18 #include "utilities/blob_db/blob_log_format.h"
22 class WritableFileWriter
;
27 * Writer is the blob log stream writer. It provides an append-only
28 * abstraction for writing blob data.
31 * Look at blob_db_format.h to see the details of the record formats.
36 // Create a writer that will append data to "*dest".
37 // "*dest" must be initially empty.
38 // "*dest" must remain live while this Writer is in use.
39 Writer(std::unique_ptr
<WritableFileWriter
>&& dest
, Env
* env
,
40 Statistics
* statistics
, uint64_t log_number
, uint64_t bpsync
,
41 bool use_fsync
, uint64_t boffset
= 0);
46 Writer(const Writer
&) = delete;
47 Writer
& operator=(const Writer
&) = delete;
49 static void ConstructBlobHeader(std::string
* buf
, const Slice
& key
,
50 const Slice
& val
, uint64_t expiration
);
52 Status
AddRecord(const Slice
& key
, const Slice
& val
, uint64_t* key_offset
,
53 uint64_t* blob_offset
);
55 Status
AddRecord(const Slice
& key
, const Slice
& val
, uint64_t expiration
,
56 uint64_t* key_offset
, uint64_t* blob_offset
);
58 Status
EmitPhysicalRecord(const std::string
& headerbuf
, const Slice
& key
,
59 const Slice
& val
, uint64_t* key_offset
,
60 uint64_t* blob_offset
);
62 Status
AppendFooter(BlobLogFooter
& footer
);
64 Status
WriteHeader(BlobLogHeader
& header
);
66 WritableFileWriter
* file() { return dest_
.get(); }
68 const WritableFileWriter
* file() const { return dest_
.get(); }
70 uint64_t get_log_number() const { return log_number_
; }
72 bool ShouldSync() const { return block_offset_
> next_sync_offset_
; }
76 void ResetSyncPointer() { next_sync_offset_
+= bytes_per_sync_
; }
79 std::unique_ptr
<WritableFileWriter
> dest_
;
81 Statistics
* statistics_
;
83 uint64_t block_offset_
; // Current offset in block
84 uint64_t bytes_per_sync_
;
85 uint64_t next_sync_offset_
;
89 enum ElemType
{ kEtNone
, kEtFileHdr
, kEtRecord
, kEtFileFooter
};
90 ElemType last_elem_type_
;
93 } // namespace blob_db
94 } // namespace rocksdb
95 #endif // ROCKSDB_LITE