Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
meta: return forward address in configuration_query_by_index_response (
Browse files Browse the repository at this point in the history
  • Loading branch information
qinzuoyan authored Dec 29, 2018
1 parent 38d7c02 commit 40eda9f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
13 changes: 12 additions & 1 deletion include/dsn/cpp/serialization_helper/dsn.layer2_types.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/core/core/dsn.layer2_types.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions src/dist/replication/meta_server/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,23 @@ void meta_service::register_rpc_handlers()
RPC_CM_DDD_DIAGNOSE, "ddd_diagnose", &meta_service::ddd_diagnose);
}

int meta_service::check_leader(dsn::message_ex *req)
int meta_service::check_leader(dsn::message_ex *req, dsn::rpc_address *forward_address)
{
dsn::rpc_address leader;
if (!_failure_detector->get_leader(&leader)) {
if (!req->header->context.u.is_forward_supported)
if (!req->header->context.u.is_forward_supported) {
if (forward_address != nullptr)
*forward_address = leader;
return -1;
}

dinfo("leader address: %s", leader.to_string());
if (!leader.is_invalid()) {
dsn_rpc_forward(req, leader);
return 0;
} else {
if (forward_address != nullptr)
forward_address->set_invalid();
return -1;
}
}
Expand All @@ -341,7 +346,24 @@ int meta_service::check_leader(dsn::message_ex *req)

#define RPC_CHECK_STATUS(dsn_msg, response_struct) \
dinfo("rpc %s called", __FUNCTION__); \
int result = check_leader(dsn_msg); \
int result = check_leader(dsn_msg, nullptr); \
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; \
}

#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) { \
Expand Down Expand Up @@ -485,7 +507,7 @@ 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(msg, response);
RPC_CHECK_STATUS_WITH_FORWARD(msg, response);

configuration_query_by_index_request request;
dsn::unmarshall(msg, request);
Expand Down Expand Up @@ -588,7 +610,7 @@ void meta_service::on_start_recovery(dsn::message_ex *req)
{
configuration_recovery_response response;
ddebug("got start recovery request, start to do recovery");
int result = check_leader(req);
int result = check_leader(req, nullptr);
if (result == 0) // request has been forwarded to others
{
return;
Expand Down
3 changes: 2 additions & 1 deletion src/dist/replication/meta_server/meta_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class meta_service : public serverlet<meta_service>
// 1. the meta is leader
// 0. meta isn't leader, and rpc-msg can forward to others
// -1. meta isn't leader, and rpc-msg can't forward to others
int check_leader(dsn::message_ex *req);
// if return -1 and `forward_address' != nullptr, then return leader by `forward_address'.
int check_leader(dsn::message_ex *req, dsn::rpc_address *forward_address);
error_code remote_storage_initialize();
bool check_freeze() const;

Expand Down
1 change: 1 addition & 0 deletions src/dsn.layer2.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct configuration_query_by_index_response
3:i32 partition_count;
4:bool is_stateful;
5:list<partition_configuration> partitions;
6:dsn.rpc_address forward_address;
}

enum app_status
Expand Down

0 comments on commit 40eda9f

Please sign in to comment.