userver: userver/dump/operations_file.hpp Source File
Loading...
Searching...
No Matches
operations_file.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/dump/operations_file.hpp
4/// @brief File-based dump Reader and Writer implementations
5
6#include <boost/filesystem/operations.hpp>
7
8#include <userver/fs/blocking/c_file.hpp>
9#include <userver/utils/cpu_relax.hpp>
10#include <userver/utils/fast_pimpl.hpp>
11
12#include <userver/dump/factory.hpp>
13#include <userver/dump/operations.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace dump {
18
19/// A handle to a dump file. File operations block the thread.
20class FileWriter final : public Writer {
21public:
22 /// @brief Creates a new dump file and opens it
23 /// @throws `Error` on a filesystem error
24 explicit FileWriter(std::string path, boost::filesystem::perms perms, tracing::ScopeTime& scope);
25
26 void Finish() override;
27
28private:
29 void WriteRaw(std::string_view data) override;
30
31 fs::blocking::CFile file_;
32 std::string final_path_;
33 std::string path_;
34 boost::filesystem::perms perms_;
35 utils::StreamingCpuRelax cpu_relax_;
36};
37
38/// A handle to a dump file. File operations block the thread.
39class FileReader final : public Reader {
40public:
41 /// @brief Opens an existing dump file
42 /// @throws `Error` on a filesystem error
43 explicit FileReader(std::string path);
44
45 void Finish() override;
46
47private:
48 std::string_view ReadRaw(std::size_t max_size) override;
49
50 void BackUp(std::size_t size) override;
51
52 fs::blocking::CFile file_;
53 std::string path_;
54 std::string curr_chunk_;
55};
56
57class FileOperationsFactory final : public OperationsFactory {
58public:
59 explicit FileOperationsFactory(boost::filesystem::perms perms);
60
61 std::unique_ptr<Reader> CreateReader(std::string full_path) override;
62
63 std::unique_ptr<Writer> CreateWriter(std::string full_path, tracing::ScopeTime& scope) override;
64
65private:
66 const boost::filesystem::perms perms_;
67};
68
69} // namespace dump
70
71USERVER_NAMESPACE_END