]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/file/sequence_file_reader.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / rocksdb / file / sequence_file_reader.h
CommitLineData
f67539c2
TL
1// Copyright (c) 2011-present, Facebook, Inc. 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// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7// Use of this source code is governed by a BSD-style license that can be
8// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10#pragma once
11#include <atomic>
12#include <string>
20effc67
TL
13
14#include "env/file_system_tracer.h"
f67539c2
TL
15#include "port/port.h"
16#include "rocksdb/env.h"
17#include "rocksdb/file_system.h"
18
19namespace ROCKSDB_NAMESPACE {
20
21// SequentialFileReader is a wrapper on top of Env::SequentialFile. It handles
22// Buffered (i.e when page cache is enabled) and Direct (with O_DIRECT / page
23// cache disabled) reads appropriately, and also updates the IO stats.
24class SequentialFileReader {
25 private:
f67539c2 26 std::string file_name_;
20effc67 27 FSSequentialFilePtr file_;
f67539c2
TL
28 std::atomic<size_t> offset_{0}; // read offset
29
30 public:
20effc67
TL
31 explicit SequentialFileReader(
32 std::unique_ptr<FSSequentialFile>&& _file, const std::string& _file_name,
33 const std::shared_ptr<IOTracer>& io_tracer = nullptr)
34 : file_name_(_file_name), file_(std::move(_file), io_tracer) {}
35
36 explicit SequentialFileReader(
37 std::unique_ptr<FSSequentialFile>&& _file, const std::string& _file_name,
38 size_t _readahead_size,
39 const std::shared_ptr<IOTracer>& io_tracer = nullptr)
40 : file_name_(_file_name),
41 file_(NewReadaheadSequentialFile(std::move(_file), _readahead_size),
42 io_tracer) {}
f67539c2
TL
43
44 SequentialFileReader(const SequentialFileReader&) = delete;
45 SequentialFileReader& operator=(const SequentialFileReader&) = delete;
46
47 Status Read(size_t n, Slice* result, char* scratch);
48
49 Status Skip(uint64_t n);
50
51 FSSequentialFile* file() { return file_.get(); }
52
53 std::string file_name() { return file_name_; }
54
55 bool use_direct_io() const { return file_->use_direct_io(); }
56
57 private:
58 // NewReadaheadSequentialFile provides a wrapper over SequentialFile to
59 // always prefetch additional data with every read.
60 static std::unique_ptr<FSSequentialFile> NewReadaheadSequentialFile(
61 std::unique_ptr<FSSequentialFile>&& file, size_t readahead_size);
62};
63} // namespace ROCKSDB_NAMESPACE