From 059f89917b73d83fc13c8e2f6b5bbe440f2c7620 Mon Sep 17 00:00:00 2001 From: wubenqi Date: Sat, 23 Sep 2017 18:34:34 +0800 Subject: [PATCH] =?UTF-8?q?thrift=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/CMakeLists.txt | 5 +- client/client.cc | 64 +- client/client.h | 11 +- client/client_command_handler.cc | 114 +- client/client_command_handler.h | 4 +- seqsvr/CMakeLists.txt | 2 + seqsvr/allocsvr/CMakeLists.txt | 24 +- seqsvr/allocsvr/alloc_server.cc | 128 +- seqsvr/allocsvr/alloc_server.h | 25 +- seqsvr/allocsvr/alloc_service_handler.cc | 61 + .../alloc_service_handler.h} | 22 +- seqsvr/allocsvr/alloc_service_impl.cc | 65 - seqsvr/allocsvr/alloc_service_impl.h | 36 - seqsvr/allocsvr/allocsvr_manager.cc | 225 ++- seqsvr/allocsvr/allocsvr_manager.h | 102 +- seqsvr/allocsvr/client_manager.cc | 32 + seqsvr/allocsvr/client_manager.h | 137 ++ seqsvr/allocsvr/lease_clerk.cc | 158 +- seqsvr/allocsvr/lease_clerk.h | 61 +- seqsvr/allocsvr/zrpc_alloc_dispatcher.cc | 90 -- seqsvr/allocsvr/zrpc_alloc_service.cc | 43 - seqsvr/allocsvr/zrpc_alloc_service.h | 36 - seqsvr/base/CMakeLists.txt | 31 + seqsvr/base/config.cc | 116 +- seqsvr/base/config.h | 132 +- seqsvr/base/message_handler_util.h | 99 -- seqsvr/base/router_table.cc | 36 +- seqsvr/base/router_table.h | 156 +- seqsvr/base/section.h | 157 +- seqsvr/base/set.cc | 38 + seqsvr/base/set.h | 78 +- seqsvr/base/thrift_util.h | 31 + seqsvr/mediatesvr/CMakeLists.txt | 17 +- seqsvr/mediatesvr/mediate_handler.cc | 2 - seqsvr/mediatesvr/mediate_server.cc | 43 +- seqsvr/mediatesvr/mediate_server.h | 23 +- seqsvr/mediatesvr/mediate_service_handler.cc | 40 + .../mediate_service_handler.h} | 27 +- seqsvr/proto/CMakeLists.txt | 55 + seqsvr/proto/build.sh | 2 + seqsvr/proto/gen-cpp2/AllocService.cpp | 88 ++ seqsvr/proto/gen-cpp2/AllocService.h | 185 +++ seqsvr/proto/gen-cpp2/AllocService.tcc | 351 +++++ seqsvr/proto/gen-cpp2/AllocService_client.cpp | 255 ++++ .../gen-cpp2/AllocService_custom_protocol.h | 19 + .../AllocService_processmap_binary.cpp | 16 + .../AllocService_processmap_compact.cpp | 16 + .../AllocService_processmap_simple_json.cpp | 16 + seqsvr/proto/gen-cpp2/MediateService.cpp | 88 ++ seqsvr/proto/gen-cpp2/MediateService.h | 185 +++ seqsvr/proto/gen-cpp2/MediateService.tcc | 323 +++++ .../proto/gen-cpp2/MediateService_client.cpp | 255 ++++ .../gen-cpp2/MediateService_custom_protocol.h | 19 + .../MediateService_processmap_binary.cpp | 16 + .../MediateService_processmap_compact.cpp | 16 + .../MediateService_processmap_simple_json.cpp | 16 + seqsvr/proto/gen-cpp2/StoreService.cpp | 124 ++ seqsvr/proto/gen-cpp2/StoreService.h | 259 ++++ seqsvr/proto/gen-cpp2/StoreService.tcc | 668 +++++++++ seqsvr/proto/gen-cpp2/StoreService_client.cpp | 491 +++++++ .../gen-cpp2/StoreService_custom_protocol.h | 19 + .../StoreService_processmap_binary.cpp | 16 + .../StoreService_processmap_compact.cpp | 16 + .../StoreService_processmap_simple_json.cpp | 16 + seqsvr/proto/gen-cpp2/seqsvr_constants.cpp | 13 + seqsvr/proto/gen-cpp2/seqsvr_constants.h | 17 + seqsvr/proto/gen-cpp2/seqsvr_data.cpp | 9 + seqsvr/proto/gen-cpp2/seqsvr_data.h | 16 + seqsvr/proto/gen-cpp2/seqsvr_types.cpp | 615 ++++++++ seqsvr/proto/gen-cpp2/seqsvr_types.h | 1280 +++++++++++++++++ seqsvr/proto/gen-cpp2/seqsvr_types.tcc | 925 ++++++++++++ .../gen-cpp2/seqsvr_types_custom_protocol.h | 18 + seqsvr/proto/seqsvr.thrift | 188 +++ seqsvr/seqsvr/CMakeLists.txt | 14 +- seqsvr/seqsvr/seq_server.cc | 40 +- seqsvr/seqsvr/seq_server.h | 20 +- seqsvr/seqsvr/seq_service_impl.cc | 59 - seqsvr/seqsvr/seq_service_impl.h | 36 - seqsvr/seqsvr/sequence_service_handler.cc | 61 + seqsvr/seqsvr/sequence_service_handler.h | 34 + seqsvr/seqsvr/zrpc_seq_dispatcher.cc | 90 -- seqsvr/seqsvr/zrpc_seq_service.cc | 43 - seqsvr/seqsvr/zrpc_seq_service.h | 36 - seqsvr/storesvr/CMakeLists.txt | 18 +- seqsvr/storesvr/store_server.cc | 65 +- seqsvr/storesvr/store_server.h | 60 +- seqsvr/storesvr/store_service_handler.cc | 53 + ...e_dispatcher.h => store_service_handler.h} | 23 +- seqsvr/storesvr/store_service_impl.cc | 49 - seqsvr/storesvr/store_service_impl.h | 37 - seqsvr/storesvr/storesvr_manager.cc | 105 +- seqsvr/storesvr/storesvr_manager.h | 41 +- seqsvr/storesvr/test/CMakeLists.txt | 18 + seqsvr/storesvr/test/store_client.cc | 121 ++ seqsvr/storesvr/zrpc_store_dispatcher.cc | 91 -- seqsvr/storesvr/zrpc_store_service.cc | 42 - seqsvr/storesvr/zrpc_store_service.h | 37 - 97 files changed, 8558 insertions(+), 1717 deletions(-) create mode 100644 seqsvr/allocsvr/alloc_service_handler.cc rename seqsvr/{seqsvr/zrpc_seq_dispatcher.h => allocsvr/alloc_service_handler.h} (51%) delete mode 100644 seqsvr/allocsvr/alloc_service_impl.cc delete mode 100644 seqsvr/allocsvr/alloc_service_impl.h create mode 100644 seqsvr/allocsvr/client_manager.cc create mode 100644 seqsvr/allocsvr/client_manager.h delete mode 100644 seqsvr/allocsvr/zrpc_alloc_dispatcher.cc delete mode 100644 seqsvr/allocsvr/zrpc_alloc_service.cc delete mode 100644 seqsvr/allocsvr/zrpc_alloc_service.h create mode 100644 seqsvr/base/CMakeLists.txt delete mode 100644 seqsvr/base/message_handler_util.h create mode 100644 seqsvr/base/set.cc create mode 100644 seqsvr/base/thrift_util.h create mode 100644 seqsvr/mediatesvr/mediate_service_handler.cc rename seqsvr/{allocsvr/zrpc_alloc_dispatcher.h => mediatesvr/mediate_service_handler.h} (51%) create mode 100644 seqsvr/proto/CMakeLists.txt create mode 100755 seqsvr/proto/build.sh create mode 100644 seqsvr/proto/gen-cpp2/AllocService.cpp create mode 100644 seqsvr/proto/gen-cpp2/AllocService.h create mode 100644 seqsvr/proto/gen-cpp2/AllocService.tcc create mode 100644 seqsvr/proto/gen-cpp2/AllocService_client.cpp create mode 100644 seqsvr/proto/gen-cpp2/AllocService_custom_protocol.h create mode 100644 seqsvr/proto/gen-cpp2/AllocService_processmap_binary.cpp create mode 100644 seqsvr/proto/gen-cpp2/AllocService_processmap_compact.cpp create mode 100644 seqsvr/proto/gen-cpp2/AllocService_processmap_simple_json.cpp create mode 100644 seqsvr/proto/gen-cpp2/MediateService.cpp create mode 100644 seqsvr/proto/gen-cpp2/MediateService.h create mode 100644 seqsvr/proto/gen-cpp2/MediateService.tcc create mode 100644 seqsvr/proto/gen-cpp2/MediateService_client.cpp create mode 100644 seqsvr/proto/gen-cpp2/MediateService_custom_protocol.h create mode 100644 seqsvr/proto/gen-cpp2/MediateService_processmap_binary.cpp create mode 100644 seqsvr/proto/gen-cpp2/MediateService_processmap_compact.cpp create mode 100644 seqsvr/proto/gen-cpp2/MediateService_processmap_simple_json.cpp create mode 100644 seqsvr/proto/gen-cpp2/StoreService.cpp create mode 100644 seqsvr/proto/gen-cpp2/StoreService.h create mode 100644 seqsvr/proto/gen-cpp2/StoreService.tcc create mode 100644 seqsvr/proto/gen-cpp2/StoreService_client.cpp create mode 100644 seqsvr/proto/gen-cpp2/StoreService_custom_protocol.h create mode 100644 seqsvr/proto/gen-cpp2/StoreService_processmap_binary.cpp create mode 100644 seqsvr/proto/gen-cpp2/StoreService_processmap_compact.cpp create mode 100644 seqsvr/proto/gen-cpp2/StoreService_processmap_simple_json.cpp create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_constants.cpp create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_constants.h create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_data.cpp create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_data.h create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_types.cpp create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_types.h create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_types.tcc create mode 100644 seqsvr/proto/gen-cpp2/seqsvr_types_custom_protocol.h create mode 100644 seqsvr/proto/seqsvr.thrift delete mode 100644 seqsvr/seqsvr/seq_service_impl.cc delete mode 100644 seqsvr/seqsvr/seq_service_impl.h create mode 100644 seqsvr/seqsvr/sequence_service_handler.cc create mode 100644 seqsvr/seqsvr/sequence_service_handler.h delete mode 100644 seqsvr/seqsvr/zrpc_seq_dispatcher.cc delete mode 100644 seqsvr/seqsvr/zrpc_seq_service.cc delete mode 100644 seqsvr/seqsvr/zrpc_seq_service.h create mode 100644 seqsvr/storesvr/store_service_handler.cc rename seqsvr/storesvr/{zrpc_store_dispatcher.h => store_service_handler.h} (57%) delete mode 100644 seqsvr/storesvr/store_service_impl.cc delete mode 100644 seqsvr/storesvr/store_service_impl.h create mode 100644 seqsvr/storesvr/test/CMakeLists.txt create mode 100644 seqsvr/storesvr/test/store_client.cc delete mode 100644 seqsvr/storesvr/zrpc_store_dispatcher.cc delete mode 100644 seqsvr/storesvr/zrpc_store_service.cc delete mode 100644 seqsvr/storesvr/zrpc_store_service.h diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 63cf169..efd31c5 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -23,11 +23,8 @@ set (SRC_LIST client_command_handler.h ../../nebula/nebula/base/readline_gets.cc ../../nebula/nebula/base/readline_gets.h - ../seqsvr/proto/cc/seqsvr.pb.cc - ../seqsvr/proto/cc/seqsvr.pb.h - ../seqsvr/base/message_handler_util.h ) add_executable (client ${SRC_LIST}) -target_link_libraries (client net base protobuf readline) +target_link_libraries (client seqsvr_base base seqsvr_gen-cpp2 boost_system boost_filesystem pthread glog gflags folly thrift thriftcpp2 thriftprotocol zstd ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} readline dl) diff --git a/client/client.cc b/client/client.cc index ef628c0..d15021b 100644 --- a/client/client.cc +++ b/client/client.cc @@ -18,37 +18,45 @@ #include "client/client.h" #include - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - -#include "nebula/net/rpc/zrpc_service_util.h" -#include "nebula/net/net_engine_manager.h" +#include +#include #include "nebula/base/readline_gets.h" +#include "proto/gen-cpp2/seqsvr_types.h" +#include "proto/gen-cpp2/AllocService.h" + #include "client/client_command_handler.h" +using namespace apache::thrift; +// +//#include "proto/cc/seqsvr.pb.h" +//#include "nebula/net/zproto/api_message_box.h" +// +//#include "nebula/net/rpc/zrpc_service_util.h" +//#include "nebula/net/net_engine_manager.h" + + bool Client::Initialize() { // 注册服务 // RegisterService("seq_client", "rpc_client", "zrpc"); // 注册服务 - RegisterService("alloc_client", "rpc_client", "zrpc"); + // RegisterService("alloc_client", "rpc_client", "zrpc"); - return BaseServer::Initialize(); + return BaseDaemon::Initialize(); } bool Client::Run() { // auto net_engine_manager = nebula::NetEngineManager::GetInstance(); // 启动成功 - try { - nebula::NetEngineManager::GetInstance()->Start(); - } catch (std::exception& e) { - LOG(ERROR) << "Run - catch exception: " << e.what(); - return false; - } catch (...) { - LOG(ERROR) << "Run - catch a invalid exception"; - return false; - } + // try { + // nebula::NetEngineManager::GetInstance()->Start(); + // } catch (std::exception& e) { + // LOG(ERROR) << "Run - catch exception: " << e.what(); + // return false; + // } catch (...) { + // LOG(ERROR) << "Run - catch a invalid exception"; + // return false; + // } // GPerftoolsProfiler profiler; // profiler.ProfilerStart(); @@ -58,7 +66,7 @@ bool Client::Run() { // profiler.ProfilerStop(); - nebula::NetEngineManager::GetInstance()->Stop(); + // nebula::NetEngineManager::GetInstance()->Stop(); return true; // return BaseServer::Run(); @@ -66,6 +74,12 @@ bool Client::Run() { void Client::DoCommandLineLoop() { + // EventBase eb; + auto client = std::make_unique( + HeaderClientChannel::newChannel( + async::TAsyncSocket::newSocket( + &main_eb_, {"127.0.0.1", 10000}))); + try { while (true) { auto line = ReadlineGets("nebula-im> "); @@ -76,7 +90,7 @@ void Client::DoCommandLineLoop() { std::vector cmds; folly::split(" ", line, cmds); - if (-2 == DoClientCommand(cmds)) { + if (-2 == DoClientCommand(client.get(), cmds)) { break; } } @@ -90,15 +104,3 @@ int main(int argc, char* argv[]) { return nebula::DoMain(argc, argv); } -void DebugTest() { - zproto::GetRouteTableReq get_route_table_req; - std::string o; - get_route_table_req.SerializeToString(&o); - std::cout << o.length() << ", " << get_route_table_req.Utf8DebugString() << std::endl; - - get_route_table_req.Clear(); - bool rv = get_route_table_req.ParseFromArray(o.c_str(), o.length()); - if (!rv) std::cout << "error!!!" << std::endl; - std::cout << o.length() << ", " << get_route_table_req.Utf8DebugString() << std::endl; -} - diff --git a/client/client.h b/client/client.h index cfc213c..18b1665 100644 --- a/client/client.h +++ b/client/client.h @@ -20,15 +20,20 @@ #include -#include "nebula/net/base_server.h" +#include "nebula/base/base_daemon.h" -class Client : public nebula::BaseServer { +class Client : public nebula::BaseDaemon { public: Client() = default; ~Client() override = default; protected: - // From BaseServer + // From BaseDaemon + // 不使用自动配置框架 + bool LoadConfig(const std::string& config_file) override { + return true; + } + bool Initialize() override; bool Run() override; diff --git a/client/client_command_handler.cc b/client/client_command_handler.cc index b188a30..b0a8b2b 100644 --- a/client/client_command_handler.cc +++ b/client/client_command_handler.cc @@ -22,9 +22,9 @@ #include "nebula/base/time_util.h" // #include "nebula/base/id_util.h" // #include "nebula/net/rpc/zrpc_service_util.h" -#include "base/message_handler_util.h" +// #include "base/message_handler_util.h" -typedef int (*ClientCommandHandlerFunc)(const std::vector&); +typedef int (*ClientCommandHandlerFunc)(seqsvr::AllocServiceAsyncClient*, const std::vector&); // struct CmdEntry { @@ -35,7 +35,7 @@ struct CmdEntry { ClientCommandHandlerFunc handler; // 命令处理函数 }; -int DoFetchNextSeq(const std::vector& command_lines) { +int DoFetchNextSeq(seqsvr::AllocServiceAsyncClient* client, const std::vector& command_lines) { uint32_t id = 0; try { id = folly::to(command_lines[1]); @@ -44,25 +44,15 @@ int DoFetchNextSeq(const std::vector& command_lines) { return 0; } - zproto::FetchNextSequenceReq fetch_next_sequence_req; - fetch_next_sequence_req.set_id(id); - fetch_next_sequence_req.set_version(0); - - ZRpcClientCall("alloc_client", - MakeRpcRequest(fetch_next_sequence_req), - [] (std::shared_ptr> seq_rsp, - ProtoRpcResponsePtr rpc_error) -> int { - if (rpc_error) { - LOG(ERROR) << "DoFetchNextSeq - rpc_error: " << rpc_error->ToString(); - } else { - LOG(INFO) << "DoFetchNextSeq - seq_rsp: " << seq_rsp->ToString(); - } - return 0; - }); + seqsvr::Sequence _return; + client->sync_FetchNextSequence(_return, id, 0); + + LOG(INFO) << "DoFetchNextSeq - seq_rsp: " << _return.sequence; + return 0; } -int DoGetCurrentSeq(const std::vector& command_lines) { +int DoGetCurrentSeq(seqsvr::AllocServiceAsyncClient* client, const std::vector& command_lines) { uint32_t id = 0; try { id = folly::to(command_lines[1]); @@ -71,87 +61,15 @@ int DoGetCurrentSeq(const std::vector& command_lines) { return 0; } - zproto::GetCurrentSequenceReq get_current_sequence_req; - get_current_sequence_req.set_id(id); - get_current_sequence_req.set_version(0); - - ZRpcClientCall("alloc_client", - MakeRpcRequest(get_current_sequence_req), - [] (std::shared_ptr> seq_rsp, - ProtoRpcResponsePtr rpc_error) -> int { - if (rpc_error) { - LOG(ERROR) << "DoGetCurrentSeq - rpc_error: " << rpc_error->ToString(); - } else { - LOG(INFO) << "DoGetCurrentSeq - seq_rsp: " << seq_rsp->ToString(); - } - return 0; - }); - return 0; -} - -int DoFetchNextSeqList(const std::vector& command_lines) { - zproto::FetchNextSequenceListReq fetch_next_sequence_list_req; - for (size_t i=1; i(command_lines[i]); - } catch (...) { - LOG(ERROR) << "DoFetchNextSeqList - user_id invalid, not a number: " << command_lines[1]; - continue; - } - fetch_next_sequence_list_req.add_id_list(id); - } - if (fetch_next_sequence_list_req.id_list_size() == 0) { - LOG(ERROR) << "DoFetchNextSeqList - invalid fetch_next_sequence_list_req's id_list!!!"; - return 0; - } + seqsvr::Sequence _return; + client->sync_GetCurrentSequence(_return, id, 0); - ZRpcClientCall("alloc_client", - MakeRpcRequest(fetch_next_sequence_list_req), - [] (std::shared_ptr> seqs_rsp, - ProtoRpcResponsePtr rpc_error) -> int { - if (rpc_error) { - LOG(ERROR) << "DoFetchNextSeqList - rpc_error: " << rpc_error->ToString(); - } else { - LOG(INFO) << "DoFetchNextSeqList - seq_rsp: " << seqs_rsp->ToString(); - } - return 0; - }); - return 0; -} + LOG(INFO) << "sync_GetCurrentSequence - seq_rsp: " << _return.sequence; -int DoGetCurrentSeqList(const std::vector& command_lines) { - zproto::GetCurrentSequenceListReq get_current_sequence_list_req; - for (size_t i=1; i(command_lines[i]); - } catch (...) { - LOG(ERROR) << "DoGetCurrentSeqList - user_id invalid, not a number: " << command_lines[1]; - continue; - } - get_current_sequence_list_req.add_id_list(id); - } - if (get_current_sequence_list_req.id_list_size() == 0) { - LOG(ERROR) << "DoGetCurrentSeqList - invalid fetch_next_sequence_list_req's id_list!!!"; - return 0; - } - - ZRpcClientCall("alloc_client", - MakeRpcRequest(get_current_sequence_list_req), - [] (std::shared_ptr> seqs_rsp, - ProtoRpcResponsePtr rpc_error) -> int { - if (rpc_error) { - LOG(ERROR) << "DoGetCurrentSeqList - rpc_error: " << rpc_error->ToString(); - } else { - LOG(INFO) << "DoGetCurrentSeqList - seq_rsp: " << seqs_rsp->ToString(); - } - return 0; - }); return 0; } -int DoQuit(const std::vector& command_lines) { +int DoQuit(seqsvr::AllocServiceAsyncClient* client, const std::vector& command_lines) { // exit(0); return -2; } @@ -160,8 +78,6 @@ CmdEntry g_cmds[] = { // login/logout {"fetch_next_seq", "fetch_next_seq id", 2, 2, DoFetchNextSeq}, {"get_current_seq", "get_current_seq id", 2, 2, DoGetCurrentSeq}, - {"fetch_next_seq_list", "fetch_next_seq_list id...", 2, 10, DoFetchNextSeqList}, - {"get_current_seq_list", "get_current_seq_list id...", 2, 10, DoGetCurrentSeqList}, // quit {"quit", "quit", 1, 0, DoQuit} }; @@ -175,7 +91,7 @@ void PrintHelp() { } -int DoClientCommand(const std::vector& command_lines) { +int DoClientCommand(seqsvr::AllocServiceAsyncClient* client, const std::vector& command_lines) { if (command_lines.empty()) { return 0; } @@ -211,7 +127,7 @@ int DoClientCommand(const std::vector& command_lines) { } } - return cmd->handler(command_lines); + return cmd->handler(client, command_lines); } diff --git a/client/client_command_handler.h b/client/client_command_handler.h index b409db1..434e50f 100644 --- a/client/client_command_handler.h +++ b/client/client_command_handler.h @@ -21,7 +21,9 @@ #include #include -int DoClientCommand(const std::vector& command_lines); +#include "proto/gen-cpp2/AllocService.h" + +int DoClientCommand(seqsvr::AllocServiceAsyncClient* client, const std::vector& command_lines); #endif diff --git a/seqsvr/CMakeLists.txt b/seqsvr/CMakeLists.txt index 50a70a4..693a241 100644 --- a/seqsvr/CMakeLists.txt +++ b/seqsvr/CMakeLists.txt @@ -1,3 +1,5 @@ +add_subdirectory(proto) +add_subdirectory(base) add_subdirectory(seqsvr) add_subdirectory(allocsvr) add_subdirectory(storesvr) diff --git a/seqsvr/allocsvr/CMakeLists.txt b/seqsvr/allocsvr/CMakeLists.txt index 4a47224..ec3fdf9 100644 --- a/seqsvr/allocsvr/CMakeLists.txt +++ b/seqsvr/allocsvr/CMakeLists.txt @@ -17,29 +17,19 @@ include_directories(. .. ../../nebula) set (SRC_LIST - ../base/section.h - ../base/set.h - ../base/router_table.cc - ../base/router_table.h lease_clerk.cc lease_clerk.h + client_manager.cc + client_manager.h allocsvr_manager.cc allocsvr_manager.h alloc_server.cc alloc_server.h - zrpc_alloc_dispatcher.cc - zrpc_alloc_dispatcher.h - zrpc_alloc_service.cc - zrpc_alloc_service.h - alloc_service_impl.cc - alloc_service_impl.h - - ../proto/cc/seqsvr.pb.cc - ../proto/cc/seqsvr.pb.h - ../proto/proto/seqsvr.proto - ../base/message_handler_util.h - ) + alloc_service_handler.cc + alloc_service_handler.h +) add_executable (allocsvr ${SRC_LIST}) -target_link_libraries (allocsvr net base protobuf) +#target_link_libraries (allocsvr net base protobuf) +target_link_libraries (allocsvr seqsvr_base base seqsvr_gen-cpp2 boost_system boost_filesystem pthread glog gflags folly thrift thriftcpp2 thriftprotocol zstd ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} dl) diff --git a/seqsvr/allocsvr/alloc_server.cc b/seqsvr/allocsvr/alloc_server.cc index 12b2715..3ba6f8a 100644 --- a/seqsvr/allocsvr/alloc_server.cc +++ b/seqsvr/allocsvr/alloc_server.cc @@ -18,16 +18,37 @@ // TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 #include "allocsvr/alloc_server.h" -#include "nebula/net/net_engine_manager.h" +#include +#include "nebula/base/config_manager.h" #include "allocsvr/allocsvr_manager.h" +#include "allocsvr/alloc_service_handler.h" -bool AllocServer::Initialize() { - RegisterService("alloc_server", "rpc_server", "zrpc"); - RegisterService("store_client", "rpc_client", "zrpc"); +AllocServer::AllocServer() { + auto config_manager = nebula::ConfigManager::GetInstance(); + config_manager->Register("allocsvr", this); + config_manager->Register("sets", this); +} + +// Override from Configurable +bool AllocServer::SetConf(const std::string& conf_name, const folly::dynamic& conf) { + LOG(INFO) << "conf_name: " << conf_name << folly::toJson(conf); - BaseServer::Initialize(); + if (conf_name == "allocsvr") { + addr_ = folly::convertTo(conf); + } else if (conf_name == "sets") { + sets_ = folly::convertTo(conf); + } + return true; +} + +bool AllocServer::Initialize() { + // RegisterService("alloc_server", "rpc_server", "zrpc"); + // RegisterService("store_client", "rpc_client", "zrpc"); + + // BaseServer::Initialize(); + #if 0 // one timer_manager_->ScheduleOneShotTimeout([]() { @@ -45,42 +66,89 @@ bool AllocServer::Initialize() { } bool AllocServer::Run() { - auto net_engine_manager = nebula::NetEngineManager::GetInstance(); - // 启动成功 - try { - net_engine_manager->Start(); - } catch (std::exception& e) { - LOG(ERROR) << "Run - catch exception: " << e.what(); - return -1; - } catch (...) { - LOG(ERROR) << "Run - catch a invalid exception"; - return -1; +// auto net_engine_manager = nebula::NetEngineManager::GetInstance(); +// // 启动成功 +// try { +// net_engine_manager->Start(); +// } catch (std::exception& e) { +// LOG(ERROR) << "Run - catch exception: " << e.what(); +// return -1; +// } catch (...) { +// LOG(ERROR) << "Run - catch a invalid exception"; +// return -1; +// } + + // auto alloc_name = std::string("alloc_server:10000"); + // static IpAddrInfo addr("127.0.0.1", 10000); + // static std::list addrs; + // addrs.emplace_back("127.0.0.1", 9090); + + // 服务发现 + // 根据本机服务找到set + // 通过set找到set所有的storesvr + IpAddrInfoList* addrs = nullptr; + for (auto& s : sets_) { + for (auto & a : s.allocsvrs) { + if (addr_ == a) { + addrs = &s.storesvrs; + break; + } + } + } + + if (addrs == nullptr) { + // 没有找到符合条件的set + LOG(ERROR) << "Not find allocsvr: " << addr_.ToString(); + return false; } auto alloc_manager = AllocSvrManager::GetInstance(); + alloc_manager->Initialize(timer_manager_.get(), addr_, *addrs); - main_eb_.runAfterDelay([&] { - auto alloc_service = net_engine_manager->Lookup("alloc_server"); - auto alloc_name = std::string("alloc_server:10000"); // + folly::to(alloc_service->GetServiceConfig().port); - - // GPerftoolsProfiler profiler; - // profiler.ProfilerStart(); - alloc_manager->Initialize(timer_manager_.get(), "set_cluster_1", alloc_name); + // 等thread线程创建成功然后返回 + // folly::EventBase* main_eb = nullptr; + std::thread t([&] () { + auto handler = std::make_shared(); + server_ = std::make_shared(); + server_->setInterface(handler); + server_->setPort(addr_.port); - // auto store_instance = StoreSvrManager::GetInstance(); - // store_instance->Initialize(1, "/tmp/seq.dat"); - }, 1000); - + LOG(INFO) << "Starting the server..."; + server_->serve(); + LOG(INFO) << "done."; + }); + +// main_eb_.runAfterDelay([&] { +// auto alloc_service = net_engine_manager->Lookup("alloc_server"); +// auto alloc_name = std::string("alloc_server:10000"); +// +// // GPerftoolsProfiler profiler; +// // profiler.ProfilerStart(); +// alloc_manager->Initialize(timer_manager_.get(), "set_cluster_1", alloc_name); +// +// // auto store_instance = StoreSvrManager::GetInstance(); +// // store_instance->Initialize(1, "/tmp/seq.dat"); +// }, 1000); +// BaseDaemon::Run(); - - // profiler.ProfilerStop(); - - net_engine_manager->Stop(); + if (server_) { + server_->stop(); + } + t.join(); +// +// // profiler.ProfilerStop(); +// +// net_engine_manager->Stop(); alloc_manager->Destroy(); return true; } +void AllocServer::Quit() { + // sleep(1); + BaseDaemon::Quit(); +} + int main(int argc, char* argv[]) { return nebula::DoMain(argc, argv); } diff --git a/seqsvr/allocsvr/alloc_server.h b/seqsvr/allocsvr/alloc_server.h index 2c43450..dbee104 100644 --- a/seqsvr/allocsvr/alloc_server.h +++ b/seqsvr/allocsvr/alloc_server.h @@ -20,19 +20,34 @@ #ifndef ALLOCSVR_ALLOC_SERVER_H_ #define ALLOCSVR_ALLOC_SERVER_H_ -#include +#include -#include "nebula/net/base_server.h" +#include "nebula/base/base_daemon.h" -class AllocServer : public nebula::BaseServer { +#include "base/section.h" +#include "base/config.h" + +// 缓存中间层AllocSvr。 +// AllocSvr则是缓存中间层,部署于多台机器, +// 每台AllocSvr负责若干号段的sequence分配,分摊海量的sequence申请请求。 +class AllocServer : public nebula::BaseDaemon, public nebula::Configurable { public: - AllocServer() = default; + AllocServer(); ~AllocServer() override = default; + // Override from Configurable + bool SetConf(const std::string& conf_name, const folly::dynamic& conf) override; + protected: bool Initialize() override; - bool Run() override; + void Quit() override; + +private: + IpAddrInfo addr_; + SetsConfig sets_; + + std::shared_ptr server_; }; #endif // ALLOCSVR_ALLOC_SERVER_H_ diff --git a/seqsvr/allocsvr/alloc_service_handler.cc b/seqsvr/allocsvr/alloc_service_handler.cc new file mode 100644 index 0000000..ca4ee41 --- /dev/null +++ b/seqsvr/allocsvr/alloc_service_handler.cc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "allocsvr/alloc_service_handler.h" + +#include "nebula/base/logger/glog_util.h" +#include "allocsvr/allocsvr_manager.h" + +folly::Future> AllocServiceHandler::future_FetchNextSequence(int32_t id, int32_t version) { + auto instance = AllocSvrManager::GetInstance(); + auto _return = std::make_unique<::seqsvr::Sequence>(); + + // IO线程 + auto evb = getEventBase(); + evb->runInEventBaseThread([]() mutable { + LOG(INFO) << "evb's thread_id"; + }); + + // TODO(@benqi): 不同的线程里,FetchNextSequence必须线程安全 + instance->FetchNextSequence(id, version, *_return); + + LOG(INFO) << "future_FetchNextSequence - id: " << id + << ", version: " << version + << ", _return: " << _return->sequence; + + return folly::makeFuture>(std::move(_return)); +} + +folly::Future> AllocServiceHandler::future_GetCurrentSequence(int32_t id, int32_t version) { + auto instance = AllocSvrManager::GetInstance(); + auto _return = std::make_unique<::seqsvr::Sequence>(); + + // TODO(@benqi): 不同的线程里,FetchNextSequence必须线程安全 + instance->GetCurrentSequence(id, version, *_return); + + // IO线程 + auto evb = getEventBase(); + evb->runInEventBaseThread([]() mutable { + LOG(INFO) << "evb's thread_id"; + }); + + LOG(INFO) << "future_GetCurrentSequence - id: " << id + << ", version: " << version + << ", _return: " << _return->sequence; + + return folly::makeFuture>(std::move(_return)); +} diff --git a/seqsvr/seqsvr/zrpc_seq_dispatcher.h b/seqsvr/allocsvr/alloc_service_handler.h similarity index 51% rename from seqsvr/seqsvr/zrpc_seq_dispatcher.h rename to seqsvr/allocsvr/alloc_service_handler.h index c7c21a4..4c17493 100644 --- a/seqsvr/seqsvr/zrpc_seq_dispatcher.h +++ b/seqsvr/allocsvr/alloc_service_handler.h @@ -15,22 +15,18 @@ * limitations under the License. */ -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 +#ifndef ALLOCSVR_ALLOC_SERVICE_HANDLER_H_ +#define ALLOCSVR_ALLOC_SERVICE_HANDLER_H_ -#ifndef SEQSVR_ZRPC_SEQ_DISPATCHER_H_ -#define SEQSVR_ZRPC_SEQ_DISPATCHER_H_ +#include "proto/gen-cpp2/AllocService.h" -#include "nebula/net/zproto/zproto_package_data.h" - -class ZRpcSeqDispatcher { +class AllocServiceHandler : public seqsvr::AllocServiceSvIf { public: - ZRpcSeqDispatcher(); - ~ZRpcSeqDispatcher() = default; + AllocServiceHandler() = default; + ~AllocServiceHandler() override = default; - static ProtoRpcResponsePtr FetchNextSequence(RpcRequestPtr request); - static ProtoRpcResponsePtr GetCurrentSequence(RpcRequestPtr request); - static ProtoRpcResponsePtr FetchNextSequenceList(RpcRequestPtr request); - static ProtoRpcResponsePtr GetCurrentSequenceList(RpcRequestPtr request); + folly::Future> future_FetchNextSequence(int32_t id, int32_t version) override; + folly::Future> future_GetCurrentSequence(int32_t id, int32_t version) override; }; -#endif // SEQSVR_RPC_SEQ_DISPATCHER_H_ +#endif diff --git a/seqsvr/allocsvr/alloc_service_impl.cc b/seqsvr/allocsvr/alloc_service_impl.cc deleted file mode 100644 index 054f965..0000000 --- a/seqsvr/allocsvr/alloc_service_impl.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成服务框架代码 - -#include "allocsvr/alloc_service_impl.h" - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - -#include "allocsvr/allocsvr_manager.h" - -int AllocServiceImpl::FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response) { - SequenceWithRouterTable seq_with_router; - AllocSvrManager::GetInstance()->FetchNextSequence(request.id(), request.version(), seq_with_router); - response->set_sequence(seq_with_router.seq); - if (seq_with_router.router) response->set_allocated_router(seq_with_router.Release()); - - return 0; -} - -int AllocServiceImpl::GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response) { - SequenceWithRouterTable seq_with_router; - AllocSvrManager::GetInstance()->GetCurrentSequence(request.id(), request.version(), seq_with_router); - response->set_sequence(seq_with_router.seq); - if (seq_with_router.router) response->set_allocated_router(seq_with_router.Release()); - - return 0; -} - -int AllocServiceImpl::FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response) { -// auto alloc_mgr = AllocSvrManager::GetInstance(); -// for (int i=0; iFetchNextSequence(request.id_list(i)); -// auto id_seq = response->add_sequence_list(); -// id_seq->set_id(request.id_list(i)); -// id_seq->set_sequence(seq); -// } - return 0; -} - -int AllocServiceImpl::GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response) { -// auto alloc_mgr = AllocSvrManager::GetInstance(); -// for (int i=0; iGetCurrentSequence(request.id_list(i)); -// auto id_seq = response->add_sequence_list(); -// id_seq->set_id(request.id_list(i)); -// id_seq->set_sequence(seq); -// } - return 0; -} diff --git a/seqsvr/allocsvr/alloc_service_impl.h b/seqsvr/allocsvr/alloc_service_impl.h deleted file mode 100644 index 93b940a..0000000 --- a/seqsvr/allocsvr/alloc_service_impl.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#ifndef ALLOCSVR_ALLOC_SERVICE_IMPL_H_ -#define ALLOCSVR_ALLOC_SERVICE_IMPL_H_ - -#include "allocsvr/zrpc_alloc_service.h" - -class AllocServiceImpl : public ZRpcAllocService { -public: - virtual ~AllocServiceImpl() = default; - - int FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response) override; - int GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response) override; - int FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response) override; - int GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response) override; -}; - -#endif - diff --git a/seqsvr/allocsvr/allocsvr_manager.cc b/seqsvr/allocsvr/allocsvr_manager.cc index e18ed87..e7bf9c8 100644 --- a/seqsvr/allocsvr/allocsvr_manager.cc +++ b/seqsvr/allocsvr/allocsvr_manager.cc @@ -18,10 +18,12 @@ #include "allocsvr/allocsvr_manager.h" #include + #include #include +#include -#include "base/message_handler_util.h" +// #include "base/message_handler_util.h" // #include "storesvr/storesvr_manager.h" /* @@ -37,15 +39,31 @@ std::shared_ptr AllocSvrManager::GetInstance() { return g_allocsvr_manager.try_get(); } -void AllocSvrManager::Initialize(nebula::TimerManager* timer_manager, const std::string& set_name, const std::string& alloc_name) { - // 首先加载路由表 - // 加载成功后再加载max_seq - set_name_ = set_name; - alloc_name_ = alloc_name; +void AllocSvrManager::Initialize(nebula::TimerManager* timer_manager, + const IpAddrInfo& alloc_addr, + const IpAddrInfoList& store_addr_list) { + + alloc_addr_ = alloc_addr; + store_addr_list_ = store_addr_list; - lease_ = std::make_unique(timer_manager, this); - lease_->Start(); + // 初始化store_client + client_ = std::make_unique( + folly::EventBaseManager::get()->getEventBase(), + store_addr_list); + LOG(INFO) << "client..."; + // 首先加载路由表 + // 加载成功后再加载max_seq + + lease_ = std::make_unique(timer_manager, client_.get(), this); + + auto evb = folly::EventBaseManager::get()->getEventBase(); + evb->runImmediatelyOrRunInEventBaseThreadAndWait([&]() { + LOG(INFO) << "evb..."; + lease_->Start(); + // LoadMaxSeq(); + }); + /* // 1. 初始化set_id_和alloc_id_ set_id_ = set_id; @@ -61,86 +79,84 @@ void AllocSvrManager::Destroy() { } } -//uint64_t AllocSvrManager::GetCurrentSequence(uint32_t id) { -//#ifdef DEBUG_TEST -// DCHECK(id g(mutex_); -// return cur_seqs_[id]; -//} -// -//uint64_t AllocSvrManager::FetchNextSequence(uint32_t id) { -//#ifdef DEBUG_TEST -// DCHECK(id g(mutex_); -// auto seq = ++cur_seqs_[id]; -// if (seq > section_max_seqs_[idx]) { -// ++section_max_seqs_[idx]; -// SaveMaxSeq(idx, section_max_seqs_[idx]); -// } -// return seq; -//} - -bool AllocSvrManager::GetCurrentSequence(uint32_t id, uint32_t client_version, SequenceWithRouterTable& o) { - if (!cache_alloc_entry_) return false; +bool AllocSvrManager::GetCurrentSequence(uint32_t id, uint32_t client_version, seqsvr::Sequence& o) { + if (!cache_my_node_) return false; if (state_ != kAllocInited) return false; - for (auto & v : cache_alloc_entry_->ranges ) { - if (id>=v.id && idsection_ranges ) { + auto idx = CalcSectionID(v.id_begin, v.size, id); + if (idx.first) { + o.sequence = cur_seqs_[id-v.id_begin]; + if (client_version < table_.version) { + o.router = table_; } return true; } } - + + LOG(INFO) << "GetCurrentSequence - id: " << id + << ", client_version: " << client_version + << ", sequence: " << o.sequence; + return false; } -bool AllocSvrManager::FetchNextSequence(uint32_t id, uint32_t client_version, SequenceWithRouterTable& o) { - if (!cache_alloc_entry_) return false; +// id计算公式 +//idx = (id-node.id_begin) +bool AllocSvrManager::FetchNextSequence(uint32_t id, uint32_t client_version, seqsvr::Sequence& o) { + if (!cache_my_node_) return false; if (state_ != kAllocInited) return false; - for (auto & v : cache_alloc_entry_->ranges ) { - if (id>=v.id && id section_max_seqs_[idx]) { - ++section_max_seqs_[idx]; - SaveMaxSeq(idx, section_max_seqs_[idx]); + for (auto & v : cache_my_node_->section_ranges ) { + auto idx = CalcSectionID(v.id_begin, v.size, id); + if (idx.first) { + o.sequence = ++cur_seqs_[id-v.id_begin]; + if (o.sequence > section_max_seqs_[idx.second]) { + SaveMaxSeq(id, o.sequence); + // TODO(@benqi): 使用返回值填充 + section_max_seqs_[idx.second] += kSeqStep; } - - if (client_version < table_.version()) { - o.router = new zproto::Router; - table_.SerializeToRouter(o.router); + if (client_version < table_.version) { + o.router = table_; } return true; } } + LOG(INFO) << "FetchNextSequence - id: " << id + << ", client_version: " << client_version + << ", sequence: " << o.sequence; + return false; } ////////////////////////////////////////////////////////////////////////////////////////////// // 租约生效 -void AllocSvrManager::OnLeaseValid(RouteTable& table) { - table_.Swap(table); - // route_search_table_.Initialize(table_); - cache_alloc_entry_ = table_.LookupAlloc(set_name_, alloc_name_); - state_ = kAllocWaitLoadSeq; - LoadMaxSeq(); +void AllocSvrManager::OnLeaseValid(seqsvr::Router& router) { + table_ = router; + + seqsvr::RouterNode* p = nullptr; + for (size_t i=0; i< table_.node_list.size(); ++i) { + auto& v = table_.node_list[i].node_addr; + if (v.ip == alloc_addr_.addr && v.port == alloc_addr_.port) { + p = &(table_.node_list[i]); + LOG(INFO) << "Lookup alloc node: " << ""; + + // TODO(@benqi): wait_load_seq... + state_ = kAllocWaitLoadSeq; + } + } + + if (!p) { + LOG(ERROR) << "Not found!"; + } else { + cache_my_node_ = p; + } } // 路由表更新 -void AllocSvrManager::OnLeaseUpdated(RouteTable& table) { - table_.Swap(table); +void AllocSvrManager::OnLeaseUpdated(seqsvr::Router& router) { +// table_.Swap(table); } // 租约失效 @@ -154,71 +170,40 @@ void AllocSvrManager::LoadMaxSeq() { // 2. 去storesvr加载max_seqs state_ = kAllocWaitRouteTable; - zproto::LoadMaxSeqsDataReq load_max_seqs_data_req; - ZRpcClientCall( - "store_client", - MakeRpcRequest(load_max_seqs_data_req), - [&] (std::shared_ptr> load_max_seqs_data_rsp, - ProtoRpcResponsePtr rpc_error) -> int { - if (rpc_error) { - LOG(ERROR) << "LoadMaxSeqsDataReq - rpc_error: " << rpc_error->ToString(); - OnMaxSeqLoaded(""); - } else { - LOG(INFO) << "LoadMaxSeqsDataReq - load_max_seqs_data_rsp: " - << load_max_seqs_data_rsp->ToString(); - OnMaxSeqLoaded((*load_max_seqs_data_rsp)->max_seqs()); - } - return 0; - }); + seqsvr::MaxSeqsData max_seqs_data; + client_->LoadMaxSeqsData(max_seqs_data); + OnMaxSeqLoaded(max_seqs_data); - // 先使用StoreSvrManager加载,跑通流程 - // auto store = StoreSvrManager::GetInstance(); - // store->Initialize(set_id, "/tmp/seq.dat"); - // std::string max_seqs_data = store->GetSectionsData(set_id, alloc_id); - // OnLoad(max_seqs_data); } -void AllocSvrManager::SaveMaxSeq(uint32_t section_id, uint64_t section_max_seq) { +void AllocSvrManager::SaveMaxSeq(uint32_t id, uint64_t section_max_seq) { // TODO(@beqni): NWR写 -// auto store = StoreSvrManager::GetInstance(); -// bool rv = store->SetSectionsData(set_id, alloc_id, section_id, section_max_seq); - - zproto::SaveMaxSeqReq save_max_seq_req; - save_max_seq_req.set_section_id(section_id); - save_max_seq_req.set_max_seq(section_max_seq); - ZRpcClientCall( - "store_client", - MakeRpcRequest(save_max_seq_req), - [section_max_seq, this] (std::shared_ptr> save_max_seq_rsp, - ProtoRpcResponsePtr rpc_error) -> int { - if (rpc_error) { - LOG(ERROR) << "SaveMaxSeqReq - rpc_error: " << rpc_error->ToString(); - this->OnMaxSeqSaved(false); - } else { - LOG(INFO) << "SaveMaxSeqReq - load_max_seqs_data_rsp: " << save_max_seq_rsp->ToString(); - this->OnMaxSeqSaved((*save_max_seq_rsp)->last_max_seq() == section_max_seq-1); - } - return 0; - }); + client_->SaveMaxSeq(id, section_max_seq); } -void AllocSvrManager::OnMaxSeqLoaded(const std::string& data) { - if (!data.empty()) { - // TODO(@benqi): 检查数据是否合法 - // 复制数据 - memcpy(section_max_seqs_.data(), data.c_str(), data.length()); - // 将cur_seq设置为max_seq - for (int i=0; i -#include +// #include #include #include "base/set.h" +#include "allocsvr/client_manager.h" #include "allocsvr/lease_clerk.h" -#include "proto/cc/seqsvr.pb.h" enum AllocSvrState { kAllocNone = 0, @@ -36,29 +36,15 @@ enum AllocSvrState { kAllocError, }; -//struct IDRangeSections { -// IDRange range; -// std::vector section_max_seqs_; -// std::vector cur_seqs_; -//}; - class RouteTable; -struct SequenceWithRouterTable { - ~SequenceWithRouterTable() { - if (router) delete router; - router = nullptr; - } - - zproto::Router* Release() { - zproto::Router* r = router; - router = nullptr; - return r; - } - - uint64_t seq{0}; - zproto::Router* router{nullptr}; -}; +// allocsvr流程: +// 1. 从存储系统里取出路由表 +// 2. 通过本机Addr信息到路由表里获取当前服务号段列表 +// 3. 启动租约服务 +// 4. 从存储系统里取出max_seqs集合 +// 5. 开始对客户端提供服务 +// // TODO(@benqi): 单机模拟set的allocsvr和storesvr // 未加载成功重试加载 class AllocSvrManager : public LeaseClerk::LeaseCallback { @@ -67,52 +53,72 @@ class AllocSvrManager : public LeaseClerk::LeaseCallback { static std::shared_ptr GetInstance(); - ////////////////////////////////////////////////////////////////////////////////////////////// - void Initialize(nebula::TimerManager* timer_manager, const std::string& set_name, const std::string& alloc_name); + //////////////////////////////////////////////////////////////////////////// + // alloc_addr: allocsvr的本机地址信息 + // store_addr_list: storesvr地址列表 + void Initialize(nebula::TimerManager* timer_manager, + const IpAddrInfo& alloc_addr, + const IpAddrInfoList& store_addr_list); + void Destroy(); - bool GetCurrentSequence(uint32_t id, uint32_t client_version, SequenceWithRouterTable& o); - bool FetchNextSequence(uint32_t id, uint32_t client_version, SequenceWithRouterTable& o); + // 客户端接口 + bool GetCurrentSequence(uint32_t id, uint32_t client_version, seqsvr::Sequence& o); + bool FetchNextSequence(uint32_t id, uint32_t client_version, seqsvr::Sequence& o); - ////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + // 租约回调接口实现 // 租约生效 - virtual void OnLeaseValid(RouteTable& table); + void OnLeaseValid(seqsvr::Router& router) override; // 路由表更新 - virtual void OnLeaseUpdated(RouteTable& table); + void OnLeaseUpdated(seqsvr::Router& router) override; // 租约失效 - virtual void OnLeaseInvalid(); + void OnLeaseInvalid() override; private: AllocSvrManager() - : section_max_seqs_(kSectionSlotSize), - cur_seqs_(kMaxIDSize), - state_(kAllocNone) {} + : state_(kAllocNone) {} friend class folly::Singleton; // bytes void LoadMaxSeq(); - void SaveMaxSeq(uint32_t section_id, uint64_t section_max_seq); + void SaveMaxSeq(uint32_t id, uint64_t section_max_seq); - void OnMaxSeqLoaded(const std::string& data); + void OnMaxSeqLoaded(seqsvr::MaxSeqsData& data); void OnMaxSeqSaved(bool result); - ////////////////////////////////////////////////////////////////////////////////////////////// - std::string set_name_; - std::string alloc_name_; + //////////////////////////////////////////////////////////////////////////// + // alloc_addr: allocsvr的本机地址信息 + // store_addr_list: storesvr地址列表 + IpAddrInfo alloc_addr_; + IpAddrInfoList store_addr_list_; + + // store客户端管理器,存储storesvr + std::unique_ptr client_; - std::vector section_max_seqs_; - std::vector cur_seqs_; - // 状态 int state_{kAllocNone}; - - std::mutex mutex_; - std::unique_ptr lease_; - AllocEntry* cache_alloc_entry_ {nullptr}; - RouteTable table_; - // RouteSearchTable route_search_table_; + // 路由表 + seqsvr::Router table_; + // 保护Router + // TODO(@benqi): + // 1. 使用读写锁, + // 2. 对router的操作封装成wrapper,预防忘记线程保护 + std::mutex table_lock_; + + // 本机路由节点 + seqsvr::RouterNode* cache_my_node_ {nullptr}; + + // 路由表租约 + std::unique_ptr lease_; + + // 同个号段内的用户共享一个max_seq + // 号段对应max_seq + std::vector section_max_seqs_; + // 用户当前cur_seqs_ + std::vector cur_seqs_; }; #endif diff --git a/seqsvr/allocsvr/client_manager.cc b/seqsvr/allocsvr/client_manager.cc new file mode 100644 index 0000000..0e980a7 --- /dev/null +++ b/seqsvr/allocsvr/client_manager.cc @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "allocsvr/client_manager.h" + +int64_t ClientUtil::SaveMaxSeq(int32_t id, int64_t max_seq) { + CheckOrMakeClient(); + + if (client_) { + // auto evb = folly::EventBaseManager::get()->getEventBase(); + // evb->runInEventBaseThread([this, section_id, max_seq] () { + auto f = client_->future_SaveMaxSeq(id, max_seq); + f.get(); + // }); + } + + return 0; +} diff --git a/seqsvr/allocsvr/client_manager.h b/seqsvr/allocsvr/client_manager.h new file mode 100644 index 0000000..81425ce --- /dev/null +++ b/seqsvr/allocsvr/client_manager.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ALLOCSVR_CLIENT_MANAGER_H_ +#define ALLOCSVR_CLIENT_MANAGER_H_ + +#include +#include + +#include "nebula/net/base/ip_addr_info.h" + +#include "proto/gen-cpp2/seqsvr_types.h" +#include "proto/gen-cpp2/StoreService.h" + + +/* + ## NWR 模型 + > NWR是一种在分布式存储系统中用于控制一致性级别的策略,应用于 Amazon Dynamo。 + NWR 模型将 CAP 的选择权交给了用户,由用户自己选择 CAP 中的哪两个。 + 其中,N 代表 N 个备份,W 代表至少写 W 份才认为成功,R 代表至少要读 R 份才认为成功。 + + - 如果 W+R>N ,是可以保证强一致性的。 + 因为 W+R > N, 所以 R > N-W,什么意思呢? + 就是读取的份数必须要大于未成功写的份数,这样至少能读到一份最新值。 + - 如果 W+R<=N,则能够保证最终一致性。 + - 如果我们要高可写的环境,我们可以配置 W=1 R=N。 + 这个时候只要写任何节点成功就认为成功,但是读的时候必须从所有的节点都读出数据。 + - 如果我们要求读的高效率,我们可以配置 W=N R=1。 + 这个时候任何一个节点读成功就认为成功,但是写的时候必须写所有三个节点成功才认为成功。 + */ + +// 分布式Quorum机制,NWR策略读写模型 +// https://my.oschina.net/manmao/blog/618344 + +// TODO(@benqi): wrapper客户端,使用客户端线程池 +// 可能需要把nebula/net集成进来 +class ClientUtil { +public: + ClientUtil(folly::EventBase* evb, const IpAddrInfo& addr) + : evb_(evb), + addr_(addr) {} + + void LoadMaxSeqsData(seqsvr::MaxSeqsData& _return) { + CheckOrMakeClient(); + if (client_) { + client_->sync_LoadMaxSeqsData(_return); + } + } + + int64_t SaveMaxSeq(int32_t id, int64_t max_seq); + + bool SaveRouteTable(const ::seqsvr::Router& router) { + CheckOrMakeClient(); + + if (client_) { + return client_->sync_SaveRouteTable(router); + } + return false; + } + + int LoadRouteTable( ::seqsvr::Router& _return) { + CheckOrMakeClient(); + + if (client_) { + try { + client_->sync_LoadRouteTable(_return); + return 0; + } catch(...) { + client_.reset(); + } + } + + return -1; + } + +private: + void CheckOrMakeClient() { + if (!client_) { + // 创建客户端 + client_ = std::make_unique( + apache::thrift::HeaderClientChannel::newChannel( + apache::thrift::async::TAsyncSocket::newSocket( + evb_, {addr_.addr, addr_.port}))); + } + } + + folly::EventBase* evb_; + IpAddrInfo addr_; + std::unique_ptr client_; + int state_; // invalid, ready, error... +}; + +// TODO(@benqi): NWR操作 +class ClientManager { +public: + ClientManager(folly::EventBase* evb, const IpAddrInfoList& addrs) { + for (const auto& addr : addrs) { + client_addr_list_.emplace_back(evb, addr); + } + } + + void LoadMaxSeqsData(seqsvr::MaxSeqsData& _return) { + client_addr_list_[0].LoadMaxSeqsData(_return); + } + + int64_t SaveMaxSeq(int32_t id, int64_t max_seq) { + return client_addr_list_[0].SaveMaxSeq(id, max_seq); + } + + bool SaveRouteTable(const ::seqsvr::Router& router) { + return client_addr_list_[0].SaveRouteTable(router); + } + + // R=N + int LoadRouteTable( ::seqsvr::Router& _return) { + return client_addr_list_[0].LoadRouteTable(_return); + } + +private: + std::vector client_addr_list_; +}; + +#endif diff --git a/seqsvr/allocsvr/lease_clerk.cc b/seqsvr/allocsvr/lease_clerk.cc index 4508fe1..d1c530f 100644 --- a/seqsvr/allocsvr/lease_clerk.cc +++ b/seqsvr/allocsvr/lease_clerk.cc @@ -17,117 +17,113 @@ #include "allocsvr/lease_clerk.h" -#include "base/message_handler_util.h" +// #include "base/message_handler_util.h" #include "nebula/base/time_util.h" +#include "allocsvr/client_manager.h" + + +LeaseClerk::LeaseClerk(nebula::TimerManager* timer_manager, + ClientManager* client, + LeaseCallback* cb) + : timer_manager_(timer_manager), + client_(client), + cb_(cb) { +} // 开始租约服务 void LeaseClerk::Start() { - // 已经启动不执行 - if (is_valid_) - return; - + // 只能执行一次 + CHECK(state_ == STATE_NONE); + + LOG(INFO) << "Start lease..."; // 启动以后请求租约 RequestLease(); + + // timer_manager_->ScheduleRepeatingTimeout( + // std::bind(&LeaseClerk::RequestLease, this), SYNC_LEASE_TIMEOUT); + } // 停止租约服务 void LeaseClerk::Stop() { - if (!is_valid_) - return; - timer_manager_->GetMainEventBase() ->runImmediatelyOrRunInEventBaseThreadAndWait([this] { // 启动检查租约失效 - timer_manager_->GetHHWheelTimer()->cancelAll(); + timer_manager_->cancelAll(); }); } -void LeaseClerk::RequestLease() { - zproto::GetRouteTableReq get_route_table_req; - ZRpcClientCall( - "store_client", MakeRpcRequest(get_route_table_req), - [this](std::shared_ptr> rpc_ok, - ProtoRpcResponsePtr rpc_error) -> int { - if (rpc_error) { - LOG(ERROR) << "RequestRouteTable - rpc_error: " - << rpc_error->ToString(); - // this->OnSave(false); - } else { - LOG(INFO) << "RequestRouteTable - rpc_ok: " << rpc_ok->ToString(); - OnHandleLease((*rpc_ok)->router()); - } - return 0; - }); -} - -void LeaseClerk::OnHandleLease(const zproto::Router &router) { - int cb = -1; - { - std::lock_guard g(lock_); - lease_invalid_time_ = NowInMsecTime() + LEASE_TIMEOUT; - if (router.version() > version_) { - version_ = router.version(); - if (!is_valid_) { - is_valid_ = true; - cb = 0; - } else { - cb = 1; - } - } else { - } - } - - if (cb_ && cb != -1) { - RouteTable table; - table.ParseFromRouter(router); - if (cb == 0) { - cb_->OnLeaseValid(table); - } else { - cb_->OnLeaseUpdated(table); - } +int LeaseClerk::RequestLease() { + LOG(INFO) << "RequestLease - LoadRouteTable..."; + // TODO(@benqi): + // 同步失败后需要停止服务 + // 一旦成功收到,则表示续租成功 + seqsvr::Router router; + auto r = client_->LoadRouteTable(router); + if (r==0) { + auto now = NowInMsecTime(); + lease_invalid_time_ = now + LEASE_TIMEOUT; + LOG(INFO) << "RequestLease - LoadRouteTable ok: now=" << now + << ", lease_invalid_time = " << lease_invalid_time_; + + return OnHandleLease(router); + } else { + LOG(ERROR) << "RequestLease - LoadRouteTable error"; + // timer_manager_->ScheduleOneShotTimeout( + // std::bind(&LeaseClerk::RequestLease, this), SYNC_LEASE_TIMEOUT); } + return 0; +} - // 数据已达 - timer_manager_->GetMainEventBase()->runInEventBaseThread([cb, this] { - if (cb == 0) { +int LeaseClerk::OnHandleLease(seqsvr::Router& router) { + // 租约是否生效? + if (router.version > version_) { + version_ = router.version; + if (state_ != STATE_VALID) { + state_ = STATE_VALID; + + LOG(INFO) << "OnHandleLease - is_valid"; + // 租约生效 + cb_->OnLeaseValid(router); + + // 数据已达 + // timer_manager_->GetMainEventBase()->runInEventBaseThread([this] { // 启动检查租约失效 - timer_manager_->GetHHWheelTimer()->cancelAll(); + timer_manager_->cancelAll(); + LOG(INFO) << "OnHandleLease - start timer..."; timer_manager_->ScheduleRepeatingTimeout( std::bind(&LeaseClerk::CheckLeaseValid, this), CHECK_LEASE_TIMEOUT); + timer_manager_->ScheduleRepeatingTimeout( + std::bind(&LeaseClerk::RequestLease, this), SYNC_LEASE_TIMEOUT); + return 1; } - - timer_manager_->ScheduleOneShotTimeout( - std::bind(&LeaseClerk::RequestLease, this), SYNC_LEASE_TIMEOUT); - }); + } + + return 0; } -void LeaseClerk::CheckLeaseValid() { +int LeaseClerk::CheckLeaseValid() { auto now = NowInMsecTime(); - + + // 租约检查 LOG(WARNING) << "CheckLeaseValid - check: now=" << now << ", lease_invalid_time = " << lease_invalid_time_; - bool is_valid = true; - { - std::lock_guard g(lock_); - if (is_valid_) { - if (now > lease_invalid_time_) { - is_valid_ = false; - LOG(WARNING) << "CheckLeaseValid - lease_invalid_time"; - } - } - - is_valid = is_valid_; - } + if (now > lease_invalid_time_) { + if (state_ == STATE_VALID) { - if (!is_valid) { - timer_manager_->GetMainEventBase()->runInEventBaseThread( - [this] { - timer_manager_->GetHHWheelTimer()->cancelAll(); - }); - } else { - if (cb_) { + state_ = STATE_INVALID; cb_->OnLeaseInvalid(); + version_ = 0; + LOG(WARNING) << "CheckLeaseValid - cancel, state: " << state_; + // lease_invalid_time"; + timer_manager_->cancelAll(); + timer_manager_->ScheduleRepeatingTimeout( + std::bind(&LeaseClerk::RequestLease, this), SYNC_LEASE_TIMEOUT); + return 1; + } } + + return 0; } diff --git a/seqsvr/allocsvr/lease_clerk.h b/seqsvr/allocsvr/lease_clerk.h index f229303..111d429 100644 --- a/seqsvr/allocsvr/lease_clerk.h +++ b/seqsvr/allocsvr/lease_clerk.h @@ -23,16 +23,39 @@ #include "nebula/base/timer_manager.h" -#include "proto/cc/seqsvr.pb.h" +// #include "proto/cc/seqsvr.pb.h" +#include "proto/gen-cpp2/seqsvr_types.h" #include "base/router_table.h" -#define LEASE_TIMEOUT 5000 // 租约时间5s -#define SYNC_LEASE_TIMEOUT 4000 // 定时同步路由4s -#define CHECK_LEASE_TIMEOUT 100 // 租约时间5s +/* + 所谓租约(leases),其实就是一个合同,即服务端给予客户端在一定期限内可以控制修改操作的权力。 + 如果服务端要修改数据,首先要征求拥有这块数据的租约的客户端的同意,之后才可以修改。 + 客户端从服务端读取数据时往往就同时获取租约,在租约期限内,如果没有收到服务端的修改请求, + 就可以保证当前缓存中的内容就是最新的。如果在租约期限内收到了修改数据的请求并且同意了, + 就需要清空缓存。在租约过期以后,客户端如果还要从缓存读取数据,就必须重新获取租约, + 我们称这个操作为“续约”{!引用自<<租约机制简介>>}。 + */ + +// ## 租约 +// 为了避免失联AllocSvr提供错误的服务,返回脏数据,AllocSvr需要跟StoreSvr保持租约。 +// 这个租约机制由以下两个条件组成: +// > - 租约失效:AllocSvr N秒内无法从StoreSvr读取加载配置时,AllocSvr停止服务 +// - 租约生效:AllocSvr读取到新的加载配置后,立即卸载需要卸载的号段, +// 需要加载的新号段等待N秒后提供服务 +// +// 这两个条件保证了切换时,新AllocSvr肯定在旧AllocSvr下线后才开始提供服务。 +// 但这种租约机制也会造成切换的号段存在小段时间的不可服务, +// 不过由于微信后台逻辑层存在重试机制及异步重试队列, +// 小段时间的不可服务是用户无感知的,而且出现租约失效、切换是小概率事件,整体上是可以接受的。 +// + +#define LEASE_TIMEOUT 5000 // 租约时间5s +#define SYNC_LEASE_TIMEOUT 4000 // 定时同步路由4s +#define CHECK_LEASE_TIMEOUT 1000 // -// 为了避免失联AllocSvr提供错误的服务,返回脏数据,AllocSvr需要跟StoreSvr保持租约。这个租约机制由以下两个条件组成: -// 租约失效:AllocSvr N秒内无法从StoreSvr读取加载配置时,AllocSvr停止服务 -// 租约生效:AllocSvr读取到新的加载配置后,立即卸载需要卸载的号段,需要加载的新号段等待N秒后提供服务 +class ClientManager; + +// 租约管理,只维护租约状态,并在租约失效和生效时生成回调 class LeaseClerk { public: enum State { @@ -42,22 +65,22 @@ class LeaseClerk { STATE_ERROR, }; + // 租约事件触发 class LeaseCallback { public: virtual ~LeaseCallback() = default; // 租约生效 - virtual void OnLeaseValid(RouteTable& table) = 0; + virtual void OnLeaseValid(seqsvr::Router& router) = 0; // 路由表更新 - virtual void OnLeaseUpdated(RouteTable& table) = 0; + virtual void OnLeaseUpdated(seqsvr::Router& router) = 0; // 租约失效 virtual void OnLeaseInvalid() = 0; }; - LeaseClerk(nebula::TimerManager* timer_manager, LeaseCallback* cb) - : timer_manager_(timer_manager), - cb_(cb) {} - + LeaseClerk(nebula::TimerManager* timer_manager, + ClientManager* client, + LeaseCallback* cb); ~LeaseClerk() = default; // 开始租约服务 @@ -67,24 +90,24 @@ class LeaseClerk { private: // 开始租约服务 - void RequestLease(); + int RequestLease(); // 定时检查租约是否失效 - void CheckLeaseValid(); + int CheckLeaseValid(); // 111 - void OnHandleLease(const zproto::Router& router); + int OnHandleLease(seqsvr::Router& router); std::mutex lock_; - bool is_valid_; - // state_{STATE_NONE}; // 生效 + // bool is_valid_{false}; + int state_{STATE_NONE}; // 生效 // 路由表 // RouteTable table_; - uint32_t version_{0}; int64_t lease_invalid_time_{0}; // 租约失效时间 nebula::TimerManager* timer_manager_{nullptr}; + ClientManager* client_{nullptr}; LeaseCallback* cb_{nullptr}; }; diff --git a/seqsvr/allocsvr/zrpc_alloc_dispatcher.cc b/seqsvr/allocsvr/zrpc_alloc_dispatcher.cc deleted file mode 100644 index 9d2ab0a..0000000 --- a/seqsvr/allocsvr/zrpc_alloc_dispatcher.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#include "allocsvr/zrpc_alloc_dispatcher.h" - -#include "allocsvr/alloc_service_impl.h" -#include "nebula/net/rpc/zrpc_service_util.h" - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - - -// #include "nebula/net/zproto/api_message_box.h" - -static ZRpcAllocDispatcher g_rpc_alloc_dispatcher; - -ZRpcAllocDispatcher::ZRpcAllocDispatcher() { - ZRpcUtil::Register("zproto.FetchNextSequenceReq", ZRpcAllocDispatcher::FetchNextSequence); - ZRpcUtil::Register("zproto.GetCurrentSequenceReq", ZRpcAllocDispatcher::GetCurrentSequence); - ZRpcUtil::Register("zproto.FetchNextSequenceListReq", ZRpcAllocDispatcher::FetchNextSequenceList); - ZRpcUtil::Register("zproto.GetCurrentSequenceListReq", ZRpcAllocDispatcher::GetCurrentSequenceList); -} - -ProtoRpcResponsePtr ZRpcAllocDispatcher::FetchNextSequence(RpcRequestPtr request) { - CAST_RPC_REQUEST(FetchNextSequenceReq, fetch_next_sequece_req); - LOG(INFO) << "DoFetchNextSequenceReq - [" << request->ToString() - << "], " << fetch_next_sequece_req.Utf8DebugString(); - - zproto::SequenceRsp sequence_rsp; - - AllocServiceImpl service_impl; - service_impl.FetchNextSequence(fetch_next_sequece_req, &sequence_rsp); - - return MakeRpcOK(sequence_rsp); -} - -ProtoRpcResponsePtr ZRpcAllocDispatcher::GetCurrentSequence(RpcRequestPtr request) { - CAST_RPC_REQUEST(GetCurrentSequenceReq, get_current_sequece_req); - LOG(INFO) << "DoGetCurrentSequenceReq - [" << request->ToString() << "], " - << get_current_sequece_req.Utf8DebugString(); - - zproto::SequenceRsp sequence_rsp; - - AllocServiceImpl service_impl; - service_impl.GetCurrentSequence(get_current_sequece_req, &sequence_rsp); - - return MakeRpcOK(sequence_rsp); -} - -ProtoRpcResponsePtr ZRpcAllocDispatcher::FetchNextSequenceList(RpcRequestPtr request) { - CAST_RPC_REQUEST(FetchNextSequenceListReq, fetch_next_sequece_list_req); - LOG(INFO) << "FetchNextSequenceList - [" << request->ToString() << "], " - << fetch_next_sequece_list_req.Utf8DebugString(); - - zproto::SequenceListRsp sequence_list_rsp; - - AllocServiceImpl service_impl; - service_impl.FetchNextSequenceList(fetch_next_sequece_list_req, &sequence_list_rsp); - - return MakeRpcOK(sequence_list_rsp); -} - -ProtoRpcResponsePtr ZRpcAllocDispatcher::GetCurrentSequenceList(RpcRequestPtr request) { - CAST_RPC_REQUEST(GetCurrentSequenceListReq, get_current_sequece_list_req); - LOG(INFO) << "GetCurrentSequenceList - [" << request->ToString() << "], " - << get_current_sequece_list_req.Utf8DebugString(); - - zproto::SequenceListRsp sequence_list_rsp; - - AllocServiceImpl service_impl; - service_impl.GetCurrentSequenceList(get_current_sequece_list_req, &sequence_list_rsp); - - return MakeRpcOK(sequence_list_rsp); -} diff --git a/seqsvr/allocsvr/zrpc_alloc_service.cc b/seqsvr/allocsvr/zrpc_alloc_service.cc deleted file mode 100644 index e099a1c..0000000 --- a/seqsvr/allocsvr/zrpc_alloc_service.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#include "allocsvr/zrpc_alloc_service.h" - -#include "nebula/base/logger/glog_util.h" - - -int ZRpcAllocService::FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response) { - LOG(ERROR) << "FetchNextSequence - FetchNextSequence unimplemented"; - return -1; -} - -int ZRpcAllocService::GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response) { - LOG(ERROR) << "GetCurrentSequence - GetCurrentSequence unimplemented"; - return -1; -} - -int ZRpcAllocService::FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response) { - LOG(ERROR) << "FetchNextSequenceList - FetchNextSequenceList unimplemented"; - return -1; -} - -int ZRpcAllocService::GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response) { - LOG(ERROR) << "GetCurrentSequenceList - GetCurrentSequenceList unimplemented"; - return -1; -} diff --git a/seqsvr/allocsvr/zrpc_alloc_service.h b/seqsvr/allocsvr/zrpc_alloc_service.h deleted file mode 100644 index 2ea5a6a..0000000 --- a/seqsvr/allocsvr/zrpc_alloc_service.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#ifndef ALLOCSVR_ZRPC_ALLOC_SERVICE_H_ -#define ALLOCSVR_ZRPC_ALLOC_SERVICE_H_ - -#include "proto/cc/seqsvr.pb.h" - -class ZRpcAllocService { -public: - virtual ~ZRpcAllocService() = default; - - virtual int FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response); - virtual int GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response); - virtual int FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response); - virtual int GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response); -}; - -#endif // ALLOCSVR_ZRPC_ALLOC_SERVICE_H_ - diff --git a/seqsvr/base/CMakeLists.txt b/seqsvr/base/CMakeLists.txt new file mode 100644 index 0000000..4c2f72f --- /dev/null +++ b/seqsvr/base/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2016, https://github.com/nebula-im/nebula +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_directories(. .. ../../nebula) + +set (SRC_LIST + config.cc + config.h + section.h + set.cc + set.h + router_table.cc + router_table.h + thrift_util.h +) + +add_library(seqsvr_base STATIC ${SRC_LIST}) + diff --git a/seqsvr/base/config.cc b/seqsvr/base/config.cc index 197cbdd..a37614e 100644 --- a/seqsvr/base/config.cc +++ b/seqsvr/base/config.cc @@ -17,76 +17,70 @@ #include "base/config.h" -/* -{ - "name": "cluster_seqsvr_test"; - "seqsvr": {[ - { "range": { "id": 0, "size": 10000000} - "allocsvrs" : [ - { "addr": { "host" : "127.0.0.1", "port" : 10000 }, - "ranges": [ {"id" : 0, "size" : 5000000 } ] - }, - { "addr": { "host" : "127.0.0.1", "port" : 10001 }, - "ranges": [ {"id" : 5000000, "size" : 5000000 } ] - } - ] - }, - { "range": { "id": 10000000, "size": 10000000} - "allocsvrs" : [ - { "addr": { "host" : "127.0.0.1", "port" : 10002 }, - "ranges": [ {"id" : 100000000, "size" : 15000000 } ] - }, - { "addr": { "host" : "127.0.0.1", "port" : 10003 }, - "ranges": [ {"id" : 150000000, "size" : 20000000 } ] - } - ] - }, - ]} -} - */ +#include "base/set.h" +#include "base/thrift_util.h" -// 测试用seqsvr -// 2个set -// 每个set2个alloc_svr -SetClusterConfig MakeTestClusterConfig() { - SetClusterConfig config; - config.name = "cluster_seqsvr_test"; - - int alloc_id = 1; - int set_id = 1; - int port = 10000; - // int alloc_config_range_id = 0; - - for (int i=0; i<2; ++i) { - SetConfig set_config; - - // set1 - set_config.set_id = set_id++; - set_config.range.id = i*10000000; - set_config.range.size = 10000000; +SetsConfig MakeTestSetsConfig(int set_size, int set_range_size) { + SetsConfig sets; + + for (int i=0; i< set_size; ++i) { + SetConfig set; + set.id = i*set_range_size; + set.size = set_range_size; + for (int j=0; j<3; ++j) { + set.allocsvrs.emplace_back("127.0.0.1", 10000+i*3+j); + } + for (int j=0; j<3; ++j) { + set.storesvrs.emplace_back("127.0.0.1", 11000+i*3+j); + } - for (int j=0; j<2; j++) { - AllocConfig alloc_config; + sets.push_back(set); + } + + return sets; +} + +seqsvr::Router MakeTestRouter(const SetsConfig& sets) { + seqsvr::Router table; + table.version = 1; - IDRange range; - // alloc_1 - alloc_config.alloc_id = alloc_id++; - alloc_config.addr.host = "127.0.0.1"; - alloc_config.addr.port = port++; - range.id = i*10000000+j*5000000; - range.size = 5000000; - alloc_config.ranges.push_back(range); - set_config.allocs.push_back(alloc_config); + for (auto& s : sets) { + // 计算每个alloc管理的号段范围 + auto per_alloc_range_sz = CalcSetSectionSize(s.size, s.allocsvrs.size()*kPerSectionIdSize); - config.sets_.push_back(set_config); + LOG(INFO) << "allocsvrs_size = " << s.allocsvrs.size() + << ", s.size = " << s.size + << ", per_alloc_range_sz = " << per_alloc_range_sz; + for (size_t i=0; i(conf); + } catch (std::runtime_error& e) { + LOG(ERROR) << "convertTo error: " << e.what(); + return false; + } + + return true; } diff --git a/seqsvr/base/config.h b/seqsvr/base/config.h index 8b8f87b..3414130 100644 --- a/seqsvr/base/config.h +++ b/seqsvr/base/config.h @@ -18,15 +18,135 @@ #ifndef SEQSVR_BASE_CONFIG_H_ #define SEQSVR_BASE_CONFIG_H_ -#include -#include +// #include "nebula/base/json/json.h" -#include "base/set.h" +#include +#include +#include +#include "nebula/net/base/ip_addr_info.h" #include "nebula/base/configurable.h" -#include "nebula/base/string_builder.h" + +#include "proto/gen-cpp2/seqsvr_types.h" +// #include "nebula/base/string_builder.h" + + +/******************************************************************* +// sets.json配置文件格式 +[ + { + "allocsvrs" : [ + { + "addr" : "127.0.0.1", + "port" : 10000 + }, + { + "addr" : "127.0.0.1", + "port" : 10001 + }, + { + "addr" : "127.0.0.1", + "port" : 10002 + } + ], + "id" : 0, + "size" : 1048576, + "storesvrs" : [ + { + "addr" : "127.0.0.1", + "port" : 11000 + }, + { + "addr" : "127.0.0.1", + "port" : 11001 + }, + { + "addr" : "127.0.0.1", + "port" : 11002 + } + ] + }, + { + "allocsvrs" : [ + { + "addr" : "127.0.0.1", + "port" : 10003 + }, + { + "addr" : "127.0.0.1", + "port" : 10004 + }, + { + "addr" : "127.0.0.1", + "port" : 10005 + } + ], + "id" : 1048576, + "size" : 1048576, + "storesvrs" : [ + { + "addr" : "127.0.0.1", + "port" : 11003 + }, + { + "addr" : "127.0.0.1", + "port" : 11004 + }, + { + "addr" : "127.0.0.1", + "port" : 11005 + } + ] + } +] +*/ + + +// 配置文件 +struct SetConfig { + uint32_t id; + uint32_t size; + IpAddrInfoList allocsvrs; + IpAddrInfoList storesvrs; +}; + +// TODO(@benqi): 使用反射Marsh/Unmarshal +namespace folly { + +template <> struct DynamicConverter { + static SetConfig convert(const dynamic& d) { + SetConfig set; + set.id = convertTo(d["id"]); + set.size = convertTo(d["size"]); + set.allocsvrs = convertTo(d["allocsvrs"]); + set.storesvrs = convertTo(d["storesvrs"]); + + return set; + } +}; + +template <> struct DynamicConstructor { + static dynamic construct(const SetConfig& x) { + dynamic d = dynamic::object; + d.insert("id", x.id); + d.insert("size", x.size); + d.insert("allocsvrs", toDynamic(x.allocsvrs)); + d.insert("storesvrs", toDynamic(x.storesvrs)); + return d; + } +}; + +} + +// struct SetsConfig { +typedef std::list SetsConfig; +///////////////////////////////////////////////////////////////////// +// DEBUG_TEST +SetsConfig MakeTestSetsConfig(int set_size, int set_range_size=1<<20); +seqsvr::Router MakeTestRouter(const SetsConfig& sets); + // 测试用 // // seqsvr集群配置信息 @@ -37,7 +157,8 @@ struct SeqSvrConfig : public nebula::Configurable { } bool SetConf(const std::string& conf_name, const folly::dynamic& conf) override; - SetList sets; + // SetList sets; + SetsConfig sets; }; //struct AllocEntry { @@ -53,3 +174,4 @@ struct SeqSvrConfig : public nebula::Configurable { //}; #endif + diff --git a/seqsvr/base/message_handler_util.h b/seqsvr/base/message_handler_util.h deleted file mode 100644 index a7f1b37..0000000 --- a/seqsvr/base/message_handler_util.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/zhatalk - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_ZPROTO_HANDLER_UTIL_H_ -#define BASE_ZPROTO_HANDLER_UTIL_H_ - -#include -#include "nebula/net/zproto/zproto_package_data.h" -#include "nebula/net/handler/nebula_handler_util.h" -#include "nebula/net/rpc/zrpc_service_util.h" - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - - -#define RPC_TIMEOUT 5000 // 5000毫秒 - -inline folly::Future WritePackage(const std::string& service_name, std::shared_ptr message_data) { - std::unique_ptr data; - message_data->SerializeToIOBuf(data); - return WriterUtil::Write(service_name, std::move(data)); -} - -inline folly::Future WritePackage(uint64_t conn_id, std::shared_ptr message_data) { - std::unique_ptr data; - message_data->SerializeToIOBuf(data); - return WriterUtil::Write(conn_id, std::move(data)); -} - -inline folly::Future WritePackage(nebula::ZProtoPipeline* pipeline, std::shared_ptr message_data) { - std::unique_ptr data; - message_data->SerializeToIOBuf(data); - return pipeline->write(std::move(data)); -} - -inline folly::Future WriteToClientPackage(uint64_t conn_id, std::shared_ptr message_data) { - std::unique_ptr data; - message_data->clear_has_attach_data(); - message_data->SerializeToIOBuf(data); - return WriterUtil::Write(conn_id, std::move(data)); -} - -inline folly::Future WriteToClientPackage(nebula::ZProtoPipeline* pipeline, std::shared_ptr message_data) { - std::unique_ptr data; - message_data->clear_has_attach_data(); - message_data->SerializeToIOBuf(data); - return pipeline->write(std::move(data)); -} - -template -inline void ZRpcClientCall(const std::string& service_name, - RpcRequestPtr request, - std::function>, ProtoRpcResponsePtr)> cb, - int timeout = RPC_TIMEOUT) { - ZRpcUtil::DoClientCall(service_name, request) - .within(std::chrono::milliseconds(timeout)) - // TODO(@benqi): conn_data可能会失效 - .then([cb](ProtoRpcResponsePtr rsp) { - static ProtoRpcResponsePtr kEmptyRpcError; - static std::shared_ptr> kEmptyRpcOk; - - CHECK(rsp); - LOG(INFO) << "ZRpcClientCall rsp: " << rsp->ToString(); - - if (rsp->GetPackageType() == Package::RPC_OK) { - auto rpc_ok = ToApiRpcOk(rsp); - // LOG(INFO) << "auth_client login_rsp: " << (*login_rsp)->Utf8DebugString(); - cb(rpc_ok, kEmptyRpcError); - } else { - cb(kEmptyRpcOk, rsp); - } - }); -} - -//// s2s中,我们将conn_id存储在PackageMessage的options里 -//inline uint64_t GetConnIDByPackageMessage(const std::shared_ptr& message_data) { -// const auto& options = message_data->options(); -// if (!options.empty() && options[0].type==0) { -// return options[0].data.n; -// } -// return -1; -//} - -#endif // BASE_HANDLER_UTIL_H_ - diff --git a/seqsvr/base/router_table.cc b/seqsvr/base/router_table.cc index 070cd91..5a734ad 100644 --- a/seqsvr/base/router_table.cc +++ b/seqsvr/base/router_table.cc @@ -22,9 +22,37 @@ #include "nebula/base/time_util.h" -void RouteTable::ParseFromRouter(const zproto::Router& router) { +///////////////////////////////////////////////////////////////////////// +// 构建测试用路由表 +void RouterTableManager::MakeTestRouteTable(seqsvr::Router& table) { + +} + +///////////////////////////////////////////////////////////////////////// +// 从配置文件加载所有路由表 +void RouterTableManager::Initialize(const std::list& node_list) { + +} + +// AllocSvr节点上线和下线 +void RouterTableManager::OnAllocSvrRegister(const seqsvr::SetNodeInfo& node) { + +} + +void RouterTableManager::OnAllocSvrUnRegister(const seqsvr::SetNodeInfo& node) { + +} + +void RouterTableManager:: ToRouterTable(seqsvr::Router& table) const { + +} + + +#if 0 +void RouteTable::ParseFromRouter(const seqsvr::Router& router) { Clear(); +/* version_ = router.version(); for (int i=0; iset_version(version_); + /* for (auto& set : sets_) { auto s = router->add_sets(); s->set_set_name(set.set_name); @@ -83,6 +113,7 @@ void RouteTable::SerializeToRouter(zproto::Router* router) const { } } } + */ } void RouteTable::MakeTestRouteTable(RouteTable& table) { @@ -171,3 +202,4 @@ void RouteTableManager::Initialize(RouteTable& table) { route_search_table_.Initialize(route_table_); } +#endif diff --git a/seqsvr/base/router_table.h b/seqsvr/base/router_table.h index 9380acc..f8b66f8 100644 --- a/seqsvr/base/router_table.h +++ b/seqsvr/base/router_table.h @@ -25,8 +25,34 @@ #include "nebula/base/string_builder.h" #include "base/set.h" -#include "proto/cc/seqsvr.pb.h" +#include "proto/gen-cpp2/seqsvr_types.h" +#include "nebula/net/base/ip_addr_info.h" +// ## 容灾2.0架构:嵌入式路由表容灾 +// - 既然Client端与AllocSvr存在路由状态不一致的问题, +// 那么让AllocSvr把当前的路由状态传递给Client端, +// 打破之前只能根据本地Client配置文件做路由决策的限制,从根本上解决这个问题。 +// +// - 所以在2.0架构中,我们把AllocSvr的路由状态嵌入到Client请求sequence的响应包中, +// 在不带来额外的资源消耗的情况下,实现了Client端与AllocSvr之间的路由状态一致。 +// +// ## 具体实现方案如下: +// +// seqsvr所有模块使用了统一的路由表,描述了uid号段到AllocSvr的全映射。 +// 这份路由表由仲裁服务根据AllocSvr的服务状态生成,写到StoreSvr中, +// 由AllocSvr当作租约读出,最后在业务返回包里旁路给Client端。 +// +// 路由表优化: +// 1. Client根据本地共享内存缓存的路由表,选择对应的AllocSvr; +// 如果路由表不存在,随机选择一台AllocSvr +// +// 2. 对选中的AllocSvr发起请求,请求带上本地路由表的版本号 +// +// 3. AllocSvr收到请求,除了处理sequence逻辑外, +// 判断Client带上版本号是否最新,如果是旧版则在响应包中附上最新的路由表 +// +// 4. Client收到响应包,除了处理sequence逻辑外,判断响应包是否带有新路由表。 +// 如果有,更新本地路由表,并决策是否返回第1步重试 /* set: id(1~10240) set: 从0~100000 @@ -36,6 +62,128 @@ // uint32_t begin; // 节点开始 //}; +// json配置格式的路由表 +/* +{ + "version":1, + "sets": [ + "set_id":1, + "set_name":"0-100", + "range": { + "id":0, + "size":10 + }, + "allocs": [ + "alloc_id":, + "addr":, + "alloc_name":, + "ranges":[ + ], + ] + ] +} +*/ + +////////////////////////////////////////////////////////////////////////////// +// 路由表关注的是AllocSvr服务节点 +// 从客户端视角看: +// 从uid找到号段section,再从section找到AllocSvr +// 从构建路由表视角看: +// 由AllocSvr找到分配的Section,构成一个列表 +// 可以设计如下数据结构 +// + +/* +// 大部分情况,一个AllocSvr里的号段大部分是连续的 +// 为了减少网络传输量,将连续的号段使用SectionRange进行压缩 +// 例如,1~10个号段, +// id_begin: 1, size: 10 +struct SectionRange { + uint32_t id_begin; // 号段起始地址 + uint32_t size; // 有多少个号段 +}; + +// 路由节点 +struct RouterNode { + IpAddrInfo node_addr; // 节点地址 + std::vector section_ranges; // 本节点管理的所有号段 +}; + +// 客户端角度看的路由表: +struct RouterTable { + uint32_t version; + // std::list node_list; // 整个集群所有allocsvr节点 +}; + */ + +///////////////////////////////////////////////////////////////////////// +// 路由搜索表,客户端用 +class RouteSearchTable { +public: + RouteSearchTable() = default; + ~RouteSearchTable() = default; + + void OnRouterTable() {} +}; + + +///////////////////////////////////////////////////////////////////////// +// 从构建路由表视角看,要实现的功能: +// 1. 由配置文件创建路由表 +// 2. 节点下线时将号段迁移到其它节点 +// 3. 节点上线时,将部分节点迁移到新上线的节点中 +// 每个节点的路由表 +class RouterTableManager { +public: + RouterTableManager() = default; + ~RouterTableManager() = default; + + ///////////////////////////////////////////////////////////////////////// + // 构建测试用路由表 + static void MakeTestRouteTable(seqsvr::Router& table); + + ///////////////////////////////////////////////////////////////////////// + // 获取版本号 + inline uint32_t GetVersion() const { + return version_; + } + + // 从配置文件加载所有路由表 + void Initialize(const std::list& node_list); + + // AllocSvr节点上线和下线 + void OnAllocSvrRegister(const seqsvr::SetNodeInfo& node); + void OnAllocSvrUnRegister(const seqsvr::SetNodeInfo& node); + + // 转换成客户端用路由表 + void ToRouterTable(seqsvr::Router& table) const; + +private: + uint32_t version_ {0}; + std::list per_set_table_list_; // 整个集群所有allocsvr节点 +}; + +/* +class RouterTable { +public: + +private: + uint32_t version; + std::vector table; + + friend class RouteSearchTable; +}; +*/ + +/* +// 以如下号段举一个case +// 假设用户号段为1~16,有2个set,每个set里分配了2个section,每个section有4个号段 +// +// |0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15| +// |sec_0 |sec_1 |sec_2 |sec_3 | +// | set_0 | set_1 | +// + typedef uint32_t SectionID; // 以第一个id作为SectionID typedef int64_t AllocID; @@ -91,8 +239,8 @@ class RouteTable { } // 序列化和反序列化 - void ParseFromRouter(const zproto::Router& router); - void SerializeToRouter(zproto::Router* router) const; + void ParseFromRouter(const seqsvr::Router& router); + void SerializeToRouter(seqsvr::Router* router) const; std::string ToString() const { CStringBuilder sb; @@ -125,7 +273,6 @@ class RouteSearchTable { ~RouteSearchTable() = default; void Initialize(RouteTable& route_table); - bool CheckSectionID(AllocID alloc_id, uint32_t section_id); private: @@ -145,5 +292,6 @@ class RouteTableManager { RouteTable route_table_; RouteSearchTable route_search_table_; }; +*/ #endif diff --git a/seqsvr/base/section.h b/seqsvr/base/section.h index db1903d..8cbbf60 100644 --- a/seqsvr/base/section.h +++ b/seqsvr/base/section.h @@ -22,65 +22,140 @@ #include +#include +#include + #define DEBUG_TEST #ifndef DEBUG_TEST -// 生产环境 +// 生产环境,按uint32_t整个空间来分 const uint32_t kMaxIDSize = 0xffffffff; // uint32_t范围的id -// const uint32_t kSetSize = 1; // 最少3个set #else -// 为了在开发机上能快速启动、运行和调试 +// 测试时,为了在开发机上能快速启动、运行和调试 const uint32_t kMaxIDSize = 1<<20; // 1MB -// const uint32_t kSetSize = 1; // 1个set #endif -const uint64_t kMaxIDMemSize = kMaxIDSize<<3; // uint32_t范围的id -const uint32_t kSectionSize = 100000; // 一个Section包含10万个uid,一个uint32_t空间共有42950个Section -const uint32_t kSectionSlotSize = (kMaxIDSize/kSectionSize)+1; // 一个Section包含10万个uid,一个uint32_t空间共有42950个Section -const uint32_t kSectionSlotMemSize = kSectionSlotSize<<3; // 一个Section包含10万个uid,一个uint32_t空间共有42950个Section -const uint64_t kMaxSeqStep = 10000; // 步长为1万 - -//// 号段 -//struct IDRange { -// uint32_t id; -// size_t size; -//}; +// ## 预分配中间层 +// - sequence只要求递增,并没有要求连续,也就是说出现一大段跳跃是允许的 +// (例如分配出的sequence序列:1,2,3,10,100,101)。 +// 于是我们实现了一个简单优雅的策略: +// 1. 内存中储存最近一个分配出去的sequence:cur_seq,以及分配上限:max_seq +// 2. 分配sequence时,将cur_seq++,同时与分配上限max_seq比较:如果cur_seq > max_seq, +// 将分配上限提升一个步长max_seq += step,并持久化max_seq +// 3. 重启时,读出持久化的max_seq,赋值给cur_seq // -//struct IDRangeList { -// -//}; +// - 实际应用中每次提升的步长为10000 +const uint64_t kSeqStep = 10000; -struct Section { - uint32_t id_bgein; // 当前section首id -}; +// ## 分号段共享存储 +// > 重启时要读取大量的max_seq数据加载到内存中。 +// - uid相邻的一段用户属于一个号段,而同个号段内的用户共享一个max_seq, +// 这样大幅减少了max_seq数据的大小,同时也降低了IO次数。 +// +// - 目前seqsvr一个Section包含10万个uid,max_seq数据只有300+KB +// 一个Section包含10万个uid,一个uint32_t空间共有42950个Section +const uint32_t kPerSectionIdSize = 100000; -struct SectionSet { - +// 整个uid空间内有多少个section +const uint32_t kMaxSectionSize = (kMaxIDSize%kPerSectionIdSize==0) ? + (kMaxIDSize/kPerSectionIdSize) : + (kMaxIDSize/kPerSectionIdSize)+1; + +// 整个uid空间总计占用section内存 +// 号段为uint64_t +const uint32_t kMaxSectionMemSize = kMaxSectionSize<<3; + +// 整个系统又按uid范围进行分Set,每个Set都是一个完整的、独立的StoreSvr+AllocSvr子系统。 +// 分Set设计目的是为了做灾难隔离,一个Set出现故障只会影响该Set内的用户,而不会影响到其它用户 +// +// @benqi: 实际部署时,按实际服务能力需配置Set数,Set最好由配置文件来定义 +// +// +// set标识符 +// id_begin为set第一个id +// +// 号段一个简单例子 +// 假设用户号段为1~16,有2个set,每个set里分配了2个section,每个section有4个号段 +// +// |0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15| +// |sec_0 |sec_4 |sec_8 |sec_12 | +// | set_0 | set_8 | +// +// 约定,任一服务所有的set_idx, section_idx, id都是基于整个号段空间的 +// + +// ID范围 +struct RangeID { + uint32_t id_begin; // 整个空间 + uint32_t size; // set集合里整个空间大小 }; -#if 0 -// 由id-->set-->cur_seq->max_seq +// section标识符 +// id_begin为section里第一个id +typedef RangeID SectionID; + +typedef RangeID SetID; // set标识符 + +// 计算出set里可以分配多少号段 +inline uint32_t CalcSetSectionSize(uint32_t range_size, + uint32_t per_range_size = kPerSectionIdSize) { + auto m = range_size % per_range_size; + auto sz = range_size / per_range_size; + return m==0 ? sz : sz + 1; +} + +// 计算出set里可以分配多少号段 +inline uint32_t CalcSetSectionSize(SetID set_id, + uint32_t per_range_size = kPerSectionIdSize) { + return CalcSetSectionSize(set_id.size, per_range_size); +} + +// 检查id是否在当前set里 +inline bool CheckIDByRange(RangeID range, uint32_t id) { + return id>=range.id_begin && id CalcSectionID(RangeID range, uint32_t id) { + if (!CheckIDByRange(range, id)) { + return std::make_pair(false, 0); + } - void Initialize(uint64_t max_seq, uint64_t* cur_seqs); + return std::make_pair(true, (id-range.id_begin) / kPerSectionIdSize); +} + +inline std::pair CalcSectionID(uint32_t begin, uint32_t size, uint32_t id) { + RangeID range{begin, size}; + + if (!CheckIDByRange(range, id)) { + return std::make_pair(false, 0); + } - uint64_t GetCurrentSeq(uint32_t id); - uint64_t GetNextSeq(uint32_t id); + return std::make_pair(true, (id-range.id_begin) / kPerSectionIdSize); +} + +// Section只关注是第几个section +struct Section { + Section(uint32_t id_begin, uint64_t* id_max_seq) + : section_id(id_begin), + max_seq(id_max_seq) { + + // 命名:section_name + folly::format(section_name, "section_{}_{}", kMaxSectionSize, id_begin); + } - // 触发max_seq事件 - uint64_t OnMaxSeq(); + ////////////////////////////////////////////////////////////////////////// + // section里分配的第一个id做为section_id + uint32_t section_id; + // section_name命名规则:section_begin(id)_end(id+slot_size-1) + std::string section_name; + // section里的max_seq值 + uint64_t* max_seq {nullptr}; -private: - // uint32_t section_idx_; - uint64_t max_seq_; - folly::Range cur_seqs_; + // 一个section分配了多少个ID + // 不能放到配置文件里,因为是全局共享的,如果配置文件写错了 + // static uint32_t kIDSize; }; -#endif - #endif diff --git a/seqsvr/base/set.cc b/seqsvr/base/set.cc new file mode 100644 index 0000000..3f21c94 --- /dev/null +++ b/seqsvr/base/set.cc @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "base/set.h" + +#include "nebula/base/logger/glog_util.h" + +uint64_t Set::SetMaxSeq(uint32_t id, uint64_t max_seq) { + auto idx = CalcSectionID(set_id, id); + if (!idx.first) { + LOG(ERROR) << "SetSectionsData - max_seq invalid: local seq = " + << id << ", req seq = " << max_seq + << ", in set: " << ToString(); + + return 0; + } + + if (max_seq > set_max_seqs_data[idx.second]) { + max_seq = (max_seq/kSeqStep+1)*kSeqStep; + set_max_seqs_data[idx.second] = max_seq; + } + + return max_seq; +} diff --git a/seqsvr/base/set.h b/seqsvr/base/set.h index d916cf7..404679c 100644 --- a/seqsvr/base/set.h +++ b/seqsvr/base/set.h @@ -15,54 +15,50 @@ * limitations under the License. */ -#ifndef SEQSVR_SET_H_ -#define SEQSVR_SET_H_ +#ifndef BASE_SET_H_ +#define BASE_SET_H_ #include "base/section.h" -#ifndef DEBUG_TEST -// 生产环境 -const uint32_t kSetSize = 1; // 最少3个set -const uint32_t kSetAllocSize = 1; // 1个set分配n个allocsvr -#else -// 为了在开发机上能快速启动、运行和调试 -const uint32_t kSetSize = 1; // 1个set -const uint32_t kSetAllocSize = 1; // 1个set分配n个allocsvr -#endif - -//struct SvrAddr { -// std::string host; // host -// uint16_t port; // port -//}; - -//struct Set { -// uint32_t set_id; // set唯一ID,由运维配置 -// uint32_t id_begin; // set集中第一个id -// uint32_t size; // 整个set管理的id值 -//}; - -#if 0 -// 初始化,通过配置获取 -// void Initialize(uint32_t set_id=1, uint32_t alloc_id=1); -// 当前服务分配给哪个set -// uint32_t GetSetID(); -// 当前Alloc模块 -// uint32_t GetSetAllocID(); - -// 单服务Set单位 -class SetUnit { +// SectionSet +class Set { public: - SetUnit(); - ~SetUnit(); + Set(SetID _set_id, folly::Range data) + : set_id(_set_id), + set_max_seqs_data(data) { + set_max_seqs_data = data; + } + + ~Set() { + set_max_seqs_data.clear(); + } - bool Initialize(uint32_t set_id=1, uint32_t alloc_id=1); + ////////////////////////////////////////////////////////////////////////// + std::string ToString() const { + return folly::sformat("set_{}_{}", set_id.id_begin, set_id.size); + } + + // 对外服务 + // void GetSectionSetData(std::string& data) const { + // data.assign((char*)set_max_seqs_data.data(), set_max_seqs_data.size()*sizeof(uint64_t)); + // } + + SetID GetID() const { + return set_id; + } + + folly::Range GetMaxSeqsData() const { + return set_max_seqs_data; + } + + uint64_t SetMaxSeq(uint32_t id, uint64_t max_seq); + + // uint64_t SetMaxSeq(uint32_t id, uint64_t max_seq); private: - // 当前序号 - std::vector cur_seqs_; - std::vector section_max_seqs_; - std::vector
sections_; + ////////////////////////////////////////////////////////////////////////// + SetID set_id; + folly::Range set_max_seqs_data; }; -#endif #endif diff --git a/seqsvr/base/thrift_util.h b/seqsvr/base/thrift_util.h new file mode 100644 index 0000000..d0e47df --- /dev/null +++ b/seqsvr/base/thrift_util.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_THRIFT_UTIL_H_ +#define BASE_THRIFT_UTIL_H_ + + +#include + +template +inline std::string convertToString(T& t) { + std::string s; + apache::thrift::SimpleJSONSerializer::serialize(t, &s); + return s; +} + +#endif diff --git a/seqsvr/mediatesvr/CMakeLists.txt b/seqsvr/mediatesvr/CMakeLists.txt index 5a780e3..ff93257 100644 --- a/seqsvr/mediatesvr/CMakeLists.txt +++ b/seqsvr/mediatesvr/CMakeLists.txt @@ -17,6 +17,10 @@ include_directories(. .. ../../nebula) set (SRC_LIST + ../../../nebula/nebula/net/base/ip_addr_info.cc + ../../../nebula/nebula/net/base/ip_addr_info.h + ../base/config.cc + ../base/config.h ../base/section.h ../base/set.h ../base/router_table.cc @@ -24,14 +28,11 @@ set (SRC_LIST mediate_server.cc mediate_server.h - mediate_handler.cc - mediate_handler.h - - ../proto/cc/seqsvr.pb.cc - ../proto/cc/seqsvr.pb.h - ../proto/proto/seqsvr.proto - ) + mediate_service_handler.cc + mediate_service_handler.h +) add_executable (mediatesvr ${SRC_LIST}) -target_link_libraries (mediatesvr net base protobuf) +#target_link_libraries (mediatesvr net base protobuf) +target_link_libraries (mediatesvr seqsvr_base base seqsvr_gen-cpp2 boost_system boost_filesystem pthread glog gflags folly thrift thriftcpp2 thriftprotocol zstd ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} dl) diff --git a/seqsvr/mediatesvr/mediate_handler.cc b/seqsvr/mediatesvr/mediate_handler.cc index f423d16..7cdae83 100644 --- a/seqsvr/mediatesvr/mediate_handler.cc +++ b/seqsvr/mediatesvr/mediate_handler.cc @@ -53,9 +53,7 @@ void UpdateRouteTable(const proxygen::HTTPMessage& headers, folly::IOBufQueue* b // AllocSvr加入和移除集群 void AddAllocSvr(const proxygen::HTTPMessage& headers, folly::IOBufQueue*, proxygen::ResponseBuilder* r) { - } void RemoveAllocSvr(const proxygen::HTTPMessage& headers, folly::IOBufQueue*, proxygen::ResponseBuilder* r) { - } diff --git a/seqsvr/mediatesvr/mediate_server.cc b/seqsvr/mediatesvr/mediate_server.cc index e7394f7..b46a9fe 100644 --- a/seqsvr/mediatesvr/mediate_server.cc +++ b/seqsvr/mediatesvr/mediate_server.cc @@ -16,36 +16,37 @@ */ #include "mediatesvr/mediate_server.h" -#include "mediatesvr/mediate_handler.h" +// #include "mediatesvr/mediate_handler.h" -bool MediateServer::Initialize() { +#include "mediatesvr/mediate_service_handler.h" - // 客户端连接服务 - RegisterService("mediate_server", "http_server", "http"); - RegisterService("store_client", "rpc_client", "zrpc"); - BaseServer::Initialize(); - -#if 0 - // one - timer_manager_->ScheduleOneShotTimeout([]() { - LOG(INFO) << "ScheduleOneShotTimeout!!!!"; - }, 1000); - - // once - timer_manager_->ScheduleRepeatingTimeout([]() { - static int i = 0; - LOG(INFO) << "ScheduleRepeatingTimeout - " << i++; - }, 1000); -#endif - +bool MediateServer::Initialize() { return true; } bool MediateServer::Run() { - BaseServer::Run(); + auto handler = std::make_shared(); + server_ = std::make_shared(); + server_->setInterface(handler); + server_->setPort(9090); + + printf("Starting the server...\n"); + server_->serve(); + printf("done.\n"); return true; } +void MediateServer::Quit() { + server_->stop(); +} + +// #include +// #include "base/config.h" + int main(int argc, char* argv[]) { + // auto sets = MakeTestSetsConfig(2); + // auto d = folly::toDynamic(sets); + // folly::PrintTo(d, &std::cout); + return nebula::DoMain(argc, argv); } diff --git a/seqsvr/mediatesvr/mediate_server.h b/seqsvr/mediatesvr/mediate_server.h index 185b29a..f0edf1d 100644 --- a/seqsvr/mediatesvr/mediate_server.h +++ b/seqsvr/mediatesvr/mediate_server.h @@ -19,21 +19,34 @@ #define MEDIATESVR_MEDIATE_SERVER_H_ #include +#include -#include "nebula/net/base_server.h" +#include "nebula/base/base_daemon.h" -// 仲裁服务的一个主要功能探测AllocSvr -// 一般会引入第三方服务,比如etcd或zookeeper +// 仲裁服务的一个主要功能探测AllocSvr: +// 这里需要引入一个仲裁服务,探测AllocSvr的服务状态,决定每个uid段由哪台AllocSvr加载。 +// 出于可靠性的考虑,仲裁模块并不直接操作AllocSvr,而是将加载配置写到StoreSvr持久化, +// 然后AllocSvr定期访问StoreSvr读取最新的加载配置,决定自己的加载状态。 +// +// TODO(@benq): 引入第三方服务,比如etcd或zookeeper // 当前暂不实现AllocSvr探测,提供一个api接口更新StoreSvr里的路由表 -class MediateServer : public nebula::BaseServer { +class MediateServer : public nebula::BaseDaemon { public: MediateServer() = default; ~MediateServer() override = default; protected: - // From BaseServer + // 不使用自动配置框架 + bool LoadConfig(const std::string& config_file) override { + return true; + } + bool Initialize() override; bool Run() override; + void Quit() override; + +private: + std::shared_ptr server_; }; #endif // MEDIATESVR_MEDIATE_SERVER_H_ diff --git a/seqsvr/mediatesvr/mediate_service_handler.cc b/seqsvr/mediatesvr/mediate_service_handler.cc new file mode 100644 index 0000000..0e6705a --- /dev/null +++ b/seqsvr/mediatesvr/mediate_service_handler.cc @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mediatesvr/mediate_service_handler.h" + +// #include "seqsvr/sequence_manager.h" + +//void MediateServiceHandler::RegisterAllocSvr() { +// +//} +// +//void MediateServiceHandler::UnRegisterAllocSvr() { +// +//} +// +//void MediateServiceHandler::UpdateRouteTable(std::unique_ptr router) { +// +//} +// +void MediateServiceHandler::RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) { + +} + +void MediateServiceHandler::UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) { + +} diff --git a/seqsvr/allocsvr/zrpc_alloc_dispatcher.h b/seqsvr/mediatesvr/mediate_service_handler.h similarity index 51% rename from seqsvr/allocsvr/zrpc_alloc_dispatcher.h rename to seqsvr/mediatesvr/mediate_service_handler.h index 4b55cf9..be4a08d 100644 --- a/seqsvr/allocsvr/zrpc_alloc_dispatcher.h +++ b/seqsvr/mediatesvr/mediate_service_handler.h @@ -15,22 +15,23 @@ * limitations under the License. */ -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 +#ifndef MEDIATESVR_MEDIATE_SERVICE_HANDLER_H_ +#define MEDIATESVR_MEDIATE_SERVICE_HANDLER_H_ -#ifndef ALLOCSVR_ZRPC_ALLCO_DISPATCHER_H_ -#define ALLOCSVR_ZRPC_ALLCO_DISPATCHER_H_ +#include "proto/gen-cpp2/MediateService.h" -#include "nebula/net/zproto/zproto_package_data.h" - -class ZRpcAllocDispatcher { +class MediateServiceHandler : public seqsvr::MediateServiceSvIf { public: - ZRpcAllocDispatcher(); - ~ZRpcAllocDispatcher() = default; + MediateServiceHandler() = default; + ~MediateServiceHandler() override = default; + + // void RegisterAllocSvr() override; + // void UnRegisterAllocSvr() override; + // void UpdateRouteTable(std::unique_ptr< ::seqsvr::Router> router) override; - static ProtoRpcResponsePtr FetchNextSequence(RpcRequestPtr request); - static ProtoRpcResponsePtr GetCurrentSequence(RpcRequestPtr request); - static ProtoRpcResponsePtr FetchNextSequenceList(RpcRequestPtr request); - static ProtoRpcResponsePtr GetCurrentSequenceList(RpcRequestPtr request); + void RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) override; + void UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) override; + }; -#endif // ALLOCSVR_ZRPC_ALLCO_DISPATCHER_H_ +#endif diff --git a/seqsvr/proto/CMakeLists.txt b/seqsvr/proto/CMakeLists.txt new file mode 100644 index 0000000..f6af722 --- /dev/null +++ b/seqsvr/proto/CMakeLists.txt @@ -0,0 +1,55 @@ +# Copyright (c) 2016, https://github.com/nebula-im/nebula +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_directories(. .. ../../nebula) + +set (SRC_LIST + seqsvr.thrift + + gen-cpp2/AllocService.cpp + gen-cpp2/AllocService.h + gen-cpp2/AllocService.tcc + gen-cpp2/AllocService_client.cpp + gen-cpp2/AllocService_custom_protocol.h + gen-cpp2/AllocService_processmap_binary.cpp + gen-cpp2/AllocService_processmap_compact.cpp + gen-cpp2/MediateService.cpp + gen-cpp2/MediateService.h + gen-cpp2/MediateService.tcc + gen-cpp2/MediateService_client.cpp + gen-cpp2/MediateService_custom_protocol.h + gen-cpp2/MediateService_processmap_binary.cpp + gen-cpp2/MediateService_processmap_compact.cpp + gen-cpp2/StoreService.cpp + gen-cpp2/StoreService.h + gen-cpp2/StoreService.tcc + gen-cpp2/StoreService_client.cpp + gen-cpp2/StoreService_custom_protocol.h + gen-cpp2/StoreService_processmap_binary.cpp + gen-cpp2/StoreService_processmap_compact.cpp + gen-cpp2/seqsvr_constants.cpp + gen-cpp2/seqsvr_constants.h + gen-cpp2/seqsvr_data.cpp + gen-cpp2/seqsvr_data.h + gen-cpp2/seqsvr_types.cpp + gen-cpp2/seqsvr_types.h + gen-cpp2/seqsvr_types.tcc + gen-cpp2/seqsvr_types_custom_protocol.h + +) + +add_library(seqsvr_gen-cpp2 STATIC ${SRC_LIST}) + diff --git a/seqsvr/proto/build.sh b/seqsvr/proto/build.sh new file mode 100755 index 0000000..d4421b6 --- /dev/null +++ b/seqsvr/proto/build.sh @@ -0,0 +1,2 @@ +python -mthrift_compiler.main --gen cpp2:json -I ../ seqsvr.thrift + diff --git a/seqsvr/proto/gen-cpp2/AllocService.cpp b/seqsvr/proto/gen-cpp2/AllocService.cpp new file mode 100644 index 0000000..79ecbb5 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService.cpp @@ -0,0 +1,88 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "AllocService.h" + +#include "AllocService.tcc" + +#include +#include +#include +#include +namespace seqsvr { + +std::unique_ptr AllocServiceSvIf::getProcessor() { + return std::make_unique(this); +} + +void AllocServiceSvIf::FetchNextSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("FetchNextSequence"); +} + +folly::Future> AllocServiceSvIf::future_FetchNextSequence(int32_t id, int32_t version) { + return apache::thrift::detail::si::future_returning_uptr([&]( ::seqsvr::Sequence& _return) { FetchNextSequence(_return, id, version); }); +} + +void AllocServiceSvIf::async_tm_FetchNextSequence(std::unique_ptr>> callback, int32_t id, int32_t version) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_FetchNextSequence(id, version); }); +} + +void AllocServiceSvIf::GetCurrentSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("GetCurrentSequence"); +} + +folly::Future> AllocServiceSvIf::future_GetCurrentSequence(int32_t id, int32_t version) { + return apache::thrift::detail::si::future_returning_uptr([&]( ::seqsvr::Sequence& _return) { GetCurrentSequence(_return, id, version); }); +} + +void AllocServiceSvIf::async_tm_GetCurrentSequence(std::unique_ptr>> callback, int32_t id, int32_t version) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_GetCurrentSequence(id, version); }); +} + +void AllocServiceSvNull::FetchNextSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/) {} + +void AllocServiceSvNull::GetCurrentSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/) {} + +const char* AllocServiceAsyncProcessor::getServiceName() { + return "AllocService"; +} + +folly::Optional AllocServiceAsyncProcessor::getCacheKey(folly::IOBuf* buf, apache::thrift::protocol::PROTOCOL_TYPES protType) { + return apache::thrift::detail::ap::get_cache_key(buf, protType, cacheKeyMap_); +} + +void AllocServiceAsyncProcessor::process(std::unique_ptr req, std::unique_ptr buf, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + apache::thrift::detail::ap::process(this, std::move(req), std::move(buf), protType, context, eb, tm); +} + +bool AllocServiceAsyncProcessor::isOnewayMethod(const folly::IOBuf* buf, const apache::thrift::transport::THeader* header) { + return apache::thrift::detail::ap::is_oneway_method(buf, header, onewayMethods_); +} + +std::unordered_set AllocServiceAsyncProcessor::onewayMethods_ {}; +std::unordered_map AllocServiceAsyncProcessor::cacheKeyMap_ {}; +const AllocServiceAsyncProcessor::BinaryProtocolProcessMap& AllocServiceAsyncProcessor::getBinaryProtocolProcessMap() { + return binaryProcessMap_; +} + +const AllocServiceAsyncProcessor::BinaryProtocolProcessMap AllocServiceAsyncProcessor::binaryProcessMap_ { + {"FetchNextSequence", &AllocServiceAsyncProcessor::_processInThread_FetchNextSequence}, + {"GetCurrentSequence", &AllocServiceAsyncProcessor::_processInThread_GetCurrentSequence}, +}; + +const AllocServiceAsyncProcessor::CompactProtocolProcessMap& AllocServiceAsyncProcessor::getCompactProtocolProcessMap() { + return compactProcessMap_; +} + +const AllocServiceAsyncProcessor::CompactProtocolProcessMap AllocServiceAsyncProcessor::compactProcessMap_ { + {"FetchNextSequence", &AllocServiceAsyncProcessor::_processInThread_FetchNextSequence}, + {"GetCurrentSequence", &AllocServiceAsyncProcessor::_processInThread_GetCurrentSequence}, +}; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/AllocService.h b/seqsvr/proto/gen-cpp2/AllocService.h new file mode 100644 index 0000000..d84ec74 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService.h @@ -0,0 +1,185 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include +#include +#include +#include +#include + + + +#include "seqsvr_types.h" + +namespace folly { + class IOBuf; + class IOBufQueue; +} +namespace apache { namespace thrift { + class Cpp2RequestContext; + class BinaryProtocolReader; + class CompactProtocolReader; + namespace transport { class THeader; } +}} + +namespace seqsvr { + +class AllocServiceSvAsyncIf { + public: + virtual ~AllocServiceSvAsyncIf() {} + virtual void async_tm_FetchNextSequence(std::unique_ptr>> callback, int32_t id, int32_t version) = 0; + // virtual void async_FetchNextSequence(std::unique_ptr>> callback, int32_t id, int32_t version) = delete; + virtual folly::Future> future_FetchNextSequence(int32_t id, int32_t version) = 0; + virtual void async_tm_GetCurrentSequence(std::unique_ptr>> callback, int32_t id, int32_t version) = 0; + // virtual void async_GetCurrentSequence(std::unique_ptr>> callback, int32_t id, int32_t version) = delete; + virtual folly::Future> future_GetCurrentSequence(int32_t id, int32_t version) = 0; +}; + +class AllocServiceAsyncProcessor; + +class AllocServiceSvIf : public AllocServiceSvAsyncIf, public apache::thrift::ServerInterface { + public: + typedef AllocServiceAsyncProcessor ProcessorType; + std::unique_ptr getProcessor() override; + virtual void FetchNextSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/); + folly::Future> future_FetchNextSequence(int32_t id, int32_t version) override; + void async_tm_FetchNextSequence(std::unique_ptr>> callback, int32_t id, int32_t version) override; + virtual void GetCurrentSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/); + folly::Future> future_GetCurrentSequence(int32_t id, int32_t version) override; + void async_tm_GetCurrentSequence(std::unique_ptr>> callback, int32_t id, int32_t version) override; +}; + +class AllocServiceSvNull : public AllocServiceSvIf { + public: + void FetchNextSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/) override; + void GetCurrentSequence( ::seqsvr::Sequence& /*_return*/, int32_t /*id*/, int32_t /*version*/) override; +}; + +class AllocServiceAsyncProcessor : public ::apache::thrift::GeneratedAsyncProcessor { + public: + const char* getServiceName() override; + using BaseAsyncProcessor = void; + using HasFrozen2 = std::false_type; + protected: + AllocServiceSvIf* iface_; + folly::Optional getCacheKey(folly::IOBuf* buf, apache::thrift::protocol::PROTOCOL_TYPES protType) override; + public: + void process(std::unique_ptr req, std::unique_ptr buf, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) override; + protected: + bool isOnewayMethod(const folly::IOBuf* buf, const apache::thrift::transport::THeader* header) override; + private: + static std::unordered_set onewayMethods_; + static std::unordered_map cacheKeyMap_; + public: + using BinaryProtocolProcessFunc = ProcessFunc; + using BinaryProtocolProcessMap = ProcessMap; + static const AllocServiceAsyncProcessor::BinaryProtocolProcessMap& getBinaryProtocolProcessMap(); + private: + static const AllocServiceAsyncProcessor::BinaryProtocolProcessMap binaryProcessMap_; + public: + using CompactProtocolProcessFunc = ProcessFunc; + using CompactProtocolProcessMap = ProcessMap; + static const AllocServiceAsyncProcessor::CompactProtocolProcessMap& getCompactProtocolProcessMap(); + private: + static const AllocServiceAsyncProcessor::CompactProtocolProcessMap compactProcessMap_; + private: + template + void _processInThread_FetchNextSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_FetchNextSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_FetchNextSequence(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::Sequence const& _return); + template + static void throw_wrapped_FetchNextSequence(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + template + void _processInThread_GetCurrentSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_GetCurrentSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_GetCurrentSequence(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::Sequence const& _return); + template + static void throw_wrapped_GetCurrentSequence(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + public: + AllocServiceAsyncProcessor(AllocServiceSvIf* iface) : + iface_(iface) {} + + virtual ~AllocServiceAsyncProcessor() {} +}; + +class AllocServiceAsyncClient : public apache::thrift::TClientBase { + public: + virtual const char* getServiceName(); + typedef std::unique_ptr channel_ptr; + + virtual ~AllocServiceAsyncClient() {} + + AllocServiceAsyncClient(std::shared_ptr channel) : + channel_(channel) { + connectionContext_.reset(new apache::thrift::Cpp2ConnContext); + } + + apache::thrift::RequestChannel* getChannel() { + return this->channel_.get(); + } + + apache::thrift::HeaderChannel* getHeaderChannel() { + return dynamic_cast(this->channel_.get()); + } + virtual void FetchNextSequence(std::unique_ptr callback, int32_t id, int32_t version); + virtual void FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version); + private: + virtual void FetchNextSequenceImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version); + public: + virtual void sync_FetchNextSequence( ::seqsvr::Sequence& _return, int32_t id, int32_t version); + virtual void sync_FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::Sequence& _return, int32_t id, int32_t version); + virtual folly::Future< ::seqsvr::Sequence> future_FetchNextSequence(int32_t id, int32_t version); + virtual folly::Future< ::seqsvr::Sequence> future_FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version); + virtual folly::Future>> header_future_FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version); + virtual void FetchNextSequence(folly::Function callback, int32_t id, int32_t version); + static folly::exception_wrapper recv_wrapped_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + static void recv_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual void recv_instance_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + template + void FetchNextSequenceT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version); + template + static folly::exception_wrapper recv_wrapped_FetchNextSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + template + static void recv_FetchNextSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + virtual void GetCurrentSequence(std::unique_ptr callback, int32_t id, int32_t version); + virtual void GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version); + private: + virtual void GetCurrentSequenceImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version); + public: + virtual void sync_GetCurrentSequence( ::seqsvr::Sequence& _return, int32_t id, int32_t version); + virtual void sync_GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::Sequence& _return, int32_t id, int32_t version); + virtual folly::Future< ::seqsvr::Sequence> future_GetCurrentSequence(int32_t id, int32_t version); + virtual folly::Future< ::seqsvr::Sequence> future_GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version); + virtual folly::Future>> header_future_GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version); + virtual void GetCurrentSequence(folly::Function callback, int32_t id, int32_t version); + static folly::exception_wrapper recv_wrapped_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + static void recv_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual void recv_instance_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + template + void GetCurrentSequenceT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version); + template + static folly::exception_wrapper recv_wrapped_GetCurrentSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + template + static void recv_GetCurrentSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state); + protected: + std::unique_ptr connectionContext_; + std::shared_ptr channel_; +}; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/AllocService.tcc b/seqsvr/proto/gen-cpp2/AllocService.tcc new file mode 100644 index 0000000..918348a --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService.tcc @@ -0,0 +1,351 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include "AllocService.h" +#include +#include +#include +#include +#include +#include +#include + +namespace seqsvr { + +typedef apache::thrift::ThriftPresult, apache::thrift::FieldData<2, apache::thrift::protocol::T_I32, int32_t*>> AllocService_FetchNextSequence_pargs; +typedef apache::thrift::ThriftPresult> AllocService_FetchNextSequence_presult; +typedef apache::thrift::ThriftPresult, apache::thrift::FieldData<2, apache::thrift::protocol::T_I32, int32_t*>> AllocService_GetCurrentSequence_pargs; +typedef apache::thrift::ThriftPresult> AllocService_GetCurrentSequence_presult; +template +void AllocServiceAsyncProcessor::_processInThread_FetchNextSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &AllocServiceAsyncProcessor::process_FetchNextSequence, this); +} + +template +void AllocServiceAsyncProcessor::process_FetchNextSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + AllocService_FetchNextSequence_pargs args; + int32_t uarg_id{0}; + args.get<0>().value = &uarg_id; + int32_t uarg_version{0}; + args.get<1>().value = &uarg_version; + std::unique_ptr c(this->getContextStack(this->getServiceName(), "AllocService.FetchNextSequence", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function FetchNextSequence"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("FetchNextSequence", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function FetchNextSequence"; + } + } + auto callback = std::make_unique>>(std::move(req), std::move(c), return_FetchNextSequence, throw_wrapped_FetchNextSequence, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_FetchNextSequence(std::move(callback), args.get<0>().ref(), args.get<1>().ref()); +} + +template +folly::IOBufQueue AllocServiceAsyncProcessor::return_FetchNextSequence(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::Sequence const& _return) { + ProtocolOut_ prot; + AllocService_FetchNextSequence_presult result; + result.get<0>().value = const_cast< ::seqsvr::Sequence*>(&_return); + result.setIsSet(0, true); + return serializeResponse("FetchNextSequence", &prot, protoSeqId, ctx, result); +} + +template +void AllocServiceAsyncProcessor::throw_wrapped_FetchNextSequence(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function FetchNextSequence"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("FetchNextSequence", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function FetchNextSequence"; + } + } +} + +template +void AllocServiceAsyncProcessor::_processInThread_GetCurrentSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &AllocServiceAsyncProcessor::process_GetCurrentSequence, this); +} + +template +void AllocServiceAsyncProcessor::process_GetCurrentSequence(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + AllocService_GetCurrentSequence_pargs args; + int32_t uarg_id{0}; + args.get<0>().value = &uarg_id; + int32_t uarg_version{0}; + args.get<1>().value = &uarg_version; + std::unique_ptr c(this->getContextStack(this->getServiceName(), "AllocService.GetCurrentSequence", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function GetCurrentSequence"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("GetCurrentSequence", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function GetCurrentSequence"; + } + } + auto callback = std::make_unique>>(std::move(req), std::move(c), return_GetCurrentSequence, throw_wrapped_GetCurrentSequence, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_GetCurrentSequence(std::move(callback), args.get<0>().ref(), args.get<1>().ref()); +} + +template +folly::IOBufQueue AllocServiceAsyncProcessor::return_GetCurrentSequence(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::Sequence const& _return) { + ProtocolOut_ prot; + AllocService_GetCurrentSequence_presult result; + result.get<0>().value = const_cast< ::seqsvr::Sequence*>(&_return); + result.setIsSet(0, true); + return serializeResponse("GetCurrentSequence", &prot, protoSeqId, ctx, result); +} + +template +void AllocServiceAsyncProcessor::throw_wrapped_GetCurrentSequence(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function GetCurrentSequence"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("GetCurrentSequence", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function GetCurrentSequence"; + } + } +} + +template +void AllocServiceAsyncClient::FetchNextSequenceT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "AllocService.FetchNextSequence", connectionContext_.get()); + AllocService_FetchNextSequence_pargs args; + args.get<0>().value = &id; + args.get<1>().value = &version; + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "FetchNextSequence", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper AllocServiceAsyncClient::recv_wrapped_FetchNextSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("FetchNextSequence") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + AllocService_FetchNextSequence_presult result; + result.get<0>().value = &_return; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + if (result.getIsSet(0)) { + // _return pointer has been filled + return; // from try_and_catch + } + else { + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::MISSING_RESULT, "failed: unknown result"); + return; // from try_and_catch + } + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +void AllocServiceAsyncClient::recv_FetchNextSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_FetchNextSequenceT(prot, _return, state); + if (ew) { + ew.throw_exception(); + } +} + +template +void AllocServiceAsyncClient::GetCurrentSequenceT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "AllocService.GetCurrentSequence", connectionContext_.get()); + AllocService_GetCurrentSequence_pargs args; + args.get<0>().value = &id; + args.get<1>().value = &version; + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "GetCurrentSequence", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper AllocServiceAsyncClient::recv_wrapped_GetCurrentSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("GetCurrentSequence") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + AllocService_GetCurrentSequence_presult result; + result.get<0>().value = &_return; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + if (result.getIsSet(0)) { + // _return pointer has been filled + return; // from try_and_catch + } + else { + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::MISSING_RESULT, "failed: unknown result"); + return; // from try_and_catch + } + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +void AllocServiceAsyncClient::recv_GetCurrentSequenceT(Protocol_* prot, ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_GetCurrentSequenceT(prot, _return, state); + if (ew) { + ew.throw_exception(); + } +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/AllocService_client.cpp b/seqsvr/proto/gen-cpp2/AllocService_client.cpp new file mode 100644 index 0000000..2161aed --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService_client.cpp @@ -0,0 +1,255 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "AllocService.h" + +#include "AllocService.tcc" + +#include +#include +#include +namespace seqsvr { + +const char* AllocServiceAsyncClient::getServiceName() { + return "AllocService"; +} + +void AllocServiceAsyncClient::FetchNextSequence(std::unique_ptr callback, int32_t id, int32_t version) { + ::apache::thrift::RpcOptions rpcOptions; + FetchNextSequenceImpl(false, rpcOptions, std::move(callback), id, version); +} + +void AllocServiceAsyncClient::FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version) { + FetchNextSequenceImpl(false, rpcOptions, std::move(callback), id, version); +} + +void AllocServiceAsyncClient::FetchNextSequenceImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + FetchNextSequenceT(&writer, useSync, rpcOptions, std::move(callback), id, version); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + FetchNextSequenceT(&writer, useSync, rpcOptions, std::move(callback), id, version); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +void AllocServiceAsyncClient::sync_FetchNextSequence( ::seqsvr::Sequence& _return, int32_t id, int32_t version) { + ::apache::thrift::RpcOptions rpcOptions; + sync_FetchNextSequence(rpcOptions, _return, id, version); +} + +void AllocServiceAsyncClient::sync_FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::Sequence& _return, int32_t id, int32_t version) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + FetchNextSequenceImpl(true, rpcOptions, std::move(callback), id, version); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + recv_FetchNextSequence(_return, _returnState); +} + +folly::Future< ::seqsvr::Sequence> AllocServiceAsyncClient::future_FetchNextSequence(int32_t id, int32_t version) { + ::apache::thrift::RpcOptions rpcOptions; + return future_FetchNextSequence(rpcOptions, id, version); +} + +folly::Future< ::seqsvr::Sequence> AllocServiceAsyncClient::future_FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version) { + folly::Promise< ::seqsvr::Sequence> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_FetchNextSequence, channel_); + FetchNextSequence(rpcOptions, std::move(callback), id, version); + return _future; +} + +folly::Future>> AllocServiceAsyncClient::header_future_FetchNextSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_FetchNextSequence, channel_); + FetchNextSequence(rpcOptions, std::move(callback), id, version); + return _future; +} + +void AllocServiceAsyncClient::FetchNextSequence(folly::Function callback, int32_t id, int32_t version) { + FetchNextSequence(std::make_unique(std::move(callback)), id, version); +} + +folly::exception_wrapper AllocServiceAsyncClient::recv_wrapped_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_FetchNextSequenceT(&reader, _return, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_FetchNextSequenceT(&reader, _return, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +void AllocServiceAsyncClient::recv_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_FetchNextSequence(_return, state); + if (ew) { + ew.throw_exception(); + } +} + +void AllocServiceAsyncClient::recv_instance_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_FetchNextSequence(_return, state); +} + +folly::exception_wrapper AllocServiceAsyncClient::recv_instance_wrapped_FetchNextSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_FetchNextSequence(_return, state); +} + +void AllocServiceAsyncClient::GetCurrentSequence(std::unique_ptr callback, int32_t id, int32_t version) { + ::apache::thrift::RpcOptions rpcOptions; + GetCurrentSequenceImpl(false, rpcOptions, std::move(callback), id, version); +} + +void AllocServiceAsyncClient::GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version) { + GetCurrentSequenceImpl(false, rpcOptions, std::move(callback), id, version); +} + +void AllocServiceAsyncClient::GetCurrentSequenceImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int32_t version) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + GetCurrentSequenceT(&writer, useSync, rpcOptions, std::move(callback), id, version); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + GetCurrentSequenceT(&writer, useSync, rpcOptions, std::move(callback), id, version); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +void AllocServiceAsyncClient::sync_GetCurrentSequence( ::seqsvr::Sequence& _return, int32_t id, int32_t version) { + ::apache::thrift::RpcOptions rpcOptions; + sync_GetCurrentSequence(rpcOptions, _return, id, version); +} + +void AllocServiceAsyncClient::sync_GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::Sequence& _return, int32_t id, int32_t version) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + GetCurrentSequenceImpl(true, rpcOptions, std::move(callback), id, version); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + recv_GetCurrentSequence(_return, _returnState); +} + +folly::Future< ::seqsvr::Sequence> AllocServiceAsyncClient::future_GetCurrentSequence(int32_t id, int32_t version) { + ::apache::thrift::RpcOptions rpcOptions; + return future_GetCurrentSequence(rpcOptions, id, version); +} + +folly::Future< ::seqsvr::Sequence> AllocServiceAsyncClient::future_GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version) { + folly::Promise< ::seqsvr::Sequence> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_GetCurrentSequence, channel_); + GetCurrentSequence(rpcOptions, std::move(callback), id, version); + return _future; +} + +folly::Future>> AllocServiceAsyncClient::header_future_GetCurrentSequence(apache::thrift::RpcOptions& rpcOptions, int32_t id, int32_t version) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_GetCurrentSequence, channel_); + GetCurrentSequence(rpcOptions, std::move(callback), id, version); + return _future; +} + +void AllocServiceAsyncClient::GetCurrentSequence(folly::Function callback, int32_t id, int32_t version) { + GetCurrentSequence(std::make_unique(std::move(callback)), id, version); +} + +folly::exception_wrapper AllocServiceAsyncClient::recv_wrapped_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_GetCurrentSequenceT(&reader, _return, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_GetCurrentSequenceT(&reader, _return, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +void AllocServiceAsyncClient::recv_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_GetCurrentSequence(_return, state); + if (ew) { + ew.throw_exception(); + } +} + +void AllocServiceAsyncClient::recv_instance_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_GetCurrentSequence(_return, state); +} + +folly::exception_wrapper AllocServiceAsyncClient::recv_instance_wrapped_GetCurrentSequence( ::seqsvr::Sequence& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_GetCurrentSequence(_return, state); +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/AllocService_custom_protocol.h b/seqsvr/proto/gen-cpp2/AllocService_custom_protocol.h new file mode 100644 index 0000000..a0d8174 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService_custom_protocol.h @@ -0,0 +1,19 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + + +/** + * This header file includes the tcc files of the corresponding header file + * and the header files of its dependent types. Include this header file + * only when you need to use custom protocols (e.g. DebugProtocol, + * VirtualProtocol) to read/write thrift structs. + */ + +#include "AllocService.tcc" + +#include "seqsvr_types_custom_protocol.h" diff --git a/seqsvr/proto/gen-cpp2/AllocService_processmap_binary.cpp b/seqsvr/proto/gen-cpp2/AllocService_processmap_binary.cpp new file mode 100644 index 0000000..70067a4 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService_processmap_binary.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "AllocService.h" + +#include "AllocService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/AllocService_processmap_compact.cpp b/seqsvr/proto/gen-cpp2/AllocService_processmap_compact.cpp new file mode 100644 index 0000000..70067a4 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService_processmap_compact.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "AllocService.h" + +#include "AllocService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/AllocService_processmap_simple_json.cpp b/seqsvr/proto/gen-cpp2/AllocService_processmap_simple_json.cpp new file mode 100644 index 0000000..70067a4 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/AllocService_processmap_simple_json.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "AllocService.h" + +#include "AllocService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/MediateService.cpp b/seqsvr/proto/gen-cpp2/MediateService.cpp new file mode 100644 index 0000000..d0751c1 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService.cpp @@ -0,0 +1,88 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "MediateService.h" + +#include "MediateService.tcc" + +#include +#include +#include +#include +namespace seqsvr { + +std::unique_ptr MediateServiceSvIf::getProcessor() { + return std::make_unique(this); +} + +void MediateServiceSvIf::RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("RegisterAllocSvr"); +} + +folly::Future MediateServiceSvIf::future_RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) { + return apache::thrift::detail::si::future([&] { return RegisterAllocSvr(std::move(node_addr)); }); +} + +void MediateServiceSvIf::async_tm_RegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_RegisterAllocSvr(std::move(node_addr)); }); +} + +void MediateServiceSvIf::UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("UnRegisterAllocSvr"); +} + +folly::Future MediateServiceSvIf::future_UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) { + return apache::thrift::detail::si::future([&] { return UnRegisterAllocSvr(std::move(node_addr)); }); +} + +void MediateServiceSvIf::async_tm_UnRegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_UnRegisterAllocSvr(std::move(node_addr)); }); +} + +void MediateServiceSvNull::RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/) {} + +void MediateServiceSvNull::UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/) {} + +const char* MediateServiceAsyncProcessor::getServiceName() { + return "MediateService"; +} + +folly::Optional MediateServiceAsyncProcessor::getCacheKey(folly::IOBuf* buf, apache::thrift::protocol::PROTOCOL_TYPES protType) { + return apache::thrift::detail::ap::get_cache_key(buf, protType, cacheKeyMap_); +} + +void MediateServiceAsyncProcessor::process(std::unique_ptr req, std::unique_ptr buf, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + apache::thrift::detail::ap::process(this, std::move(req), std::move(buf), protType, context, eb, tm); +} + +bool MediateServiceAsyncProcessor::isOnewayMethod(const folly::IOBuf* buf, const apache::thrift::transport::THeader* header) { + return apache::thrift::detail::ap::is_oneway_method(buf, header, onewayMethods_); +} + +std::unordered_set MediateServiceAsyncProcessor::onewayMethods_ {}; +std::unordered_map MediateServiceAsyncProcessor::cacheKeyMap_ {}; +const MediateServiceAsyncProcessor::BinaryProtocolProcessMap& MediateServiceAsyncProcessor::getBinaryProtocolProcessMap() { + return binaryProcessMap_; +} + +const MediateServiceAsyncProcessor::BinaryProtocolProcessMap MediateServiceAsyncProcessor::binaryProcessMap_ { + {"RegisterAllocSvr", &MediateServiceAsyncProcessor::_processInThread_RegisterAllocSvr}, + {"UnRegisterAllocSvr", &MediateServiceAsyncProcessor::_processInThread_UnRegisterAllocSvr}, +}; + +const MediateServiceAsyncProcessor::CompactProtocolProcessMap& MediateServiceAsyncProcessor::getCompactProtocolProcessMap() { + return compactProcessMap_; +} + +const MediateServiceAsyncProcessor::CompactProtocolProcessMap MediateServiceAsyncProcessor::compactProcessMap_ { + {"RegisterAllocSvr", &MediateServiceAsyncProcessor::_processInThread_RegisterAllocSvr}, + {"UnRegisterAllocSvr", &MediateServiceAsyncProcessor::_processInThread_UnRegisterAllocSvr}, +}; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/MediateService.h b/seqsvr/proto/gen-cpp2/MediateService.h new file mode 100644 index 0000000..3478f1d --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService.h @@ -0,0 +1,185 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include +#include +#include +#include +#include + + + +#include "seqsvr_types.h" + +namespace folly { + class IOBuf; + class IOBufQueue; +} +namespace apache { namespace thrift { + class Cpp2RequestContext; + class BinaryProtocolReader; + class CompactProtocolReader; + namespace transport { class THeader; } +}} + +namespace seqsvr { + +class MediateServiceSvAsyncIf { + public: + virtual ~MediateServiceSvAsyncIf() {} + virtual void async_tm_RegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) = 0; + // virtual void async_RegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) = delete; + virtual folly::Future future_RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) = 0; + virtual void async_tm_UnRegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) = 0; + // virtual void async_UnRegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) = delete; + virtual folly::Future future_UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) = 0; +}; + +class MediateServiceAsyncProcessor; + +class MediateServiceSvIf : public MediateServiceSvAsyncIf, public apache::thrift::ServerInterface { + public: + typedef MediateServiceAsyncProcessor ProcessorType; + std::unique_ptr getProcessor() override; + virtual void RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/); + folly::Future future_RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) override; + void async_tm_RegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) override; + virtual void UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/); + folly::Future future_UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) override; + void async_tm_UnRegisterAllocSvr(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::NodeAddrInfo> node_addr) override; +}; + +class MediateServiceSvNull : public MediateServiceSvIf { + public: + void RegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/) override; + void UnRegisterAllocSvr(std::unique_ptr< ::seqsvr::NodeAddrInfo> /*node_addr*/) override; +}; + +class MediateServiceAsyncProcessor : public ::apache::thrift::GeneratedAsyncProcessor { + public: + const char* getServiceName() override; + using BaseAsyncProcessor = void; + using HasFrozen2 = std::false_type; + protected: + MediateServiceSvIf* iface_; + folly::Optional getCacheKey(folly::IOBuf* buf, apache::thrift::protocol::PROTOCOL_TYPES protType) override; + public: + void process(std::unique_ptr req, std::unique_ptr buf, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) override; + protected: + bool isOnewayMethod(const folly::IOBuf* buf, const apache::thrift::transport::THeader* header) override; + private: + static std::unordered_set onewayMethods_; + static std::unordered_map cacheKeyMap_; + public: + using BinaryProtocolProcessFunc = ProcessFunc; + using BinaryProtocolProcessMap = ProcessMap; + static const MediateServiceAsyncProcessor::BinaryProtocolProcessMap& getBinaryProtocolProcessMap(); + private: + static const MediateServiceAsyncProcessor::BinaryProtocolProcessMap binaryProcessMap_; + public: + using CompactProtocolProcessFunc = ProcessFunc; + using CompactProtocolProcessMap = ProcessMap; + static const MediateServiceAsyncProcessor::CompactProtocolProcessMap& getCompactProtocolProcessMap(); + private: + static const MediateServiceAsyncProcessor::CompactProtocolProcessMap compactProcessMap_; + private: + template + void _processInThread_RegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_RegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_RegisterAllocSvr(int32_t protoSeqId, apache::thrift::ContextStack* ctx); + template + static void throw_wrapped_RegisterAllocSvr(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + template + void _processInThread_UnRegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_UnRegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_UnRegisterAllocSvr(int32_t protoSeqId, apache::thrift::ContextStack* ctx); + template + static void throw_wrapped_UnRegisterAllocSvr(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + public: + MediateServiceAsyncProcessor(MediateServiceSvIf* iface) : + iface_(iface) {} + + virtual ~MediateServiceAsyncProcessor() {} +}; + +class MediateServiceAsyncClient : public apache::thrift::TClientBase { + public: + virtual const char* getServiceName(); + typedef std::unique_ptr channel_ptr; + + virtual ~MediateServiceAsyncClient() {} + + MediateServiceAsyncClient(std::shared_ptr channel) : + channel_(channel) { + connectionContext_.reset(new apache::thrift::Cpp2ConnContext); + } + + apache::thrift::RequestChannel* getChannel() { + return this->channel_.get(); + } + + apache::thrift::HeaderChannel* getHeaderChannel() { + return dynamic_cast(this->channel_.get()); + } + virtual void RegisterAllocSvr(std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + virtual void RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + private: + virtual void RegisterAllocSvrImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + public: + virtual void sync_RegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr); + virtual void sync_RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr); + virtual folly::Future future_RegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr); + virtual folly::Future future_RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr); + virtual folly::Future>> header_future_RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr); + virtual void RegisterAllocSvr(folly::Function callback, const ::seqsvr::NodeAddrInfo& node_addr); + static folly::exception_wrapper recv_wrapped_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + static void recv_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual void recv_instance_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + template + void RegisterAllocSvrT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + template + static folly::exception_wrapper recv_wrapped_RegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state); + template + static void recv_RegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state); + virtual void UnRegisterAllocSvr(std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + virtual void UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + private: + virtual void UnRegisterAllocSvrImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + public: + virtual void sync_UnRegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr); + virtual void sync_UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr); + virtual folly::Future future_UnRegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr); + virtual folly::Future future_UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr); + virtual folly::Future>> header_future_UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr); + virtual void UnRegisterAllocSvr(folly::Function callback, const ::seqsvr::NodeAddrInfo& node_addr); + static folly::exception_wrapper recv_wrapped_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + static void recv_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual void recv_instance_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state); + template + void UnRegisterAllocSvrT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr); + template + static folly::exception_wrapper recv_wrapped_UnRegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state); + template + static void recv_UnRegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state); + protected: + std::unique_ptr connectionContext_; + std::shared_ptr channel_; +}; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/MediateService.tcc b/seqsvr/proto/gen-cpp2/MediateService.tcc new file mode 100644 index 0000000..1a761fa --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService.tcc @@ -0,0 +1,323 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include "MediateService.h" +#include +#include +#include +#include +#include +#include +#include + +namespace seqsvr { + +typedef apache::thrift::ThriftPresult> MediateService_RegisterAllocSvr_pargs; +typedef apache::thrift::ThriftPresult MediateService_RegisterAllocSvr_presult; +typedef apache::thrift::ThriftPresult> MediateService_UnRegisterAllocSvr_pargs; +typedef apache::thrift::ThriftPresult MediateService_UnRegisterAllocSvr_presult; +template +void MediateServiceAsyncProcessor::_processInThread_RegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &MediateServiceAsyncProcessor::process_RegisterAllocSvr, this); +} + +template +void MediateServiceAsyncProcessor::process_RegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + MediateService_RegisterAllocSvr_pargs args; + std::unique_ptr< ::seqsvr::NodeAddrInfo> uarg_node_addr(new ::seqsvr::NodeAddrInfo()); + args.get<0>().value = uarg_node_addr.get(); + std::unique_ptr c(this->getContextStack(this->getServiceName(), "MediateService.RegisterAllocSvr", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function RegisterAllocSvr"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("RegisterAllocSvr", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function RegisterAllocSvr"; + } + } + auto callback = std::make_unique>(std::move(req), std::move(c), return_RegisterAllocSvr, throw_wrapped_RegisterAllocSvr, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_RegisterAllocSvr(std::move(callback), std::move(uarg_node_addr)); +} + +template +folly::IOBufQueue MediateServiceAsyncProcessor::return_RegisterAllocSvr(int32_t protoSeqId, apache::thrift::ContextStack* ctx) { + ProtocolOut_ prot; + MediateService_RegisterAllocSvr_presult result; + return serializeResponse("RegisterAllocSvr", &prot, protoSeqId, ctx, result); +} + +template +void MediateServiceAsyncProcessor::throw_wrapped_RegisterAllocSvr(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function RegisterAllocSvr"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("RegisterAllocSvr", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function RegisterAllocSvr"; + } + } +} + +template +void MediateServiceAsyncProcessor::_processInThread_UnRegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &MediateServiceAsyncProcessor::process_UnRegisterAllocSvr, this); +} + +template +void MediateServiceAsyncProcessor::process_UnRegisterAllocSvr(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + MediateService_UnRegisterAllocSvr_pargs args; + std::unique_ptr< ::seqsvr::NodeAddrInfo> uarg_node_addr(new ::seqsvr::NodeAddrInfo()); + args.get<0>().value = uarg_node_addr.get(); + std::unique_ptr c(this->getContextStack(this->getServiceName(), "MediateService.UnRegisterAllocSvr", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function UnRegisterAllocSvr"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("UnRegisterAllocSvr", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function UnRegisterAllocSvr"; + } + } + auto callback = std::make_unique>(std::move(req), std::move(c), return_UnRegisterAllocSvr, throw_wrapped_UnRegisterAllocSvr, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_UnRegisterAllocSvr(std::move(callback), std::move(uarg_node_addr)); +} + +template +folly::IOBufQueue MediateServiceAsyncProcessor::return_UnRegisterAllocSvr(int32_t protoSeqId, apache::thrift::ContextStack* ctx) { + ProtocolOut_ prot; + MediateService_UnRegisterAllocSvr_presult result; + return serializeResponse("UnRegisterAllocSvr", &prot, protoSeqId, ctx, result); +} + +template +void MediateServiceAsyncProcessor::throw_wrapped_UnRegisterAllocSvr(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function UnRegisterAllocSvr"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("UnRegisterAllocSvr", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function UnRegisterAllocSvr"; + } + } +} + +template +void MediateServiceAsyncClient::RegisterAllocSvrT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "MediateService.RegisterAllocSvr", connectionContext_.get()); + MediateService_RegisterAllocSvr_pargs args; + args.get<0>().value = const_cast< ::seqsvr::NodeAddrInfo*>(&node_addr); + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "RegisterAllocSvr", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper MediateServiceAsyncClient::recv_wrapped_RegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("RegisterAllocSvr") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + MediateService_RegisterAllocSvr_presult result; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +void MediateServiceAsyncClient::recv_RegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_RegisterAllocSvrT(prot, state); + if (ew) { + ew.throw_exception(); + } +} + +template +void MediateServiceAsyncClient::UnRegisterAllocSvrT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "MediateService.UnRegisterAllocSvr", connectionContext_.get()); + MediateService_UnRegisterAllocSvr_pargs args; + args.get<0>().value = const_cast< ::seqsvr::NodeAddrInfo*>(&node_addr); + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "UnRegisterAllocSvr", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper MediateServiceAsyncClient::recv_wrapped_UnRegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("UnRegisterAllocSvr") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + MediateService_UnRegisterAllocSvr_presult result; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +void MediateServiceAsyncClient::recv_UnRegisterAllocSvrT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_UnRegisterAllocSvrT(prot, state); + if (ew) { + ew.throw_exception(); + } +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/MediateService_client.cpp b/seqsvr/proto/gen-cpp2/MediateService_client.cpp new file mode 100644 index 0000000..a766ab5 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService_client.cpp @@ -0,0 +1,255 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "MediateService.h" + +#include "MediateService.tcc" + +#include +#include +#include +namespace seqsvr { + +const char* MediateServiceAsyncClient::getServiceName() { + return "MediateService"; +} + +void MediateServiceAsyncClient::RegisterAllocSvr(std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + ::apache::thrift::RpcOptions rpcOptions; + RegisterAllocSvrImpl(false, rpcOptions, std::move(callback), node_addr); +} + +void MediateServiceAsyncClient::RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + RegisterAllocSvrImpl(false, rpcOptions, std::move(callback), node_addr); +} + +void MediateServiceAsyncClient::RegisterAllocSvrImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + RegisterAllocSvrT(&writer, useSync, rpcOptions, std::move(callback), node_addr); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + RegisterAllocSvrT(&writer, useSync, rpcOptions, std::move(callback), node_addr); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +void MediateServiceAsyncClient::sync_RegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr) { + ::apache::thrift::RpcOptions rpcOptions; + sync_RegisterAllocSvr(rpcOptions, node_addr); +} + +void MediateServiceAsyncClient::sync_RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + RegisterAllocSvrImpl(true, rpcOptions, std::move(callback), node_addr); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + recv_RegisterAllocSvr(_returnState); +} + +folly::Future MediateServiceAsyncClient::future_RegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr) { + ::apache::thrift::RpcOptions rpcOptions; + return future_RegisterAllocSvr(rpcOptions, node_addr); +} + +folly::Future MediateServiceAsyncClient::future_RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr) { + folly::Promise _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_RegisterAllocSvr, channel_); + RegisterAllocSvr(rpcOptions, std::move(callback), node_addr); + return _future; +} + +folly::Future>> MediateServiceAsyncClient::header_future_RegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_RegisterAllocSvr, channel_); + RegisterAllocSvr(rpcOptions, std::move(callback), node_addr); + return _future; +} + +void MediateServiceAsyncClient::RegisterAllocSvr(folly::Function callback, const ::seqsvr::NodeAddrInfo& node_addr) { + RegisterAllocSvr(std::make_unique(std::move(callback)), node_addr); +} + +folly::exception_wrapper MediateServiceAsyncClient::recv_wrapped_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_RegisterAllocSvrT(&reader, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_RegisterAllocSvrT(&reader, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +void MediateServiceAsyncClient::recv_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_RegisterAllocSvr(state); + if (ew) { + ew.throw_exception(); + } +} + +void MediateServiceAsyncClient::recv_instance_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + recv_RegisterAllocSvr(state); +} + +folly::exception_wrapper MediateServiceAsyncClient::recv_instance_wrapped_RegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_RegisterAllocSvr(state); +} + +void MediateServiceAsyncClient::UnRegisterAllocSvr(std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + ::apache::thrift::RpcOptions rpcOptions; + UnRegisterAllocSvrImpl(false, rpcOptions, std::move(callback), node_addr); +} + +void MediateServiceAsyncClient::UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + UnRegisterAllocSvrImpl(false, rpcOptions, std::move(callback), node_addr); +} + +void MediateServiceAsyncClient::UnRegisterAllocSvrImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::NodeAddrInfo& node_addr) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + UnRegisterAllocSvrT(&writer, useSync, rpcOptions, std::move(callback), node_addr); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + UnRegisterAllocSvrT(&writer, useSync, rpcOptions, std::move(callback), node_addr); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +void MediateServiceAsyncClient::sync_UnRegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr) { + ::apache::thrift::RpcOptions rpcOptions; + sync_UnRegisterAllocSvr(rpcOptions, node_addr); +} + +void MediateServiceAsyncClient::sync_UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + UnRegisterAllocSvrImpl(true, rpcOptions, std::move(callback), node_addr); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + recv_UnRegisterAllocSvr(_returnState); +} + +folly::Future MediateServiceAsyncClient::future_UnRegisterAllocSvr(const ::seqsvr::NodeAddrInfo& node_addr) { + ::apache::thrift::RpcOptions rpcOptions; + return future_UnRegisterAllocSvr(rpcOptions, node_addr); +} + +folly::Future MediateServiceAsyncClient::future_UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr) { + folly::Promise _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_UnRegisterAllocSvr, channel_); + UnRegisterAllocSvr(rpcOptions, std::move(callback), node_addr); + return _future; +} + +folly::Future>> MediateServiceAsyncClient::header_future_UnRegisterAllocSvr(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::NodeAddrInfo& node_addr) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_UnRegisterAllocSvr, channel_); + UnRegisterAllocSvr(rpcOptions, std::move(callback), node_addr); + return _future; +} + +void MediateServiceAsyncClient::UnRegisterAllocSvr(folly::Function callback, const ::seqsvr::NodeAddrInfo& node_addr) { + UnRegisterAllocSvr(std::make_unique(std::move(callback)), node_addr); +} + +folly::exception_wrapper MediateServiceAsyncClient::recv_wrapped_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_UnRegisterAllocSvrT(&reader, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_UnRegisterAllocSvrT(&reader, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +void MediateServiceAsyncClient::recv_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_UnRegisterAllocSvr(state); + if (ew) { + ew.throw_exception(); + } +} + +void MediateServiceAsyncClient::recv_instance_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + recv_UnRegisterAllocSvr(state); +} + +folly::exception_wrapper MediateServiceAsyncClient::recv_instance_wrapped_UnRegisterAllocSvr(::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_UnRegisterAllocSvr(state); +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/MediateService_custom_protocol.h b/seqsvr/proto/gen-cpp2/MediateService_custom_protocol.h new file mode 100644 index 0000000..3d1c763 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService_custom_protocol.h @@ -0,0 +1,19 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + + +/** + * This header file includes the tcc files of the corresponding header file + * and the header files of its dependent types. Include this header file + * only when you need to use custom protocols (e.g. DebugProtocol, + * VirtualProtocol) to read/write thrift structs. + */ + +#include "MediateService.tcc" + +#include "seqsvr_types_custom_protocol.h" diff --git a/seqsvr/proto/gen-cpp2/MediateService_processmap_binary.cpp b/seqsvr/proto/gen-cpp2/MediateService_processmap_binary.cpp new file mode 100644 index 0000000..9bea61b --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService_processmap_binary.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "MediateService.h" + +#include "MediateService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/MediateService_processmap_compact.cpp b/seqsvr/proto/gen-cpp2/MediateService_processmap_compact.cpp new file mode 100644 index 0000000..9bea61b --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService_processmap_compact.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "MediateService.h" + +#include "MediateService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/MediateService_processmap_simple_json.cpp b/seqsvr/proto/gen-cpp2/MediateService_processmap_simple_json.cpp new file mode 100644 index 0000000..9bea61b --- /dev/null +++ b/seqsvr/proto/gen-cpp2/MediateService_processmap_simple_json.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "MediateService.h" + +#include "MediateService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/StoreService.cpp b/seqsvr/proto/gen-cpp2/StoreService.cpp new file mode 100644 index 0000000..c5801c3 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService.cpp @@ -0,0 +1,124 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "StoreService.h" + +#include "StoreService.tcc" + +#include +#include +#include +#include +namespace seqsvr { + +std::unique_ptr StoreServiceSvIf::getProcessor() { + return std::make_unique(this); +} + +void StoreServiceSvIf::LoadMaxSeqsData( ::seqsvr::MaxSeqsData& /*_return*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("LoadMaxSeqsData"); +} + +folly::Future> StoreServiceSvIf::future_LoadMaxSeqsData() { + return apache::thrift::detail::si::future_returning_uptr([&]( ::seqsvr::MaxSeqsData& _return) { LoadMaxSeqsData(_return); }); +} + +void StoreServiceSvIf::async_tm_LoadMaxSeqsData(std::unique_ptr>> callback) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_LoadMaxSeqsData(); }); +} + +int64_t StoreServiceSvIf::SaveMaxSeq(int32_t /*id*/, int64_t /*max_seq*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("SaveMaxSeq"); +} + +folly::Future StoreServiceSvIf::future_SaveMaxSeq(int32_t id, int64_t max_seq) { + return apache::thrift::detail::si::future([&] { return SaveMaxSeq(id, max_seq); }); +} + +void StoreServiceSvIf::async_tm_SaveMaxSeq(std::unique_ptr> callback, int32_t id, int64_t max_seq) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_SaveMaxSeq(id, max_seq); }); +} + +void StoreServiceSvIf::LoadRouteTable( ::seqsvr::Router& /*_return*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("LoadRouteTable"); +} + +folly::Future> StoreServiceSvIf::future_LoadRouteTable() { + return apache::thrift::detail::si::future_returning_uptr([&]( ::seqsvr::Router& _return) { LoadRouteTable(_return); }); +} + +void StoreServiceSvIf::async_tm_LoadRouteTable(std::unique_ptr>> callback) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_LoadRouteTable(); }); +} + +bool StoreServiceSvIf::SaveRouteTable(std::unique_ptr< ::seqsvr::Router> /*router*/) { + apache::thrift::detail::si::throw_app_exn_unimplemented("SaveRouteTable"); +} + +folly::Future StoreServiceSvIf::future_SaveRouteTable(std::unique_ptr< ::seqsvr::Router> router) { + return apache::thrift::detail::si::future([&] { return SaveRouteTable(std::move(router)); }); +} + +void StoreServiceSvIf::async_tm_SaveRouteTable(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::Router> router) { + apache::thrift::detail::si::async_tm(this, std::move(callback), [&] { return future_SaveRouteTable(std::move(router)); }); +} + +void StoreServiceSvNull::LoadMaxSeqsData( ::seqsvr::MaxSeqsData& /*_return*/) {} + +int64_t StoreServiceSvNull::SaveMaxSeq(int32_t /*id*/, int64_t /*max_seq*/) { + return 0; +} + +void StoreServiceSvNull::LoadRouteTable( ::seqsvr::Router& /*_return*/) {} + +bool StoreServiceSvNull::SaveRouteTable(std::unique_ptr< ::seqsvr::Router> /*router*/) { + return 0; +} + +const char* StoreServiceAsyncProcessor::getServiceName() { + return "StoreService"; +} + +folly::Optional StoreServiceAsyncProcessor::getCacheKey(folly::IOBuf* buf, apache::thrift::protocol::PROTOCOL_TYPES protType) { + return apache::thrift::detail::ap::get_cache_key(buf, protType, cacheKeyMap_); +} + +void StoreServiceAsyncProcessor::process(std::unique_ptr req, std::unique_ptr buf, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + apache::thrift::detail::ap::process(this, std::move(req), std::move(buf), protType, context, eb, tm); +} + +bool StoreServiceAsyncProcessor::isOnewayMethod(const folly::IOBuf* buf, const apache::thrift::transport::THeader* header) { + return apache::thrift::detail::ap::is_oneway_method(buf, header, onewayMethods_); +} + +std::unordered_set StoreServiceAsyncProcessor::onewayMethods_ {}; +std::unordered_map StoreServiceAsyncProcessor::cacheKeyMap_ {}; +const StoreServiceAsyncProcessor::BinaryProtocolProcessMap& StoreServiceAsyncProcessor::getBinaryProtocolProcessMap() { + return binaryProcessMap_; +} + +const StoreServiceAsyncProcessor::BinaryProtocolProcessMap StoreServiceAsyncProcessor::binaryProcessMap_ { + {"LoadMaxSeqsData", &StoreServiceAsyncProcessor::_processInThread_LoadMaxSeqsData}, + {"SaveMaxSeq", &StoreServiceAsyncProcessor::_processInThread_SaveMaxSeq}, + {"LoadRouteTable", &StoreServiceAsyncProcessor::_processInThread_LoadRouteTable}, + {"SaveRouteTable", &StoreServiceAsyncProcessor::_processInThread_SaveRouteTable}, +}; + +const StoreServiceAsyncProcessor::CompactProtocolProcessMap& StoreServiceAsyncProcessor::getCompactProtocolProcessMap() { + return compactProcessMap_; +} + +const StoreServiceAsyncProcessor::CompactProtocolProcessMap StoreServiceAsyncProcessor::compactProcessMap_ { + {"LoadMaxSeqsData", &StoreServiceAsyncProcessor::_processInThread_LoadMaxSeqsData}, + {"SaveMaxSeq", &StoreServiceAsyncProcessor::_processInThread_SaveMaxSeq}, + {"LoadRouteTable", &StoreServiceAsyncProcessor::_processInThread_LoadRouteTable}, + {"SaveRouteTable", &StoreServiceAsyncProcessor::_processInThread_SaveRouteTable}, +}; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/StoreService.h b/seqsvr/proto/gen-cpp2/StoreService.h new file mode 100644 index 0000000..02d7791 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService.h @@ -0,0 +1,259 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include +#include +#include +#include +#include + + + +#include "seqsvr_types.h" + +namespace folly { + class IOBuf; + class IOBufQueue; +} +namespace apache { namespace thrift { + class Cpp2RequestContext; + class BinaryProtocolReader; + class CompactProtocolReader; + namespace transport { class THeader; } +}} + +namespace seqsvr { + +class StoreServiceSvAsyncIf { + public: + virtual ~StoreServiceSvAsyncIf() {} + virtual void async_tm_LoadMaxSeqsData(std::unique_ptr>> callback) = 0; + // virtual void async_LoadMaxSeqsData(std::unique_ptr>> callback) = delete; + virtual folly::Future> future_LoadMaxSeqsData() = 0; + virtual void async_tm_SaveMaxSeq(std::unique_ptr> callback, int32_t id, int64_t max_seq) = 0; + // virtual void async_SaveMaxSeq(std::unique_ptr> callback, int32_t id, int64_t max_seq) = delete; + virtual folly::Future future_SaveMaxSeq(int32_t id, int64_t max_seq) = 0; + virtual void async_tm_LoadRouteTable(std::unique_ptr>> callback) = 0; + // virtual void async_LoadRouteTable(std::unique_ptr>> callback) = delete; + virtual folly::Future> future_LoadRouteTable() = 0; + virtual void async_tm_SaveRouteTable(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::Router> router) = 0; + // virtual void async_SaveRouteTable(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::Router> router) = delete; + virtual folly::Future future_SaveRouteTable(std::unique_ptr< ::seqsvr::Router> router) = 0; +}; + +class StoreServiceAsyncProcessor; + +class StoreServiceSvIf : public StoreServiceSvAsyncIf, public apache::thrift::ServerInterface { + public: + typedef StoreServiceAsyncProcessor ProcessorType; + std::unique_ptr getProcessor() override; + virtual void LoadMaxSeqsData( ::seqsvr::MaxSeqsData& /*_return*/); + folly::Future> future_LoadMaxSeqsData() override; + void async_tm_LoadMaxSeqsData(std::unique_ptr>> callback) override; + virtual int64_t SaveMaxSeq(int32_t /*id*/, int64_t /*max_seq*/); + folly::Future future_SaveMaxSeq(int32_t id, int64_t max_seq) override; + void async_tm_SaveMaxSeq(std::unique_ptr> callback, int32_t id, int64_t max_seq) override; + virtual void LoadRouteTable( ::seqsvr::Router& /*_return*/); + folly::Future> future_LoadRouteTable() override; + void async_tm_LoadRouteTable(std::unique_ptr>> callback) override; + virtual bool SaveRouteTable(std::unique_ptr< ::seqsvr::Router> /*router*/); + folly::Future future_SaveRouteTable(std::unique_ptr< ::seqsvr::Router> router) override; + void async_tm_SaveRouteTable(std::unique_ptr> callback, std::unique_ptr< ::seqsvr::Router> router) override; +}; + +class StoreServiceSvNull : public StoreServiceSvIf { + public: + void LoadMaxSeqsData( ::seqsvr::MaxSeqsData& /*_return*/) override; + int64_t SaveMaxSeq(int32_t /*id*/, int64_t /*max_seq*/) override; + void LoadRouteTable( ::seqsvr::Router& /*_return*/) override; + bool SaveRouteTable(std::unique_ptr< ::seqsvr::Router> /*router*/) override; +}; + +class StoreServiceAsyncProcessor : public ::apache::thrift::GeneratedAsyncProcessor { + public: + const char* getServiceName() override; + using BaseAsyncProcessor = void; + using HasFrozen2 = std::false_type; + protected: + StoreServiceSvIf* iface_; + folly::Optional getCacheKey(folly::IOBuf* buf, apache::thrift::protocol::PROTOCOL_TYPES protType) override; + public: + void process(std::unique_ptr req, std::unique_ptr buf, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) override; + protected: + bool isOnewayMethod(const folly::IOBuf* buf, const apache::thrift::transport::THeader* header) override; + private: + static std::unordered_set onewayMethods_; + static std::unordered_map cacheKeyMap_; + public: + using BinaryProtocolProcessFunc = ProcessFunc; + using BinaryProtocolProcessMap = ProcessMap; + static const StoreServiceAsyncProcessor::BinaryProtocolProcessMap& getBinaryProtocolProcessMap(); + private: + static const StoreServiceAsyncProcessor::BinaryProtocolProcessMap binaryProcessMap_; + public: + using CompactProtocolProcessFunc = ProcessFunc; + using CompactProtocolProcessMap = ProcessMap; + static const StoreServiceAsyncProcessor::CompactProtocolProcessMap& getCompactProtocolProcessMap(); + private: + static const StoreServiceAsyncProcessor::CompactProtocolProcessMap compactProcessMap_; + private: + template + void _processInThread_LoadMaxSeqsData(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_LoadMaxSeqsData(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_LoadMaxSeqsData(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::MaxSeqsData const& _return); + template + static void throw_wrapped_LoadMaxSeqsData(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + template + void _processInThread_SaveMaxSeq(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_SaveMaxSeq(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_SaveMaxSeq(int32_t protoSeqId, apache::thrift::ContextStack* ctx, int64_t const& _return); + template + static void throw_wrapped_SaveMaxSeq(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + template + void _processInThread_LoadRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_LoadRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_LoadRouteTable(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::Router const& _return); + template + static void throw_wrapped_LoadRouteTable(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + template + void _processInThread_SaveRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + void process_SaveRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm); + template + static folly::IOBufQueue return_SaveRouteTable(int32_t protoSeqId, apache::thrift::ContextStack* ctx, bool const& _return); + template + static void throw_wrapped_SaveRouteTable(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx); + public: + StoreServiceAsyncProcessor(StoreServiceSvIf* iface) : + iface_(iface) {} + + virtual ~StoreServiceAsyncProcessor() {} +}; + +class StoreServiceAsyncClient : public apache::thrift::TClientBase { + public: + virtual const char* getServiceName(); + typedef std::unique_ptr channel_ptr; + + virtual ~StoreServiceAsyncClient() {} + + StoreServiceAsyncClient(std::shared_ptr channel) : + channel_(channel) { + connectionContext_.reset(new apache::thrift::Cpp2ConnContext); + } + + apache::thrift::RequestChannel* getChannel() { + return this->channel_.get(); + } + + apache::thrift::HeaderChannel* getHeaderChannel() { + return dynamic_cast(this->channel_.get()); + } + virtual void LoadMaxSeqsData(std::unique_ptr callback); + virtual void LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); + private: + virtual void LoadMaxSeqsDataImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); + public: + virtual void sync_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return); + virtual void sync_LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::MaxSeqsData& _return); + virtual folly::Future< ::seqsvr::MaxSeqsData> future_LoadMaxSeqsData(); + virtual folly::Future< ::seqsvr::MaxSeqsData> future_LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions); + virtual folly::Future>> header_future_LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions); + virtual void LoadMaxSeqsData(folly::Function callback); + static folly::exception_wrapper recv_wrapped_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state); + static void recv_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual void recv_instance_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state); + template + void LoadMaxSeqsDataT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); + template + static folly::exception_wrapper recv_wrapped_LoadMaxSeqsDataT(Protocol_* prot, ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state); + template + static void recv_LoadMaxSeqsDataT(Protocol_* prot, ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state); + virtual void SaveMaxSeq(std::unique_ptr callback, int32_t id, int64_t max_seq); + virtual void SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int64_t max_seq); + private: + virtual void SaveMaxSeqImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int64_t max_seq); + public: + virtual int64_t sync_SaveMaxSeq(int32_t id, int64_t max_seq); + virtual int64_t sync_SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, int32_t id, int64_t max_seq); + virtual folly::Future future_SaveMaxSeq(int32_t id, int64_t max_seq); + virtual folly::Future future_SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, int32_t id, int64_t max_seq); + virtual folly::Future>> header_future_SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, int32_t id, int64_t max_seq); + virtual void SaveMaxSeq(folly::Function callback, int32_t id, int64_t max_seq); + static folly::exception_wrapper recv_wrapped_SaveMaxSeq(int64_t& _return, ::apache::thrift::ClientReceiveState& state); + static int64_t recv_SaveMaxSeq(::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual int64_t recv_instance_SaveMaxSeq(::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_SaveMaxSeq(int64_t& _return, ::apache::thrift::ClientReceiveState& state); + template + void SaveMaxSeqT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int64_t max_seq); + template + static folly::exception_wrapper recv_wrapped_SaveMaxSeqT(Protocol_* prot, int64_t& _return, ::apache::thrift::ClientReceiveState& state); + template + static int64_t recv_SaveMaxSeqT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state); + virtual void LoadRouteTable(std::unique_ptr callback); + virtual void LoadRouteTable(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); + private: + virtual void LoadRouteTableImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); + public: + virtual void sync_LoadRouteTable( ::seqsvr::Router& _return); + virtual void sync_LoadRouteTable(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::Router& _return); + virtual folly::Future< ::seqsvr::Router> future_LoadRouteTable(); + virtual folly::Future< ::seqsvr::Router> future_LoadRouteTable(apache::thrift::RpcOptions& rpcOptions); + virtual folly::Future>> header_future_LoadRouteTable(apache::thrift::RpcOptions& rpcOptions); + virtual void LoadRouteTable(folly::Function callback); + static folly::exception_wrapper recv_wrapped_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state); + static void recv_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual void recv_instance_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state); + template + void LoadRouteTableT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); + template + static folly::exception_wrapper recv_wrapped_LoadRouteTableT(Protocol_* prot, ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state); + template + static void recv_LoadRouteTableT(Protocol_* prot, ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state); + virtual void SaveRouteTable(std::unique_ptr callback, const ::seqsvr::Router& router); + virtual void SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::Router& router); + private: + virtual void SaveRouteTableImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::Router& router); + public: + virtual bool sync_SaveRouteTable(const ::seqsvr::Router& router); + virtual bool sync_SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::Router& router); + virtual folly::Future future_SaveRouteTable(const ::seqsvr::Router& router); + virtual folly::Future future_SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::Router& router); + virtual folly::Future>> header_future_SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::Router& router); + virtual void SaveRouteTable(folly::Function callback, const ::seqsvr::Router& router); + static folly::exception_wrapper recv_wrapped_SaveRouteTable(bool& _return, ::apache::thrift::ClientReceiveState& state); + static bool recv_SaveRouteTable(::apache::thrift::ClientReceiveState& state); + // Mock friendly virtual instance method + virtual bool recv_instance_SaveRouteTable(::apache::thrift::ClientReceiveState& state); + virtual folly::exception_wrapper recv_instance_wrapped_SaveRouteTable(bool& _return, ::apache::thrift::ClientReceiveState& state); + template + void SaveRouteTableT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::Router& router); + template + static folly::exception_wrapper recv_wrapped_SaveRouteTableT(Protocol_* prot, bool& _return, ::apache::thrift::ClientReceiveState& state); + template + static bool recv_SaveRouteTableT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state); + protected: + std::unique_ptr connectionContext_; + std::shared_ptr channel_; +}; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/StoreService.tcc b/seqsvr/proto/gen-cpp2/StoreService.tcc new file mode 100644 index 0000000..848ea03 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService.tcc @@ -0,0 +1,668 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include "StoreService.h" +#include +#include +#include +#include +#include +#include +#include + +namespace seqsvr { + +typedef apache::thrift::ThriftPresult StoreService_LoadMaxSeqsData_pargs; +typedef apache::thrift::ThriftPresult> StoreService_LoadMaxSeqsData_presult; +typedef apache::thrift::ThriftPresult, apache::thrift::FieldData<2, apache::thrift::protocol::T_I64, int64_t*>> StoreService_SaveMaxSeq_pargs; +typedef apache::thrift::ThriftPresult> StoreService_SaveMaxSeq_presult; +typedef apache::thrift::ThriftPresult StoreService_LoadRouteTable_pargs; +typedef apache::thrift::ThriftPresult> StoreService_LoadRouteTable_presult; +typedef apache::thrift::ThriftPresult> StoreService_SaveRouteTable_pargs; +typedef apache::thrift::ThriftPresult> StoreService_SaveRouteTable_presult; +template +void StoreServiceAsyncProcessor::_processInThread_LoadMaxSeqsData(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &StoreServiceAsyncProcessor::process_LoadMaxSeqsData, this); +} + +template +void StoreServiceAsyncProcessor::process_LoadMaxSeqsData(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + StoreService_LoadMaxSeqsData_pargs args; + std::unique_ptr c(this->getContextStack(this->getServiceName(), "StoreService.LoadMaxSeqsData", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function LoadMaxSeqsData"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("LoadMaxSeqsData", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function LoadMaxSeqsData"; + } + } + auto callback = std::make_unique>>(std::move(req), std::move(c), return_LoadMaxSeqsData, throw_wrapped_LoadMaxSeqsData, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_LoadMaxSeqsData(std::move(callback)); +} + +template +folly::IOBufQueue StoreServiceAsyncProcessor::return_LoadMaxSeqsData(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::MaxSeqsData const& _return) { + ProtocolOut_ prot; + StoreService_LoadMaxSeqsData_presult result; + result.get<0>().value = const_cast< ::seqsvr::MaxSeqsData*>(&_return); + result.setIsSet(0, true); + return serializeResponse("LoadMaxSeqsData", &prot, protoSeqId, ctx, result); +} + +template +void StoreServiceAsyncProcessor::throw_wrapped_LoadMaxSeqsData(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function LoadMaxSeqsData"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("LoadMaxSeqsData", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function LoadMaxSeqsData"; + } + } +} + +template +void StoreServiceAsyncProcessor::_processInThread_SaveMaxSeq(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &StoreServiceAsyncProcessor::process_SaveMaxSeq, this); +} + +template +void StoreServiceAsyncProcessor::process_SaveMaxSeq(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + StoreService_SaveMaxSeq_pargs args; + int32_t uarg_id{0}; + args.get<0>().value = &uarg_id; + int64_t uarg_max_seq{0}; + args.get<1>().value = &uarg_max_seq; + std::unique_ptr c(this->getContextStack(this->getServiceName(), "StoreService.SaveMaxSeq", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function SaveMaxSeq"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("SaveMaxSeq", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function SaveMaxSeq"; + } + } + auto callback = std::make_unique>(std::move(req), std::move(c), return_SaveMaxSeq, throw_wrapped_SaveMaxSeq, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_SaveMaxSeq(std::move(callback), args.get<0>().ref(), args.get<1>().ref()); +} + +template +folly::IOBufQueue StoreServiceAsyncProcessor::return_SaveMaxSeq(int32_t protoSeqId, apache::thrift::ContextStack* ctx, int64_t const& _return) { + ProtocolOut_ prot; + StoreService_SaveMaxSeq_presult result; + result.get<0>().value = const_cast(&_return); + result.setIsSet(0, true); + return serializeResponse("SaveMaxSeq", &prot, protoSeqId, ctx, result); +} + +template +void StoreServiceAsyncProcessor::throw_wrapped_SaveMaxSeq(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function SaveMaxSeq"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("SaveMaxSeq", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function SaveMaxSeq"; + } + } +} + +template +void StoreServiceAsyncProcessor::_processInThread_LoadRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &StoreServiceAsyncProcessor::process_LoadRouteTable, this); +} + +template +void StoreServiceAsyncProcessor::process_LoadRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + StoreService_LoadRouteTable_pargs args; + std::unique_ptr c(this->getContextStack(this->getServiceName(), "StoreService.LoadRouteTable", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function LoadRouteTable"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("LoadRouteTable", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function LoadRouteTable"; + } + } + auto callback = std::make_unique>>(std::move(req), std::move(c), return_LoadRouteTable, throw_wrapped_LoadRouteTable, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_LoadRouteTable(std::move(callback)); +} + +template +folly::IOBufQueue StoreServiceAsyncProcessor::return_LoadRouteTable(int32_t protoSeqId, apache::thrift::ContextStack* ctx, ::seqsvr::Router const& _return) { + ProtocolOut_ prot; + StoreService_LoadRouteTable_presult result; + result.get<0>().value = const_cast< ::seqsvr::Router*>(&_return); + result.setIsSet(0, true); + return serializeResponse("LoadRouteTable", &prot, protoSeqId, ctx, result); +} + +template +void StoreServiceAsyncProcessor::throw_wrapped_LoadRouteTable(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function LoadRouteTable"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("LoadRouteTable", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function LoadRouteTable"; + } + } +} + +template +void StoreServiceAsyncProcessor::_processInThread_SaveRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot, apache::thrift::Cpp2RequestContext* ctx, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + auto pri = iface_->getRequestPriority(ctx, apache::thrift::concurrency::NORMAL); + processInThread(std::move(req), std::move(buf),std::move(iprot), ctx, eb, tm, pri, false, &StoreServiceAsyncProcessor::process_SaveRouteTable, this); +} + +template +void StoreServiceAsyncProcessor::process_SaveRouteTable(std::unique_ptr req, std::unique_ptr buf, std::unique_ptr iprot,apache::thrift::Cpp2RequestContext* ctx,folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) { + // make sure getConnectionContext is null + // so async calls don't accidentally use it + iface_->setConnectionContext(nullptr); + StoreService_SaveRouteTable_pargs args; + std::unique_ptr< ::seqsvr::Router> uarg_router(new ::seqsvr::Router()); + args.get<0>().value = uarg_router.get(); + std::unique_ptr c(this->getContextStack(this->getServiceName(), "StoreService.SaveRouteTable", ctx)); + try { + deserializeRequest(args, buf.get(), iprot.get(), c.get()); + } + catch (const std::exception& ex) { + ProtocolOut_ prot; + if (req) { + LOG(ERROR) << ex.what() << " in function SaveRouteTable"; + apache::thrift::TApplicationException x(apache::thrift::TApplicationException::TApplicationExceptionType::PROTOCOL_ERROR, ex.what()); + folly::IOBufQueue queue = serializeException("SaveRouteTable", &prot, ctx->getProtoSeqId(), nullptr, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), ctx->getHeader()->getWriteTransforms(), ctx->getHeader()->getMinCompressBytes())); + eb->runInEventBaseThread([queue = std::move(queue), req = std::move(req)]() mutable { + req->sendReply(queue.move()); + } + ); + return; + } + else { + LOG(ERROR) << ex.what() << " in oneway function SaveRouteTable"; + } + } + auto callback = std::make_unique>(std::move(req), std::move(c), return_SaveRouteTable, throw_wrapped_SaveRouteTable, ctx->getProtoSeqId(), eb, tm, ctx); + if (!callback->isRequestActive()) { + callback.release()->deleteInThread(); + return; + } + ctx->setStartedProcessing(); + iface_->async_tm_SaveRouteTable(std::move(callback), std::move(uarg_router)); +} + +template +folly::IOBufQueue StoreServiceAsyncProcessor::return_SaveRouteTable(int32_t protoSeqId, apache::thrift::ContextStack* ctx, bool const& _return) { + ProtocolOut_ prot; + StoreService_SaveRouteTable_presult result; + result.get<0>().value = const_cast(&_return); + result.setIsSet(0, true); + return serializeResponse("SaveRouteTable", &prot, protoSeqId, ctx, result); +} + +template +void StoreServiceAsyncProcessor::throw_wrapped_SaveRouteTable(std::unique_ptr req,int32_t protoSeqId,apache::thrift::ContextStack* ctx,folly::exception_wrapper ew,apache::thrift::Cpp2RequestContext* reqCtx) { + if (!ew) { + return; + } + ProtocolOut_ prot; + { + if (req) { + LOG(ERROR) << ew.what().toStdString() << " in function SaveRouteTable"; + apache::thrift::TApplicationException x(ew.what().toStdString()); + ctx->userExceptionWrapped(false, ew); + ctx->handlerErrorWrapped(ew); + folly::IOBufQueue queue = serializeException("SaveRouteTable", &prot, protoSeqId, ctx, x); + queue.append(apache::thrift::transport::THeader::transform(queue.move(), reqCtx->getHeader()->getWriteTransforms(), reqCtx->getHeader()->getMinCompressBytes())); + req->sendReply(queue.move()); + return; + } + else { + LOG(ERROR) << ew.what().toStdString() << " in oneway function SaveRouteTable"; + } + } +} + +template +void StoreServiceAsyncClient::LoadMaxSeqsDataT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "StoreService.LoadMaxSeqsData", connectionContext_.get()); + StoreService_LoadMaxSeqsData_pargs args; + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "LoadMaxSeqsData", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_LoadMaxSeqsDataT(Protocol_* prot, ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("LoadMaxSeqsData") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + StoreService_LoadMaxSeqsData_presult result; + result.get<0>().value = &_return; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + if (result.getIsSet(0)) { + // _return pointer has been filled + return; // from try_and_catch + } + else { + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::MISSING_RESULT, "failed: unknown result"); + return; // from try_and_catch + } + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +void StoreServiceAsyncClient::recv_LoadMaxSeqsDataT(Protocol_* prot, ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_LoadMaxSeqsDataT(prot, _return, state); + if (ew) { + ew.throw_exception(); + } +} + +template +void StoreServiceAsyncClient::SaveMaxSeqT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int64_t max_seq) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "StoreService.SaveMaxSeq", connectionContext_.get()); + StoreService_SaveMaxSeq_pargs args; + args.get<0>().value = &id; + args.get<1>().value = &max_seq; + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "SaveMaxSeq", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_SaveMaxSeqT(Protocol_* prot, int64_t& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("SaveMaxSeq") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + StoreService_SaveMaxSeq_presult result; + result.get<0>().value = &_return; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + if (result.getIsSet(0)) { + // _return pointer has been filled + return; // from try_and_catch + } + else { + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::MISSING_RESULT, "failed: unknown result"); + return; // from try_and_catch + } + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +int64_t StoreServiceAsyncClient::recv_SaveMaxSeqT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state) { + int64_t _return; + auto ew = recv_wrapped_SaveMaxSeqT(prot, _return, state); + if (ew) { + ew.throw_exception(); + } + return _return; +} + +template +void StoreServiceAsyncClient::LoadRouteTableT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "StoreService.LoadRouteTable", connectionContext_.get()); + StoreService_LoadRouteTable_pargs args; + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "LoadRouteTable", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_LoadRouteTableT(Protocol_* prot, ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("LoadRouteTable") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + StoreService_LoadRouteTable_presult result; + result.get<0>().value = &_return; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + if (result.getIsSet(0)) { + // _return pointer has been filled + return; // from try_and_catch + } + else { + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::MISSING_RESULT, "failed: unknown result"); + return; // from try_and_catch + } + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +void StoreServiceAsyncClient::recv_LoadRouteTableT(Protocol_* prot, ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_LoadRouteTableT(prot, _return, state); + if (ew) { + ew.throw_exception(); + } +} + +template +void StoreServiceAsyncClient::SaveRouteTableT(Protocol_* prot, bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::Router& router) { + auto header = std::make_shared(apache::thrift::transport::THeader::ALLOW_BIG_FRAMES); + header->setProtocolId(getChannel()->getProtocolId()); + header->setHeaders(rpcOptions.releaseWriteHeaders()); + connectionContext_->setRequestHeader(header.get()); + std::unique_ptr ctx = this->getContextStack(this->getServiceName(), "StoreService.SaveRouteTable", connectionContext_.get()); + StoreService_SaveRouteTable_pargs args; + args.get<0>().value = const_cast< ::seqsvr::Router*>(&router); + auto sizer = [&](Protocol_* p) { return args.serializedSizeZC(p); }; + auto writer = [&](Protocol_* p) { args.write(p); }; + apache::thrift::clientSendT(prot, rpcOptions, std::move(callback), std::move(ctx), header, channel_.get(), "SaveRouteTable", writer, sizer, false, useSync); + connectionContext_->setRequestHeader(nullptr); +} + +template +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_SaveRouteTableT(Protocol_* prot, bool& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + prot->setInput(state.buf()); + auto guard = folly::makeGuard([&] {prot->setInput(nullptr);}); + apache::thrift::ContextStack* ctx = state.ctx(); + std::string _fname; + int32_t protoSeqId = 0; + apache::thrift::MessageType mtype; + ctx->preRead(); + folly::exception_wrapper interior_ew; + auto caught_ew = folly::try_and_catch([&]() { + prot->readMessageBegin(_fname, mtype, protoSeqId); + if (mtype == apache::thrift::T_EXCEPTION) { + apache::thrift::TApplicationException x; + x.read(prot); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(x); + return; // from try_and_catch + } + if (mtype != apache::thrift::T_REPLY) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::INVALID_MESSAGE_TYPE); + return; // from try_and_catch + } + if (_fname.compare("SaveRouteTable") != 0) { + prot->skip(apache::thrift::protocol::T_STRUCT); + prot->readMessageEnd(); + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::WRONG_METHOD_NAME); + return; // from try_and_catch + } + ::apache::thrift::SerializedMessage smsg; + smsg.protocolType = prot->protocolType(); + smsg.buffer = state.buf(); + ctx->onReadData(smsg); + StoreService_SaveRouteTable_presult result; + result.get<0>().value = &_return; + result.read(prot); + prot->readMessageEnd(); + ctx->postRead(state.header(), state.buf()->length()); + if (result.getIsSet(0)) { + // _return pointer has been filled + return; // from try_and_catch + } + else { + interior_ew = folly::make_exception_wrapper(apache::thrift::TApplicationException::TApplicationExceptionType::MISSING_RESULT, "failed: unknown result"); + return; // from try_and_catch + } + } + ); + auto ew = interior_ew ? std::move(interior_ew) : std::move(caught_ew); + if (ew) { + ctx->handlerErrorWrapped(ew); + } + return ew; +} + +template +bool StoreServiceAsyncClient::recv_SaveRouteTableT(Protocol_* prot, ::apache::thrift::ClientReceiveState& state) { + bool _return; + auto ew = recv_wrapped_SaveRouteTableT(prot, _return, state); + if (ew) { + ew.throw_exception(); + } + return _return; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/StoreService_client.cpp b/seqsvr/proto/gen-cpp2/StoreService_client.cpp new file mode 100644 index 0000000..1e14fd2 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService_client.cpp @@ -0,0 +1,491 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "StoreService.h" + +#include "StoreService.tcc" + +#include +#include +#include +namespace seqsvr { + +const char* StoreServiceAsyncClient::getServiceName() { + return "StoreService"; +} + +void StoreServiceAsyncClient::LoadMaxSeqsData(std::unique_ptr callback) { + ::apache::thrift::RpcOptions rpcOptions; + LoadMaxSeqsDataImpl(false, rpcOptions, std::move(callback)); +} + +void StoreServiceAsyncClient::LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback) { + LoadMaxSeqsDataImpl(false, rpcOptions, std::move(callback)); +} + +void StoreServiceAsyncClient::LoadMaxSeqsDataImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + LoadMaxSeqsDataT(&writer, useSync, rpcOptions, std::move(callback)); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + LoadMaxSeqsDataT(&writer, useSync, rpcOptions, std::move(callback)); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +void StoreServiceAsyncClient::sync_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return) { + ::apache::thrift::RpcOptions rpcOptions; + sync_LoadMaxSeqsData(rpcOptions, _return); +} + +void StoreServiceAsyncClient::sync_LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::MaxSeqsData& _return) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + LoadMaxSeqsDataImpl(true, rpcOptions, std::move(callback)); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + recv_LoadMaxSeqsData(_return, _returnState); +} + +folly::Future< ::seqsvr::MaxSeqsData> StoreServiceAsyncClient::future_LoadMaxSeqsData() { + ::apache::thrift::RpcOptions rpcOptions; + return future_LoadMaxSeqsData(rpcOptions); +} + +folly::Future< ::seqsvr::MaxSeqsData> StoreServiceAsyncClient::future_LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions) { + folly::Promise< ::seqsvr::MaxSeqsData> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_LoadMaxSeqsData, channel_); + LoadMaxSeqsData(rpcOptions, std::move(callback)); + return _future; +} + +folly::Future>> StoreServiceAsyncClient::header_future_LoadMaxSeqsData(apache::thrift::RpcOptions& rpcOptions) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_LoadMaxSeqsData, channel_); + LoadMaxSeqsData(rpcOptions, std::move(callback)); + return _future; +} + +void StoreServiceAsyncClient::LoadMaxSeqsData(folly::Function callback) { + LoadMaxSeqsData(std::make_unique(std::move(callback))); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_LoadMaxSeqsDataT(&reader, _return, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_LoadMaxSeqsDataT(&reader, _return, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +void StoreServiceAsyncClient::recv_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_LoadMaxSeqsData(_return, state); + if (ew) { + ew.throw_exception(); + } +} + +void StoreServiceAsyncClient::recv_instance_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_LoadMaxSeqsData(_return, state); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_instance_wrapped_LoadMaxSeqsData( ::seqsvr::MaxSeqsData& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_LoadMaxSeqsData(_return, state); +} + +void StoreServiceAsyncClient::SaveMaxSeq(std::unique_ptr callback, int32_t id, int64_t max_seq) { + ::apache::thrift::RpcOptions rpcOptions; + SaveMaxSeqImpl(false, rpcOptions, std::move(callback), id, max_seq); +} + +void StoreServiceAsyncClient::SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int64_t max_seq) { + SaveMaxSeqImpl(false, rpcOptions, std::move(callback), id, max_seq); +} + +void StoreServiceAsyncClient::SaveMaxSeqImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, int32_t id, int64_t max_seq) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + SaveMaxSeqT(&writer, useSync, rpcOptions, std::move(callback), id, max_seq); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + SaveMaxSeqT(&writer, useSync, rpcOptions, std::move(callback), id, max_seq); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +int64_t StoreServiceAsyncClient::sync_SaveMaxSeq(int32_t id, int64_t max_seq) { + ::apache::thrift::RpcOptions rpcOptions; + return sync_SaveMaxSeq(rpcOptions, id, max_seq); +} + +int64_t StoreServiceAsyncClient::sync_SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, int32_t id, int64_t max_seq) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + SaveMaxSeqImpl(true, rpcOptions, std::move(callback), id, max_seq); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + return recv_SaveMaxSeq(_returnState); +} + +folly::Future StoreServiceAsyncClient::future_SaveMaxSeq(int32_t id, int64_t max_seq) { + ::apache::thrift::RpcOptions rpcOptions; + return future_SaveMaxSeq(rpcOptions, id, max_seq); +} + +folly::Future StoreServiceAsyncClient::future_SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, int32_t id, int64_t max_seq) { + folly::Promise _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_SaveMaxSeq, channel_); + SaveMaxSeq(rpcOptions, std::move(callback), id, max_seq); + return _future; +} + +folly::Future>> StoreServiceAsyncClient::header_future_SaveMaxSeq(apache::thrift::RpcOptions& rpcOptions, int32_t id, int64_t max_seq) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_SaveMaxSeq, channel_); + SaveMaxSeq(rpcOptions, std::move(callback), id, max_seq); + return _future; +} + +void StoreServiceAsyncClient::SaveMaxSeq(folly::Function callback, int32_t id, int64_t max_seq) { + SaveMaxSeq(std::make_unique(std::move(callback)), id, max_seq); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_SaveMaxSeq(int64_t& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_SaveMaxSeqT(&reader, _return, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_SaveMaxSeqT(&reader, _return, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +int64_t StoreServiceAsyncClient::recv_SaveMaxSeq(::apache::thrift::ClientReceiveState& state) { + int64_t _return; + auto ew = recv_wrapped_SaveMaxSeq(_return, state); + if (ew) { + ew.throw_exception(); + } + return _return; +} + +int64_t StoreServiceAsyncClient::recv_instance_SaveMaxSeq(::apache::thrift::ClientReceiveState& state) { + return recv_SaveMaxSeq(state); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_instance_wrapped_SaveMaxSeq(int64_t& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_SaveMaxSeq(_return, state); +} + +void StoreServiceAsyncClient::LoadRouteTable(std::unique_ptr callback) { + ::apache::thrift::RpcOptions rpcOptions; + LoadRouteTableImpl(false, rpcOptions, std::move(callback)); +} + +void StoreServiceAsyncClient::LoadRouteTable(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback) { + LoadRouteTableImpl(false, rpcOptions, std::move(callback)); +} + +void StoreServiceAsyncClient::LoadRouteTableImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + LoadRouteTableT(&writer, useSync, rpcOptions, std::move(callback)); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + LoadRouteTableT(&writer, useSync, rpcOptions, std::move(callback)); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +void StoreServiceAsyncClient::sync_LoadRouteTable( ::seqsvr::Router& _return) { + ::apache::thrift::RpcOptions rpcOptions; + sync_LoadRouteTable(rpcOptions, _return); +} + +void StoreServiceAsyncClient::sync_LoadRouteTable(apache::thrift::RpcOptions& rpcOptions, ::seqsvr::Router& _return) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + LoadRouteTableImpl(true, rpcOptions, std::move(callback)); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + recv_LoadRouteTable(_return, _returnState); +} + +folly::Future< ::seqsvr::Router> StoreServiceAsyncClient::future_LoadRouteTable() { + ::apache::thrift::RpcOptions rpcOptions; + return future_LoadRouteTable(rpcOptions); +} + +folly::Future< ::seqsvr::Router> StoreServiceAsyncClient::future_LoadRouteTable(apache::thrift::RpcOptions& rpcOptions) { + folly::Promise< ::seqsvr::Router> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_LoadRouteTable, channel_); + LoadRouteTable(rpcOptions, std::move(callback)); + return _future; +} + +folly::Future>> StoreServiceAsyncClient::header_future_LoadRouteTable(apache::thrift::RpcOptions& rpcOptions) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_LoadRouteTable, channel_); + LoadRouteTable(rpcOptions, std::move(callback)); + return _future; +} + +void StoreServiceAsyncClient::LoadRouteTable(folly::Function callback) { + LoadRouteTable(std::make_unique(std::move(callback))); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_LoadRouteTableT(&reader, _return, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_LoadRouteTableT(&reader, _return, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +void StoreServiceAsyncClient::recv_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state) { + auto ew = recv_wrapped_LoadRouteTable(_return, state); + if (ew) { + ew.throw_exception(); + } +} + +void StoreServiceAsyncClient::recv_instance_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_LoadRouteTable(_return, state); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_instance_wrapped_LoadRouteTable( ::seqsvr::Router& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_LoadRouteTable(_return, state); +} + +void StoreServiceAsyncClient::SaveRouteTable(std::unique_ptr callback, const ::seqsvr::Router& router) { + ::apache::thrift::RpcOptions rpcOptions; + SaveRouteTableImpl(false, rpcOptions, std::move(callback), router); +} + +void StoreServiceAsyncClient::SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::Router& router) { + SaveRouteTableImpl(false, rpcOptions, std::move(callback), router); +} + +void StoreServiceAsyncClient::SaveRouteTableImpl(bool useSync, apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback, const ::seqsvr::Router& router) { + switch(getChannel()->getProtocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolWriter writer; + SaveRouteTableT(&writer, useSync, rpcOptions, std::move(callback), router); + break; + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolWriter writer; + SaveRouteTableT(&writer, useSync, rpcOptions, std::move(callback), router); + break; + } + default: + { + apache::thrift::detail::ac::throw_app_exn("Could not find Protocol"); + } + } +} + +bool StoreServiceAsyncClient::sync_SaveRouteTable(const ::seqsvr::Router& router) { + ::apache::thrift::RpcOptions rpcOptions; + return sync_SaveRouteTable(rpcOptions, router); +} + +bool StoreServiceAsyncClient::sync_SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::Router& router) { + apache::thrift::ClientReceiveState _returnState; + auto callback = std::make_unique(&_returnState, false); + SaveRouteTableImpl(true, rpcOptions, std::move(callback), router); + SCOPE_EXIT { + if (_returnState.header() && !_returnState.header()->getHeaders().empty()) { + rpcOptions.setReadHeaders(_returnState.header()->releaseHeaders()); + } + }; + if (!_returnState.buf()) { + assert(_returnState.exception()); + _returnState.exception().throw_exception(); + } + return recv_SaveRouteTable(_returnState); +} + +folly::Future StoreServiceAsyncClient::future_SaveRouteTable(const ::seqsvr::Router& router) { + ::apache::thrift::RpcOptions rpcOptions; + return future_SaveRouteTable(rpcOptions, router); +} + +folly::Future StoreServiceAsyncClient::future_SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::Router& router) { + folly::Promise _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_SaveRouteTable, channel_); + SaveRouteTable(rpcOptions, std::move(callback), router); + return _future; +} + +folly::Future>> StoreServiceAsyncClient::header_future_SaveRouteTable(apache::thrift::RpcOptions& rpcOptions, const ::seqsvr::Router& router) { + folly::Promise>> _promise; + auto _future = _promise.getFuture(); + auto callback = std::make_unique>(std::move(_promise), recv_wrapped_SaveRouteTable, channel_); + SaveRouteTable(rpcOptions, std::move(callback), router); + return _future; +} + +void StoreServiceAsyncClient::SaveRouteTable(folly::Function callback, const ::seqsvr::Router& router) { + SaveRouteTable(std::make_unique(std::move(callback)), router); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_wrapped_SaveRouteTable(bool& _return, ::apache::thrift::ClientReceiveState& state) { + if (state.isException()) { + return std::move(state.exception()); + } + if (!state.buf()) { + return folly::make_exception_wrapper("recv_ called without result"); + } + switch(state.protocolId()) { + case apache::thrift::protocol::T_BINARY_PROTOCOL: + { + apache::thrift::BinaryProtocolReader reader; + return recv_wrapped_SaveRouteTableT(&reader, _return, state); + } + case apache::thrift::protocol::T_COMPACT_PROTOCOL: + { + apache::thrift::CompactProtocolReader reader; + return recv_wrapped_SaveRouteTableT(&reader, _return, state); + } + default: + { + } + } + return folly::make_exception_wrapper("Could not find Protocol"); +} + +bool StoreServiceAsyncClient::recv_SaveRouteTable(::apache::thrift::ClientReceiveState& state) { + bool _return; + auto ew = recv_wrapped_SaveRouteTable(_return, state); + if (ew) { + ew.throw_exception(); + } + return _return; +} + +bool StoreServiceAsyncClient::recv_instance_SaveRouteTable(::apache::thrift::ClientReceiveState& state) { + return recv_SaveRouteTable(state); +} + +folly::exception_wrapper StoreServiceAsyncClient::recv_instance_wrapped_SaveRouteTable(bool& _return, ::apache::thrift::ClientReceiveState& state) { + return recv_wrapped_SaveRouteTable(_return, state); +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/StoreService_custom_protocol.h b/seqsvr/proto/gen-cpp2/StoreService_custom_protocol.h new file mode 100644 index 0000000..5f4da43 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService_custom_protocol.h @@ -0,0 +1,19 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + + +/** + * This header file includes the tcc files of the corresponding header file + * and the header files of its dependent types. Include this header file + * only when you need to use custom protocols (e.g. DebugProtocol, + * VirtualProtocol) to read/write thrift structs. + */ + +#include "StoreService.tcc" + +#include "seqsvr_types_custom_protocol.h" diff --git a/seqsvr/proto/gen-cpp2/StoreService_processmap_binary.cpp b/seqsvr/proto/gen-cpp2/StoreService_processmap_binary.cpp new file mode 100644 index 0000000..2c9d53f --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService_processmap_binary.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "StoreService.h" + +#include "StoreService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/StoreService_processmap_compact.cpp b/seqsvr/proto/gen-cpp2/StoreService_processmap_compact.cpp new file mode 100644 index 0000000..2c9d53f --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService_processmap_compact.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "StoreService.h" + +#include "StoreService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/StoreService_processmap_simple_json.cpp b/seqsvr/proto/gen-cpp2/StoreService_processmap_simple_json.cpp new file mode 100644 index 0000000..2c9d53f --- /dev/null +++ b/seqsvr/proto/gen-cpp2/StoreService_processmap_simple_json.cpp @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "StoreService.h" + +#include "StoreService.tcc" + +namespace seqsvr { + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift diff --git a/seqsvr/proto/gen-cpp2/seqsvr_constants.cpp b/seqsvr/proto/gen-cpp2/seqsvr_constants.cpp new file mode 100644 index 0000000..e2ba733 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_constants.cpp @@ -0,0 +1,13 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "seqsvr_constants.h" + +#include + +namespace seqsvr { + +} // seqsvr diff --git a/seqsvr/proto/gen-cpp2/seqsvr_constants.h b/seqsvr/proto/gen-cpp2/seqsvr_constants.h new file mode 100644 index 0000000..876e9ed --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_constants.h @@ -0,0 +1,17 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include "seqsvr_types.h" +#include +namespace seqsvr { + +struct seqsvr_constants { + +}; + +} // seqsvr diff --git a/seqsvr/proto/gen-cpp2/seqsvr_data.cpp b/seqsvr/proto/gen-cpp2/seqsvr_data.cpp new file mode 100644 index 0000000..83786ab --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_data.cpp @@ -0,0 +1,9 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "seqsvr_data.h" + + diff --git a/seqsvr/proto/gen-cpp2/seqsvr_data.h b/seqsvr/proto/gen-cpp2/seqsvr_data.h new file mode 100644 index 0000000..eee4342 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_data.h @@ -0,0 +1,16 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include +#include + +#include + +#include "seqsvr_types.h" + + diff --git a/seqsvr/proto/gen-cpp2/seqsvr_types.cpp b/seqsvr/proto/gen-cpp2/seqsvr_types.cpp new file mode 100644 index 0000000..e171427 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_types.cpp @@ -0,0 +1,615 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#include "seqsvr_types.h" + +#include "seqsvr_types.tcc" + +#include + +#include + +#include "seqsvr_data.h" + + + +namespace seqsvr { + +void NodeAddrInfo::__clear() { + // clear all fields + ip = apache::thrift::StringTraits< std::string>::fromStringLiteral(""); + port = 0; + __isset.__clear(); +} + +bool NodeAddrInfo::operator==(const NodeAddrInfo& rhs) const { + if (!((ip == rhs.ip))) { + return false; + } + if (!((port == rhs.port))) { + return false; + } + return true; +} + +void NodeAddrInfo::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "ip") { + fid = 1; + _ftype = apache::thrift::protocol::T_STRING; + } + else if (_fname == "port") { + fid = 2; + _ftype = apache::thrift::protocol::T_I32; + } +} + +void swap(NodeAddrInfo& a, NodeAddrInfo& b) { + using ::std::swap; + swap(a.ip, b.ip); + swap(a.port, b.port); + swap(a.__isset, b.__isset); +} + +template uint32_t NodeAddrInfo::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t NodeAddrInfo::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t NodeAddrInfo::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t NodeAddrInfo::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t NodeAddrInfo::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t NodeAddrInfo::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t NodeAddrInfo::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t NodeAddrInfo::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t NodeAddrInfo::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t NodeAddrInfo::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t NodeAddrInfo::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t NodeAddrInfo::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void RangeID::__clear() { + // clear all fields + id_begin = 0; + size = 0; + __isset.__clear(); +} + +bool RangeID::operator==(const RangeID& rhs) const { + if (!((id_begin == rhs.id_begin))) { + return false; + } + if (!((size == rhs.size))) { + return false; + } + return true; +} + +void RangeID::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "id_begin") { + fid = 1; + _ftype = apache::thrift::protocol::T_I32; + } + else if (_fname == "size") { + fid = 2; + _ftype = apache::thrift::protocol::T_I32; + } +} + +void swap(RangeID& a, RangeID& b) { + using ::std::swap; + swap(a.id_begin, b.id_begin); + swap(a.size, b.size); + swap(a.__isset, b.__isset); +} + +template uint32_t RangeID::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t RangeID::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t RangeID::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t RangeID::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t RangeID::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t RangeID::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t RangeID::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t RangeID::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t RangeID::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t RangeID::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t RangeID::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t RangeID::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void RouterNode::__clear() { + // clear all fields + ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::clear(&node_addr); + section_ranges.clear(); + __isset.__clear(); +} + +bool RouterNode::operator==(const RouterNode& rhs) const { + if (!((node_addr == rhs.node_addr))) { + return false; + } + if (!((section_ranges == rhs.section_ranges))) { + return false; + } + return true; +} + +const ::seqsvr::NodeAddrInfo& RouterNode::get_node_addr() const& { + return node_addr; +} + + ::seqsvr::NodeAddrInfo RouterNode::get_node_addr() && { + return std::move(node_addr); +} + +const std::vector< ::seqsvr::RangeID>& RouterNode::get_section_ranges() const& { + return section_ranges; +} + +std::vector< ::seqsvr::RangeID> RouterNode::get_section_ranges() && { + return std::move(section_ranges); +} + +void RouterNode::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "node_addr") { + fid = 1; + _ftype = apache::thrift::protocol::T_STRUCT; + } + else if (_fname == "section_ranges") { + fid = 2; + _ftype = apache::thrift::protocol::T_LIST; + } +} + +void swap(RouterNode& a, RouterNode& b) { + using ::std::swap; + swap(a.node_addr, b.node_addr); + swap(a.section_ranges, b.section_ranges); + swap(a.__isset, b.__isset); +} + +template uint32_t RouterNode::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t RouterNode::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t RouterNode::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t RouterNode::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t RouterNode::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t RouterNode::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t RouterNode::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t RouterNode::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t RouterNode::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t RouterNode::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t RouterNode::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t RouterNode::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void Router::__clear() { + // clear all fields + version = 0; + node_list.clear(); + __isset.__clear(); +} + +bool Router::operator==(const Router& rhs) const { + if (!((version == rhs.version))) { + return false; + } + if (!((node_list == rhs.node_list))) { + return false; + } + return true; +} + +const std::vector< ::seqsvr::RouterNode>& Router::get_node_list() const& { + return node_list; +} + +std::vector< ::seqsvr::RouterNode> Router::get_node_list() && { + return std::move(node_list); +} + +void Router::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "version") { + fid = 1; + _ftype = apache::thrift::protocol::T_I32; + } + else if (_fname == "node_list") { + fid = 2; + _ftype = apache::thrift::protocol::T_LIST; + } +} + +void swap(Router& a, Router& b) { + using ::std::swap; + swap(a.version, b.version); + swap(a.node_list, b.node_list); + swap(a.__isset, b.__isset); +} + +template uint32_t Router::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t Router::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t Router::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t Router::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t Router::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t Router::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t Router::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t Router::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t Router::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t Router::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t Router::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t Router::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void SetNodeInfo::__clear() { + // clear all fields + ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::clear(&set_id); + ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::clear(&node_addr); + __isset.__clear(); +} + +bool SetNodeInfo::operator==(const SetNodeInfo& rhs) const { + if (!((set_id == rhs.set_id))) { + return false; + } + if (!((node_addr == rhs.node_addr))) { + return false; + } + return true; +} + +const ::seqsvr::RangeID& SetNodeInfo::get_set_id() const& { + return set_id; +} + + ::seqsvr::RangeID SetNodeInfo::get_set_id() && { + return std::move(set_id); +} + +const ::seqsvr::NodeAddrInfo& SetNodeInfo::get_node_addr() const& { + return node_addr; +} + + ::seqsvr::NodeAddrInfo SetNodeInfo::get_node_addr() && { + return std::move(node_addr); +} + +void SetNodeInfo::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "set_id") { + fid = 1; + _ftype = apache::thrift::protocol::T_STRUCT; + } + else if (_fname == "node_addr") { + fid = 2; + _ftype = apache::thrift::protocol::T_STRUCT; + } +} + +void swap(SetNodeInfo& a, SetNodeInfo& b) { + using ::std::swap; + swap(a.set_id, b.set_id); + swap(a.node_addr, b.node_addr); + swap(a.__isset, b.__isset); +} + +template uint32_t SetNodeInfo::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t SetNodeInfo::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t SetNodeInfo::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t SetNodeInfo::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t SetNodeInfo::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t SetNodeInfo::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t SetNodeInfo::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t SetNodeInfo::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t SetNodeInfo::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t SetNodeInfo::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t SetNodeInfo::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t SetNodeInfo::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void SetNodeInfoList::__clear() { + // clear all fields + ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::clear(&set_id); + node_addrs.clear(); + __isset.__clear(); +} + +bool SetNodeInfoList::operator==(const SetNodeInfoList& rhs) const { + if (!((set_id == rhs.set_id))) { + return false; + } + if (!((node_addrs == rhs.node_addrs))) { + return false; + } + return true; +} + +const ::seqsvr::RangeID& SetNodeInfoList::get_set_id() const& { + return set_id; +} + + ::seqsvr::RangeID SetNodeInfoList::get_set_id() && { + return std::move(set_id); +} + +const std::vector< ::seqsvr::NodeAddrInfo>& SetNodeInfoList::get_node_addrs() const& { + return node_addrs; +} + +std::vector< ::seqsvr::NodeAddrInfo> SetNodeInfoList::get_node_addrs() && { + return std::move(node_addrs); +} + +void SetNodeInfoList::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "set_id") { + fid = 1; + _ftype = apache::thrift::protocol::T_STRUCT; + } + else if (_fname == "node_addrs") { + fid = 2; + _ftype = apache::thrift::protocol::T_LIST; + } +} + +void swap(SetNodeInfoList& a, SetNodeInfoList& b) { + using ::std::swap; + swap(a.set_id, b.set_id); + swap(a.node_addrs, b.node_addrs); + swap(a.__isset, b.__isset); +} + +template uint32_t SetNodeInfoList::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t SetNodeInfoList::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t SetNodeInfoList::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t SetNodeInfoList::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t SetNodeInfoList::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t SetNodeInfoList::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t SetNodeInfoList::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t SetNodeInfoList::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t SetNodeInfoList::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t SetNodeInfoList::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t SetNodeInfoList::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t SetNodeInfoList::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void PerSetRouterTable::__clear() { + // clear all fields + ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::clear(&set_id); + node_list.clear(); + __isset.__clear(); +} + +bool PerSetRouterTable::operator==(const PerSetRouterTable& rhs) const { + if (!((set_id == rhs.set_id))) { + return false; + } + if (!((node_list == rhs.node_list))) { + return false; + } + return true; +} + +const ::seqsvr::RangeID& PerSetRouterTable::get_set_id() const& { + return set_id; +} + + ::seqsvr::RangeID PerSetRouterTable::get_set_id() && { + return std::move(set_id); +} + +const std::vector< ::seqsvr::RouterNode>& PerSetRouterTable::get_node_list() const& { + return node_list; +} + +std::vector< ::seqsvr::RouterNode> PerSetRouterTable::get_node_list() && { + return std::move(node_list); +} + +void PerSetRouterTable::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "set_id") { + fid = 1; + _ftype = apache::thrift::protocol::T_STRUCT; + } + else if (_fname == "node_list") { + fid = 2; + _ftype = apache::thrift::protocol::T_LIST; + } +} + +void swap(PerSetRouterTable& a, PerSetRouterTable& b) { + using ::std::swap; + swap(a.set_id, b.set_id); + swap(a.node_list, b.node_list); + swap(a.__isset, b.__isset); +} + +template uint32_t PerSetRouterTable::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t PerSetRouterTable::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t PerSetRouterTable::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t PerSetRouterTable::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t PerSetRouterTable::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t PerSetRouterTable::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t PerSetRouterTable::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t PerSetRouterTable::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t PerSetRouterTable::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t PerSetRouterTable::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t PerSetRouterTable::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t PerSetRouterTable::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void Sequence::__clear() { + // clear all fields + sequence = 0; + ::apache::thrift::Cpp2Ops< ::seqsvr::Router>::clear(&router); + __isset.__clear(); +} + +bool Sequence::operator==(const Sequence& rhs) const { + if (!((sequence == rhs.sequence))) { + return false; + } + if (__isset.router != rhs.__isset.router) { + return false; + } + else if (__isset.router && !((router == rhs.router))) { + return false; + } + return true; +} + +const ::seqsvr::Router* Sequence::get_router() const& { + return __isset.router ? std::addressof(router) : nullptr; +} + + ::seqsvr::Router* Sequence::get_router() & { + return __isset.router ? std::addressof(router) : nullptr; +} + +void Sequence::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "sequence") { + fid = 1; + _ftype = apache::thrift::protocol::T_I64; + } + else if (_fname == "router") { + fid = 2; + _ftype = apache::thrift::protocol::T_STRUCT; + } +} + +void swap(Sequence& a, Sequence& b) { + using ::std::swap; + swap(a.sequence, b.sequence); + swap(a.router, b.router); + swap(a.__isset, b.__isset); +} + +template uint32_t Sequence::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t Sequence::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t Sequence::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t Sequence::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t Sequence::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t Sequence::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t Sequence::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t Sequence::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t Sequence::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t Sequence::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t Sequence::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t Sequence::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +void MaxSeqsData::__clear() { + // clear all fields + ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::clear(&set_id); + max_seqs.clear(); + __isset.__clear(); +} + +bool MaxSeqsData::operator==(const MaxSeqsData& rhs) const { + if (!((set_id == rhs.set_id))) { + return false; + } + if (!((max_seqs == rhs.max_seqs))) { + return false; + } + return true; +} + +const ::seqsvr::RangeID& MaxSeqsData::get_set_id() const& { + return set_id; +} + + ::seqsvr::RangeID MaxSeqsData::get_set_id() && { + return std::move(set_id); +} + +const std::vector& MaxSeqsData::get_max_seqs() const& { + return max_seqs; +} + +std::vector MaxSeqsData::get_max_seqs() && { + return std::move(max_seqs); +} + +void MaxSeqsData::translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype) { + if (false) {} + else if (_fname == "set_id") { + fid = 1; + _ftype = apache::thrift::protocol::T_STRUCT; + } + else if (_fname == "max_seqs") { + fid = 2; + _ftype = apache::thrift::protocol::T_LIST; + } +} + +void swap(MaxSeqsData& a, MaxSeqsData& b) { + using ::std::swap; + swap(a.set_id, b.set_id); + swap(a.max_seqs, b.max_seqs); + swap(a.__isset, b.__isset); +} + +template uint32_t MaxSeqsData::read<>(apache::thrift::BinaryProtocolReader*); +template uint32_t MaxSeqsData::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t MaxSeqsData::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t MaxSeqsData::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t MaxSeqsData::read<>(apache::thrift::CompactProtocolReader*); +template uint32_t MaxSeqsData::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t MaxSeqsData::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t MaxSeqsData::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t MaxSeqsData::read<>(apache::thrift::SimpleJSONProtocolReader*); +template uint32_t MaxSeqsData::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +template uint32_t MaxSeqsData::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +template uint32_t MaxSeqsData::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +} // seqsvr diff --git a/seqsvr/proto/gen-cpp2/seqsvr_types.h b/seqsvr/proto/gen-cpp2/seqsvr_types.h new file mode 100644 index 0000000..525f2ab --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_types.h @@ -0,0 +1,1280 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include +#include +#include +#include +#include + +#include + + + +namespace seqsvr { + +class NodeAddrInfo; +class RangeID; +class RouterNode; +class Router; +class SetNodeInfo; +class SetNodeInfoList; +class PerSetRouterTable; +class Sequence; +class MaxSeqsData; + +class NodeAddrInfo : private apache::thrift::detail::st::ComparisonOperators { + public: + + NodeAddrInfo() : + port(0) {} + // FragileConstructor for use in initialization lists only + + NodeAddrInfo(apache::thrift::FragileConstructor, std::string ip__arg, int32_t port__arg) : + ip(std::move(ip__arg)), + port(std::move(port__arg)) { + __isset.ip = true; + __isset.port = true; + } + template + NodeAddrInfo(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + NodeAddrInfo(std::forward(args)...) + { + ip = arg.move(); + __isset.ip = true; + } + template + NodeAddrInfo(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + NodeAddrInfo(std::forward(args)...) + { + port = arg.move(); + __isset.port = true; + } + + NodeAddrInfo(NodeAddrInfo&&) = default; + + NodeAddrInfo(const NodeAddrInfo&) = default; + + NodeAddrInfo& operator=(NodeAddrInfo&&) = default; + + NodeAddrInfo& operator=(const NodeAddrInfo&) = default; + void __clear(); + + virtual ~NodeAddrInfo() {} + + std::string ip; + int32_t port; + + struct __isset { + void __clear() { + ip = false; + port = false; + } + + bool ip = false; + bool port = false; + } __isset; + bool operator==(const NodeAddrInfo& rhs) const; + + bool operator < (const NodeAddrInfo& rhs) const { + if (!(ip == rhs.ip)) { + return ip < rhs.ip; + } + if (!(port == rhs.port)) { + return port < rhs.port; + } + (void)rhs; + return false; + } + + const std::string& get_ip() const& { + return ip; + } + + std::string get_ip() && { + return std::move(ip); + } + + template + std::string& set_ip(T_NodeAddrInfo_ip_struct_setter&& ip_) { + ip = std::forward(ip_); + __isset.ip = true; + return ip; + } + + int32_t get_port() const { + return port; + } + + int32_t& set_port(int32_t port_) { + port = port_; + __isset.port = true; + return port; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(NodeAddrInfo& a, NodeAddrInfo& b); +extern template uint32_t NodeAddrInfo::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t NodeAddrInfo::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t NodeAddrInfo::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t NodeAddrInfo::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t NodeAddrInfo::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t NodeAddrInfo::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t NodeAddrInfo::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t NodeAddrInfo::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t NodeAddrInfo::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t NodeAddrInfo::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t NodeAddrInfo::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t NodeAddrInfo::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::NodeAddrInfo>::clear( ::seqsvr::NodeAddrInfo* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::NodeAddrInfo>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::NodeAddrInfo>::write(Protocol* proto, ::seqsvr::NodeAddrInfo const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::NodeAddrInfo>::read(Protocol* proto, ::seqsvr::NodeAddrInfo* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::NodeAddrInfo>::serializedSize(Protocol const* proto, ::seqsvr::NodeAddrInfo const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::NodeAddrInfo>::serializedSizeZC(Protocol const* proto, ::seqsvr::NodeAddrInfo const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class RangeID : private apache::thrift::detail::st::ComparisonOperators { + public: + + RangeID() : + id_begin(0), + size(0) {} + // FragileConstructor for use in initialization lists only + + RangeID(apache::thrift::FragileConstructor, int32_t id_begin__arg, int32_t size__arg) : + id_begin(std::move(id_begin__arg)), + size(std::move(size__arg)) { + __isset.id_begin = true; + __isset.size = true; + } + template + RangeID(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + RangeID(std::forward(args)...) + { + id_begin = arg.move(); + __isset.id_begin = true; + } + template + RangeID(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + RangeID(std::forward(args)...) + { + size = arg.move(); + __isset.size = true; + } + + RangeID(RangeID&&) = default; + + RangeID(const RangeID&) = default; + + RangeID& operator=(RangeID&&) = default; + + RangeID& operator=(const RangeID&) = default; + void __clear(); + + virtual ~RangeID() {} + + int32_t id_begin; + int32_t size; + + struct __isset { + void __clear() { + id_begin = false; + size = false; + } + + bool id_begin = false; + bool size = false; + } __isset; + bool operator==(const RangeID& rhs) const; + + bool operator < (const RangeID& rhs) const { + if (!(id_begin == rhs.id_begin)) { + return id_begin < rhs.id_begin; + } + if (!(size == rhs.size)) { + return size < rhs.size; + } + (void)rhs; + return false; + } + + int32_t get_id_begin() const { + return id_begin; + } + + int32_t& set_id_begin(int32_t id_begin_) { + id_begin = id_begin_; + __isset.id_begin = true; + return id_begin; + } + + int32_t get_size() const { + return size; + } + + int32_t& set_size(int32_t size_) { + size = size_; + __isset.size = true; + return size; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(RangeID& a, RangeID& b); +extern template uint32_t RangeID::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t RangeID::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t RangeID::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t RangeID::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t RangeID::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t RangeID::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t RangeID::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t RangeID::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t RangeID::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t RangeID::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t RangeID::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t RangeID::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::RangeID>::clear( ::seqsvr::RangeID* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::RangeID>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RangeID>::write(Protocol* proto, ::seqsvr::RangeID const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RangeID>::read(Protocol* proto, ::seqsvr::RangeID* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RangeID>::serializedSize(Protocol const* proto, ::seqsvr::RangeID const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RangeID>::serializedSizeZC(Protocol const* proto, ::seqsvr::RangeID const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class RouterNode : private apache::thrift::detail::st::ComparisonOperators { + public: + + RouterNode() {} + // FragileConstructor for use in initialization lists only + + RouterNode(apache::thrift::FragileConstructor, ::seqsvr::NodeAddrInfo node_addr__arg, std::vector< ::seqsvr::RangeID> section_ranges__arg) : + node_addr(std::move(node_addr__arg)), + section_ranges(std::move(section_ranges__arg)) { + __isset.node_addr = true; + __isset.section_ranges = true; + } + template + RouterNode(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + RouterNode(std::forward(args)...) + { + node_addr = arg.move(); + __isset.node_addr = true; + } + template + RouterNode(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + RouterNode(std::forward(args)...) + { + section_ranges = arg.move(); + __isset.section_ranges = true; + } + + RouterNode(RouterNode&&) = default; + + RouterNode(const RouterNode&) = default; + + RouterNode& operator=(RouterNode&&) = default; + + RouterNode& operator=(const RouterNode&) = default; + void __clear(); + + virtual ~RouterNode() {} + + ::seqsvr::NodeAddrInfo node_addr; + std::vector< ::seqsvr::RangeID> section_ranges; + + struct __isset { + void __clear() { + node_addr = false; + section_ranges = false; + } + + bool node_addr = false; + bool section_ranges = false; + } __isset; + bool operator==(const RouterNode& rhs) const; + + bool operator < (const RouterNode& rhs) const { + if (!(node_addr == rhs.node_addr)) { + return node_addr < rhs.node_addr; + } + if (!(section_ranges == rhs.section_ranges)) { + return section_ranges < rhs.section_ranges; + } + (void)rhs; + return false; + } + const ::seqsvr::NodeAddrInfo& get_node_addr() const&; + ::seqsvr::NodeAddrInfo get_node_addr() &&; + + template + ::seqsvr::NodeAddrInfo& set_node_addr(T_RouterNode_node_addr_struct_setter&& node_addr_) { + node_addr = std::forward(node_addr_); + __isset.node_addr = true; + return node_addr; + } + const std::vector< ::seqsvr::RangeID>& get_section_ranges() const&; + std::vector< ::seqsvr::RangeID> get_section_ranges() &&; + + template + std::vector< ::seqsvr::RangeID>& set_section_ranges(T_RouterNode_section_ranges_struct_setter&& section_ranges_) { + section_ranges = std::forward(section_ranges_); + __isset.section_ranges = true; + return section_ranges; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(RouterNode& a, RouterNode& b); +extern template uint32_t RouterNode::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t RouterNode::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t RouterNode::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t RouterNode::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t RouterNode::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t RouterNode::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t RouterNode::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t RouterNode::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t RouterNode::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t RouterNode::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t RouterNode::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t RouterNode::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::RouterNode>::clear( ::seqsvr::RouterNode* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::RouterNode>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RouterNode>::write(Protocol* proto, ::seqsvr::RouterNode const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RouterNode>::read(Protocol* proto, ::seqsvr::RouterNode* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RouterNode>::serializedSize(Protocol const* proto, ::seqsvr::RouterNode const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::RouterNode>::serializedSizeZC(Protocol const* proto, ::seqsvr::RouterNode const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class Router : private apache::thrift::detail::st::ComparisonOperators { + public: + + Router() : + version(0) {} + // FragileConstructor for use in initialization lists only + + Router(apache::thrift::FragileConstructor, int32_t version__arg, std::vector< ::seqsvr::RouterNode> node_list__arg) : + version(std::move(version__arg)), + node_list(std::move(node_list__arg)) { + __isset.version = true; + __isset.node_list = true; + } + template + Router(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + Router(std::forward(args)...) + { + version = arg.move(); + __isset.version = true; + } + template + Router(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + Router(std::forward(args)...) + { + node_list = arg.move(); + __isset.node_list = true; + } + + Router(Router&&) = default; + + Router(const Router&) = default; + + Router& operator=(Router&&) = default; + + Router& operator=(const Router&) = default; + void __clear(); + + virtual ~Router() {} + + int32_t version; + std::vector< ::seqsvr::RouterNode> node_list; + + struct __isset { + void __clear() { + version = false; + node_list = false; + } + + bool version = false; + bool node_list = false; + } __isset; + bool operator==(const Router& rhs) const; + + bool operator < (const Router& rhs) const { + if (!(version == rhs.version)) { + return version < rhs.version; + } + if (!(node_list == rhs.node_list)) { + return node_list < rhs.node_list; + } + (void)rhs; + return false; + } + + int32_t get_version() const { + return version; + } + + int32_t& set_version(int32_t version_) { + version = version_; + __isset.version = true; + return version; + } + const std::vector< ::seqsvr::RouterNode>& get_node_list() const&; + std::vector< ::seqsvr::RouterNode> get_node_list() &&; + + template + std::vector< ::seqsvr::RouterNode>& set_node_list(T_Router_node_list_struct_setter&& node_list_) { + node_list = std::forward(node_list_); + __isset.node_list = true; + return node_list; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(Router& a, Router& b); +extern template uint32_t Router::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t Router::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t Router::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t Router::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t Router::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t Router::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t Router::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t Router::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t Router::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t Router::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t Router::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t Router::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::Router>::clear( ::seqsvr::Router* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::Router>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Router>::write(Protocol* proto, ::seqsvr::Router const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Router>::read(Protocol* proto, ::seqsvr::Router* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Router>::serializedSize(Protocol const* proto, ::seqsvr::Router const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Router>::serializedSizeZC(Protocol const* proto, ::seqsvr::Router const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class SetNodeInfo : private apache::thrift::detail::st::ComparisonOperators { + public: + + SetNodeInfo() {} + // FragileConstructor for use in initialization lists only + + SetNodeInfo(apache::thrift::FragileConstructor, ::seqsvr::RangeID set_id__arg, ::seqsvr::NodeAddrInfo node_addr__arg) : + set_id(std::move(set_id__arg)), + node_addr(std::move(node_addr__arg)) { + __isset.set_id = true; + __isset.node_addr = true; + } + template + SetNodeInfo(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + SetNodeInfo(std::forward(args)...) + { + set_id = arg.move(); + __isset.set_id = true; + } + template + SetNodeInfo(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + SetNodeInfo(std::forward(args)...) + { + node_addr = arg.move(); + __isset.node_addr = true; + } + + SetNodeInfo(SetNodeInfo&&) = default; + + SetNodeInfo(const SetNodeInfo&) = default; + + SetNodeInfo& operator=(SetNodeInfo&&) = default; + + SetNodeInfo& operator=(const SetNodeInfo&) = default; + void __clear(); + + virtual ~SetNodeInfo() {} + + ::seqsvr::RangeID set_id; + ::seqsvr::NodeAddrInfo node_addr; + + struct __isset { + void __clear() { + set_id = false; + node_addr = false; + } + + bool set_id = false; + bool node_addr = false; + } __isset; + bool operator==(const SetNodeInfo& rhs) const; + + bool operator < (const SetNodeInfo& rhs) const { + if (!(set_id == rhs.set_id)) { + return set_id < rhs.set_id; + } + if (!(node_addr == rhs.node_addr)) { + return node_addr < rhs.node_addr; + } + (void)rhs; + return false; + } + const ::seqsvr::RangeID& get_set_id() const&; + ::seqsvr::RangeID get_set_id() &&; + + template + ::seqsvr::RangeID& set_set_id(T_SetNodeInfo_set_id_struct_setter&& set_id_) { + set_id = std::forward(set_id_); + __isset.set_id = true; + return set_id; + } + const ::seqsvr::NodeAddrInfo& get_node_addr() const&; + ::seqsvr::NodeAddrInfo get_node_addr() &&; + + template + ::seqsvr::NodeAddrInfo& set_node_addr(T_SetNodeInfo_node_addr_struct_setter&& node_addr_) { + node_addr = std::forward(node_addr_); + __isset.node_addr = true; + return node_addr; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(SetNodeInfo& a, SetNodeInfo& b); +extern template uint32_t SetNodeInfo::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t SetNodeInfo::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t SetNodeInfo::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t SetNodeInfo::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t SetNodeInfo::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t SetNodeInfo::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t SetNodeInfo::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t SetNodeInfo::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t SetNodeInfo::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t SetNodeInfo::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t SetNodeInfo::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t SetNodeInfo::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::SetNodeInfo>::clear( ::seqsvr::SetNodeInfo* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::SetNodeInfo>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfo>::write(Protocol* proto, ::seqsvr::SetNodeInfo const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfo>::read(Protocol* proto, ::seqsvr::SetNodeInfo* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfo>::serializedSize(Protocol const* proto, ::seqsvr::SetNodeInfo const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfo>::serializedSizeZC(Protocol const* proto, ::seqsvr::SetNodeInfo const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class SetNodeInfoList : private apache::thrift::detail::st::ComparisonOperators { + public: + + SetNodeInfoList() {} + // FragileConstructor for use in initialization lists only + + SetNodeInfoList(apache::thrift::FragileConstructor, ::seqsvr::RangeID set_id__arg, std::vector< ::seqsvr::NodeAddrInfo> node_addrs__arg) : + set_id(std::move(set_id__arg)), + node_addrs(std::move(node_addrs__arg)) { + __isset.set_id = true; + __isset.node_addrs = true; + } + template + SetNodeInfoList(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + SetNodeInfoList(std::forward(args)...) + { + set_id = arg.move(); + __isset.set_id = true; + } + template + SetNodeInfoList(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + SetNodeInfoList(std::forward(args)...) + { + node_addrs = arg.move(); + __isset.node_addrs = true; + } + + SetNodeInfoList(SetNodeInfoList&&) = default; + + SetNodeInfoList(const SetNodeInfoList&) = default; + + SetNodeInfoList& operator=(SetNodeInfoList&&) = default; + + SetNodeInfoList& operator=(const SetNodeInfoList&) = default; + void __clear(); + + virtual ~SetNodeInfoList() {} + + ::seqsvr::RangeID set_id; + std::vector< ::seqsvr::NodeAddrInfo> node_addrs; + + struct __isset { + void __clear() { + set_id = false; + node_addrs = false; + } + + bool set_id = false; + bool node_addrs = false; + } __isset; + bool operator==(const SetNodeInfoList& rhs) const; + + bool operator < (const SetNodeInfoList& rhs) const { + if (!(set_id == rhs.set_id)) { + return set_id < rhs.set_id; + } + if (!(node_addrs == rhs.node_addrs)) { + return node_addrs < rhs.node_addrs; + } + (void)rhs; + return false; + } + const ::seqsvr::RangeID& get_set_id() const&; + ::seqsvr::RangeID get_set_id() &&; + + template + ::seqsvr::RangeID& set_set_id(T_SetNodeInfoList_set_id_struct_setter&& set_id_) { + set_id = std::forward(set_id_); + __isset.set_id = true; + return set_id; + } + const std::vector< ::seqsvr::NodeAddrInfo>& get_node_addrs() const&; + std::vector< ::seqsvr::NodeAddrInfo> get_node_addrs() &&; + + template + std::vector< ::seqsvr::NodeAddrInfo>& set_node_addrs(T_SetNodeInfoList_node_addrs_struct_setter&& node_addrs_) { + node_addrs = std::forward(node_addrs_); + __isset.node_addrs = true; + return node_addrs; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(SetNodeInfoList& a, SetNodeInfoList& b); +extern template uint32_t SetNodeInfoList::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t SetNodeInfoList::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t SetNodeInfoList::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t SetNodeInfoList::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t SetNodeInfoList::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t SetNodeInfoList::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t SetNodeInfoList::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t SetNodeInfoList::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t SetNodeInfoList::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t SetNodeInfoList::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t SetNodeInfoList::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t SetNodeInfoList::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::SetNodeInfoList>::clear( ::seqsvr::SetNodeInfoList* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::SetNodeInfoList>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfoList>::write(Protocol* proto, ::seqsvr::SetNodeInfoList const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfoList>::read(Protocol* proto, ::seqsvr::SetNodeInfoList* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfoList>::serializedSize(Protocol const* proto, ::seqsvr::SetNodeInfoList const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::SetNodeInfoList>::serializedSizeZC(Protocol const* proto, ::seqsvr::SetNodeInfoList const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class PerSetRouterTable : private apache::thrift::detail::st::ComparisonOperators { + public: + + PerSetRouterTable() {} + // FragileConstructor for use in initialization lists only + + PerSetRouterTable(apache::thrift::FragileConstructor, ::seqsvr::RangeID set_id__arg, std::vector< ::seqsvr::RouterNode> node_list__arg) : + set_id(std::move(set_id__arg)), + node_list(std::move(node_list__arg)) { + __isset.set_id = true; + __isset.node_list = true; + } + template + PerSetRouterTable(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + PerSetRouterTable(std::forward(args)...) + { + set_id = arg.move(); + __isset.set_id = true; + } + template + PerSetRouterTable(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + PerSetRouterTable(std::forward(args)...) + { + node_list = arg.move(); + __isset.node_list = true; + } + + PerSetRouterTable(PerSetRouterTable&&) = default; + + PerSetRouterTable(const PerSetRouterTable&) = default; + + PerSetRouterTable& operator=(PerSetRouterTable&&) = default; + + PerSetRouterTable& operator=(const PerSetRouterTable&) = default; + void __clear(); + + virtual ~PerSetRouterTable() {} + + ::seqsvr::RangeID set_id; + std::vector< ::seqsvr::RouterNode> node_list; + + struct __isset { + void __clear() { + set_id = false; + node_list = false; + } + + bool set_id = false; + bool node_list = false; + } __isset; + bool operator==(const PerSetRouterTable& rhs) const; + + bool operator < (const PerSetRouterTable& rhs) const { + if (!(set_id == rhs.set_id)) { + return set_id < rhs.set_id; + } + if (!(node_list == rhs.node_list)) { + return node_list < rhs.node_list; + } + (void)rhs; + return false; + } + const ::seqsvr::RangeID& get_set_id() const&; + ::seqsvr::RangeID get_set_id() &&; + + template + ::seqsvr::RangeID& set_set_id(T_PerSetRouterTable_set_id_struct_setter&& set_id_) { + set_id = std::forward(set_id_); + __isset.set_id = true; + return set_id; + } + const std::vector< ::seqsvr::RouterNode>& get_node_list() const&; + std::vector< ::seqsvr::RouterNode> get_node_list() &&; + + template + std::vector< ::seqsvr::RouterNode>& set_node_list(T_PerSetRouterTable_node_list_struct_setter&& node_list_) { + node_list = std::forward(node_list_); + __isset.node_list = true; + return node_list; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(PerSetRouterTable& a, PerSetRouterTable& b); +extern template uint32_t PerSetRouterTable::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t PerSetRouterTable::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t PerSetRouterTable::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t PerSetRouterTable::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t PerSetRouterTable::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t PerSetRouterTable::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t PerSetRouterTable::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t PerSetRouterTable::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t PerSetRouterTable::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t PerSetRouterTable::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t PerSetRouterTable::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t PerSetRouterTable::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::PerSetRouterTable>::clear( ::seqsvr::PerSetRouterTable* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::PerSetRouterTable>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::PerSetRouterTable>::write(Protocol* proto, ::seqsvr::PerSetRouterTable const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::PerSetRouterTable>::read(Protocol* proto, ::seqsvr::PerSetRouterTable* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::PerSetRouterTable>::serializedSize(Protocol const* proto, ::seqsvr::PerSetRouterTable const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::PerSetRouterTable>::serializedSizeZC(Protocol const* proto, ::seqsvr::PerSetRouterTable const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class Sequence : private apache::thrift::detail::st::ComparisonOperators { + public: + + Sequence() : + sequence(0) {} + // FragileConstructor for use in initialization lists only + + Sequence(apache::thrift::FragileConstructor, int64_t sequence__arg, ::seqsvr::Router router__arg) : + sequence(std::move(sequence__arg)), + router(std::move(router__arg)) { + __isset.sequence = true; + __isset.router = true; + } + template + Sequence(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + Sequence(std::forward(args)...) + { + sequence = arg.move(); + __isset.sequence = true; + } + template + Sequence(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + Sequence(std::forward(args)...) + { + router = arg.move(); + __isset.router = true; + } + + Sequence(Sequence&&) = default; + + Sequence(const Sequence&) = default; + + Sequence& operator=(Sequence&&) = default; + + Sequence& operator=(const Sequence&) = default; + void __clear(); + + virtual ~Sequence() {} + + int64_t sequence; + ::seqsvr::Router router; + + struct __isset { + void __clear() { + sequence = false; + router = false; + } + + bool sequence = false; + bool router = false; + } __isset; + bool operator==(const Sequence& rhs) const; + bool operator < (const Sequence& rhs) const; + + int64_t get_sequence() const { + return sequence; + } + + int64_t& set_sequence(int64_t sequence_) { + sequence = sequence_; + __isset.sequence = true; + return sequence; + } + const ::seqsvr::Router* get_router() const&; + ::seqsvr::Router* get_router() &; + ::seqsvr::Router* get_router() && = delete; + + template + ::seqsvr::Router& set_router(T_Sequence_router_struct_setter&& router_) { + router = std::forward(router_); + __isset.router = true; + return router; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(Sequence& a, Sequence& b); +extern template uint32_t Sequence::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t Sequence::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t Sequence::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t Sequence::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t Sequence::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t Sequence::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t Sequence::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t Sequence::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t Sequence::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t Sequence::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t Sequence::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t Sequence::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::Sequence>::clear( ::seqsvr::Sequence* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::Sequence>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Sequence>::write(Protocol* proto, ::seqsvr::Sequence const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Sequence>::read(Protocol* proto, ::seqsvr::Sequence* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Sequence>::serializedSize(Protocol const* proto, ::seqsvr::Sequence const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::Sequence>::serializedSizeZC(Protocol const* proto, ::seqsvr::Sequence const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +class MaxSeqsData : private apache::thrift::detail::st::ComparisonOperators { + public: + + MaxSeqsData() {} + // FragileConstructor for use in initialization lists only + + MaxSeqsData(apache::thrift::FragileConstructor, ::seqsvr::RangeID set_id__arg, std::vector max_seqs__arg) : + set_id(std::move(set_id__arg)), + max_seqs(std::move(max_seqs__arg)) { + __isset.set_id = true; + __isset.max_seqs = true; + } + template + MaxSeqsData(::apache::thrift::detail::argument_wrapper<1, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + MaxSeqsData(std::forward(args)...) + { + set_id = arg.move(); + __isset.set_id = true; + } + template + MaxSeqsData(::apache::thrift::detail::argument_wrapper<2, T__ThriftWrappedArgument__Ctor> arg, Args__ThriftWrappedArgument__Ctor&&... args): + MaxSeqsData(std::forward(args)...) + { + max_seqs = arg.move(); + __isset.max_seqs = true; + } + + MaxSeqsData(MaxSeqsData&&) = default; + + MaxSeqsData(const MaxSeqsData&) = default; + + MaxSeqsData& operator=(MaxSeqsData&&) = default; + + MaxSeqsData& operator=(const MaxSeqsData&) = default; + void __clear(); + + virtual ~MaxSeqsData() {} + + ::seqsvr::RangeID set_id; + std::vector max_seqs; + + struct __isset { + void __clear() { + set_id = false; + max_seqs = false; + } + + bool set_id = false; + bool max_seqs = false; + } __isset; + bool operator==(const MaxSeqsData& rhs) const; + + bool operator < (const MaxSeqsData& rhs) const { + if (!(set_id == rhs.set_id)) { + return set_id < rhs.set_id; + } + if (!(max_seqs == rhs.max_seqs)) { + return max_seqs < rhs.max_seqs; + } + (void)rhs; + return false; + } + const ::seqsvr::RangeID& get_set_id() const&; + ::seqsvr::RangeID get_set_id() &&; + + template + ::seqsvr::RangeID& set_set_id(T_MaxSeqsData_set_id_struct_setter&& set_id_) { + set_id = std::forward(set_id_); + __isset.set_id = true; + return set_id; + } + const std::vector& get_max_seqs() const&; + std::vector get_max_seqs() &&; + + template + std::vector& set_max_seqs(T_MaxSeqsData_max_seqs_struct_setter&& max_seqs_) { + max_seqs = std::forward(max_seqs_); + __isset.max_seqs = true; + return max_seqs; + } + + template + uint32_t read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + static void translateFieldName(FOLLY_MAYBE_UNUSED folly::StringPiece _fname, FOLLY_MAYBE_UNUSED int16_t& fid, FOLLY_MAYBE_UNUSED apache::thrift::protocol::TType& _ftype); +}; + +void swap(MaxSeqsData& a, MaxSeqsData& b); +extern template uint32_t MaxSeqsData::read<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t MaxSeqsData::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t MaxSeqsData::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t MaxSeqsData::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t MaxSeqsData::read<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t MaxSeqsData::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t MaxSeqsData::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t MaxSeqsData::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t MaxSeqsData::read<>(apache::thrift::SimpleJSONProtocolReader*); +extern template uint32_t MaxSeqsData::write<>(apache::thrift::SimpleJSONProtocolWriter*) const; +extern template uint32_t MaxSeqsData::serializedSize<>(apache::thrift::SimpleJSONProtocolWriter const*) const; +extern template uint32_t MaxSeqsData::serializedSizeZC<>(apache::thrift::SimpleJSONProtocolWriter const*) const; + +} // seqsvr +namespace apache { namespace thrift { + +template <> inline void Cpp2Ops< ::seqsvr::MaxSeqsData>::clear( ::seqsvr::MaxSeqsData* obj) { + return obj->__clear(); +} + +template <> inline constexpr apache::thrift::protocol::TType Cpp2Ops< ::seqsvr::MaxSeqsData>::thriftType() { + return apache::thrift::protocol::T_STRUCT; +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::MaxSeqsData>::write(Protocol* proto, ::seqsvr::MaxSeqsData const* obj) { + return obj->write(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::MaxSeqsData>::read(Protocol* proto, ::seqsvr::MaxSeqsData* obj) { + return obj->read(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::MaxSeqsData>::serializedSize(Protocol const* proto, ::seqsvr::MaxSeqsData const* obj) { + return obj->serializedSize(proto); +} + +template <> template uint32_t Cpp2Ops< ::seqsvr::MaxSeqsData>::serializedSizeZC(Protocol const* proto, ::seqsvr::MaxSeqsData const* obj) { + return obj->serializedSizeZC(proto); +} + +}} // apache::thrift +namespace seqsvr { + +} // seqsvr diff --git a/seqsvr/proto/gen-cpp2/seqsvr_types.tcc b/seqsvr/proto/gen-cpp2/seqsvr_types.tcc new file mode 100644 index 0000000..5b9286b --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_types.tcc @@ -0,0 +1,925 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + +#include "seqsvr_types.h" +#include +#include +#include +#include +// #include +#include +#include + +#include +#include +#include +namespace seqsvr { + +template +uint32_t NodeAddrInfo::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_STRING) { + xfer += iprot->readString(this->ip); + this->__isset.ip = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_I32) { + xfer += iprot->readI32(this->port); + this->__isset.port = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t NodeAddrInfo::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("NodeAddrInfo"); + xfer += prot_->serializedFieldSize("ip", apache::thrift::protocol::T_STRING, 1); + xfer += prot_->serializedSizeString(this->ip); + xfer += prot_->serializedFieldSize("port", apache::thrift::protocol::T_I32, 2); + xfer += prot_->serializedSizeI32(this->port); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t NodeAddrInfo::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("NodeAddrInfo"); + xfer += prot_->serializedFieldSize("ip", apache::thrift::protocol::T_STRING, 1); + xfer += prot_->serializedSizeString(this->ip); + xfer += prot_->serializedFieldSize("port", apache::thrift::protocol::T_I32, 2); + xfer += prot_->serializedSizeI32(this->port); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t NodeAddrInfo::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("NodeAddrInfo"); + xfer += prot_->writeFieldBegin("ip", apache::thrift::protocol::T_STRING, 1); + xfer += prot_->writeString(this->ip); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("port", apache::thrift::protocol::T_I32, 2); + xfer += prot_->writeI32(this->port); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t RangeID::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_I32) { + xfer += iprot->readI32(this->id_begin); + this->__isset.id_begin = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_I32) { + xfer += iprot->readI32(this->size); + this->__isset.size = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t RangeID::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("RangeID"); + xfer += prot_->serializedFieldSize("id_begin", apache::thrift::protocol::T_I32, 1); + xfer += prot_->serializedSizeI32(this->id_begin); + xfer += prot_->serializedFieldSize("size", apache::thrift::protocol::T_I32, 2); + xfer += prot_->serializedSizeI32(this->size); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t RangeID::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("RangeID"); + xfer += prot_->serializedFieldSize("id_begin", apache::thrift::protocol::T_I32, 1); + xfer += prot_->serializedSizeI32(this->id_begin); + xfer += prot_->serializedFieldSize("size", apache::thrift::protocol::T_I32, 2); + xfer += prot_->serializedSizeI32(this->size); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t RangeID::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("RangeID"); + xfer += prot_->writeFieldBegin("id_begin", apache::thrift::protocol::T_I32, 1); + xfer += prot_->writeI32(this->id_begin); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("size", apache::thrift::protocol::T_I32, 2); + xfer += prot_->writeI32(this->size); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t RouterNode::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_STRUCT) { + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::read(iprot, &this->node_addr); + this->__isset.node_addr = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_LIST) { + this->section_ranges = std::vector< ::seqsvr::RangeID>(); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RangeID>>::read(*iprot, this->section_ranges); + this->__isset.section_ranges = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t RouterNode::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("RouterNode"); + xfer += prot_->serializedFieldSize("node_addr", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::serializedSize(prot_, &this->node_addr); + xfer += prot_->serializedFieldSize("section_ranges", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RangeID>>::serializedSize(*prot_, this->section_ranges); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t RouterNode::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("RouterNode"); + xfer += prot_->serializedFieldSize("node_addr", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::serializedSizeZC(prot_, &this->node_addr); + xfer += prot_->serializedFieldSize("section_ranges", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RangeID>>::serializedSize(*prot_, this->section_ranges); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t RouterNode::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("RouterNode"); + xfer += prot_->writeFieldBegin("node_addr", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::write(prot_, &this->node_addr); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("section_ranges", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RangeID>>::write(*prot_, this->section_ranges); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t Router::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_I32) { + xfer += iprot->readI32(this->version); + this->__isset.version = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_LIST) { + this->node_list = std::vector< ::seqsvr::RouterNode>(); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::read(*iprot, this->node_list); + this->__isset.node_list = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t Router::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("Router"); + xfer += prot_->serializedFieldSize("version", apache::thrift::protocol::T_I32, 1); + xfer += prot_->serializedSizeI32(this->version); + xfer += prot_->serializedFieldSize("node_list", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::serializedSize(*prot_, this->node_list); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t Router::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("Router"); + xfer += prot_->serializedFieldSize("version", apache::thrift::protocol::T_I32, 1); + xfer += prot_->serializedSizeI32(this->version); + xfer += prot_->serializedFieldSize("node_list", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::serializedSize(*prot_, this->node_list); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t Router::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("Router"); + xfer += prot_->writeFieldBegin("version", apache::thrift::protocol::T_I32, 1); + xfer += prot_->writeI32(this->version); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("node_list", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::write(*prot_, this->node_list); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t SetNodeInfo::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_STRUCT) { + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::read(iprot, &this->set_id); + this->__isset.set_id = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_STRUCT) { + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::read(iprot, &this->node_addr); + this->__isset.node_addr = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t SetNodeInfo::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("SetNodeInfo"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSize(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("node_addr", apache::thrift::protocol::T_STRUCT, 2); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::serializedSize(prot_, &this->node_addr); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t SetNodeInfo::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("SetNodeInfo"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSizeZC(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("node_addr", apache::thrift::protocol::T_STRUCT, 2); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::serializedSizeZC(prot_, &this->node_addr); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t SetNodeInfo::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("SetNodeInfo"); + xfer += prot_->writeFieldBegin("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::write(prot_, &this->set_id); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("node_addr", apache::thrift::protocol::T_STRUCT, 2); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::NodeAddrInfo>::write(prot_, &this->node_addr); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t SetNodeInfoList::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_STRUCT) { + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::read(iprot, &this->set_id); + this->__isset.set_id = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_LIST) { + this->node_addrs = std::vector< ::seqsvr::NodeAddrInfo>(); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::NodeAddrInfo>>::read(*iprot, this->node_addrs); + this->__isset.node_addrs = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t SetNodeInfoList::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("SetNodeInfoList"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSize(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("node_addrs", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::NodeAddrInfo>>::serializedSize(*prot_, this->node_addrs); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t SetNodeInfoList::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("SetNodeInfoList"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSizeZC(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("node_addrs", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::NodeAddrInfo>>::serializedSize(*prot_, this->node_addrs); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t SetNodeInfoList::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("SetNodeInfoList"); + xfer += prot_->writeFieldBegin("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::write(prot_, &this->set_id); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("node_addrs", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::NodeAddrInfo>>::write(*prot_, this->node_addrs); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t PerSetRouterTable::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_STRUCT) { + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::read(iprot, &this->set_id); + this->__isset.set_id = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_LIST) { + this->node_list = std::vector< ::seqsvr::RouterNode>(); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::read(*iprot, this->node_list); + this->__isset.node_list = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t PerSetRouterTable::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("PerSetRouterTable"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSize(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("node_list", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::serializedSize(*prot_, this->node_list); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t PerSetRouterTable::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("PerSetRouterTable"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSizeZC(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("node_list", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::serializedSize(*prot_, this->node_list); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t PerSetRouterTable::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("PerSetRouterTable"); + xfer += prot_->writeFieldBegin("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::write(prot_, &this->set_id); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("node_list", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::structure>, std::vector< ::seqsvr::RouterNode>>::write(*prot_, this->node_list); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t Sequence::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_I64) { + xfer += iprot->readI64(this->sequence); + this->__isset.sequence = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_STRUCT) { + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::Router>::read(iprot, &this->router); + this->__isset.router = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t Sequence::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("Sequence"); + xfer += prot_->serializedFieldSize("sequence", apache::thrift::protocol::T_I64, 1); + xfer += prot_->serializedSizeI64(this->sequence); + if (this->__isset.router) { + xfer += prot_->serializedFieldSize("router", apache::thrift::protocol::T_STRUCT, 2); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::Router>::serializedSize(prot_, &this->router); + } + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t Sequence::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("Sequence"); + xfer += prot_->serializedFieldSize("sequence", apache::thrift::protocol::T_I64, 1); + xfer += prot_->serializedSizeI64(this->sequence); + if (this->__isset.router) { + xfer += prot_->serializedFieldSize("router", apache::thrift::protocol::T_STRUCT, 2); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::Router>::serializedSizeZC(prot_, &this->router); + } + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t Sequence::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("Sequence"); + xfer += prot_->writeFieldBegin("sequence", apache::thrift::protocol::T_I64, 1); + xfer += prot_->writeI64(this->sequence); + xfer += prot_->writeFieldEnd(); + if (this->__isset.router) { + xfer += prot_->writeFieldBegin("router", apache::thrift::protocol::T_STRUCT, 2); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::Router>::write(prot_, &this->router); + xfer += prot_->writeFieldEnd(); + } + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +template +uint32_t MaxSeqsData::read(Protocol_* iprot) { + uint32_t xfer = 0; + std::string _fname; + apache::thrift::protocol::TType _ftype; + int16_t fid; + + xfer += iprot->readStructBegin(_fname); + + using apache::thrift::TProtocolException; + + + while (true) { + xfer += iprot->readFieldBegin(_fname, _ftype, fid); + if (_ftype == apache::thrift::protocol::T_STOP) { + break; + } + if (fid == std::numeric_limits::min()) { + this->translateFieldName(_fname, fid, _ftype); + } + switch (fid) { + case 1: + { + if (_ftype == apache::thrift::protocol::T_STRUCT) { + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::read(iprot, &this->set_id); + this->__isset.set_id = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + case 2: + { + if (_ftype == apache::thrift::protocol::T_LIST) { + this->max_seqs = std::vector(); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::integral>, std::vector>::read(*iprot, this->max_seqs); + this->__isset.max_seqs = true; + } else { + xfer += iprot->skip(_ftype); + } + break; + } + default: + { + xfer += iprot->skip(_ftype); + break; + } + } + xfer += iprot->readFieldEnd(); + } + xfer += iprot->readStructEnd(); + + return xfer; +} + +template +uint32_t MaxSeqsData::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("MaxSeqsData"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSize(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("max_seqs", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::integral>, std::vector>::serializedSize(*prot_, this->max_seqs); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t MaxSeqsData::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("MaxSeqsData"); + xfer += prot_->serializedFieldSize("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::serializedSizeZC(prot_, &this->set_id); + xfer += prot_->serializedFieldSize("max_seqs", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::integral>, std::vector>::serializedSize(*prot_, this->max_seqs); + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t MaxSeqsData::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("MaxSeqsData"); + xfer += prot_->writeFieldBegin("set_id", apache::thrift::protocol::T_STRUCT, 1); + xfer += ::apache::thrift::Cpp2Ops< ::seqsvr::RangeID>::write(prot_, &this->set_id); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldBegin("max_seqs", apache::thrift::protocol::T_LIST, 2); + xfer += ::apache::thrift::detail::pm::protocol_methods< ::apache::thrift::type_class::list<::apache::thrift::type_class::integral>, std::vector>::write(*prot_, this->max_seqs); + xfer += prot_->writeFieldEnd(); + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +} // seqsvr +namespace apache { namespace thrift { + +}} // apache::thrift +namespace seqsvr { + +} // seqsvr diff --git a/seqsvr/proto/gen-cpp2/seqsvr_types_custom_protocol.h b/seqsvr/proto/gen-cpp2/seqsvr_types_custom_protocol.h new file mode 100644 index 0000000..0d88f69 --- /dev/null +++ b/seqsvr/proto/gen-cpp2/seqsvr_types_custom_protocol.h @@ -0,0 +1,18 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +#pragma once + + +/** + * This header file includes the tcc files of the corresponding header file + * and the header files of its dependent types. Include this header file + * only when you need to use custom protocols (e.g. DebugProtocol, + * VirtualProtocol) to read/write thrift structs. + */ + +#include "seqsvr_types.tcc" + diff --git a/seqsvr/proto/seqsvr.thrift b/seqsvr/proto/seqsvr.thrift new file mode 100644 index 0000000..db28bd0 --- /dev/null +++ b/seqsvr/proto/seqsvr.thrift @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The first thing to know about are types. The available types in Thrift are: + * + * bool Boolean, one byte + * byte Signed byte + * i16 Signed 16-bit integer + * i32 Signed 32-bit integer + * i64 Signed 64-bit integer + * double 64-bit floating point value + * string String + * binary Blob (byte array) + * map Map from one type to another + * list Ordered list of one type + * set Set of unique elements of one type + * + * Did you also notice that Thrift supports C style comments? + */ + +namespace cpp2 seqsvr + +//////////////////////////////////////////////////////////////////////////////////// +// 路由表 +/* +struct IpPort { + 1: string str; + 2: i32 port; +} + +struct Range { + 1: i32 id; + 2: i32 size; +} + +struct AllocSvrEntry { + 1: string alloc_name; + 2: IpPort addr; + 3: list ranges; +} + +struct SetEntry { + 1: string set_name; + 2: list allocs; // set集合 + 3: Range range; // 号段范围 +} + +struct Router { + 1: i32 version; + // string name = 2; // 服务名,可能会有多个seqsvr提供服务,为统一管理,提供一个唯一名字 + 2: list sets; // set集合,1个集群分配的set +} +*/ + +////////////////////////////////////////////////////////////////////////////// +// 路由表关注的是AllocSvr服务节点 +// 从网络传输视角看: +// 只要传输整个路由列表,设计的数据结构要求紧凑,传输数据量小 +// + +struct NodeAddrInfo { + 1: string ip; + 2: i32 port; +} + +struct RangeID { + 1: i32 id_begin; // 起始地址 + 2: i32 size; // 大小 +} + +// 大部分情况,一个AllocSvr里的号段大部分是连续的 +// 为了减少网络传输量,将连续的号段使用SectionRange进行压缩 +// 例如,1~10个号段, +// id_begin: 1, size: 10 +//struct SectionRange { +// 1: i32 id_begin; // 号段起始地址 +// 2: i32 size; // 有多少个号段 +//} + +// 路由Alloc节点 +struct RouterNode { + 1: NodeAddrInfo node_addr; // 节点地址 + 2: list section_ranges; // 本节点管理的所有号段 +} + +////////////////////////////////////////////////////////////////////////////// +// 客户端眼里的路由表: +struct Router { + 1: i32 version; + 2: list node_list; // 整个集群所有allocsvr节点 +} + +////////////////////////////////////////////////////////////////////////////// +// 仲裁服务眼里的路由表 +// +// 附带set信息的节点, +// 1. 从配置文件中加载 +// 2. Alloc节点上下线 +struct SetNodeInfo { + 1: RangeID set_id; + 2: NodeAddrInfo node_addr; +} + +struct SetNodeInfoList { + 1: RangeID set_id; + 2: list node_addrs; // set里分配了多少AllocSvr +} +// 一个set中的路由表 +struct PerSetRouterTable { + 1: RangeID set_id; + 2: list node_list; +} + +////////////////////////////////////////////////////////////////////////////// +// AllocSvr +struct Sequence { + // 1. 无法提供服务 + // 2. id不存在,仅返回路由表 + // 3. id存在,返回sequence,路由表未更新 + // 4. id存在,返回sequence,路由表需要更新 + // int32 result = 1; + + 1: i64 sequence; + 2: optional Router router; +} + +// struct IdSeq { +// 1: i32 id; +// 2: i64 sequence; +// } + +////////////////////////////////////////////////////////////////////////////// +// StoreSvr +struct MaxSeqsData { + 1: RangeID set_id; // set_id + 2: list max_seqs; // seqs_data +} + +service AllocService { + // 获取下一个Seq + Sequence FetchNextSequence(1: i32 id, 2: i32 version); + // 查询当前Seq + Sequence GetCurrentSequence(1: i32 id, 2: i32 version); + + // FetchNextSequenceListReq -> SequenceListRsp + // list FetchNextSequenceList(1: list id_list); + // list GetCurrentSequenceList(1: list id_list); +} + +//////////////////////////////////////////////////////////////////////////////////// +// StoreSvr +service StoreService { + // 加载max_seqs数据 + MaxSeqsData LoadMaxSeqsData(); + // SaveMaxSeq + i64 SaveMaxSeq(1: i32 id, 2: i64 max_seq); + // 拉取路由表 + Router LoadRouteTable(); + + // 接收仲裁服务生成的路由表 + bool SaveRouteTable(1: Router router); +} + +//////////////////////////////////////////////////////////////////////////////////// +// 仲裁服务 +service MediateService { + void RegisterAllocSvr(1: NodeAddrInfo node_addr); + void UnRegisterAllocSvr(1: NodeAddrInfo node_addr); + + // 当前暂不实现AllocSvr探测,提供一个api接口手动更新StoreSvr里的路由表 + // void UpdateRouteTable(1: Router router); +} + diff --git a/seqsvr/seqsvr/CMakeLists.txt b/seqsvr/seqsvr/CMakeLists.txt index 653d3ad..3d6f26c 100644 --- a/seqsvr/seqsvr/CMakeLists.txt +++ b/seqsvr/seqsvr/CMakeLists.txt @@ -19,20 +19,12 @@ include_directories(. .. ../../nebula) set (SRC_LIST sequence_manager.cc sequence_manager.h + sequence_service_handler.cc + sequence_service_handler.h seq_server.cc seq_server.h - zrpc_seq_dispatcher.cc - zrpc_seq_dispatcher.h - zrpc_seq_service.cc - zrpc_seq_service.h - seq_service_impl.cc - seq_service_impl.h - - ../proto/cc/seqsvr.pb.cc - ../proto/cc/seqsvr.pb.h - ../proto/proto/seqsvr.proto ) add_executable (seqsvr ${SRC_LIST}) -target_link_libraries (seqsvr net base protobuf) +target_link_libraries (seqsvr seqsvr_base base seqsvr_gen-cpp2 boost_system boost_filesystem pthread glog gflags folly thrift thriftcpp2 thriftprotocol zstd ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} dl) diff --git a/seqsvr/seqsvr/seq_server.cc b/seqsvr/seqsvr/seq_server.cc index 40513ed..fc12aa7 100644 --- a/seqsvr/seqsvr/seq_server.cc +++ b/seqsvr/seqsvr/seq_server.cc @@ -18,13 +18,17 @@ // TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 #include "seqsvr/seq_server.h" + #include "seqsvr/sequence_manager.h" +#include "seqsvr/sequence_service_handler.h" + +// using namespace apache::thrift; bool SeqServer::Initialize() { SequenceManager::GetInstance()->Initialize("/tmp/seq.dat"); - - RegisterService("seq_server", "rpc_server", "zrpc"); - BaseServer::Initialize(); + + // RegisterService("seq_server", "rpc_server", "zrpc"); + // BaseServer::Initialize(); #if 0 // one @@ -39,9 +43,39 @@ bool SeqServer::Initialize() { }, 1000); #endif +/* + folly::init(&argc, &argv, true); + + auto handler = make_shared(); + auto server = make_shared(); + server->setInterface(handler); + server->setPort(9090); + + printf("Starting the server...\n"); + server->serve(); + printf("done.\n"); + */ + return true; } +bool SeqServer::Run() { + // auto channel = std::make_shared(); + auto handler = std::make_shared(); + server_ = std::make_shared(); + server_->setInterface(handler); + server_->setPort(9090); + + printf("Starting the server...\n"); + server_->serve(); + printf("done.\n"); + return true; +} + +void SeqServer::Quit() { + server_->stop(); +} + int main(int argc, char* argv[]) { return nebula::DoMain(argc, argv); } diff --git a/seqsvr/seqsvr/seq_server.h b/seqsvr/seqsvr/seq_server.h index 8796efe..d369ac1 100644 --- a/seqsvr/seqsvr/seq_server.h +++ b/seqsvr/seqsvr/seq_server.h @@ -15,27 +15,31 @@ * limitations under the License. */ -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - #ifndef SEQSVR_SEQ_SERVER_H_ #define SEQSVR_SEQ_SERVER_H_ #include +#include -#include "nebula/net/base_server.h" +#include "nebula/base/base_daemon.h" -class SeqServer : public nebula::BaseServer { +class SeqServer : public nebula::BaseDaemon { public: SeqServer() = default; ~SeqServer() override = default; protected: - bool Initialize() override; - - bool Run() override { - BaseServer::Run(); + // 不使用自动配置框架 + bool LoadConfig(const std::string& config_file) override { return true; } + + bool Initialize() override; + bool Run() override; + void Quit() override; + +private: + std::shared_ptr server_; }; #endif // SEQSVR_SEQ_SERVER_H_ diff --git a/seqsvr/seqsvr/seq_service_impl.cc b/seqsvr/seqsvr/seq_service_impl.cc deleted file mode 100644 index 8a87e0b..0000000 --- a/seqsvr/seqsvr/seq_service_impl.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成服务框架代码 - -#include "seqsvr/seq_service_impl.h" - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - -#include "seqsvr/sequence_manager.h" - -int SeqServiceImpl::FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response) { - auto seq = SequenceManager::GetInstance()->FetchNextSequence(request.id()); - response->set_sequence(seq); - return 0; -} - -int SeqServiceImpl::GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response) { - auto seq = SequenceManager::GetInstance()->GetCurrentSequence(request.id()); - response->set_sequence(seq); - return 0; -} - -int SeqServiceImpl::FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response) { - auto seq_mgr = SequenceManager::GetInstance(); - for (int i=0; iFetchNextSequence(request.id_list(i)); - auto id_seq = response->add_sequence_list(); - id_seq->set_id(request.id_list(i)); - id_seq->set_sequence(seq); - } - return 0; -} - -int SeqServiceImpl::GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response) { - auto seq_mgr = SequenceManager::GetInstance(); - for (int i=0; iGetCurrentSequence(request.id_list(i)); - auto id_seq = response->add_sequence_list(); - id_seq->set_id(request.id_list(i)); - id_seq->set_sequence(seq); - } - return 0; -} diff --git a/seqsvr/seqsvr/seq_service_impl.h b/seqsvr/seqsvr/seq_service_impl.h deleted file mode 100644 index 2dcd45f..0000000 --- a/seqsvr/seqsvr/seq_service_impl.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#ifndef SEQSVR_SEQ_SERVICE_IMPL_H_ -#define SEQSVR_SEQ_SERVICE_IMPL_H_ - -#include "seqsvr/zrpc_seq_service.h" - -class SeqServiceImpl : public ZRpcSeqService { -public: - virtual ~SeqServiceImpl() = default; - - int FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response) override; - int GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response) override; - int FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response) override; - int GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response) override; -}; - -#endif - diff --git a/seqsvr/seqsvr/sequence_service_handler.cc b/seqsvr/seqsvr/sequence_service_handler.cc new file mode 100644 index 0000000..034745b --- /dev/null +++ b/seqsvr/seqsvr/sequence_service_handler.cc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "seqsvr/sequence_service_handler.h" + +#include "nebula/base/logger/glog_util.h" +#include "seqsvr/sequence_manager.h" + +SequenceServiceHandler::SequenceServiceHandler() { + LOG(INFO) << "New SequenceServiceHandler!"; +} + +SequenceServiceHandler::~SequenceServiceHandler() { + LOG(INFO) << "Delete SequenceServiceHandler"; +} + +void SequenceServiceHandler::FetchNextSequence( ::seqsvr::SequenceData& result, int32_t id, int32_t version) { + auto seq = SequenceManager::GetInstance()->FetchNextSequence(id); + result.set_sequence(seq); +} + +void SequenceServiceHandler::GetCurrentSequence( ::seqsvr::SequenceData& result, int32_t id, int32_t version) { + auto seq = SequenceManager::GetInstance()->GetCurrentSequence(id); + result.set_sequence(seq); +} + +void SequenceServiceHandler::FetchNextSequenceList(std::vector< ::seqsvr::IdSeq>& result, std::unique_ptr> id_list) { + auto seq_mgr = SequenceManager::GetInstance(); + for (size_t i=0; isize(); ++i) { + auto seq = seq_mgr->FetchNextSequence((*id_list)[i]); + seqsvr::IdSeq id_seq; + id_seq.id = (*id_list)[i]; + id_seq.sequence = seq; + result.push_back(id_seq); + } +} + +void SequenceServiceHandler::GetCurrentSequenceList(std::vector< ::seqsvr::IdSeq>& result, std::unique_ptr> id_list) { + auto seq_mgr = SequenceManager::GetInstance(); + for (size_t i=0; isize(); ++i) { + auto seq = seq_mgr->GetCurrentSequence((*id_list)[i]); + seqsvr::IdSeq id_seq; + id_seq.id = (*id_list)[i]; + id_seq.sequence = seq; + result.push_back(id_seq); + } +} diff --git a/seqsvr/seqsvr/sequence_service_handler.h b/seqsvr/seqsvr/sequence_service_handler.h new file mode 100644 index 0000000..c056871 --- /dev/null +++ b/seqsvr/seqsvr/sequence_service_handler.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SEQSVR_SEQUENCE_SERVICE_HANDLER_H_ +#define SEQSVR_SEQUENCE_SERVICE_HANDLER_H_ + +#include "proto/gen-cpp2/SequenceService.h" + +class SequenceServiceHandler : public seqsvr::SequenceServiceSvIf { +public: + SequenceServiceHandler(); + ~SequenceServiceHandler() override; + + void FetchNextSequence( ::seqsvr::SequenceData& result, int32_t id, int32_t version) override; + void GetCurrentSequence( ::seqsvr::SequenceData& result, int32_t id, int32_t version) override; + void FetchNextSequenceList(std::vector< ::seqsvr::IdSeq>& result, std::unique_ptr> id_list) override; + void GetCurrentSequenceList(std::vector< ::seqsvr::IdSeq>& result, std::unique_ptr> id_list) override; +}; + +#endif diff --git a/seqsvr/seqsvr/zrpc_seq_dispatcher.cc b/seqsvr/seqsvr/zrpc_seq_dispatcher.cc deleted file mode 100644 index 5644f1c..0000000 --- a/seqsvr/seqsvr/zrpc_seq_dispatcher.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#include "seqsvr/zrpc_seq_dispatcher.h" - -#include "seqsvr/seq_service_impl.h" -#include "nebula/net/rpc/zrpc_service_util.h" - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - - -// #include "nebula/net/zproto/api_message_box.h" - -static ZRpcSeqDispatcher g_rpc_seq_dispatcher; - -ZRpcSeqDispatcher::ZRpcSeqDispatcher() { - ZRpcUtil::Register("zproto.FetchNextSequenceReq", ZRpcSeqDispatcher::FetchNextSequence); - ZRpcUtil::Register("zproto.GetCurrentSequenceReq", ZRpcSeqDispatcher::GetCurrentSequence); - ZRpcUtil::Register("zproto.FetchNextSequenceListReq", ZRpcSeqDispatcher::FetchNextSequenceList); - ZRpcUtil::Register("zproto.GetCurrentSequenceListReq", ZRpcSeqDispatcher::GetCurrentSequenceList); -} - -ProtoRpcResponsePtr ZRpcSeqDispatcher::FetchNextSequence(RpcRequestPtr request) { - CAST_RPC_REQUEST(FetchNextSequenceReq, fetch_next_sequece_req); - LOG(INFO) << "DoFetchNextSequenceReq - [" << request->ToString() - << "], " << fetch_next_sequece_req.Utf8DebugString(); - - zproto::SequenceRsp sequence_rsp; - - SeqServiceImpl service_impl; - service_impl.FetchNextSequence(fetch_next_sequece_req, &sequence_rsp); - - return MakeRpcOK(sequence_rsp); -} - -ProtoRpcResponsePtr ZRpcSeqDispatcher::GetCurrentSequence(RpcRequestPtr request) { - CAST_RPC_REQUEST(GetCurrentSequenceReq, get_current_sequece_req); - LOG(INFO) << "DoGetCurrentSequenceReq - [" << request->ToString() << "], " - << get_current_sequece_req.Utf8DebugString(); - - zproto::SequenceRsp sequence_rsp; - - SeqServiceImpl service_impl; - service_impl.GetCurrentSequence(get_current_sequece_req, &sequence_rsp); - - return MakeRpcOK(sequence_rsp); -} - -ProtoRpcResponsePtr ZRpcSeqDispatcher::FetchNextSequenceList(RpcRequestPtr request) { - CAST_RPC_REQUEST(FetchNextSequenceListReq, fetch_next_sequece_list_req); - LOG(INFO) << "FetchNextSequenceList - [" << request->ToString() << "], " - << fetch_next_sequece_list_req.Utf8DebugString(); - - zproto::SequenceListRsp sequence_list_rsp; - - SeqServiceImpl service_impl; - service_impl.FetchNextSequenceList(fetch_next_sequece_list_req, &sequence_list_rsp); - - return MakeRpcOK(sequence_list_rsp); -} - -ProtoRpcResponsePtr ZRpcSeqDispatcher::GetCurrentSequenceList(RpcRequestPtr request) { - CAST_RPC_REQUEST(GetCurrentSequenceListReq, get_current_sequece_list_req); - LOG(INFO) << "GetCurrentSequenceList - [" << request->ToString() << "], " - << get_current_sequece_list_req.Utf8DebugString(); - - zproto::SequenceListRsp sequence_list_rsp; - - SeqServiceImpl service_impl; - service_impl.GetCurrentSequenceList(get_current_sequece_list_req, &sequence_list_rsp); - - return MakeRpcOK(sequence_list_rsp); -} diff --git a/seqsvr/seqsvr/zrpc_seq_service.cc b/seqsvr/seqsvr/zrpc_seq_service.cc deleted file mode 100644 index 5f139c8..0000000 --- a/seqsvr/seqsvr/zrpc_seq_service.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#include "seqsvr/zrpc_seq_service.h" - -#include "nebula/base/logger/glog_util.h" - - -int ZRpcSeqService::FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response) { - LOG(ERROR) << "FetchNextSequence - FetchNextSequence unimplemented"; - return -1; -} - -int ZRpcSeqService::GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response) { - LOG(ERROR) << "GetCurrentSequence - GetCurrentSequence unimplemented"; - return -1; -} - -int ZRpcSeqService::FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response) { - LOG(ERROR) << "FetchNextSequenceList - FetchNextSequenceList unimplemented"; - return -1; -} - -int ZRpcSeqService::GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response) { - LOG(ERROR) << "GetCurrentSequenceList - GetCurrentSequenceList unimplemented"; - return -1; -} diff --git a/seqsvr/seqsvr/zrpc_seq_service.h b/seqsvr/seqsvr/zrpc_seq_service.h deleted file mode 100644 index 9025697..0000000 --- a/seqsvr/seqsvr/zrpc_seq_service.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#ifndef SEQSVR_ZRPC_SEQ_SERVICE_H_ -#define SEQSVR_ZRPC_SEQ_SERVICE_H_ - -#include "proto/cc/seqsvr.pb.h" - -class ZRpcSeqService { -public: - virtual ~ZRpcSeqService() = default; - - virtual int FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response); - virtual int GetCurrentSequence(const zproto::GetCurrentSequenceReq& request, zproto::SequenceRsp* response); - virtual int FetchNextSequenceList(const zproto::FetchNextSequenceListReq& request, zproto::SequenceListRsp* response); - virtual int GetCurrentSequenceList(const zproto::GetCurrentSequenceListReq& request, zproto::SequenceListRsp* response); -}; - -#endif - diff --git a/seqsvr/storesvr/CMakeLists.txt b/seqsvr/storesvr/CMakeLists.txt index f248b33..d8de6bd 100644 --- a/seqsvr/storesvr/CMakeLists.txt +++ b/seqsvr/storesvr/CMakeLists.txt @@ -17,24 +17,16 @@ include_directories(. .. ../../nebula) set (SRC_LIST - ../base/section.h - ../base/set.h store_server.cc store_server.h storesvr_manager.cc storesvr_manager.h - zrpc_store_dispatcher.cc - zrpc_store_dispatcher.h - zrpc_store_service.cc - zrpc_store_service.h - store_service_impl.cc - store_service_impl.h - - ../proto/cc/seqsvr.pb.cc - ../proto/cc/seqsvr.pb.h - ../proto/proto/seqsvr.proto + store_service_handler.cc + store_service_handler.h ) add_executable (storesvr ${SRC_LIST}) -target_link_libraries (storesvr net base protobuf) +# target_link_libraries (storesvr net base protobuf) +target_link_libraries (storesvr seqsvr_base base seqsvr_gen-cpp2 boost_system boost_filesystem pthread glog gflags folly thrift thriftcpp2 thriftprotocol zstd ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} dl) +add_subdirectory(test) diff --git a/seqsvr/storesvr/store_server.cc b/seqsvr/storesvr/store_server.cc index b05f20d..878f628 100644 --- a/seqsvr/storesvr/store_server.cc +++ b/seqsvr/storesvr/store_server.cc @@ -22,38 +22,65 @@ #include "nebula/base/config_manager.h" #include "storesvr/storesvr_manager.h" - +#include "storesvr/store_service_handler.h" +#include "base/thrift_util.h" StoreServer::StoreServer() { auto config_manager = nebula::ConfigManager::GetInstance(); - - config_manager->Register("store", &store_config_); + config_manager->Register("system", this); + config_manager->Register("storesvr", this); + config_manager->Register("sets", this); } +// Override from Configurable +bool StoreServer::StoreServer::SetConf(const std::string& conf_name, const folly::dynamic& conf) { + if (conf_name == "storesvr") { + addr_ = folly::convertTo(conf); + } else if (conf_name == "system") { + db_path_ = folly::convertTo(conf["db_path"]); + set_id_.id_begin = folly::convertTo(conf["set_id"]); + set_id_.size = folly::convertTo(conf["set_size"]); + } else if (conf_name == "sets") { + sets_ = folly::convertTo(conf); + } + + return true; +} bool StoreServer::Initialize() { - auto store_instance = StoreSvrManager::GetInstance(); - store_instance->Initialize(store_config_.set_name, store_config_.store_path); - - RegisterService("store_server", "rpc_server", "zrpc"); - BaseServer::Initialize(); + auto instance = StoreSvrManager::GetInstance(); + instance->Initialize(set_id_, db_path_); + +#ifdef DEBUG_TEST + auto router = MakeTestRouter(sets_); + LOG(INFO) << "MakeTestRouter: " << convertToString(router); + instance->SaveCacheRouter(router); +#endif -#if 0 - // one - timer_manager_->ScheduleOneShotTimeout([]() { - LOG(INFO) << "ScheduleOneShotTimeout!!!!"; - }, 1000); + // RegisterService("store_server", "rpc_server", "zrpc"); + // BaseServer::Initialize(); - // once - timer_manager_->ScheduleRepeatingTimeout([]() { - static int i = 0; - LOG(INFO) << "ScheduleRepeatingTimeout - " << i++; - }, 1000); -#endif + return true; +} + +bool StoreServer::Run() { + auto handler = std::make_shared(); + server_ = std::make_shared(); + server_->setInterface(handler); + server_->setPort(addr_.port); + printf("Starting the server...\n"); + server_->serve(); + printf("done.\n"); return true; } +void StoreServer::Quit() { + server_->stop(); + sleep(1); + BaseDaemon::Quit(); +} + int main(int argc, char* argv[]) { return nebula::DoMain(argc, argv); } diff --git a/seqsvr/storesvr/store_server.h b/seqsvr/storesvr/store_server.h index f16b417..02860c6 100644 --- a/seqsvr/storesvr/store_server.h +++ b/seqsvr/storesvr/store_server.h @@ -15,49 +15,49 @@ * limitations under the License. */ -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - #ifndef STORESVR_STORE_SERVER_H_ #define STORESVR_STORE_SERVER_H_ -#include +#include #include "nebula/base/configurable.h" -#include "nebula/net/base_server.h" - -struct StoreConfig : public nebula::Configurable { - virtual ~StoreConfig() = default; - - // Override from Configurable - bool SetConf(const std::string& conf_name, const folly::dynamic& conf) override { - folly::dynamic v = nullptr; - - v = Configurable::GetConfigValue(conf, "store_path"); - if (v.isString()) store_path = v.asString(); - v = Configurable::GetConfigValue(conf, "set_name"); - if (v.isString()) set_name = v.asString(); - - return true; - } - - std::string store_path; - std::string set_name; -}; - -class StoreServer : public nebula::BaseServer { +#include "nebula/base/base_daemon.h" + +#include "base/section.h" +#include "base/config.h" + +// 把存储层StoreSvr +// StoreSvr为存储层,利用了多机NRW策略来保证数据持久化后不丢失 +// +// NWR模型,把CAP的选择权交给了用户,让用户自己选择CAP中的哪两个。 +// +// N代表N个副本(replication), +// W代表写入数据时至少要写入W份副本才认为成功, +// R表示读取数据时至少要读取R份副本。 +// 对于R和W的选择,要求W+R > N。 +class StoreServer : public nebula::BaseDaemon, public nebula::Configurable { public: StoreServer(); ~StoreServer() override = default; + // Override from Configurable + bool SetConf(const std::string& conf_name, const folly::dynamic& conf) override; + protected: bool Initialize() override; + bool Run() override; + void Quit() override; + + // StoreConfig store_config_; + +private: + std::shared_ptr server_; - bool Run() override { - BaseServer::Run(); - return true; - } + SetID set_id_; + IpAddrInfo addr_; + SetsConfig sets_; + std::string db_path_; - StoreConfig store_config_; }; #endif // STORESVR_STORE_SERVER_H_ diff --git a/seqsvr/storesvr/store_service_handler.cc b/seqsvr/storesvr/store_service_handler.cc new file mode 100644 index 0000000..6dc107f --- /dev/null +++ b/seqsvr/storesvr/store_service_handler.cc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016, https://github.com/nebula-im + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成服务框架代码 + +#include "storesvr/store_service_handler.h" + +#include "base/thrift_util.h" +#include "storesvr/storesvr_manager.h" + +void StoreServiceHandler::LoadMaxSeqsData(seqsvr::MaxSeqsData& _return) { + auto instance = StoreSvrManager::GetInstance(); + instance->GetMaxSeqsData(_return); + + LOG(INFO) << "LoadMaxSeqsData - _return: " << convertToString(_return); +} + +int64_t StoreServiceHandler::SaveMaxSeq(int32_t id, int64_t max_seq) { + LOG(INFO) << "SaveMaxSeq - id: " << id << ", max_seq: " << max_seq; + auto instance = StoreSvrManager::GetInstance(); + return instance->SetSectionMaxSeq(id, max_seq); +} + +void StoreServiceHandler::LoadRouteTable(seqsvr::Router& _return) { + auto instance = StoreSvrManager::GetInstance(); + instance->GetCacheRouter(_return); + + LOG(INFO) << "LoadRouteTable - _return: " << convertToString(_return); +} + +bool StoreServiceHandler::SaveRouteTable(std::unique_ptr router) { + auto instance = StoreSvrManager::GetInstance(); + return instance->SaveCacheRouter(*router); + // response->mutable_router()->CopyFrom(StoreSvrManager::GetInstance()->GetCacheRouter()); + + LOG(INFO) << "SaveRouteTable - router: " << convertToString(*router); + return true; +} + diff --git a/seqsvr/storesvr/zrpc_store_dispatcher.h b/seqsvr/storesvr/store_service_handler.h similarity index 57% rename from seqsvr/storesvr/zrpc_store_dispatcher.h rename to seqsvr/storesvr/store_service_handler.h index ba42dbf..ecae1a0 100644 --- a/seqsvr/storesvr/zrpc_store_dispatcher.h +++ b/seqsvr/storesvr/store_service_handler.h @@ -17,21 +17,22 @@ // TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 -#ifndef STORESVR_ZRPC_STORE_DISPATCHER_H_ -#define STORESVR_ZRPC_STORE_DISPATCHER_H_ +#ifndef STORESVR_STORE_SERVICE_HANDLER_H_ +#define STORESVR_STORE_SERVICE_HANDLER_H_ -#include "nebula/net/zproto/zproto_package_data.h" +#include "proto/gen-cpp2/StoreService.h" -class ZRpcStoreDispatcher { +class StoreServiceHandler : public seqsvr::StoreServiceSvIf { public: - ZRpcStoreDispatcher(); - ~ZRpcStoreDispatcher() = default; + virtual ~StoreServiceHandler() = default; - static ProtoRpcResponsePtr LoadMaxSeqsData(RpcRequestPtr request); - static ProtoRpcResponsePtr SaveMaxSeq(RpcRequestPtr request); + void LoadMaxSeqsData(seqsvr::MaxSeqsData& _return) override; + int64_t SaveMaxSeq(int32_t id, int64_t max_seq) override; - static ProtoRpcResponsePtr UpdateRouteTable(RpcRequestPtr request); - static ProtoRpcResponsePtr GetRouteTable(RpcRequestPtr request); + void LoadRouteTable(seqsvr::Router& _return) override; + + bool SaveRouteTable(std::unique_ptr router) override; }; -#endif // STORESVR_ZRPC_STORE_DISPATCHER_H_ +#endif + diff --git a/seqsvr/storesvr/store_service_impl.cc b/seqsvr/storesvr/store_service_impl.cc deleted file mode 100644 index 01538b7..0000000 --- a/seqsvr/storesvr/store_service_impl.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成服务框架代码 - -#include "storesvr/store_service_impl.h" - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - -#include "storesvr/storesvr_manager.h" - -int StoreServiceImpl::LoadMaxSeqsData(const zproto::LoadMaxSeqsDataReq& request, zproto::LoadMaxSeqsDataRsp* response) { - auto max_seqs = response->mutable_max_seqs(); - StoreSvrManager::GetInstance()->GetSectionsData(max_seqs); - return 0; -} - -int StoreServiceImpl::SaveMaxSeq(const zproto::SaveMaxSeqReq& request, zproto::SaveMaxSeqRsp* response) { - uint64_t last_max_seq = StoreSvrManager::GetInstance()->SetSectionsData(request.section_id(), - request.max_seq()); - response->set_last_max_seq(last_max_seq); - return 0; -} - -int StoreServiceImpl::UpdateRouteTable(const zproto::UpdateRouteTableReq& request, zproto::UpdateRouteTableRsp* response) { - StoreSvrManager::GetInstance()->SaveCacheRouter(request.router()); - return 0; -} - -int StoreServiceImpl::GetRouteTable(const zproto::GetRouteTableReq& request, zproto::GetRouteTableRsp* response) { - response->mutable_router()->CopyFrom(StoreSvrManager::GetInstance()->GetCacheRouter()); - return 0; -} - diff --git a/seqsvr/storesvr/store_service_impl.h b/seqsvr/storesvr/store_service_impl.h deleted file mode 100644 index 4eea116..0000000 --- a/seqsvr/storesvr/store_service_impl.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#ifndef STORESVR_STORE_SERVICE_IMPL_H_ -#define STORESVR_STORE_SERVICE_IMPL_H_ - -#include "storesvr/zrpc_store_service.h" - -class StoreServiceImpl : public ZRpcStoreService { -public: - virtual ~StoreServiceImpl() = default; - - int LoadMaxSeqsData(const zproto::LoadMaxSeqsDataReq& request, zproto::LoadMaxSeqsDataRsp* response) override; - int SaveMaxSeq(const zproto::SaveMaxSeqReq& request, zproto::SaveMaxSeqRsp* response) override; - - int UpdateRouteTable(const zproto::UpdateRouteTableReq& request, zproto::UpdateRouteTableRsp* response) override; - int GetRouteTable(const zproto::GetRouteTableReq& request, zproto::GetRouteTableRsp* response) override; -}; - -#endif - diff --git a/seqsvr/storesvr/storesvr_manager.cc b/seqsvr/storesvr/storesvr_manager.cc index 825800c..a5345d9 100644 --- a/seqsvr/storesvr/storesvr_manager.cc +++ b/seqsvr/storesvr/storesvr_manager.cc @@ -21,12 +21,13 @@ #include #include -/* - 1. 内存中储存最近一个分配出去的sequence:cur_seq,以及分配上限:max_seq - 2. 分配sequence时,将cur_seq++,同时与分配上限max_seq比较: - 如果cur_seq > max_seq,将分配上限提升一个步长max_seq += step,并持久化max_seq - 3. 重启时,读出持久化的max_seq,赋值给cur_seq - */ +#include + +// 1. 内存中储存最近一个分配出去的sequence:cur_seq,以及分配上限:max_seq +// 2. 分配sequence时,将cur_seq++,同时与分配上限max_seq比较: +// 如果cur_seq > max_seq,将分配上限提升一个步长max_seq += step,并持久化max_seq +// 3. 重启时,读出持久化的max_seq,赋值给cur_seq +// // folly::Singleton ; static folly::Singleton g_storesvr_manager; @@ -34,7 +35,9 @@ std::shared_ptr StoreSvrManager::GetInstance() { return g_storesvr_manager.try_get(); } -bool StoreSvrManager::Initialize(const std::string& set_name, const std::string& filepath) { +bool StoreSvrManager::Initialize(SetID set_id, const std::string& filepath) { + CHECK(!inited_); + boost::filesystem::path f2(filepath); if (!boost::filesystem::exists(f2)) { LOG(ERROR) << "Initialize - store db's filepath not exist!! " << filepath; @@ -42,29 +45,41 @@ bool StoreSvrManager::Initialize(const std::string& set_name, const std::string& } // set_id_ = set_id; - seq_file_path_ = filepath + "/seqdb.dat"; - route_table_file_path_ = filepath + "/router.dat"; + auto seq_file_path = folly::sformat("{}/set_{}_{}.db", + filepath, + set_id.id_begin, + set_id.size); + + auto section_size = CalcSetSectionSize(set_id); + auto section_mem_size = section_size << 3; + + route_table_file_path_ = folly::sformat("{}/router_{}_{}.dat", + filepath, + set_id.id_begin, + set_id.size); + // filepath + "/router.dat"; // 是不是第一次 bool is_first = false; // 1. 文件不存在,则创建文件 - boost::filesystem::path f(seq_file_path_); + boost::filesystem::path f(seq_file_path); if (!boost::filesystem::exists(f)) { - section_fd_ = folly::openNoInt(seq_file_path_.c_str(), O_CREAT | O_RDWR); + section_fd_ = folly::openNoInt(seq_file_path.c_str(), O_CREAT | O_RDWR); PCHECK(section_fd_!=-1) << ""; - PCHECK(folly::ftruncateNoInt(section_fd_, kSectionSlotMemSize) == 0) << kSectionSlotMemSize; + PCHECK(folly::ftruncateNoInt(section_fd_, section_mem_size) == 0) + << section_mem_size; // section_fd_ = folly::truncateNoInt(filepath.c_str(), SECTION_SLOT_MEM_SIZE); is_first = true; } else { auto sz = boost::filesystem::file_size(f); - if (sz == kSectionSlotMemSize) { - section_fd_ = folly::openNoInt(seq_file_path_.c_str(), O_RDWR); + if (sz == section_mem_size) { + section_fd_ = folly::openNoInt(seq_file_path.c_str(), O_RDWR); } else { // 直接退出 - LOG(FATAL) << "section' file size invalid, sz = " << sz; + LOG(FATAL) << "section's file size invalid, sz = " << sz; folly::closeNoInt(section_fd_); return false; @@ -78,21 +93,25 @@ bool StoreSvrManager::Initialize(const std::string& set_name, const std::string& } // 绑定文件映射 - section_max_seqs_mapping_ = new folly::MemoryMapping(section_fd_, 0, kSectionSlotMemSize, folly::MemoryMapping::writable()); + section_max_seqs_mapping_ = new folly::MemoryMapping(section_fd_, 0, section_mem_size, folly::MemoryMapping::writable()); CHECK(section_max_seqs_mapping_); - mapping_mem_ = section_max_seqs_mapping_->asWritableRange(); + auto mapping_mem = section_max_seqs_mapping_->asWritableRange(); if (is_first) { - memset(mapping_mem_.data(), 0, mapping_mem_.size()); + memset(mapping_mem.data(), 0, mapping_mem.size()*8); } - + + // 至此,初始化set成功 + set_ = std::make_unique(set_id, mapping_mem); + f = boost::filesystem::path(route_table_file_path_); if (boost::filesystem::exists(f)) { std::string data; if (folly::readFile(route_table_file_path_.c_str(), data)) { - if(!cache_router_.ParseFromString(data)) { + auto rv = apache::thrift::SimpleJSONSerializer::deserialize(data, cache_router_); + if (rv != data.length()) { LOG(ERROR) << "Initialize - router data invalid!!!!!"; - cache_router_.Clear(); + // cache_router_.Clear(); } } } @@ -110,41 +129,43 @@ StoreSvrManager::~StoreSvrManager() { folly::closeNoInt(section_fd_); } -std::string StoreSvrManager::GetSectionsData() { - // TODO(@benqi): 映射到set_id/alloc_id - std::string section_max_seqs((char*)mapping_mem_.data(), mapping_mem_.size()*sizeof(uint64_t)); - return section_max_seqs; -} - -bool StoreSvrManager::GetSectionsData(std::string* data) { - data->assign((char*)mapping_mem_.data(), mapping_mem_.size()*sizeof(uint64_t)); +bool StoreSvrManager::GetMaxSeqsData(seqsvr::MaxSeqsData& max_seqs) { + if (!inited_ || !set_) { + return false; + } + + // return set_->GetSectionSetData(max_seqs); + max_seqs.set_id.id_begin = set_->GetID().id_begin; + max_seqs.set_id.size = set_->GetID().size; + max_seqs.max_seqs.assign( + set_->GetMaxSeqsData().begin(), + set_->GetMaxSeqsData().end()); + return true; } -uint64_t StoreSvrManager::SetSectionsData(uint32_t section_id, uint64_t max_seq) { - // TODO(@benqi): 映射到set_id/alloc_id - uint64_t rv = (max_seq/kMaxSeqStep+1)*kMaxSeqStep; +uint64_t StoreSvrManager::SetSectionMaxSeq(uint32_t id, uint64_t max_seq) { + CHECK(inited_); + CHECK(set_); - // TODO(@benqi): 1. msync, 2. 是否要锁? - if (rv > mapping_mem_[section_id]) { - mapping_mem_[section_id] = rv; - } else { - LOG(ERROR) << "SetSectionsData - max_seq invalid: local seq = " << rv << ", req seq = " << max_seq; - rv = 0; - } - return rv; + return set_->SetMaxSeq(id, max_seq); } -bool StoreSvrManager::SaveCacheRouter(const zproto::Router& router) { +bool StoreSvrManager::SaveCacheRouter(const seqsvr::Router& router) { std::string data; - if (!router.SerializeToString(&data)) { + apache::thrift::SimpleJSONSerializer::serialize(router, &data); + + if (data.empty()) { LOG(ERROR) << "SaveCacheRouter - cache_router_ serialize error!!!!"; return false; } + // data.push_back('\n'); if (!folly::writeFile(data, route_table_file_path_.c_str())) { LOG(WARNING) << "SaveCacheRouter - write route_table error!!!"; + return false; } + cache_router_ = router; return true; } diff --git a/seqsvr/storesvr/storesvr_manager.h b/seqsvr/storesvr/storesvr_manager.h index b0aaf80..6989d1e 100644 --- a/seqsvr/storesvr/storesvr_manager.h +++ b/seqsvr/storesvr/storesvr_manager.h @@ -21,42 +21,49 @@ #include #include -#include "proto/cc/seqsvr.pb.h" +#include "proto/gen-cpp2/seqsvr_types.h" #include "base/set.h" -// TODO(@benqi): 单机模拟set的allocsvr和storesvr + class StoreSvrManager { public: ~StoreSvrManager(); static std::shared_ptr GetInstance(); - bool Initialize(const std::string& set_name, const std::string& filepath); - - std::string GetSectionsData(); - bool GetSectionsData(std::string* data); + // 通过配置文件加载 + // 参数说明 + // set_size: 整个系统里分配了多少个set + // set_idx:属于第几个set + // filepath: 存储路径 + bool Initialize(SetID set_id, const std::string& filepath); - uint64_t SetSectionsData(uint32_t section_id, uint64_t max_seq); + bool GetMaxSeqsData(seqsvr::MaxSeqsData& max_seqs); + uint64_t SetSectionMaxSeq(uint32_t id, uint64_t max_seq); - zproto::Router& GetCacheRouter() { - return cache_router_; + void GetCacheRouter(seqsvr::Router& router) { + router = cache_router_; } - - bool SaveCacheRouter(const zproto::Router& router); + bool SaveCacheRouter(const seqsvr::Router& router); private: StoreSvrManager() = default; friend class folly::Singleton; + bool inited_ = false; + + // std::string seq_file_path_; + // set + std::unique_ptr set_; + + // 使用内存映射文件文件操作section文件 int section_fd_ {-1}; folly::MemoryMapping* section_max_seqs_mapping_ {nullptr}; - folly::Range mapping_mem_; - - bool inited_ = false; - std::string seq_file_path_; - std::string route_table_file_path_; + // folly::Range mapping_mem_; - zproto::Router cache_router_; + // 路由表存储文件 + std::string route_table_file_path_; + seqsvr::Router cache_router_; }; #endif diff --git a/seqsvr/storesvr/test/CMakeLists.txt b/seqsvr/storesvr/test/CMakeLists.txt new file mode 100644 index 0000000..6b7d6a8 --- /dev/null +++ b/seqsvr/storesvr/test/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2016, https://github.com/nebula-im/nebula +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +add_executable (store_client store_client.cc) +target_link_libraries (store_client base seqsvr_gen-cpp2 boost_system boost_filesystem pthread glog gflags folly thrift thriftcpp2 thriftprotocol zstd ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} readline dl) diff --git a/seqsvr/storesvr/test/store_client.cc b/seqsvr/storesvr/test/store_client.cc new file mode 100644 index 0000000..91c211b --- /dev/null +++ b/seqsvr/storesvr/test/store_client.cc @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include + +#include +#include +#include + +#include "proto/gen-cpp2/seqsvr_types.h" +#include "proto/gen-cpp2/StoreService.h" + +#include + +using namespace std; +using namespace folly; +using namespace apache::thrift; +using namespace seqsvr; +/* +stdcxx::shared_ptr socket(new TSocket("localhost", 9090)); +stdcxx::shared_ptr transport(new TBufferedTransport(socket)); +stdcxx::shared_ptr protocol(new TBinaryProtocol(transport)); +CalculatorClient client(protocol); + +try { + transport->open(); +*/ + +int main(int argc, char** argv) { + folly::init(&argc, &argv, true); + + EventBase eb; + auto client = std::make_unique( + HeaderClientChannel::newChannel( + async::TAsyncSocket::newSocket( + &eb, {"127.0.0.1", 9090}))); + + try { + /* + struct NodeAddrInfo { + 1: string ip; + 2: i32 port; + } + + // 大部分情况,一个AllocSvr里的号段大部分是连续的 + // 为了减少网络传输量,将连续的号段使用SectionRange进行压缩 + // 例如,1~10个号段, + // id_begin: 1, size: 10 + struct SectionRange { + 1: i32 id_begin; // 号段起始地址 + 2: i32 size; // 有多少个号段 + } + + // 路由Alloc节点 + struct RouterNode { + 1: NodeAddrInfo node_addr; // 节点地址 + 2: list section_ranges; // 本节点管理的所有号段 + } + + ////////////////////////////////////////////////////////////////////////////// + // 客户端眼里的路由表: + struct Router { + 1: i32 version; + 2: list node_list; // 整个集群所有allocsvr节点 + } + + */ + + RouterNode node; + node.node_addr.ip = "127.0.0.1"; + node.node_addr.port = 10000; + + SectionRange range; + + range.id_begin = 0; + range.size = 1<<19; + node.section_ranges.push_back(range); + + range.id_begin = 1<<19; + range.size = 1<<19; + node.section_ranges.push_back(range); + + Router table; + table.version = 1; + table.node_list.push_back(node); + + // auto s = makeTestStruct(); + std::string data; + apache::thrift::SimpleJSONSerializer::serialize(table, &data); + // auto data = q.move(); + + // apache::thrift::JSONSerializer::serialize(table, &data); + printf("update route table: %s\n", data.c_str()); + + + auto rv = client->sync_SaveRouteTable(table); +// Request req; +// req.str = "hello"; +// Response rsp; +// client->sync_helloWorld( rsp, req); + printf("update route table: %d\n", rv); + } catch (TException &tx) { + printf("ERROR: %s\n", tx.what()); + } +} diff --git a/seqsvr/storesvr/zrpc_store_dispatcher.cc b/seqsvr/storesvr/zrpc_store_dispatcher.cc deleted file mode 100644 index 1af4526..0000000 --- a/seqsvr/storesvr/zrpc_store_dispatcher.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#include "storesvr/zrpc_store_dispatcher.h" - -#include "storesvr/store_service_impl.h" -#include "nebula/net/rpc/zrpc_service_util.h" - -#include "proto/cc/seqsvr.pb.h" -#include "nebula/net/zproto/api_message_box.h" - - -// #include "nebula/net/zproto/api_message_box.h" - -static ZRpcStoreDispatcher g_rpc_store_dispatcher; - -ZRpcStoreDispatcher::ZRpcStoreDispatcher() { - ZRpcUtil::Register("zproto.LoadMaxSeqsDataReq", ZRpcStoreDispatcher::LoadMaxSeqsData); - ZRpcUtil::Register("zproto.SaveMaxSeqReq", ZRpcStoreDispatcher::SaveMaxSeq); - - ZRpcUtil::Register("zproto.UpdateRouteTableReq", ZRpcStoreDispatcher::UpdateRouteTable); - ZRpcUtil::Register("zproto.GetRouteTableReq", ZRpcStoreDispatcher::GetRouteTable); -} - -ProtoRpcResponsePtr ZRpcStoreDispatcher::LoadMaxSeqsData(RpcRequestPtr request) { - CAST_RPC_REQUEST(LoadMaxSeqsDataReq, load_max_seqs_data_req); - LOG(INFO) << "LoadMaxSeqsData - [" << request->ToString() - << "], " << load_max_seqs_data_req.Utf8DebugString(); - - zproto::LoadMaxSeqsDataRsp load_max_seqs_data_rsp; - - StoreServiceImpl service_impl; - service_impl.LoadMaxSeqsData(load_max_seqs_data_req, &load_max_seqs_data_rsp); - - return MakeRpcOK(load_max_seqs_data_rsp); -} - -ProtoRpcResponsePtr ZRpcStoreDispatcher::SaveMaxSeq(RpcRequestPtr request) { - CAST_RPC_REQUEST(SaveMaxSeqReq, save_max_seq_req); - LOG(INFO) << "LoadMaxSeqsData - [" << request->ToString() - << "], " << save_max_seq_req.Utf8DebugString(); - - zproto::SaveMaxSeqRsp save_max_seq_rsp; - - StoreServiceImpl service_impl; - service_impl.SaveMaxSeq(save_max_seq_req, &save_max_seq_rsp); - - return MakeRpcOK(save_max_seq_rsp); -} - -ProtoRpcResponsePtr ZRpcStoreDispatcher::UpdateRouteTable(RpcRequestPtr request) { - CAST_RPC_REQUEST(UpdateRouteTableReq, update_route_table_req); - LOG(INFO) << "UpdateRouteTable - [" << request->ToString() - << "], " << update_route_table_req.Utf8DebugString(); - - zproto::UpdateRouteTableRsp update_route_table_rsp; - - StoreServiceImpl service_impl; - service_impl.UpdateRouteTable(update_route_table_req, &update_route_table_rsp); - - return MakeRpcOK(update_route_table_rsp); -} - -ProtoRpcResponsePtr ZRpcStoreDispatcher::GetRouteTable(RpcRequestPtr request) { - CAST_RPC_REQUEST(GetRouteTableReq, get_route_table_req); - LOG(INFO) << "GetRouteTable - [" << request->ToString() - << "], " << get_route_table_req.Utf8DebugString(); - - zproto::GetRouteTableRsp get_route_table_rsp; - - StoreServiceImpl service_impl; - service_impl.GetRouteTable(get_route_table_req, &get_route_table_rsp); - - return MakeRpcOK(get_route_table_rsp); -} diff --git a/seqsvr/storesvr/zrpc_store_service.cc b/seqsvr/storesvr/zrpc_store_service.cc deleted file mode 100644 index 815e7f7..0000000 --- a/seqsvr/storesvr/zrpc_store_service.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#include "storesvr/zrpc_store_service.h" - -#include "nebula/base/logger/glog_util.h" - -int ZRpcStoreService::LoadMaxSeqsData(const zproto::LoadMaxSeqsDataReq& request, zproto::LoadMaxSeqsDataRsp* response) { - LOG(ERROR) << "LoadMaxSeqsData - LoadMaxSeqsData unimplemented"; - return -1; -} - -int ZRpcStoreService::SaveMaxSeq(const zproto::SaveMaxSeqReq& request, zproto::SaveMaxSeqRsp* response) { - LOG(ERROR) << "SaveMaxSeq - SaveMaxSeq unimplemented"; - return -1; -} - -int ZRpcStoreService::UpdateRouteTable(const zproto::UpdateRouteTableReq& request, zproto::UpdateRouteTableRsp* response) { - LOG(ERROR) << "UpdateRouteTable - SaveMaxSeq unimplemented"; - return -1; -} - -int ZRpcStoreService::GetRouteTable(const zproto::GetRouteTableReq& request, zproto::GetRouteTableRsp* response) { - LOG(ERROR) << "GetRouteTable - SaveMaxSeq unimplemented"; - return -1; -} diff --git a/seqsvr/storesvr/zrpc_store_service.h b/seqsvr/storesvr/zrpc_store_service.h deleted file mode 100644 index 53dfe92..0000000 --- a/seqsvr/storesvr/zrpc_store_service.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016, https://github.com/nebula-im - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(@benqi): 使用zrpc-code-gen代码生成工具自动生成 - -#ifndef STORESVR_ZRPC_STORE_SERVICE_H_ -#define STORESVR_ZRPC_STORE_SERVICE_H_ - -#include "proto/cc/seqsvr.pb.h" - -class ZRpcStoreService { -public: - virtual ~ZRpcStoreService() = default; - - virtual int LoadMaxSeqsData(const zproto::LoadMaxSeqsDataReq& request, zproto::LoadMaxSeqsDataRsp* response); - virtual int SaveMaxSeq(const zproto::SaveMaxSeqReq& request, zproto::SaveMaxSeqRsp* response); - - virtual int UpdateRouteTable(const zproto::UpdateRouteTableReq& request, zproto::UpdateRouteTableRsp* response); - virtual int GetRouteTable(const zproto::GetRouteTableReq& request, zproto::GetRouteTableRsp* response); -}; - -#endif -