solve comments

This commit is contained in:
Chaoguang Lin 2021-09-13 15:54:36 -07:00
parent 6cca6b9e6f
commit e7d3516084
4 changed files with 44 additions and 20 deletions

View File

@ -26,6 +26,7 @@
#include "fdbclient/IClientApi.h"
#include "fdbclient/Knobs.h"
#include "fdbclient/Schemas.h"
#include "fdbclient/ManagementAPI.actor.h"
#include "flow/Arena.h"
#include "flow/FastRef.h"
@ -126,8 +127,7 @@ ACTOR Future<bool> changeCoordinators(Reference<IDatabase> db, std::vector<Strin
state Error err(e);
if (e.code() == error_code_special_keys_api_failure) {
std::string errorMsgStr = wait(fdb_cli::getSpecialKeysFailureErrorMessage(tr));
if (errorMsgStr ==
"Too few fdbserver machines to provide coordination at the current redundancy level" &&
if (errorMsgStr == ManagementAPI::generateErrorMessage(CoordinatorsResult::NOT_ENOUGH_MACHINES) &&
notEnoughMachineResults < 1) {
// we could get not_enough_machines if we happen to see the database while the cluster controller is
// updating the worker list, so make sure it happens twice before returning a failure
@ -135,7 +135,8 @@ ACTOR Future<bool> changeCoordinators(Reference<IDatabase> db, std::vector<Strin
wait(delay(1.0));
tr->reset();
continue;
} else if (errorMsgStr == "No change (existing configuration satisfies request)") {
} else if (errorMsgStr ==
ManagementAPI::generateErrorMessage(CoordinatorsResult::SAME_NETWORK_ADDRESSES)) {
if (retries)
printf("Coordination state changed\n");
else

View File

@ -2659,6 +2659,40 @@ bool schemaMatch(json_spirit::mValue const& schemaValue,
}
}
std::string ManagementAPI::generateErrorMessage(const CoordinatorsResult& res) {
// Note: the error message here should not be changed if possible
// If you do change the message here,
// please update the corresponding fdbcli code to support both the old and the new message
std::string msg;
switch (res) {
case CoordinatorsResult::INVALID_NETWORK_ADDRESSES:
msg = "The specified network addresses are invalid";
break;
case CoordinatorsResult::SAME_NETWORK_ADDRESSES:
msg = "No change (existing configuration satisfies request)";
break;
case CoordinatorsResult::NOT_COORDINATORS:
msg = "Coordination servers are not running on the specified network addresses";
break;
case CoordinatorsResult::DATABASE_UNREACHABLE:
msg = "Database unreachable";
break;
case CoordinatorsResult::BAD_DATABASE_STATE:
msg = "The database is in an unexpected state from which changing coordinators might be unsafe";
break;
case CoordinatorsResult::COORDINATOR_UNREACHABLE:
msg = "One of the specified coordinators is unreachable";
break;
case CoordinatorsResult::NOT_ENOUGH_MACHINES:
msg = "Too few fdbserver machines to provide coordination at the current redundancy level";
break;
default:
break;
}
return msg;
}
TEST_CASE("/ManagementAPI/AutoQuorumChange/checkLocality") {
wait(Future<Void>(Void()));

View File

@ -324,6 +324,10 @@ Future<Void> removeCachedRange(Reference<DB> db, KeyRangeRef range) {
return changeCachedRange(db, range, false);
}
// return the corresponding error message for the CoordinatorsResult
// used by special keys and fdbcli
std::string generateErrorMessage(const CoordinatorsResult& res);
} // namespace ManagementAPI
#include "flow/unactorcompiler.h"

View File

@ -1691,29 +1691,14 @@ ACTOR static Future<Optional<std::string>> coordinatorsCommitActor(ReadYourWrite
.detail("Result", r.present() ? static_cast<int>(r.get()) : -1); // -1 means success
if (r.present()) {
auto res = r.get();
std::string error_msg;
bool retriable = false;
if (res == CoordinatorsResult::INVALID_NETWORK_ADDRESSES) {
error_msg = "The specified network addresses are invalid";
} else if (res == CoordinatorsResult::SAME_NETWORK_ADDRESSES) {
error_msg = "No change (existing configuration satisfies request)";
} else if (res == CoordinatorsResult::NOT_COORDINATORS) {
error_msg = "Coordination servers are not running on the specified network addresses";
} else if (res == CoordinatorsResult::DATABASE_UNREACHABLE) {
error_msg = "Database unreachable";
} else if (res == CoordinatorsResult::BAD_DATABASE_STATE) {
error_msg = "The database is in an unexpected state from which changing coordinators might be unsafe";
} else if (res == CoordinatorsResult::COORDINATOR_UNREACHABLE) {
error_msg = "One of the specified coordinators is unreachable";
if (res == CoordinatorsResult::COORDINATOR_UNREACHABLE) {
retriable = true;
} else if (res == CoordinatorsResult::NOT_ENOUGH_MACHINES) {
error_msg = "Too few fdbserver machines to provide coordination at the current redundancy level";
} else if (res == CoordinatorsResult::SUCCESS) {
TraceEvent(SevError, "SpecialKeysForCoordinators").detail("UnexpectedSuccessfulResult", "");
} else {
ASSERT(false);
}
msg = ManagementAPIError::toJsonString(retriable, "coordinators", error_msg);
msg = ManagementAPIError::toJsonString(retriable, "coordinators", ManagementAPI::generateErrorMessage(res));
}
return msg;
}