作者: 韩晨旭 10225101440 李畅 10225102463

54 righe
1.5 KiB

  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. #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_
  5. #define STORAGE_LEVELDB_DB_LOG_WRITER_H_
  6. #include <cstdint>
  7. #include "db/log_format.h"
  8. #include "leveldb/slice.h"
  9. #include "leveldb/status.h"
  10. namespace leveldb {
  11. class WritableFile;
  12. namespace log {
  13. class Writer {
  14. public:
  15. // Create a writer that will append data to "*dest".
  16. // "*dest" must be initially empty.
  17. // "*dest" must remain live while this Writer is in use.
  18. explicit Writer(WritableFile* dest);
  19. // Create a writer that will append data to "*dest".
  20. // "*dest" must have initial length "dest_length".
  21. // "*dest" must remain live while this Writer is in use.
  22. Writer(WritableFile* dest, uint64_t dest_length);
  23. Writer(const Writer&) = delete;
  24. Writer& operator=(const Writer&) = delete;
  25. ~Writer();
  26. Status AddRecord(const Slice& slice);
  27. private:
  28. Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length);
  29. WritableFile* dest_;
  30. int block_offset_; // Current offset in block
  31. // crc32c values for all supported record types. These are
  32. // pre-computed to reduce the overhead of computing the crc of the
  33. // record type stored in the header.
  34. uint32_t type_crc_[kMaxRecordType + 1];
  35. };
  36. } // namespace log
  37. } // namespace leveldb
  38. #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_