2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_
|
|
|
|
#define STORAGE_LEVELDB_DB_LOG_WRITER_H_
|
|
|
|
|
2020-04-29 19:59:39 +00:00
|
|
|
#include <cstdint>
|
2019-05-02 11:01:00 -07:00
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
#include "db/log_format.h"
|
2011-03-30 18:35:40 +00:00
|
|
|
#include "leveldb/slice.h"
|
|
|
|
#include "leveldb/status.h"
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
|
|
|
|
class WritableFile;
|
|
|
|
|
|
|
|
namespace log {
|
|
|
|
|
|
|
|
class Writer {
|
|
|
|
public:
|
|
|
|
// Create a writer that will append data to "*dest".
|
|
|
|
// "*dest" must be initially empty.
|
|
|
|
// "*dest" must remain live while this Writer is in use.
|
|
|
|
explicit Writer(WritableFile* dest);
|
2014-12-11 08:13:18 -08:00
|
|
|
|
|
|
|
// Create a writer that will append data to "*dest".
|
|
|
|
// "*dest" must have initial length "dest_length".
|
|
|
|
// "*dest" must remain live while this Writer is in use.
|
|
|
|
Writer(WritableFile* dest, uint64_t dest_length);
|
|
|
|
|
2019-05-03 09:31:18 -07:00
|
|
|
Writer(const Writer&) = delete;
|
|
|
|
Writer& operator=(const Writer&) = delete;
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
~Writer();
|
|
|
|
|
|
|
|
Status AddRecord(const Slice& slice);
|
|
|
|
|
|
|
|
private:
|
2019-05-03 09:31:18 -07:00
|
|
|
Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length);
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
WritableFile* dest_;
|
2019-05-02 11:01:00 -07:00
|
|
|
int block_offset_; // Current offset in block
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
// crc32c values for all supported record types. These are
|
|
|
|
// pre-computed to reduce the overhead of computing the crc of the
|
|
|
|
// record type stored in the header.
|
|
|
|
uint32_t type_crc_[kMaxRecordType + 1];
|
|
|
|
};
|
|
|
|
|
2011-10-31 17:22:06 +00:00
|
|
|
} // namespace log
|
|
|
|
} // namespace leveldb
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
#endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_
|