-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling when reading request and Region meta change in…
… concurrency (#1101) * Improve error handling when reading request and Region meta change in concurrency * Add retry from local storage * Move definitions of FailPoints into cpp file Signed-off-by: JaySon-Huang <[email protected]>
- Loading branch information
1 parent
e68bb98
commit b6a151a
Showing
16 changed files
with
416 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include <Common/FailPoint.h> | ||
|
||
#include <boost/core/noncopyable.hpp> | ||
#include <condition_variable> | ||
#include <mutex> | ||
|
||
namespace DB | ||
{ | ||
std::unordered_map<String, std::shared_ptr<FailPointChannel>> FailPointHelper::fail_point_wait_channels; | ||
|
||
#define APPLY_FOR_FAILPOINTS(M) \ | ||
M(exception_between_drop_meta_and_data) \ | ||
M(exception_between_alter_data_and_meta) \ | ||
M(exception_drop_table_during_remove_meta) \ | ||
M(exception_between_rename_table_data_and_metadata); \ | ||
M(exception_between_create_database_meta_and_directory); \ | ||
M(exception_before_rename_table_old_meta_removed); \ | ||
M(exception_after_step_1_in_exchange_partition) \ | ||
M(exception_before_step_2_rename_in_exchange_partition) \ | ||
M(exception_after_step_2_in_exchange_partition) \ | ||
M(exception_before_step_3_rename_in_exchange_partition) \ | ||
M(exception_after_step_3_in_exchange_partition) \ | ||
M(region_exception_after_read_from_storage_some_error) \ | ||
M(region_exception_after_read_from_storage_all_error) | ||
|
||
#define APPLY_FOR_FAILPOINTS_WITH_CHANNEL(M) M(pause_after_learner_read) | ||
|
||
namespace FailPoints | ||
{ | ||
#define M(NAME) extern const char NAME[] = #NAME ""; | ||
APPLY_FOR_FAILPOINTS(M) | ||
APPLY_FOR_FAILPOINTS_WITH_CHANNEL(M) | ||
#undef M | ||
} // namespace FailPoints | ||
|
||
#ifdef FIU_ENABLE | ||
class FailPointChannel : private boost::noncopyable | ||
{ | ||
public: | ||
// wake up all waiting threads when destroy | ||
~FailPointChannel() { cv.notify_all(); } | ||
|
||
void wait() | ||
{ | ||
std::unique_lock lock(m); | ||
cv.wait(lock); | ||
} | ||
|
||
private: | ||
std::mutex m; | ||
std::condition_variable cv; | ||
}; | ||
|
||
void FailPointHelper::enableFailPoint(const String & fail_point_name) | ||
{ | ||
#define M(NAME) \ | ||
if (fail_point_name == FailPoints::NAME) \ | ||
{ \ | ||
/* FIU_ONETIME -- Only fail once; the point of failure will be automatically disabled afterwards.*/ \ | ||
fiu_enable(FailPoints::NAME, 1, nullptr, FIU_ONETIME); \ | ||
return; \ | ||
} | ||
|
||
APPLY_FOR_FAILPOINTS(M) | ||
#undef M | ||
|
||
#define M(NAME) \ | ||
if (fail_point_name == FailPoints::NAME) \ | ||
{ \ | ||
/* FIU_ONETIME -- Only fail once; the point of failure will be automatically disabled afterwards.*/ \ | ||
fiu_enable(FailPoints::NAME, 1, nullptr, FIU_ONETIME); \ | ||
fail_point_wait_channels.try_emplace(FailPoints::NAME, std::make_shared<FailPointChannel>()); \ | ||
return; \ | ||
} | ||
|
||
APPLY_FOR_FAILPOINTS_WITH_CHANNEL(M) | ||
#undef M | ||
throw Exception("Cannot find fail point " + fail_point_name, ErrorCodes::FAIL_POINT_ERROR); | ||
} | ||
|
||
void FailPointHelper::disableFailPoint(const String & fail_point_name) | ||
{ | ||
if (auto iter = fail_point_wait_channels.find(fail_point_name); iter != fail_point_wait_channels.end()) | ||
fail_point_wait_channels.erase(iter); | ||
fiu_disable(fail_point_name.c_str()); | ||
} | ||
|
||
void FailPointHelper::wait(const String & fail_point_name) | ||
{ | ||
if (auto iter = fail_point_wait_channels.find(fail_point_name); iter == fail_point_wait_channels.end()) | ||
throw Exception("Can not find channel for fail point" + fail_point_name); | ||
else | ||
{ | ||
auto ptr = iter->second; | ||
ptr->wait(); | ||
} | ||
} | ||
#else | ||
class FailPointChannel | ||
{ | ||
}; | ||
|
||
void FailPointHelper::enableFailPoint(const String & fail_point_name) {} | ||
|
||
void FailPointHelper::disableFailPoint(const String & fail_point_name) {} | ||
|
||
void FailPointHelper::wait(const String & fail_point_name) {} | ||
#endif | ||
|
||
} // namespace DB |
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
Oops, something went wrong.