diff --git a/include/dsn/cpp/serialization_helper/dsn.layer2_types.h b/include/dsn/cpp/serialization_helper/dsn.layer2_types.h index f72c1df233..7cad4ceaa2 100644 --- a/include/dsn/cpp/serialization_helper/dsn.layer2_types.h +++ b/include/dsn/cpp/serialization_helper/dsn.layer2_types.h @@ -203,12 +203,7 @@ inline std::ostream &operator<<(std::ostream &out, const configuration_query_by_ typedef struct _configuration_query_by_index_response__isset { _configuration_query_by_index_response__isset() - : err(false), - app_id(false), - partition_count(false), - is_stateful(false), - partitions(false), - forward_address(false) + : err(false), app_id(false), partition_count(false), is_stateful(false), partitions(false) { } bool err : 1; @@ -216,7 +211,6 @@ typedef struct _configuration_query_by_index_response__isset bool partition_count : 1; bool is_stateful : 1; bool partitions : 1; - bool forward_address : 1; } _configuration_query_by_index_response__isset; class configuration_query_by_index_response @@ -234,7 +228,6 @@ class configuration_query_by_index_response int32_t partition_count; bool is_stateful; std::vector partitions; - ::dsn::rpc_address forward_address; _configuration_query_by_index_response__isset __isset; @@ -248,8 +241,6 @@ class configuration_query_by_index_response void __set_partitions(const std::vector &val); - void __set_forward_address(const ::dsn::rpc_address &val); - bool operator==(const configuration_query_by_index_response &rhs) const { if (!(err == rhs.err)) @@ -262,8 +253,6 @@ class configuration_query_by_index_response return false; if (!(partitions == rhs.partitions)) return false; - if (!(forward_address == rhs.forward_address)) - return false; return true; } bool operator!=(const configuration_query_by_index_response &rhs) const diff --git a/src/core/core/dsn.layer2_types.cpp b/src/core/core/dsn.layer2_types.cpp index e42b5d4044..f50d65bf0f 100644 --- a/src/core/core/dsn.layer2_types.cpp +++ b/src/core/core/dsn.layer2_types.cpp @@ -500,11 +500,6 @@ void configuration_query_by_index_response::__set_partitions( this->partitions = val; } -void configuration_query_by_index_response::__set_forward_address(const ::dsn::rpc_address &val) -{ - this->forward_address = val; -} - uint32_t configuration_query_by_index_response::read(::apache::thrift::protocol::TProtocol *iprot) { @@ -575,14 +570,6 @@ uint32_t configuration_query_by_index_response::read(::apache::thrift::protocol: xfer += iprot->skip(ftype); } break; - case 6: - if (ftype == ::apache::thrift::protocol::T_STRUCT) { - xfer += this->forward_address.read(iprot); - this->__isset.forward_address = true; - } else { - xfer += iprot->skip(ftype); - } - break; default: xfer += iprot->skip(ftype); break; @@ -630,10 +617,6 @@ configuration_query_by_index_response::write(::apache::thrift::protocol::TProtoc } xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldBegin("forward_address", ::apache::thrift::protocol::T_STRUCT, 6); - xfer += this->forward_address.write(oprot); - xfer += oprot->writeFieldEnd(); - xfer += oprot->writeFieldStop(); xfer += oprot->writeStructEnd(); return xfer; @@ -647,7 +630,6 @@ void swap(configuration_query_by_index_response &a, configuration_query_by_index swap(a.partition_count, b.partition_count); swap(a.is_stateful, b.is_stateful); swap(a.partitions, b.partitions); - swap(a.forward_address, b.forward_address); swap(a.__isset, b.__isset); } @@ -659,7 +641,6 @@ configuration_query_by_index_response::configuration_query_by_index_response( partition_count = other32.partition_count; is_stateful = other32.is_stateful; partitions = other32.partitions; - forward_address = other32.forward_address; __isset = other32.__isset; } configuration_query_by_index_response::configuration_query_by_index_response( @@ -670,7 +651,6 @@ configuration_query_by_index_response::configuration_query_by_index_response( partition_count = std::move(other33.partition_count); is_stateful = std::move(other33.is_stateful); partitions = std::move(other33.partitions); - forward_address = std::move(other33.forward_address); __isset = std::move(other33.__isset); } configuration_query_by_index_response &configuration_query_by_index_response:: @@ -681,7 +661,6 @@ operator=(const configuration_query_by_index_response &other34) partition_count = other34.partition_count; is_stateful = other34.is_stateful; partitions = other34.partitions; - forward_address = other34.forward_address; __isset = other34.__isset; return *this; } @@ -693,7 +672,6 @@ operator=(configuration_query_by_index_response &&other35) partition_count = std::move(other35.partition_count); is_stateful = std::move(other35.is_stateful); partitions = std::move(other35.partitions); - forward_address = std::move(other35.forward_address); __isset = std::move(other35.__isset); return *this; } @@ -710,8 +688,6 @@ void configuration_query_by_index_response::printTo(std::ostream &out) const << "is_stateful=" << to_string(is_stateful); out << ", " << "partitions=" << to_string(partitions); - out << ", " - << "forward_address=" << to_string(forward_address); out << ")"; } diff --git a/src/dist/replication/meta_server/meta_service.cpp b/src/dist/replication/meta_server/meta_service.cpp index d1c2994cc1..5b3d31976d 100644 --- a/src/dist/replication/meta_server/meta_service.cpp +++ b/src/dist/replication/meta_server/meta_service.cpp @@ -361,23 +361,6 @@ int meta_service::check_leader(dsn::message_ex *req, dsn::rpc_address *forward_a return; \ } -#define RPC_CHECK_STATUS_WITH_FORWARD(dsn_msg, response_struct) \ - dinfo("rpc %s called", __FUNCTION__); \ - int result = check_leader(dsn_msg, &response_struct.forward_address); \ - if (result == 0) \ - return; \ - if (result == -1 || !_started) { \ - if (result == -1) \ - response_struct.err = ERR_FORWARD_TO_OTHERS; \ - else if (_recovering) \ - response_struct.err = ERR_UNDER_RECOVERY; \ - else \ - response_struct.err = ERR_SERVICE_NOT_ACTIVE; \ - ddebug("reject request with %s", response_struct.err.to_string()); \ - reply(dsn_msg, response_struct); \ - return; \ - } - // table operations void meta_service::on_create_app(dsn::message_ex *req) { @@ -507,7 +490,31 @@ void meta_service::on_query_configuration_by_node(dsn::message_ex *msg) void meta_service::on_query_configuration_by_index(dsn::message_ex *msg) { configuration_query_by_index_response response; - RPC_CHECK_STATUS_WITH_FORWARD(msg, response); + + // here we do not use RPC_CHECK_STATUS macro, but specially handle it + // to response forward address. + dinfo("rpc %s called", __FUNCTION__); + rpc_address forward_address; + int result = check_leader(msg, &forward_address); + if (result == 0) + return; + if (result == -1 || !_started) { + if (result == -1) { + response.err = ERR_FORWARD_TO_OTHERS; + if (!forward_address.is_invalid()) { + partition_configuration config; + config.primary = forward_address; + response.partitions.push_back(std::move(config)); + } + } else if (_recovering) { + response.err = ERR_UNDER_RECOVERY; + } else { + response.err = ERR_SERVICE_NOT_ACTIVE; + } + ddebug("reject request with %s", response.err.to_string()); + reply(msg, response); + return; + } configuration_query_by_index_request request; dsn::unmarshall(msg, request); diff --git a/src/dsn.layer2.thrift b/src/dsn.layer2.thrift index fd16b8e7d2..49c45b8ef1 100644 --- a/src/dsn.layer2.thrift +++ b/src/dsn.layer2.thrift @@ -22,6 +22,8 @@ struct configuration_query_by_index_request 2:list partition_indices; } +// for server version > 1.11.2, if err == ERR_FORWARD_TO_OTHERS, +// then the forward address will be put in partitions[0].primary if exist. struct configuration_query_by_index_response { 1:dsn.error_code err; @@ -29,7 +31,6 @@ struct configuration_query_by_index_response 3:i32 partition_count; 4:bool is_stateful; 5:list partitions; - 6:dsn.rpc_address forward_address; } enum app_status