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