Skip to content

Commit

Permalink
Umegane dev 965 (#58)
Browse files Browse the repository at this point in the history
Temporarily replace exception throwing with logging and process termination
  • Loading branch information
umegane authored Oct 23, 2024
1 parent 477b405 commit 3398b45
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 180 deletions.
20 changes: 20 additions & 0 deletions docs/internal/exception_handling_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@ Limnestoneの処理の中で、I/Oエラーが発生すると、std::runtime_err
* datastore::recover()
* datastore::shutdown()

## 暫定対処

現在API呼び出し側で、limestone_exceptionをキャッチする仕組みが未実装である。
このままだと、I/Oエラーが発生した場合に、プロセスがストールしてしまうことが
あるため、limestone_exceptionをスローする可能性があるAPIについて、
limestone_exceptionをスローするのではなく、FATALのログを出力して
abortする対応をする。

また、APIのDoxygenコメントに以下の記述を追加する。

```
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
```





3 changes: 3 additions & 0 deletions include/limestone/api/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class cursor {
* @brief change the current cursor to point to the next entry
* @attention this function is not thread-safe.
* @exception limestone_exception if an error occurs while reading the log entry
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @return true if the next entry exists, false otherwise
*/
bool next();
Expand Down
15 changes: 15 additions & 0 deletions include/limestone/api/datastore.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class datastore {
* @brief create an object with the given configuration
* @param conf a reference to a configuration object used in the object construction
* @exception limestone_exception if an I/O error occurs during construction
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
*/
explicit datastore(configuration const& conf);

Expand Down Expand Up @@ -114,6 +117,9 @@ class datastore {
* @brief transition this object to an operational state
* @details after this method is called, create_channel() can be invoked.
* @exception limestone_io_exception Thrown if an I/O error occurs.
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function is not thread-safe, and the from directory must not contain any files other than log files.
*/
void ready();
Expand Down Expand Up @@ -153,6 +159,9 @@ class datastore {
* @brief change the current epoch ID
* @param new epoch id which must be greater than current epoch ID.
* @exception limestone_io_exception Thrown if an I/O error occurs.
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function should be called after the ready() is called.
*/
void switch_epoch(epoch_id_type epoch_id);
Expand Down Expand Up @@ -194,6 +203,9 @@ class datastore {
* @brief start backup operation
* @detail a backup object is created, which contains a list of log files.
* @exception limestone_io_exception Thrown if an I/O error occurs.
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @return a reference to the backup object.
*/
backup& begin_backup();
Expand All @@ -203,6 +215,9 @@ class datastore {
* @brief start backup operation
* @detail a backup_detail object is created, which contains a list of log entry.
* @exception limestone_io_exception Thrown if an I/O error occurs.
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @return a reference to the backup_detail object.
*/
std::unique_ptr<backup_detail> begin_backup(backup_type btype);
Expand Down
24 changes: 24 additions & 0 deletions include/limestone/api/log_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class log_channel {
* @brief join a persistence session for the current epoch in this channel
* @attention this function is not thread-safe.
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @note the current epoch is the last epoch specified by datastore::switch_epoch()
* @note datastore::switch_epoch() and this function can be called simultaneously.
* If these functions are invoked at the same time, the result will be as if one of them was called first,
Expand All @@ -58,6 +61,9 @@ class log_channel {
* @brief notifies the completion of an operation in this channel for the current persistent session the channel is participating in
* @attention this function is not thread-safe.
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @note when all channels that have participated in the current persistent session call end_session() and the current epoch is
* greater than the session's epoch, the persistent session itself is complete
*/
Expand All @@ -76,6 +82,9 @@ class log_channel {
* @param value the value byte string for the entry to be added
* @param write_version (optional) the write version of the entry to be added. If omitted, the default value is used
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function is not thread-safe.
*/
void add_entry(storage_id_type storage_id, std::string_view key, std::string_view value, write_version_type write_version);
Expand All @@ -88,6 +97,9 @@ class log_channel {
* @param write_version (optional) the write version of the entry to be added. If omitted, the default value is used
* @param large_objects (optional) the list of large objects associated with the entry to be added
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function is not thread-safe.
*/
void add_entry(storage_id_type storage_id, std::string_view key, std::string_view value, write_version_type write_version, const std::vector<large_object_input>& large_objects);
Expand All @@ -98,6 +110,9 @@ class log_channel {
* @param key the key byte string for the entry to be deleted
* @param write_version the write version of the entry to be removed
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function is not thread-safe.
* @note no deletion operation is performed on the entry that has been added to the current persistent session, instead,
* the entries to be deleted are treated as if they do not exist in a recover() operation from a log stored in the current persistent session
Expand All @@ -109,6 +124,9 @@ class log_channel {
* @param storage_id the storage ID of the entry to be added
* @param write_version the write version of the entry to be added
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function is not thread-safe.
* @impl this operation may be ignored.
*/
Expand All @@ -119,6 +137,9 @@ class log_channel {
* @param storage_id the storage ID of the entry to be removed
* @param write_version the write version of the entry to be removed
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function is not thread-safe.
* @note no deletion operation is performed on the entry that has been added to the current persistent session, instead,
* the target entries are treated as if they do not exist in the recover() operation from the log stored in the current persistent session.
Expand All @@ -130,6 +151,9 @@ class log_channel {
* @param storage_id the storage ID of the entry to be removed
* @param write_version the write version of the entry to be removed
* @exception limestone_exception if I/O error occurs
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @attention this function is not thread-safe.
* @note no deletion operation is performed on the entry that has been added to the current persistent session, instead,
* the target entries are treated as if they do not exist in the recover() operation from the log stored in the current persistent session.
Expand Down
3 changes: 3 additions & 0 deletions include/limestone/api/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class snapshot {
* @details the returned cursor points to the first element by calling cursor::next().
* @attention this function is thread-safe.
* @exception limestone_exception if the file stream of the cursor is not good.
* @note Currently, this function does not throw an exception but logs the error and aborts the process.
* However, throwing an exception is the intended behavior, and this will be restored in future versions.
* Therefore, callers of this API must handle the exception properly as per the original design.
* @return unique pointer of the cursor
*/
[[nodiscard]] std::unique_ptr<cursor> get_cursor() const;
Expand Down
7 changes: 6 additions & 1 deletion src/limestone/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ cursor::~cursor() noexcept {
}

bool cursor::next() {
return pimpl->next();
try {
return pimpl->next();
} catch (...) {
HANDLE_EXCEPTION_AND_ABORT();
throw; // Unreachable, but required to satisfy the compiler
}
}

storage_id_type cursor::storage() const noexcept {
Expand Down
Loading

0 comments on commit 3398b45

Please sign in to comment.