From 8431b257712a6fc91efbda173d8c58211488e80b Mon Sep 17 00:00:00 2001 From: Robert Escriva Date: Mon, 25 May 2015 11:04:23 -0400 Subject: [PATCH] Use defended_call for online/suspect --- common/coordinator_link.cc | 11 +++++++++ common/coordinator_link.h | 5 ++++ coordinator/coordinator.cc | 6 ----- daemon/coordinator_link_wrapper.cc | 38 ++++++++++++++++++++++++++---- daemon/coordinator_link_wrapper.h | 5 ++++ 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/common/coordinator_link.cc b/common/coordinator_link.cc index f0a14753..bee407cd 100644 --- a/common/coordinator_link.cc +++ b/common/coordinator_link.cc @@ -95,6 +95,17 @@ coordinator_link :: rpc(const char* func, REPLICANT_CALL_ROBUST, status, output, output_sz); } +int64_t +coordinator_link :: rpc_defended(const char* enter_func, + const char* enter_data, size_t enter_data_sz, + const char* exit_func, + const char* exit_data, size_t exit_data_sz, + replicant_returncode* status) +{ + return replicant_client_defended_call(m_repl, "hyperdex", enter_func, enter_data, enter_data_sz, + exit_func, exit_data, exit_data_sz, status); +} + int64_t coordinator_link :: backup(replicant_returncode* status, char** output, size_t* output_sz) diff --git a/common/coordinator_link.h b/common/coordinator_link.h index 11441a49..33d0f8b3 100644 --- a/common/coordinator_link.h +++ b/common/coordinator_link.h @@ -65,6 +65,11 @@ class coordinator_link const char* data, size_t data_sz, replicant_returncode* status, char** output, size_t* output_sz); + int64_t rpc_defended(const char* enter_func, + const char* enter_data, size_t enter_data_sz, + const char* exit_func, + const char* exit_data, size_t exit_data_sz, + replicant_returncode* status); int64_t backup(replicant_returncode* status, char** output, size_t* output_sz); int64_t wait(const char* cond, uint64_t state, diff --git a/coordinator/coordinator.cc b/coordinator/coordinator.cc index fa0a4b81..9fc29ae7 100644 --- a/coordinator/coordinator.cc +++ b/coordinator/coordinator.cc @@ -359,12 +359,6 @@ coordinator :: server_online(rsm_context* ctx, generate_next_configuration(ctx); } -#if 0 - char buf[sizeof(uint64_t)]; - e::pack64be(sid.get(), buf); - uint64_t client = replicant_state_machine_get_client(ctx); - replicant_state_machine_suspect(ctx, client, "server_suspect", buf, sizeof(uint64_t)); -#endif return generate_response(ctx, COORD_SUCCESS); } diff --git a/daemon/coordinator_link_wrapper.cc b/daemon/coordinator_link_wrapper.cc index 2d4833c8..a6b6046d 100644 --- a/daemon/coordinator_link_wrapper.cc +++ b/daemon/coordinator_link_wrapper.cc @@ -771,13 +771,16 @@ coordinator_link_wrapper :: ensure_available() } size_t sz = sizeof(uint64_t) + pack_size(m_daemon->m_bind_to); - std::auto_ptr buf(e::buffer::create(sz)); - buf->pack() << m_daemon->m_us << m_daemon->m_bind_to; + std::auto_ptr enter_buf(e::buffer::create(sz)); + enter_buf->pack() << m_daemon->m_us << m_daemon->m_bind_to; + char exit_buf[sizeof(uint64_t)]; + e::pack64be(m_daemon->m_us.get(), exit_buf); e::intrusive_ptr rpc = new coord_rpc_available(); rpc->msg << "server online"; - m_online_id = make_rpc_nosync("server_online", - reinterpret_cast(buf->data()), buf->size(), - rpc); + m_online_id = make_rpc_defended("server_online", + enter_buf->cdata(), enter_buf->size(), + "server_suspect", exit_buf, sizeof(uint64_t), + rpc); } class coordinator_link_wrapper::coord_rpc_config_ack : public coord_rpc @@ -1056,6 +1059,31 @@ coordinator_link_wrapper :: make_rpc_nosync(const char* func, return id; } +int64_t +coordinator_link_wrapper :: make_rpc_defended(const char* enter_func, + const char* enter_data, size_t enter_data_sz, + const char* exit_func, + const char* exit_data, size_t exit_data_sz, + e::intrusive_ptr rpc) +{ + int64_t id = m_coord->rpc_defended(enter_func, enter_data, enter_data_sz, + exit_func, exit_data, exit_data_sz, + &rpc->status); + + if (id < 0) + { + LOG(ERROR) << "coordinator error: " << rpc->msg.str() + << ": " << m_coord->error_message() + << " @ " << m_coord->error_location(); + } + else + { + m_rpcs.insert(std::make_pair(id, rpc)); + } + + return id; +} + int64_t coordinator_link_wrapper :: wait_nosync(const char* cond, uint64_t state, e::intrusive_ptr rpc) diff --git a/daemon/coordinator_link_wrapper.h b/daemon/coordinator_link_wrapper.h index 92d66338..aabecae8 100644 --- a/daemon/coordinator_link_wrapper.h +++ b/daemon/coordinator_link_wrapper.h @@ -121,6 +121,11 @@ class coordinator_link_wrapper int64_t make_rpc_nosync(const char* func, const char* data, size_t data_sz, e::intrusive_ptr rpc); + int64_t make_rpc_defended(const char* enter_func, + const char* enter_data, size_t enter_data_sz, + const char* exit_func, + const char* exit_data, size_t exit_data_sz, + e::intrusive_ptr rpc); int64_t wait_nosync(const char* cond, uint64_t state, e::intrusive_ptr rpc);