1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 5 #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_
6 #define STORAGE_LEVELDB_DB_LOG_WRITER_H_
7 8 #include <stdint.h>
9 10 #include "db/log_format.h"
11 #include "leveldb/slice.h"
12 #include "leveldb/status.h"
13 14 namespace leveldb {
15 16 class WritableFile;
17 18 namespace log {
19 20 class Writer {
21 public:
22 // Create a writer that will append data to "*dest".
23 // "*dest" must be initially empty.
24 // "*dest" must remain live while this Writer is in use.
25 explicit Writer(WritableFile* dest);
26 27 // Create a writer that will append data to "*dest".
28 // "*dest" must have initial length "dest_length".
29 // "*dest" must remain live while this Writer is in use.
30 Writer(WritableFile* dest, uint64_t dest_length);
31 32 Writer(const Writer&) = delete;
33 Writer& operator=(const Writer&) = delete;
34 35 ~Writer();
36 37 Status AddRecord(const Slice& slice);
38 39 private:
40 Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length);
41 42 WritableFile* dest_;
43 int block_offset_; // Current offset in block
44 45 // crc32c values for all supported record types. These are
46 // pre-computed to reduce the overhead of computing the crc of the
47 // record type stored in the header.
48 uint32_t type_crc_[kMaxRecordType + 1];
49 };
50 51 } // namespace log
52 } // namespace leveldb
53 54 #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_
55