Bitcoin
log_writer.h
Go to the documentation of this file.
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 #include "db/log_format.h"
10 #include "leveldb/slice.h"
11 #include "leveldb/status.h"
12 
13 namespace leveldb {
14 
15 class WritableFile;
16 
17 namespace log {
18 
19 class Writer {
20  public:
21  // Create a writer that will append data to "*dest".
22  // "*dest" must be initially empty.
23  // "*dest" must remain live while this Writer is in use.
24  explicit Writer(WritableFile* dest);
25 
26  // Create a writer that will append data to "*dest".
27  // "*dest" must have initial length "dest_length".
28  // "*dest" must remain live while this Writer is in use.
29  Writer(WritableFile* dest, uint64_t dest_length);
30 
31  ~Writer();
32 
33  Status AddRecord(const Slice& slice);
34 
35  private:
37  int block_offset_; // Current offset in block
38 
39  // crc32c values for all supported record types. These are
40  // pre-computed to reduce the overhead of computing the crc of the
41  // record type stored in the header.
43 
44  Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length);
45 
46  // No copying allowed
47  Writer(const Writer&);
48  void operator=(const Writer&);
49 };
50 
51 } // namespace log
52 } // namespace leveldb
53 
54 #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_
Definition: autocompact_test.cc:11
int block_offset_
Definition: log_writer.h:37
void operator=(const Writer &)
Definition: env.h:233
~Writer()
Definition: log_writer.cc:33
WritableFile * dest_
Definition: log_writer.h:36
Writer(WritableFile *dest)
Definition: log_writer.cc:22
RecordType
Definition: log_format.h:14
Status EmitPhysicalRecord(RecordType type, const char *ptr, size_t length)
Definition: log_writer.cc:84
unsigned int uint32_t
Definition: stdint.h:21
unsigned long long uint64_t
Definition: stdint.h:22
Definition: slice.h:25
Status AddRecord(const Slice &slice)
Definition: log_writer.cc:36
Definition: status.h:21
Definition: log_writer.h:19
static const int kMaxRecordType
Definition: log_format.h:25
uint32_t type_crc_[kMaxRecordType+1]
Definition: log_writer.h:42