forked from UWQuickstep/quickstep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorageErrors.hpp
243 lines (201 loc) · 5.73 KB
/
StorageErrors.hpp
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
**/
#ifndef QUICKSTEP_STORAGE_STORAGE_ERRORS_HPP_
#define QUICKSTEP_STORAGE_STORAGE_ERRORS_HPP_
#include <cstddef>
#include <exception>
#include <string>
#include "storage/StorageBlockInfo.hpp"
namespace quickstep {
/** \addtogroup Storage
* @{
*/
/**
* @brief Exception thrown when the memory provided to a block or subblock is
* too small for even basic metadata.
**/
class BlockMemoryTooSmall : public std::exception {
public:
/**
* @brief Constructor.
*
* @param block_type The type of block or subblock that we were attempting
* to create.
* @param block_size The number of bytes allocated to the block or subblock.
**/
BlockMemoryTooSmall(const std::string &block_type, const std::size_t block_size);
~BlockMemoryTooSmall() throw() {
}
virtual const char* what() const throw() {
return message_.c_str();
}
private:
std::string message_;
};
/**
* @brief Exception thrown when trying to access a block which isn't in memory.
**/
class BlockNotFoundInMemory : public std::exception {
public:
explicit BlockNotFoundInMemory(block_id id) {
message_ = "BlockNotFoundInMemory: The block with ID "
+ BlockIdUtil::ToString(id) + " was not found in memory";
}
virtual const char* what() const throw() {
return message_.c_str();
}
private:
std::string message_;
};
/**
* @brief Exception thrown when trying to load a block which can't be found on
* the persistent storage.
**/
class BlockNotFoundInPersistentStorage : public std::exception {
public:
virtual const char* what() const throw() {
return "BlockNotFoundInPersistentStorage: The specified block was not found in the persistent storage";
}
};
/**
* @brief Exception thrown when the persistent storage is not in the proper
* format.
**/
class CorruptPersistentStorage : public std::exception {
public:
virtual const char* what() const throw() {
return "CorruptPersistentStorage: The persistent storage is corrupt";
}
};
/**
* @brief Exception thrown when there is an error while writing to an open
* file (e.g. running out of space).
**/
class FileReadError : public std::exception {
public:
explicit FileReadError(const std::string &filename);
virtual ~FileReadError() throw() {
}
virtual const char *what() const throw() {
return message_.c_str();
}
private:
std::string message_;
};
/**
* @brief Exception thrown when there is an error while writing to an open
* file (e.g. running out of space).
**/
class FileWriteError : public std::exception {
public:
explicit FileWriteError(const std::string &filename);
virtual ~FileWriteError() throw() {
}
virtual const char *what() const throw() {
return message_.c_str();
}
private:
std::string message_;
};
/**
* @brief Exception throw when a re-loaded block appears to be corrupted.
**/
class MalformedBlock : public std::exception {
public:
virtual const char* what() const throw() {
return "MalformedBlock: A reconstituted block appears to be malformed";
}
};
/**
* @brief Exception thrown when an attempt to allocate memory fails.
**/
class OutOfMemory : public std::exception {
public:
/**
* @brief Constructor.
*
* @param num_slots The number of slots to allocate.
**/
explicit OutOfMemory(const std::size_t num_slots);
virtual const char* what() const throw() {
return message_.c_str();
}
private:
std::string message_;
};
/**
* @brief Exception thrown when attempting to insert a tuple which is so large
* that it can't fit in an empty block.
**/
class TupleTooLargeForBlock : public std::exception {
public:
/**
* @brief Constructor.
*
* @param tuple_size The size of the huge tuple in bytes.
**/
explicit TupleTooLargeForBlock(const std::size_t tuple_size);
~TupleTooLargeForBlock() throw() {
}
virtual const char* what() const throw() {
return message_.c_str();
}
/**
* @brief Get the size of the tuple that caused this exception.
*
* @param return The size of the tuple that caused this exception, in bytes.
**/
std::size_t getTupleSize() const {
return tuple_size_;
}
private:
std::size_t tuple_size_;
std::string message_;
};
/**
* @brief Exception thrown when a file can't be deleted.
**/
class UnableToDeleteFile : public std::exception {
public:
explicit UnableToDeleteFile(const std::string &filename);
virtual ~UnableToDeleteFile() throw() {
}
virtual const char* what() const throw() {
return message_.c_str();
}
private:
std::string message_;
};
/**
* @brief Exception thrown when a file can't be opened.
**/
class UnableToOpenFile : public std::exception {
public:
explicit UnableToOpenFile(const std::string &filename);
virtual ~UnableToOpenFile() throw() {
}
virtual const char* what() const throw() {
return message_.c_str();
}
private:
std::string message_;
};
/** @} */
} // namespace quickstep
#endif // QUICKSTEP_STORAGE_STORAGE_ERRORS_HPP_