Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

75 řádky
2.2 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_READER_H_
  5. #define STORAGE_LEVELDB_DB_LOG_READER_H_
  6. #include "db/log_format.h"
  7. #include "leveldb/slice.h"
  8. #include "leveldb/status.h"
  9. namespace leveldb {
  10. class SequentialFile;
  11. namespace log {
  12. class Reader {
  13. public:
  14. // Interface for reporting errors.
  15. class Reporter {
  16. public:
  17. virtual ~Reporter();
  18. // Some corruption was detected. "size" is the approximate number
  19. // of bytes dropped due to the corruption.
  20. virtual void Corruption(size_t bytes, const Status& status) = 0;
  21. };
  22. // Create a reader that will return log records from "*file".
  23. // "*file" must remain live while this Reader is in use.
  24. //
  25. // If "reporter" is non-NULL, it is notified whenever some data is
  26. // dropped due to a detected corruption. "*reporter" must remain
  27. // live while this Reader is in use.
  28. //
  29. // If "checksum" is true, verify checksums if available.
  30. Reader(SequentialFile* file, Reporter* reporter, bool checksum);
  31. ~Reader();
  32. // Read the next record into *record. Returns true if read
  33. // successfully, false if we hit end of the input. May use
  34. // "*scratch" as temporary storage. The contents filled in *record
  35. // will only be valid until the next mutating operation on this
  36. // reader or the next mutation to *scratch.
  37. bool ReadRecord(Slice* record, std::string* scratch);
  38. private:
  39. SequentialFile* const file_;
  40. Reporter* const reporter_;
  41. bool const checksum_;
  42. char* const backing_store_;
  43. Slice buffer_;
  44. bool eof_; // Last Read() indicated EOF by returning < kBlockSize
  45. // Extend record types with the following special values
  46. enum {
  47. kEof = kMaxRecordType + 1,
  48. kBadRecord = kMaxRecordType + 2
  49. };
  50. // Return type, or one of the preceding special values
  51. unsigned int ReadPhysicalRecord(Slice* result);
  52. void ReportDrop(size_t bytes, const char* reason);
  53. // No copying allowed
  54. Reader(const Reader&);
  55. void operator=(const Reader&);
  56. };
  57. }
  58. }
  59. #endif // STORAGE_LEVELDB_DB_LOG_READER_H_