-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDiskFileImplementations.hpp
More file actions
204 lines (171 loc) · 5.71 KB
/
Copy pathDiskFileImplementations.hpp
File metadata and controls
204 lines (171 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* SPDX-FileCopyrightText: 2021 CERN
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include "XrdClException.hpp"
#include "common/exception/Exception.hpp"
#include "disk/DiskFile.hpp"
#include "taped/file/Structures.hpp"
#include "taped/session/VolumeInfo.hpp"
#include <xrootd/XrdCl/XrdClFile.hh>
namespace cta::disk {
/**
* Namespace managing the reading and writing of files to and from disk.
*/
//Forward declarations
class XRootdDiskFileRemover;
//==============================================================================
// LOCAL FILES
//==============================================================================
class LocalReadFile : public ReadFile {
public:
explicit LocalReadFile(const std::string& path);
size_t size() const final;
size_t read(void* data, const size_t size) const final;
~LocalReadFile() noexcept final;
private:
int m_fd;
};
class LocalWriteFile : public WriteFile {
public:
explicit LocalWriteFile(const std::string& path);
void write(const void* data, const size_t size) final;
void close() final;
~LocalWriteFile() noexcept final;
private:
int m_fd;
bool m_closeTried = false;
};
//==============================================================================
// XROOT FILES
//==============================================================================
class XrootBaseReadFile : public ReadFile {
public:
explicit XrootBaseReadFile(uint16_t timeout) : m_timeout(timeout) {}
size_t size() const final;
size_t read(void* data, const size_t size) const final;
~XrootBaseReadFile() noexcept override;
protected:
// Access to parent's protected member...
void setURL(const std::string& v) { m_URL = v; }
// There is no const-correctness with XrdCl...
mutable XrdCl::File m_xrootFile;
mutable uint64_t m_readPosition;
const uint16_t m_timeout;
};
class XrootReadFile : public XrootBaseReadFile {
public:
explicit XrootReadFile(const std::string& xrootUrl, uint16_t timeout = 0);
};
class XrootBaseWriteFile : public WriteFile {
public:
explicit XrootBaseWriteFile(uint16_t timeout) : m_timeout(timeout) {}
void write(const void* data, const size_t size) final;
void close() final;
~XrootBaseWriteFile() noexcept override;
protected:
// Access to parent's protected member...
void setURL(const std::string& v) { m_URL = v; }
XrdCl::File m_xrootFile;
uint64_t m_writePosition = 0;
const uint16_t m_timeout;
bool m_closeTried = false;
};
class XrootWriteFile : public XrootBaseWriteFile {
public:
explicit XrootWriteFile(const std::string& xrootUrl, uint16_t timeout = 0);
};
//==============================================================================
// LocalDisk Removers
//==============================================================================
/**
* This class allows to delete a file from a local disk
*/
class LocalDiskFileRemover : public DiskFileRemover {
public:
/**
* Constructor of the LocalDiskFileRemover
* @param path the path of the file to be removed
*/
explicit LocalDiskFileRemover(const std::string& path);
void remove() override;
};
/**
* This class allows to asynchronously delete a file from a local disk
*/
class AsyncLocalDiskFileRemover : public AsyncDiskFileRemover {
public:
/**
* Constructor of the asynchronous remover
* @param diskFileRemover the instance of the LocalDiskFileRemover that will delete the file
*/
explicit AsyncLocalDiskFileRemover(const std::string& path);
void asyncDelete() override;
void wait() override;
private:
std::unique_ptr<LocalDiskFileRemover> m_diskFileRemover;
};
/**
* This class allows to asynchronously delete a file via XRootD
*/
class AsyncXRootdDiskFileRemover : public AsyncDiskFileRemover {
public:
friend class XRootdDiskFileRemover;
explicit AsyncXRootdDiskFileRemover(const std::string& path);
void asyncDelete() override;
void wait() override;
private:
std::unique_ptr<XRootdDiskFileRemover> m_diskFileRemover;
class XRootdFileRemoverResponseHandler : public XrdCl::ResponseHandler {
public:
std::promise<void> m_deletionPromise;
public:
void HandleResponse(XrdCl::XRootDStatus* status, XrdCl::AnyObject* response) override;
};
XRootdFileRemoverResponseHandler m_responseHandler;
};
/**
* This class allows to delete a file via XRootD (asynchronously or not)
*/
class XRootdDiskFileRemover : public DiskFileRemover {
public:
explicit XRootdDiskFileRemover(const std::string& path);
/**
* Remove the file in a synchronous way
* @throws an exception if the XRootD call status is an Error
*/
void remove();
/**
* Remove the file in an asynchronous way
* @param responseHandler : the structure that will be updated when the asynchronous deletion is terminated
* (even if it fails)
* @throws an exception if the XRootD call status is an Error
*/
void removeAsync(AsyncXRootdDiskFileRemover::XRootdFileRemoverResponseHandler& responseHandler);
private:
XrdCl::FileSystem m_xrootFileSystem;
std::string m_truncatedFileURL; // root://.../ part of the path is removed
const uint16_t c_xrootTimeout = 15;
};
class LocalDirectory : public Directory {
public:
explicit LocalDirectory(const std::string& path);
void mkdir() override;
bool exist() override;
std::set<std::string> getFilesName() override;
void rmdir() override;
};
class XRootdDirectory : public Directory {
public:
explicit XRootdDirectory(const std::string& path);
void mkdir() override;
bool exist() override;
std::set<std::string> getFilesName() override;
void rmdir() override;
private:
XrdCl::FileSystem m_xrootFileSystem;
std::string m_truncatedDirectoryURL; // root://.../ part of the path is removed
const uint16_t c_xrootTimeout = 15;
};
} // namespace cta::disk