-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crash simulator facility without actually SIGKILL (#423)
* Crash simulator facility without actually SIGKILL
- Loading branch information
Showing
9 changed files
with
130 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#ifdef _PRERELEASE | ||
#include <functional> | ||
#include <sisl/utility/urcu_helper.hpp> | ||
#include <iomgr/iomgr_flip.hpp> | ||
|
||
namespace homestore { | ||
|
||
class CrashSimulator { | ||
public: | ||
CrashSimulator(std::function< void(void) > cb = nullptr) : m_restart_cb{cb} {} | ||
~CrashSimulator() = default; | ||
|
||
void crash() { | ||
if (m_restart_cb) { | ||
m_crashed.update([](auto* s) { *s = true; }); | ||
|
||
// We can restart on a new thread to allow other operations to continue | ||
std::thread t([this]() { m_restart_cb(); }); | ||
t.detach(); | ||
} else { | ||
raise(SIGKILL); | ||
} | ||
} | ||
|
||
bool is_crashed() const { return ((m_restart_cb != nullptr) && *(m_crashed.access().get())); } | ||
|
||
bool crash_if_flip_set(const std::string& flip_name) { | ||
if (iomgr_flip::instance()->test_flip(flip_name)) { | ||
this->crash(); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
private: | ||
std::function< void(void) > m_restart_cb{nullptr}; | ||
sisl::urcu_scoped_ptr< bool > m_crashed; | ||
}; | ||
} // namespace homestore | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters