HDFS-11027: libbhdfs++: Don't retry if there is an authentication failure. Contributed by Xiaowei Zhu.
This commit is contained in:
parent
59a3926946
commit
b7d9a0f827
@ -62,6 +62,9 @@ class Status {
|
|||||||
// get error code
|
// get error code
|
||||||
int code() const { return code_; }
|
int code() const { return code_; }
|
||||||
|
|
||||||
|
// if retry can possibly recover an error
|
||||||
|
bool notWorthRetry() const;
|
||||||
|
|
||||||
enum Code {
|
enum Code {
|
||||||
kOk = 0,
|
kOk = 0,
|
||||||
kInvalidArgument = static_cast<unsigned>(std::errc::invalid_argument),
|
kInvalidArgument = static_cast<unsigned>(std::errc::invalid_argument),
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace hdfs {
|
namespace hdfs {
|
||||||
|
|
||||||
@ -49,6 +50,12 @@ const static std::map<std::string, int> kKnownServerExceptionClasses = {
|
|||||||
{kPathIsNotEmptyDirectoryException, Status::kPathIsNotEmptyDirectory}
|
{kPathIsNotEmptyDirectoryException, Status::kPathIsNotEmptyDirectory}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Errors that retry cannot fix. TODO: complete the list.
|
||||||
|
const static std::set<int> noRetryExceptions = {
|
||||||
|
Status::kPermissionDenied,
|
||||||
|
Status::kAuthenticationFailed,
|
||||||
|
Status::kAccessControlException
|
||||||
|
};
|
||||||
|
|
||||||
Status::Status(int code, const char *msg1)
|
Status::Status(int code, const char *msg1)
|
||||||
: code_(code) {
|
: code_(code) {
|
||||||
@ -120,7 +127,7 @@ Status Status::Exception(const char *exception_class_name, const char *error_mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status Status::Error(const char *error_message) {
|
Status Status::Error(const char *error_message) {
|
||||||
return Status(kAuthenticationFailed, error_message);
|
return Exception("Exception", error_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Status::AuthenticationFailed() {
|
Status Status::AuthenticationFailed() {
|
||||||
@ -147,4 +154,8 @@ std::string Status::ToString() const {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Status::notWorthRetry() const {
|
||||||
|
return noRetryExceptions.find(code_) != noRetryExceptions.end();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,9 @@ void RpcEngine::RpcCommsError(
|
|||||||
|
|
||||||
RetryAction retry = RetryAction::fail(""); // Default to fail
|
RetryAction retry = RetryAction::fail(""); // Default to fail
|
||||||
|
|
||||||
if (retry_policy()) {
|
if (status.notWorthRetry()) {
|
||||||
|
retry = RetryAction::fail(status.ToString().c_str());
|
||||||
|
} else if (retry_policy()) {
|
||||||
retry = retry_policy()->ShouldRetry(status, req->IncrementRetryCount(), req->get_failover_count(), true);
|
retry = retry_policy()->ShouldRetry(status, req->IncrementRetryCount(), req->get_failover_count(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user