Coverage Report

Created: 2024-07-27 06:53

/src/rocksdb/file/line_file_reader.h
Line
Count
Source
1
//  Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2
//  This source code is licensed under both the GPLv2 (found in the
3
//  COPYING file in the root directory) and Apache 2.0 License
4
//  (found in the LICENSE.Apache file in the root directory).
5
6
#pragma once
7
#include <array>
8
9
#include "file/sequence_file_reader.h"
10
11
namespace ROCKSDB_NAMESPACE {
12
13
// A wrapper on top of Env::SequentialFile for reading text lines from a file.
14
// Lines are delimited by '\n'. The last line may or may not include a
15
// trailing newline. Uses SequentialFileReader internally.
16
class LineFileReader {
17
 private:
18
  std::array<char, 8192> buf_;
19
  SequentialFileReader sfr_;
20
  IOStatus io_status_;
21
  const char* buf_begin_ = buf_.data();
22
  const char* buf_end_ = buf_.data();
23
  size_t line_number_ = 0;
24
  bool at_eof_ = false;
25
26
 public:
27
  // See SequentialFileReader constructors
28
  template <typename... Args>
29
  explicit LineFileReader(Args&&... args)
30
25.9k
      : sfr_(std::forward<Args&&>(args)...) {}
rocksdb::LineFileReader::LineFileReader<std::__1::unique_ptr<rocksdb::FSSequentialFile, std::__1::default_delete<rocksdb::FSSequentialFile> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long&>(std::__1::unique_ptr<rocksdb::FSSequentialFile, std::__1::default_delete<rocksdb::FSSequentialFile> >&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long&)
Line
Count
Source
30
25.9k
      : sfr_(std::forward<Args&&>(args)...) {}
Unexecuted instantiation: rocksdb::LineFileReader::LineFileReader<std::__1::unique_ptr<rocksdb::FSSequentialFile, std::__1::default_delete<rocksdb::FSSequentialFile> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, decltype(nullptr), std::__1::vector<std::__1::shared_ptr<rocksdb::EventListener>, std::__1::allocator<std::__1::shared_ptr<rocksdb::EventListener> > >, rocksdb::RateLimiter*&>(std::__1::unique_ptr<rocksdb::FSSequentialFile, std::__1::default_delete<rocksdb::FSSequentialFile> >&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, decltype(nullptr)&&, std::__1::vector<std::__1::shared_ptr<rocksdb::EventListener>, std::__1::allocator<std::__1::shared_ptr<rocksdb::EventListener> > >&&, rocksdb::RateLimiter*&)
31
32
  static IOStatus Create(const std::shared_ptr<FileSystem>& fs,
33
                         const std::string& fname, const FileOptions& file_opts,
34
                         std::unique_ptr<LineFileReader>* reader,
35
                         IODebugContext* dbg, RateLimiter* rate_limiter);
36
37
  LineFileReader(const LineFileReader&) = delete;
38
  LineFileReader& operator=(const LineFileReader&) = delete;
39
40
  // Reads another line from the file, returning true on success and saving
41
  // the line to `out`, without delimiter, or returning false on failure. You
42
  // must check GetStatus() to determine whether the failure was just
43
  // end-of-file (OK status) or an I/O error (another status).
44
  // The internal rate limiter will be charged at the specified priority.
45
  bool ReadLine(std::string* out, Env::IOPriority rate_limiter_priority);
46
47
  // Returns the number of the line most recently returned from ReadLine.
48
  // Return value is unspecified if ReadLine has returned false due to
49
  // I/O error. After ReadLine returns false due to end-of-file, return
50
  // value is the last returned line number, or equivalently the total
51
  // number of lines returned.
52
6.73M
  size_t GetLineNumber() const { return line_number_; }
53
54
  // Returns any error encountered during read. The error is considered
55
  // permanent and no retry or recovery is attempted with the same
56
  // LineFileReader.
57
25.9k
  const IOStatus& GetStatus() const { return io_status_; }
58
};
59
60
}  // namespace ROCKSDB_NAMESPACE