diff --git a/client/client.cc b/client/client.cc index 31ea5d7..ef628c0 100644 --- a/client/client.cc +++ b/client/client.cc @@ -89,3 +89,16 @@ void Client::DoCommandLineLoop() { 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_command_handler.cc b/client/client_command_handler.cc index 9e09edd..b188a30 100644 --- a/client/client_command_handler.cc +++ b/client/client_command_handler.cc @@ -46,7 +46,8 @@ int DoFetchNextSeq(const std::vector& command_lines) { 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, @@ -72,7 +73,8 @@ int DoGetCurrentSeq(const std::vector& command_lines) { 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, diff --git a/seqsvr/allocsvr/CMakeLists.txt b/seqsvr/allocsvr/CMakeLists.txt index 8031f8f..4a47224 100644 --- a/seqsvr/allocsvr/CMakeLists.txt +++ b/seqsvr/allocsvr/CMakeLists.txt @@ -21,6 +21,8 @@ set (SRC_LIST ../base/set.h ../base/router_table.cc ../base/router_table.h + lease_clerk.cc + lease_clerk.h allocsvr_manager.cc allocsvr_manager.h alloc_server.cc @@ -36,9 +38,6 @@ set (SRC_LIST ../proto/cc/seqsvr.pb.h ../proto/proto/seqsvr.proto ../base/message_handler_util.h - - ../storesvr/storesvr_manager.cc - ../storesvr/storesvr_manager.h ) add_executable (allocsvr ${SRC_LIST}) diff --git a/seqsvr/allocsvr/alloc_server.cc b/seqsvr/allocsvr/alloc_server.cc index 060c744..12b2715 100644 --- a/seqsvr/allocsvr/alloc_server.cc +++ b/seqsvr/allocsvr/alloc_server.cc @@ -57,18 +57,27 @@ bool AllocServer::Run() { return -1; } - // GPerftoolsProfiler profiler; - // profiler.ProfilerStart(); - AllocSvrManager::GetInstance()->Initialize(1, 1); + auto alloc_manager = AllocSvrManager::GetInstance(); - // auto store_instance = StoreSvrManager::GetInstance(); - // store_instance->Initialize(1, "/tmp/seq.dat"); + 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); + + // auto store_instance = StoreSvrManager::GetInstance(); + // store_instance->Initialize(1, "/tmp/seq.dat"); + }, 1000); BaseDaemon::Run(); // profiler.ProfilerStop(); net_engine_manager->Stop(); + alloc_manager->Destroy(); + return true; } diff --git a/seqsvr/allocsvr/alloc_service_impl.cc b/seqsvr/allocsvr/alloc_service_impl.cc index 79a3cca..054f965 100644 --- a/seqsvr/allocsvr/alloc_service_impl.cc +++ b/seqsvr/allocsvr/alloc_service_impl.cc @@ -25,35 +25,41 @@ #include "allocsvr/allocsvr_manager.h" int AllocServiceImpl::FetchNextSequence(const zproto::FetchNextSequenceReq& request, zproto::SequenceRsp* response) { - auto seq = AllocSvrManager::GetInstance()->FetchNextSequence(request.id()); - response->set_sequence(seq); + 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) { - auto seq = AllocSvrManager::GetInstance()->GetCurrentSequence(request.id()); - response->set_sequence(seq); + 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); - } +// 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); - } +// 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/allocsvr_manager.cc b/seqsvr/allocsvr/allocsvr_manager.cc index b709e47..e18ed87 100644 --- a/seqsvr/allocsvr/allocsvr_manager.cc +++ b/seqsvr/allocsvr/allocsvr_manager.cc @@ -37,59 +37,139 @@ std::shared_ptr AllocSvrManager::GetInstance() { return g_allocsvr_manager.try_get(); } -void AllocSvrManager::Initialize(uint32_t set_id, uint32_t alloc_id) { +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; + + lease_ = std::make_unique(timer_manager, this); + lease_->Start(); + +/* // 1. 初始化set_id_和alloc_id_ set_id_ = set_id; alloc_id_ = alloc_id; Load(set_id, alloc_id); + */ } -uint64_t AllocSvrManager::GetCurrentSequence(uint32_t id) { -#ifdef DEBUG_TEST - DCHECK(id g(mutex_); - return cur_seqs_[id]; +void AllocSvrManager::Destroy() { + if (lease_) { + lease_->Stop(); + } } -uint64_t AllocSvrManager::FetchNextSequence(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; + if (state_ != kAllocInited) return false; - auto idx = id/kSectionSize; - std::lock_guard g(mutex_); - auto seq = ++cur_seqs_[id]; - if (seq > section_max_seqs_[idx]) { - ++section_max_seqs_[idx]; - Save(set_id_, alloc_id_, idx, section_max_seqs_[idx]); + for (auto & v : cache_alloc_entry_->ranges ) { + if (id>=v.id && idranges ) { + if (id>=v.id && id section_max_seqs_[idx]) { + ++section_max_seqs_[idx]; + SaveMaxSeq(idx, section_max_seqs_[idx]); + } + + if (client_version < table_.version()) { + o.router = new zproto::Router; + table_.SerializeToRouter(o.router); + } + return true; + } + } + + 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::OnLeaseUpdated(RouteTable& table) { + table_.Swap(table); +} + +// 租约失效 +void AllocSvrManager::OnLeaseInvalid() { +} + +////////////////////////////////////////////////////////////////////////////////////////////// // bytes -void AllocSvrManager::Load(uint32_t set_id, uint32_t alloc_id) { +void AllocSvrManager::LoadMaxSeq() { + // TODO(@beqni): NWR读 // 2. 去storesvr加载max_seqs - state_ = kAllocWaitLoad; + state_ = kAllocWaitRouteTable; zproto::LoadMaxSeqsDataReq load_max_seqs_data_req; - load_max_seqs_data_req.set_set_id(set_id); - load_max_seqs_data_req.set_alloc_id(alloc_id); - - 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(); - OnLoad(""); - } else { - LOG(INFO) << "LoadMaxSeqsDataReq - load_max_seqs_data_rsp: " << load_max_seqs_data_rsp->ToString(); - OnLoad((*load_max_seqs_data_rsp)->max_seqs()); - } - return 0; - }); + 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; + }); // 先使用StoreSvrManager加载,跑通流程 // auto store = StoreSvrManager::GetInstance(); @@ -98,32 +178,32 @@ void AllocSvrManager::Load(uint32_t set_id, uint32_t alloc_id) { // OnLoad(max_seqs_data); } -void AllocSvrManager::Save(uint32_t set_id, uint32_t alloc_id, uint32_t section_id, uint64_t section_max_seq) { +void AllocSvrManager::SaveMaxSeq(uint32_t section_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_set_id(set_id); - save_max_seq_req.set_alloc_id(alloc_id); 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->OnSave(false); - } else { - LOG(INFO) << "SaveMaxSeqReq - load_max_seqs_data_rsp: " << save_max_seq_rsp->ToString(); - this->OnSave((*save_max_seq_rsp)->last_max_seq() == section_max_seq-1); - } - return 0; - }); + 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; + }); } -void AllocSvrManager::OnLoad(const std::string& data) { +void AllocSvrManager::OnMaxSeqLoaded(const std::string& data) { if (!data.empty()) { // TODO(@benqi): 检查数据是否合法 // 复制数据 @@ -135,12 +215,13 @@ void AllocSvrManager::OnLoad(const std::string& data) { std::fill(cur_seqs_.begin()+(kSectionSlotSize-1)*kSectionSize, cur_seqs_.end(), section_max_seqs_[kSectionSlotSize-1]); - state_ = kAllocLoaded; + state_ = kAllocInited; } else { state_ = kAllocError; } } -void AllocSvrManager::OnSave(bool result) { +void AllocSvrManager::OnMaxSeqSaved(bool result) { } + diff --git a/seqsvr/allocsvr/allocsvr_manager.h b/seqsvr/allocsvr/allocsvr_manager.h index 162c89b..6de2cb2 100644 --- a/seqsvr/allocsvr/allocsvr_manager.h +++ b/seqsvr/allocsvr/allocsvr_manager.h @@ -24,28 +24,64 @@ #include #include "base/set.h" +#include "allocsvr/lease_clerk.h" +#include "proto/cc/seqsvr.pb.h" enum AllocSvrState { kAllocNone = 0, - kAllocWaitLoad, - kAllocLoading, - kAllocLoaded, + kAllocWaitRouteTable, + // kAllocWaitLoad, + kAllocWaitLoadSeq, + kAllocInited, 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}; +}; + // TODO(@benqi): 单机模拟set的allocsvr和storesvr // 未加载成功重试加载 -class AllocSvrManager { +class AllocSvrManager : public LeaseClerk::LeaseCallback { public: ~AllocSvrManager() = default; static std::shared_ptr GetInstance(); - void Initialize(uint32_t set_id, uint32_t alloc_id); + ////////////////////////////////////////////////////////////////////////////////////////////// + void Initialize(nebula::TimerManager* timer_manager, const std::string& set_name, const std::string& alloc_name); + void Destroy(); - uint64_t GetCurrentSequence(uint32_t id); - uint64_t FetchNextSequence(uint32_t id); + bool GetCurrentSequence(uint32_t id, uint32_t client_version, SequenceWithRouterTable& o); + bool FetchNextSequence(uint32_t id, uint32_t client_version, SequenceWithRouterTable& o); + ////////////////////////////////////////////////////////////////////////////////////////////// + // 租约生效 + virtual void OnLeaseValid(RouteTable& table); + // 路由表更新 + virtual void OnLeaseUpdated(RouteTable& table); + // 租约失效 + virtual void OnLeaseInvalid(); + private: AllocSvrManager() : section_max_seqs_(kSectionSlotSize), @@ -55,21 +91,28 @@ class AllocSvrManager { friend class folly::Singleton; // bytes - void Load(uint32_t set_id, uint32_t alloc_id); - void Save(uint32_t set_id, uint32_t alloc_id, uint32_t section_id, uint64_t section_max_seq); + void LoadMaxSeq(); + void SaveMaxSeq(uint32_t section_id, uint64_t section_max_seq); - void OnLoad(const std::string& data); - void OnSave(bool result); + void OnMaxSeqLoaded(const std::string& data); + void OnMaxSeqSaved(bool result); - uint32_t set_id_{1}; - uint32_t alloc_id_{1}; + ////////////////////////////////////////////////////////////////////////////////////////////// + std::string set_name_; + std::string alloc_name_; 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_; }; #endif diff --git a/seqsvr/allocsvr/lease_clerk.cc b/seqsvr/allocsvr/lease_clerk.cc new file mode 100644 index 0000000..4508fe1 --- /dev/null +++ b/seqsvr/allocsvr/lease_clerk.cc @@ -0,0 +1,133 @@ +/* + * 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/lease_clerk.h" + +#include "base/message_handler_util.h" +#include "nebula/base/time_util.h" + +// 开始租约服务 +void LeaseClerk::Start() { + // 已经启动不执行 + if (is_valid_) + return; + + // 启动以后请求租约 + RequestLease(); +} + +// 停止租约服务 +void LeaseClerk::Stop() { + if (!is_valid_) + return; + + timer_manager_->GetMainEventBase() + ->runImmediatelyOrRunInEventBaseThreadAndWait([this] { + // 启动检查租约失效 + timer_manager_->GetHHWheelTimer()->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); + } + } + + // 数据已达 + timer_manager_->GetMainEventBase()->runInEventBaseThread([cb, this] { + if (cb == 0) { + // 启动检查租约失效 + timer_manager_->GetHHWheelTimer()->cancelAll(); + timer_manager_->ScheduleRepeatingTimeout( + std::bind(&LeaseClerk::CheckLeaseValid, this), CHECK_LEASE_TIMEOUT); + } + + timer_manager_->ScheduleOneShotTimeout( + std::bind(&LeaseClerk::RequestLease, this), SYNC_LEASE_TIMEOUT); + }); +} + +void 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 (!is_valid) { + timer_manager_->GetMainEventBase()->runInEventBaseThread( + [this] { + timer_manager_->GetHHWheelTimer()->cancelAll(); + }); + } else { + if (cb_) { + cb_->OnLeaseInvalid(); + } + } +} diff --git a/seqsvr/allocsvr/lease_clerk.h b/seqsvr/allocsvr/lease_clerk.h new file mode 100644 index 0000000..f229303 --- /dev/null +++ b/seqsvr/allocsvr/lease_clerk.h @@ -0,0 +1,91 @@ +/* + * 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_LEASE_CLERK_H_ +#define ALLOCSVR_LEASE_CLERK_H_ + +#include +#include + +#include "nebula/base/timer_manager.h" + +#include "proto/cc/seqsvr.pb.h" +#include "base/router_table.h" + +#define LEASE_TIMEOUT 5000 // 租约时间5s +#define SYNC_LEASE_TIMEOUT 4000 // 定时同步路由4s +#define CHECK_LEASE_TIMEOUT 100 // 租约时间5s + +// 为了避免失联AllocSvr提供错误的服务,返回脏数据,AllocSvr需要跟StoreSvr保持租约。这个租约机制由以下两个条件组成: +// 租约失效:AllocSvr N秒内无法从StoreSvr读取加载配置时,AllocSvr停止服务 +// 租约生效:AllocSvr读取到新的加载配置后,立即卸载需要卸载的号段,需要加载的新号段等待N秒后提供服务 +class LeaseClerk { +public: + enum State { + STATE_NONE = 0, + STATE_VALID, + STATE_INVALID, + STATE_ERROR, + }; + + class LeaseCallback { + public: + virtual ~LeaseCallback() = default; + + // 租约生效 + virtual void OnLeaseValid(RouteTable& table) = 0; + // 路由表更新 + virtual void OnLeaseUpdated(RouteTable& table) = 0; + // 租约失效 + virtual void OnLeaseInvalid() = 0; + }; + + LeaseClerk(nebula::TimerManager* timer_manager, LeaseCallback* cb) + : timer_manager_(timer_manager), + cb_(cb) {} + + ~LeaseClerk() = default; + + // 开始租约服务 + void Start(); + // 停止租约服务 + void Stop(); + +private: + // 开始租约服务 + void RequestLease(); + // 定时检查租约是否失效 + void CheckLeaseValid(); + + // 111 + void OnHandleLease(const zproto::Router& router); + + std::mutex lock_; + bool is_valid_; + // state_{STATE_NONE}; // 生效 + + // 路由表 + // RouteTable table_; + + uint32_t version_{0}; + int64_t lease_invalid_time_{0}; // 租约失效时间 + + nebula::TimerManager* timer_manager_{nullptr}; + LeaseCallback* cb_{nullptr}; +}; + +#endif // ALLOCSVR_ALLOC_SERVER_H_ diff --git a/seqsvr/base/router_table.cc b/seqsvr/base/router_table.cc index 9f19f97..070cd91 100644 --- a/seqsvr/base/router_table.cc +++ b/seqsvr/base/router_table.cc @@ -17,6 +17,9 @@ #include "base/router_table.h" +#include +#include + #include "nebula/base/time_util.h" void RouteTable::ParseFromRouter(const zproto::Router& router) { @@ -30,19 +33,21 @@ void RouteTable::ParseFromRouter(const zproto::Router& router) { Set set; set.set_id = i; + set.set_name = s.set_name(); set.range.id = s.range().id(); set.range.size = s.range().size(); - for (int j=0; j> 32 | j; alloc_entry.addr.host = a.addr().host(); alloc_entry.addr.port = a.addr().port(); - for (int k=0; kadd_sets(); + s->set_set_name(set.set_name); auto s_range = s->mutable_range(); s_range->set_id(set.range.id); s_range->set_size(set.range.size); for (auto & alloc_node : set.allocs) { auto a = s->add_allocs(); + a->set_alloc_name(alloc_node.alloc_name); auto a_addr = a->mutable_addr(); a_addr->set_host(alloc_node.addr.host); a_addr->set_port(alloc_node.addr.port); @@ -80,7 +87,6 @@ void RouteTable::SerializeToRouter(zproto::Router* router) const { void RouteTable::MakeTestRouteTable(RouteTable& table) { table.set_version(Now()); - int alloc_id = 0; int set_id = 0; int port = 10000; @@ -93,7 +99,8 @@ void RouteTable::MakeTestRouteTable(RouteTable& table) { set.set_id = set_id++; set.range.id = i*10000000; set.range.size = 10000000; - + set.set_name = std::string("set_cluster_" + folly::to(set_id)); + for (int j=0; j<2; j++) { AllocEntry alloc_config; @@ -102,6 +109,7 @@ void RouteTable::MakeTestRouteTable(RouteTable& table) { alloc_config.alloc_id = (int64_t) set_id>>32 | alloc_id++; alloc_config.addr.host = "127.0.0.1"; alloc_config.addr.port = port++; + alloc_config.alloc_name = std::string("alloc_server:") + folly::to(alloc_config.addr.port); range.id = i*10000000+j*5000000; range.size = 5000000; alloc_config.ranges.push_back(range); @@ -111,6 +119,23 @@ void RouteTable::MakeTestRouteTable(RouteTable& table) { } } +AllocEntry* RouteTable::LookupAlloc(const std::string& set_name, const std::string& alloc_name) { + AllocEntry* alloc_entry = nullptr; + + for (auto& set : sets_) { + if (set.set_name == set_name) { + for (auto & alloc_node : set.allocs) { + if (alloc_node.alloc_name == alloc_name) { + alloc_entry = &alloc_node; + break; + } + } + } + } + + return alloc_entry; +} + //////////////////////////////////////////////////////////////////////////////////// void RouteSearchTable::Initialize(RouteTable& route_table) { table_.clear(); @@ -127,6 +152,19 @@ void RouteSearchTable::Initialize(RouteTable& route_table) { } } +bool RouteSearchTable::CheckSectionID(AllocID alloc_id, uint32_t section_id) { + for(auto& v : table_) { + if (section_id >= v.range.id && section_id < v.range.id + v.range.size) { + if (alloc_id == v.alloc->alloc_id) { + return true; + } + } + } + + return false; +} + + //////////////////////////////////////////////////////////////////////////////////// void RouteTableManager::Initialize(RouteTable& table) { route_table_.Swap(table); diff --git a/seqsvr/base/router_table.h b/seqsvr/base/router_table.h index c9a2c2d..9380acc 100644 --- a/seqsvr/base/router_table.h +++ b/seqsvr/base/router_table.h @@ -56,14 +56,16 @@ struct IDRange { struct AllocEntry { AllocID alloc_id; SvrAddr addr; + std::string alloc_name; std::vector ranges; }; // set配置信息 struct Set { - SetID set_id; // set_id + SetID set_id; // set_id + std::string set_name; std::vector allocs; // set集合 - IDRange range; // 号段范围 + IDRange range; // 号段范围 }; // class RouteSearchTable; @@ -75,6 +77,10 @@ class RouteTable { static void MakeTestRouteTable(RouteTable& table); + uint32_t version() const { + return version_; + } + inline void set_version(uint32_t v) { version_ = v; } @@ -89,10 +95,12 @@ class RouteTable { void SerializeToRouter(zproto::Router* router) const; std::string ToString() const { - StringBuilder sb; + CStringBuilder sb; return sb.ToString(); } + AllocEntry* LookupAlloc(const std::string& set_name, const std::string& alloc_name); + private: void Clear() { version_ = 0; @@ -118,6 +126,8 @@ class RouteSearchTable { void Initialize(RouteTable& route_table); + bool CheckSectionID(AllocID alloc_id, uint32_t section_id); + private: std::vector table_; }; diff --git a/seqsvr/mediatesvr/mediate_handler.cc b/seqsvr/mediatesvr/mediate_handler.cc index 4e6664e..f423d16 100644 --- a/seqsvr/mediatesvr/mediate_handler.cc +++ b/seqsvr/mediatesvr/mediate_handler.cc @@ -22,7 +22,7 @@ #include "base/message_handler_util.h" #include "base/router_table.h" -REGISTER_HTTP_HANDLER(UpdateRouteTable, "/media/router/update", UpdateRouteTable); +REGISTER_HTTP_HANDLER(UpdateRouteTable, "/mediate/router/update", UpdateRouteTable); // 初始化路由表 void UpdateRouteTable(const proxygen::HTTPMessage& headers, folly::IOBufQueue* body, proxygen::ResponseBuilder* r) { diff --git a/seqsvr/proto/cc/seqsvr.pb.cc b/seqsvr/proto/cc/seqsvr.pb.cc index 4cbd9b7..0604ec9 100644 --- a/seqsvr/proto/cc/seqsvr.pb.cc +++ b/seqsvr/proto/cc/seqsvr.pb.cc @@ -123,7 +123,8 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(Range), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Range, _internal_metadata_)); AllocSvrEntry_descriptor_ = file->message_type(2); - static const int AllocSvrEntry_offsets_[2] = { + static const int AllocSvrEntry_offsets_[3] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AllocSvrEntry, alloc_name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AllocSvrEntry, addr_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AllocSvrEntry, ranges_), }; @@ -138,7 +139,8 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(AllocSvrEntry), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AllocSvrEntry, _internal_metadata_)); SetEntry_descriptor_ = file->message_type(3); - static const int SetEntry_offsets_[2] = { + static const int SetEntry_offsets_[3] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SetEntry, set_name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SetEntry, allocs_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SetEntry, range_), }; @@ -153,9 +155,8 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(SetEntry), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SetEntry, _internal_metadata_)); Router_descriptor_ = file->message_type(4); - static const int Router_offsets_[3] = { + static const int Router_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Router, version_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Router, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Router, sets_), }; Router_reflection_ = @@ -223,8 +224,9 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(GetRouteTableRsp), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GetRouteTableRsp, _internal_metadata_)); FetchNextSequenceReq_descriptor_ = file->message_type(9); - static const int FetchNextSequenceReq_offsets_[1] = { + static const int FetchNextSequenceReq_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FetchNextSequenceReq, id_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FetchNextSequenceReq, version_), }; FetchNextSequenceReq_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( @@ -237,8 +239,9 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(FetchNextSequenceReq), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FetchNextSequenceReq, _internal_metadata_)); GetCurrentSequenceReq_descriptor_ = file->message_type(10); - static const int GetCurrentSequenceReq_offsets_[1] = { + static const int GetCurrentSequenceReq_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GetCurrentSequenceReq, id_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GetCurrentSequenceReq, version_), }; GetCurrentSequenceReq_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( @@ -251,8 +254,9 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(GetCurrentSequenceReq), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GetCurrentSequenceReq, _internal_metadata_)); SequenceRsp_descriptor_ = file->message_type(11); - static const int SequenceRsp_offsets_[1] = { + static const int SequenceRsp_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SequenceRsp, sequence_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SequenceRsp, router_), }; SequenceRsp_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( @@ -322,9 +326,7 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(SequenceListRsp), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SequenceListRsp, _internal_metadata_)); LoadMaxSeqsDataReq_descriptor_ = file->message_type(16); - static const int LoadMaxSeqsDataReq_offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(LoadMaxSeqsDataReq, set_id_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(LoadMaxSeqsDataReq, alloc_id_), + static const int LoadMaxSeqsDataReq_offsets_[1] = { }; LoadMaxSeqsDataReq_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( @@ -351,9 +353,7 @@ void protobuf_AssignDesc_seqsvr_2eproto() { sizeof(LoadMaxSeqsDataRsp), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(LoadMaxSeqsDataRsp, _internal_metadata_)); SaveMaxSeqReq_descriptor_ = file->message_type(18); - static const int SaveMaxSeqReq_offsets_[4] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SaveMaxSeqReq, set_id_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SaveMaxSeqReq, alloc_id_), + static const int SaveMaxSeqReq_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SaveMaxSeqReq, section_id_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SaveMaxSeqReq, max_seq_), }; @@ -487,9 +487,10 @@ void protobuf_InitDefaults_seqsvr_2eproto_impl() { ::google::protobuf::internal::GetEmptyString(); IpPort_default_instance_.DefaultConstruct(); Range_default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); AllocSvrEntry_default_instance_.DefaultConstruct(); - SetEntry_default_instance_.DefaultConstruct(); ::google::protobuf::internal::GetEmptyString(); + SetEntry_default_instance_.DefaultConstruct(); Router_default_instance_.DefaultConstruct(); UpdateRouteTableReq_default_instance_.DefaultConstruct(); UpdateRouteTableRsp_default_instance_.DefaultConstruct(); @@ -541,31 +542,31 @@ void protobuf_AddDesc_seqsvr_2eproto_impl() { ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\014seqsvr.proto\022\006zproto\"$\n\006IpPort\022\014\n\004host" "\030\001 \001(\t\022\014\n\004port\030\002 \001(\r\"!\n\005Range\022\n\n\002id\030\001 \001(" - "\r\022\014\n\004size\030\002 \001(\r\"L\n\rAllocSvrEntry\022\034\n\004addr" - "\030\001 \001(\0132\016.zproto.IpPort\022\035\n\006ranges\030\002 \003(\0132\r" - ".zproto.Range\"O\n\010SetEntry\022%\n\006allocs\030\001 \003(" - "\0132\025.zproto.AllocSvrEntry\022\034\n\005range\030\002 \001(\0132" - "\r.zproto.Range\"G\n\006Router\022\017\n\007version\030\001 \001(" - "\r\022\014\n\004name\030\002 \001(\t\022\036\n\004sets\030\003 \003(\0132\020.zproto.S" - "etEntry\"5\n\023UpdateRouteTableReq\022\036\n\006router" - "\030\001 \001(\0132\016.zproto.Router\"\025\n\023UpdateRouteTab" - "leRsp\"\022\n\020GetRouteTableReq\"2\n\020GetRouteTab" - "leRsp\022\036\n\006router\030\001 \001(\0132\016.zproto.Router\"\"\n" - "\024FetchNextSequenceReq\022\n\n\002id\030\001 \001(\r\"#\n\025Get" - "CurrentSequenceReq\022\n\n\002id\030\001 \001(\r\"\037\n\013Sequen" - "ceRsp\022\020\n\010sequence\030\001 \001(\004\"+\n\030FetchNextSequ" - "enceListReq\022\017\n\007id_list\030\001 \003(\r\",\n\031GetCurre" - "ntSequenceListReq\022\017\n\007id_list\030\001 \003(\r\"%\n\005Id" - "Seq\022\n\n\002id\030\001 \001(\r\022\020\n\010sequence\030\002 \001(\004\"7\n\017Seq" - "uenceListRsp\022$\n\rsequence_list\030\001 \003(\0132\r.zp" - "roto.IdSeq\"6\n\022LoadMaxSeqsDataReq\022\016\n\006set_" - "id\030\001 \001(\r\022\020\n\010alloc_id\030\002 \001(\r\"&\n\022LoadMaxSeq" - "sDataRsp\022\020\n\010max_seqs\030\001 \001(\014\"V\n\rSaveMaxSeq" - "Req\022\016\n\006set_id\030\001 \001(\r\022\020\n\010alloc_id\030\002 \001(\r\022\022\n" - "\nsection_id\030\003 \001(\r\022\017\n\007max_seq\030\004 \001(\004\"%\n\rSa" - "veMaxSeqRsp\022\024\n\014last_max_seq\030\001 \001(\004B)\n\027com" - ".zchat.engine.zprotoB\014ZProtoSeqsvrH\002b\006pr" - "oto3", 1044); + "\r\022\014\n\004size\030\002 \001(\r\"`\n\rAllocSvrEntry\022\022\n\nallo" + "c_name\030\001 \001(\t\022\034\n\004addr\030\002 \001(\0132\016.zproto.IpPo" + "rt\022\035\n\006ranges\030\003 \003(\0132\r.zproto.Range\"a\n\010Set" + "Entry\022\020\n\010set_name\030\001 \001(\t\022%\n\006allocs\030\002 \003(\0132" + "\025.zproto.AllocSvrEntry\022\034\n\005range\030\003 \001(\0132\r." + "zproto.Range\"9\n\006Router\022\017\n\007version\030\001 \001(\r\022" + "\036\n\004sets\030\002 \003(\0132\020.zproto.SetEntry\"5\n\023Updat" + "eRouteTableReq\022\036\n\006router\030\001 \001(\0132\016.zproto." + "Router\"\025\n\023UpdateRouteTableRsp\"\022\n\020GetRout" + "eTableReq\"2\n\020GetRouteTableRsp\022\036\n\006router\030" + "\001 \001(\0132\016.zproto.Router\"3\n\024FetchNextSequen" + "ceReq\022\n\n\002id\030\001 \001(\r\022\017\n\007version\030\002 \001(\r\"4\n\025Ge" + "tCurrentSequenceReq\022\n\n\002id\030\001 \001(\r\022\017\n\007versi" + "on\030\002 \001(\r\"\?\n\013SequenceRsp\022\020\n\010sequence\030\002 \001(" + "\004\022\036\n\006router\030\003 \001(\0132\016.zproto.Router\"+\n\030Fet" + "chNextSequenceListReq\022\017\n\007id_list\030\001 \003(\r\"," + "\n\031GetCurrentSequenceListReq\022\017\n\007id_list\030\001" + " \003(\r\"%\n\005IdSeq\022\n\n\002id\030\001 \001(\r\022\020\n\010sequence\030\002 " + "\001(\004\"7\n\017SequenceListRsp\022$\n\rsequence_list\030" + "\001 \003(\0132\r.zproto.IdSeq\"\024\n\022LoadMaxSeqsDataR" + "eq\"&\n\022LoadMaxSeqsDataRsp\022\020\n\010max_seqs\030\001 \001" + "(\014\"4\n\rSaveMaxSeqReq\022\022\n\nsection_id\030\003 \001(\r\022" + "\017\n\007max_seq\030\004 \001(\004\"%\n\rSaveMaxSeqRsp\022\024\n\014las" + "t_max_seq\030\001 \001(\004B)\n\027com.zchat.engine.zpro" + "toB\014ZProtoSeqsvrH\002b\006proto3", 1066); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "seqsvr.proto", &protobuf_RegisterTypes); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_seqsvr_2eproto); @@ -853,6 +854,7 @@ inline const Range* Range::internal_default_instance() { // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int AllocSvrEntry::kAllocNameFieldNumber; const int AllocSvrEntry::kAddrFieldNumber; const int AllocSvrEntry::kRangesFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -878,6 +880,7 @@ AllocSvrEntry::AllocSvrEntry(const AllocSvrEntry& from) } void AllocSvrEntry::SharedCtor() { + alloc_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); addr_ = NULL; _cached_size_ = 0; } @@ -888,6 +891,7 @@ AllocSvrEntry::~AllocSvrEntry() { } void AllocSvrEntry::SharedDtor() { + alloc_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != &AllocSvrEntry_default_instance_.get()) { delete addr_; } @@ -939,7 +943,51 @@ ::google::protobuf::Metadata AllocSvrEntry::GetMetadata() const { #if PROTOBUF_INLINE_NOT_IN_HEADERS // AllocSvrEntry -// optional .zproto.IpPort addr = 1; +// optional string alloc_name = 1; +void AllocSvrEntry::clear_alloc_name() { + alloc_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +const ::std::string& AllocSvrEntry::alloc_name() const { + // @@protoc_insertion_point(field_get:zproto.AllocSvrEntry.alloc_name) + return alloc_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +void AllocSvrEntry::set_alloc_name(const ::std::string& value) { + + alloc_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:zproto.AllocSvrEntry.alloc_name) +} +void AllocSvrEntry::set_alloc_name(const char* value) { + + alloc_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:zproto.AllocSvrEntry.alloc_name) +} +void AllocSvrEntry::set_alloc_name(const char* value, size_t size) { + + alloc_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:zproto.AllocSvrEntry.alloc_name) +} +::std::string* AllocSvrEntry::mutable_alloc_name() { + + // @@protoc_insertion_point(field_mutable:zproto.AllocSvrEntry.alloc_name) + return alloc_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +::std::string* AllocSvrEntry::release_alloc_name() { + // @@protoc_insertion_point(field_release:zproto.AllocSvrEntry.alloc_name) + + return alloc_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +void AllocSvrEntry::set_allocated_alloc_name(::std::string* alloc_name) { + if (alloc_name != NULL) { + + } else { + + } + alloc_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), alloc_name); + // @@protoc_insertion_point(field_set_allocated:zproto.AllocSvrEntry.alloc_name) +} + +// optional .zproto.IpPort addr = 2; bool AllocSvrEntry::has_addr() const { return this != internal_default_instance() && addr_ != NULL; } @@ -978,7 +1026,7 @@ void AllocSvrEntry::set_allocated_addr(::zproto::IpPort* addr) { // @@protoc_insertion_point(field_set_allocated:zproto.AllocSvrEntry.addr) } -// repeated .zproto.Range ranges = 2; +// repeated .zproto.Range ranges = 3; int AllocSvrEntry::ranges_size() const { return ranges_.size(); } @@ -1016,6 +1064,7 @@ inline const AllocSvrEntry* AllocSvrEntry::internal_default_instance() { // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int SetEntry::kSetNameFieldNumber; const int SetEntry::kAllocsFieldNumber; const int SetEntry::kRangeFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -1041,6 +1090,7 @@ SetEntry::SetEntry(const SetEntry& from) } void SetEntry::SharedCtor() { + set_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); range_ = NULL; _cached_size_ = 0; } @@ -1051,6 +1101,7 @@ SetEntry::~SetEntry() { } void SetEntry::SharedDtor() { + set_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); if (this != &SetEntry_default_instance_.get()) { delete range_; } @@ -1102,7 +1153,51 @@ ::google::protobuf::Metadata SetEntry::GetMetadata() const { #if PROTOBUF_INLINE_NOT_IN_HEADERS // SetEntry -// repeated .zproto.AllocSvrEntry allocs = 1; +// optional string set_name = 1; +void SetEntry::clear_set_name() { + set_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +const ::std::string& SetEntry::set_name() const { + // @@protoc_insertion_point(field_get:zproto.SetEntry.set_name) + return set_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +void SetEntry::set_set_name(const ::std::string& value) { + + set_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:zproto.SetEntry.set_name) +} +void SetEntry::set_set_name(const char* value) { + + set_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:zproto.SetEntry.set_name) +} +void SetEntry::set_set_name(const char* value, size_t size) { + + set_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:zproto.SetEntry.set_name) +} +::std::string* SetEntry::mutable_set_name() { + + // @@protoc_insertion_point(field_mutable:zproto.SetEntry.set_name) + return set_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +::std::string* SetEntry::release_set_name() { + // @@protoc_insertion_point(field_release:zproto.SetEntry.set_name) + + return set_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +void SetEntry::set_allocated_set_name(::std::string* set_name) { + if (set_name != NULL) { + + } else { + + } + set_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), set_name); + // @@protoc_insertion_point(field_set_allocated:zproto.SetEntry.set_name) +} + +// repeated .zproto.AllocSvrEntry allocs = 2; int SetEntry::allocs_size() const { return allocs_.size(); } @@ -1132,7 +1227,7 @@ SetEntry::allocs() const { return allocs_; } -// optional .zproto.Range range = 2; +// optional .zproto.Range range = 3; bool SetEntry::has_range() const { return this != internal_default_instance() && range_ != NULL; } @@ -1180,7 +1275,6 @@ inline const SetEntry* SetEntry::internal_default_instance() { #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Router::kVersionFieldNumber; -const int Router::kNameFieldNumber; const int Router::kSetsFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -1203,7 +1297,6 @@ Router::Router(const Router& from) } void Router::SharedCtor() { - name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); version_ = 0u; _cached_size_ = 0; } @@ -1214,7 +1307,6 @@ Router::~Router() { } void Router::SharedDtor() { - name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } void Router::SetCachedSize(int size) const { @@ -1277,51 +1369,7 @@ void Router::set_version(::google::protobuf::uint32 value) { // @@protoc_insertion_point(field_set:zproto.Router.version) } -// optional string name = 2; -void Router::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -const ::std::string& Router::name() const { - // @@protoc_insertion_point(field_get:zproto.Router.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -void Router::set_name(const ::std::string& value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:zproto.Router.name) -} -void Router::set_name(const char* value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:zproto.Router.name) -} -void Router::set_name(const char* value, size_t size) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:zproto.Router.name) -} -::std::string* Router::mutable_name() { - - // @@protoc_insertion_point(field_mutable:zproto.Router.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -::std::string* Router::release_name() { - // @@protoc_insertion_point(field_release:zproto.Router.name) - - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -void Router::set_allocated_name(::std::string* name) { - if (name != NULL) { - - } else { - - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:zproto.Router.name) -} - -// repeated .zproto.SetEntry sets = 3; +// repeated .zproto.SetEntry sets = 2; int Router::sets_size() const { return sets_.size(); } @@ -1796,6 +1844,7 @@ inline const GetRouteTableRsp* GetRouteTableRsp::internal_default_instance() { #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int FetchNextSequenceReq::kIdFieldNumber; +const int FetchNextSequenceReq::kVersionFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 FetchNextSequenceReq::FetchNextSequenceReq() @@ -1817,7 +1866,8 @@ FetchNextSequenceReq::FetchNextSequenceReq(const FetchNextSequenceReq& from) } void FetchNextSequenceReq::SharedCtor() { - id_ = 0u; + ::memset(&id_, 0, reinterpret_cast(&version_) - + reinterpret_cast(&id_) + sizeof(version_)); _cached_size_ = 0; } @@ -1889,6 +1939,20 @@ void FetchNextSequenceReq::set_id(::google::protobuf::uint32 value) { // @@protoc_insertion_point(field_set:zproto.FetchNextSequenceReq.id) } +// optional uint32 version = 2; +void FetchNextSequenceReq::clear_version() { + version_ = 0u; +} +::google::protobuf::uint32 FetchNextSequenceReq::version() const { + // @@protoc_insertion_point(field_get:zproto.FetchNextSequenceReq.version) + return version_; +} +void FetchNextSequenceReq::set_version(::google::protobuf::uint32 value) { + + version_ = value; + // @@protoc_insertion_point(field_set:zproto.FetchNextSequenceReq.version) +} + inline const FetchNextSequenceReq* FetchNextSequenceReq::internal_default_instance() { return &FetchNextSequenceReq_default_instance_.get(); } @@ -1898,6 +1962,7 @@ inline const FetchNextSequenceReq* FetchNextSequenceReq::internal_default_instan #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int GetCurrentSequenceReq::kIdFieldNumber; +const int GetCurrentSequenceReq::kVersionFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 GetCurrentSequenceReq::GetCurrentSequenceReq() @@ -1919,7 +1984,8 @@ GetCurrentSequenceReq::GetCurrentSequenceReq(const GetCurrentSequenceReq& from) } void GetCurrentSequenceReq::SharedCtor() { - id_ = 0u; + ::memset(&id_, 0, reinterpret_cast(&version_) - + reinterpret_cast(&id_) + sizeof(version_)); _cached_size_ = 0; } @@ -1991,6 +2057,20 @@ void GetCurrentSequenceReq::set_id(::google::protobuf::uint32 value) { // @@protoc_insertion_point(field_set:zproto.GetCurrentSequenceReq.id) } +// optional uint32 version = 2; +void GetCurrentSequenceReq::clear_version() { + version_ = 0u; +} +::google::protobuf::uint32 GetCurrentSequenceReq::version() const { + // @@protoc_insertion_point(field_get:zproto.GetCurrentSequenceReq.version) + return version_; +} +void GetCurrentSequenceReq::set_version(::google::protobuf::uint32 value) { + + version_ = value; + // @@protoc_insertion_point(field_set:zproto.GetCurrentSequenceReq.version) +} + inline const GetCurrentSequenceReq* GetCurrentSequenceReq::internal_default_instance() { return &GetCurrentSequenceReq_default_instance_.get(); } @@ -2000,6 +2080,7 @@ inline const GetCurrentSequenceReq* GetCurrentSequenceReq::internal_default_inst #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int SequenceRsp::kSequenceFieldNumber; +const int SequenceRsp::kRouterFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 SequenceRsp::SequenceRsp() @@ -2010,6 +2091,8 @@ SequenceRsp::SequenceRsp() } void SequenceRsp::InitAsDefaultInstance() { + router_ = const_cast< ::zproto::Router*>( + ::zproto::Router::internal_default_instance()); } SequenceRsp::SequenceRsp(const SequenceRsp& from) @@ -2021,6 +2104,7 @@ SequenceRsp::SequenceRsp(const SequenceRsp& from) } void SequenceRsp::SharedCtor() { + router_ = NULL; sequence_ = GOOGLE_ULONGLONG(0); _cached_size_ = 0; } @@ -2031,6 +2115,9 @@ SequenceRsp::~SequenceRsp() { } void SequenceRsp::SharedDtor() { + if (this != &SequenceRsp_default_instance_.get()) { + delete router_; + } } void SequenceRsp::SetCachedSize(int size) const { @@ -2079,7 +2166,7 @@ ::google::protobuf::Metadata SequenceRsp::GetMetadata() const { #if PROTOBUF_INLINE_NOT_IN_HEADERS // SequenceRsp -// optional uint64 sequence = 1; +// optional uint64 sequence = 2; void SequenceRsp::clear_sequence() { sequence_ = GOOGLE_ULONGLONG(0); } @@ -2093,6 +2180,45 @@ void SequenceRsp::set_sequence(::google::protobuf::uint64 value) { // @@protoc_insertion_point(field_set:zproto.SequenceRsp.sequence) } +// optional .zproto.Router router = 3; +bool SequenceRsp::has_router() const { + return this != internal_default_instance() && router_ != NULL; +} +void SequenceRsp::clear_router() { + if (GetArenaNoVirtual() == NULL && router_ != NULL) delete router_; + router_ = NULL; +} +const ::zproto::Router& SequenceRsp::router() const { + // @@protoc_insertion_point(field_get:zproto.SequenceRsp.router) + return router_ != NULL ? *router_ + : *::zproto::Router::internal_default_instance(); +} +::zproto::Router* SequenceRsp::mutable_router() { + + if (router_ == NULL) { + router_ = new ::zproto::Router; + } + // @@protoc_insertion_point(field_mutable:zproto.SequenceRsp.router) + return router_; +} +::zproto::Router* SequenceRsp::release_router() { + // @@protoc_insertion_point(field_release:zproto.SequenceRsp.router) + + ::zproto::Router* temp = router_; + router_ = NULL; + return temp; +} +void SequenceRsp::set_allocated_router(::zproto::Router* router) { + delete router_; + router_ = router; + if (router) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:zproto.SequenceRsp.router) +} + inline const SequenceRsp* SequenceRsp::internal_default_instance() { return &SequenceRsp_default_instance_.get(); } @@ -2570,8 +2696,6 @@ inline const SequenceListRsp* SequenceListRsp::internal_default_instance() { // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int LoadMaxSeqsDataReq::kSetIdFieldNumber; -const int LoadMaxSeqsDataReq::kAllocIdFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 LoadMaxSeqsDataReq::LoadMaxSeqsDataReq() @@ -2593,8 +2717,6 @@ LoadMaxSeqsDataReq::LoadMaxSeqsDataReq(const LoadMaxSeqsDataReq& from) } void LoadMaxSeqsDataReq::SharedCtor() { - ::memset(&set_id_, 0, reinterpret_cast(&alloc_id_) - - reinterpret_cast(&set_id_) + sizeof(alloc_id_)); _cached_size_ = 0; } @@ -2652,34 +2774,6 @@ ::google::protobuf::Metadata LoadMaxSeqsDataReq::GetMetadata() const { #if PROTOBUF_INLINE_NOT_IN_HEADERS // LoadMaxSeqsDataReq -// optional uint32 set_id = 1; -void LoadMaxSeqsDataReq::clear_set_id() { - set_id_ = 0u; -} -::google::protobuf::uint32 LoadMaxSeqsDataReq::set_id() const { - // @@protoc_insertion_point(field_get:zproto.LoadMaxSeqsDataReq.set_id) - return set_id_; -} -void LoadMaxSeqsDataReq::set_set_id(::google::protobuf::uint32 value) { - - set_id_ = value; - // @@protoc_insertion_point(field_set:zproto.LoadMaxSeqsDataReq.set_id) -} - -// optional uint32 alloc_id = 2; -void LoadMaxSeqsDataReq::clear_alloc_id() { - alloc_id_ = 0u; -} -::google::protobuf::uint32 LoadMaxSeqsDataReq::alloc_id() const { - // @@protoc_insertion_point(field_get:zproto.LoadMaxSeqsDataReq.alloc_id) - return alloc_id_; -} -void LoadMaxSeqsDataReq::set_alloc_id(::google::protobuf::uint32 value) { - - alloc_id_ = value; - // @@protoc_insertion_point(field_set:zproto.LoadMaxSeqsDataReq.alloc_id) -} - inline const LoadMaxSeqsDataReq* LoadMaxSeqsDataReq::internal_default_instance() { return &LoadMaxSeqsDataReq_default_instance_.get(); } @@ -2821,8 +2915,6 @@ inline const LoadMaxSeqsDataRsp* LoadMaxSeqsDataRsp::internal_default_instance() // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 -const int SaveMaxSeqReq::kSetIdFieldNumber; -const int SaveMaxSeqReq::kAllocIdFieldNumber; const int SaveMaxSeqReq::kSectionIdFieldNumber; const int SaveMaxSeqReq::kMaxSeqFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -2846,8 +2938,8 @@ SaveMaxSeqReq::SaveMaxSeqReq(const SaveMaxSeqReq& from) } void SaveMaxSeqReq::SharedCtor() { - ::memset(&set_id_, 0, reinterpret_cast(§ion_id_) - - reinterpret_cast(&set_id_) + sizeof(section_id_)); + ::memset(&max_seq_, 0, reinterpret_cast(§ion_id_) - + reinterpret_cast(&max_seq_) + sizeof(section_id_)); _cached_size_ = 0; } @@ -2905,34 +2997,6 @@ ::google::protobuf::Metadata SaveMaxSeqReq::GetMetadata() const { #if PROTOBUF_INLINE_NOT_IN_HEADERS // SaveMaxSeqReq -// optional uint32 set_id = 1; -void SaveMaxSeqReq::clear_set_id() { - set_id_ = 0u; -} -::google::protobuf::uint32 SaveMaxSeqReq::set_id() const { - // @@protoc_insertion_point(field_get:zproto.SaveMaxSeqReq.set_id) - return set_id_; -} -void SaveMaxSeqReq::set_set_id(::google::protobuf::uint32 value) { - - set_id_ = value; - // @@protoc_insertion_point(field_set:zproto.SaveMaxSeqReq.set_id) -} - -// optional uint32 alloc_id = 2; -void SaveMaxSeqReq::clear_alloc_id() { - alloc_id_ = 0u; -} -::google::protobuf::uint32 SaveMaxSeqReq::alloc_id() const { - // @@protoc_insertion_point(field_get:zproto.SaveMaxSeqReq.alloc_id) - return alloc_id_; -} -void SaveMaxSeqReq::set_alloc_id(::google::protobuf::uint32 value) { - - alloc_id_ = value; - // @@protoc_insertion_point(field_set:zproto.SaveMaxSeqReq.alloc_id) -} - // optional uint32 section_id = 3; void SaveMaxSeqReq::clear_section_id() { section_id_ = 0u; diff --git a/seqsvr/proto/cc/seqsvr.pb.h b/seqsvr/proto/cc/seqsvr.pb.h index 97494a9..76412b7 100644 --- a/seqsvr/proto/cc/seqsvr.pb.h +++ b/seqsvr/proto/cc/seqsvr.pb.h @@ -263,19 +263,30 @@ class AllocSvrEntry : public ::google::protobuf::Message /* @@protoc_insertion_p // accessors ------------------------------------------------------- - // optional .zproto.IpPort addr = 1; + // optional string alloc_name = 1; + void clear_alloc_name(); + static const int kAllocNameFieldNumber = 1; + const ::std::string& alloc_name() const; + void set_alloc_name(const ::std::string& value); + void set_alloc_name(const char* value); + void set_alloc_name(const char* value, size_t size); + ::std::string* mutable_alloc_name(); + ::std::string* release_alloc_name(); + void set_allocated_alloc_name(::std::string* alloc_name); + + // optional .zproto.IpPort addr = 2; bool has_addr() const; void clear_addr(); - static const int kAddrFieldNumber = 1; + static const int kAddrFieldNumber = 2; const ::zproto::IpPort& addr() const; ::zproto::IpPort* mutable_addr(); ::zproto::IpPort* release_addr(); void set_allocated_addr(::zproto::IpPort* addr); - // repeated .zproto.Range ranges = 2; + // repeated .zproto.Range ranges = 3; int ranges_size() const; void clear_ranges(); - static const int kRangesFieldNumber = 2; + static const int kRangesFieldNumber = 3; const ::zproto::Range& ranges(int index) const; ::zproto::Range* mutable_ranges(int index); ::zproto::Range* add_ranges(); @@ -289,6 +300,7 @@ class AllocSvrEntry : public ::google::protobuf::Message /* @@protoc_insertion_p ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::RepeatedPtrField< ::zproto::Range > ranges_; + ::google::protobuf::internal::ArenaStringPtr alloc_name_; ::zproto::IpPort* addr_; mutable int _cached_size_; friend void protobuf_InitDefaults_seqsvr_2eproto_impl(); @@ -348,10 +360,21 @@ class SetEntry : public ::google::protobuf::Message /* @@protoc_insertion_point( // accessors ------------------------------------------------------- - // repeated .zproto.AllocSvrEntry allocs = 1; + // optional string set_name = 1; + void clear_set_name(); + static const int kSetNameFieldNumber = 1; + const ::std::string& set_name() const; + void set_set_name(const ::std::string& value); + void set_set_name(const char* value); + void set_set_name(const char* value, size_t size); + ::std::string* mutable_set_name(); + ::std::string* release_set_name(); + void set_allocated_set_name(::std::string* set_name); + + // repeated .zproto.AllocSvrEntry allocs = 2; int allocs_size() const; void clear_allocs(); - static const int kAllocsFieldNumber = 1; + static const int kAllocsFieldNumber = 2; const ::zproto::AllocSvrEntry& allocs(int index) const; ::zproto::AllocSvrEntry* mutable_allocs(int index); ::zproto::AllocSvrEntry* add_allocs(); @@ -360,10 +383,10 @@ class SetEntry : public ::google::protobuf::Message /* @@protoc_insertion_point( const ::google::protobuf::RepeatedPtrField< ::zproto::AllocSvrEntry >& allocs() const; - // optional .zproto.Range range = 2; + // optional .zproto.Range range = 3; bool has_range() const; void clear_range(); - static const int kRangeFieldNumber = 2; + static const int kRangeFieldNumber = 3; const ::zproto::Range& range() const; ::zproto::Range* mutable_range(); ::zproto::Range* release_range(); @@ -374,6 +397,7 @@ class SetEntry : public ::google::protobuf::Message /* @@protoc_insertion_point( ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::RepeatedPtrField< ::zproto::AllocSvrEntry > allocs_; + ::google::protobuf::internal::ArenaStringPtr set_name_; ::zproto::Range* range_; mutable int _cached_size_; friend void protobuf_InitDefaults_seqsvr_2eproto_impl(); @@ -439,21 +463,10 @@ class Router : public ::google::protobuf::Message /* @@protoc_insertion_point(cl ::google::protobuf::uint32 version() const; void set_version(::google::protobuf::uint32 value); - // optional string name = 2; - void clear_name(); - static const int kNameFieldNumber = 2; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .zproto.SetEntry sets = 3; + // repeated .zproto.SetEntry sets = 2; int sets_size() const; void clear_sets(); - static const int kSetsFieldNumber = 3; + static const int kSetsFieldNumber = 2; const ::zproto::SetEntry& sets(int index) const; ::zproto::SetEntry* mutable_sets(int index); ::zproto::SetEntry* add_sets(); @@ -467,7 +480,6 @@ class Router : public ::google::protobuf::Message /* @@protoc_insertion_point(cl ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::RepeatedPtrField< ::zproto::SetEntry > sets_; - ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::uint32 version_; mutable int _cached_size_; friend void protobuf_InitDefaults_seqsvr_2eproto_impl(); @@ -801,11 +813,18 @@ class FetchNextSequenceReq : public ::google::protobuf::Message /* @@protoc_inse ::google::protobuf::uint32 id() const; void set_id(::google::protobuf::uint32 value); + // optional uint32 version = 2; + void clear_version(); + static const int kVersionFieldNumber = 2; + ::google::protobuf::uint32 version() const; + void set_version(::google::protobuf::uint32 value); + // @@protoc_insertion_point(class_scope:zproto.FetchNextSequenceReq) private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 id_; + ::google::protobuf::uint32 version_; mutable int _cached_size_; friend void protobuf_InitDefaults_seqsvr_2eproto_impl(); friend void protobuf_AddDesc_seqsvr_2eproto_impl(); @@ -870,11 +889,18 @@ class GetCurrentSequenceReq : public ::google::protobuf::Message /* @@protoc_ins ::google::protobuf::uint32 id() const; void set_id(::google::protobuf::uint32 value); + // optional uint32 version = 2; + void clear_version(); + static const int kVersionFieldNumber = 2; + ::google::protobuf::uint32 version() const; + void set_version(::google::protobuf::uint32 value); + // @@protoc_insertion_point(class_scope:zproto.GetCurrentSequenceReq) private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 id_; + ::google::protobuf::uint32 version_; mutable int _cached_size_; friend void protobuf_InitDefaults_seqsvr_2eproto_impl(); friend void protobuf_AddDesc_seqsvr_2eproto_impl(); @@ -933,16 +959,26 @@ class SequenceRsp : public ::google::protobuf::Message /* @@protoc_insertion_poi // accessors ------------------------------------------------------- - // optional uint64 sequence = 1; + // optional uint64 sequence = 2; void clear_sequence(); - static const int kSequenceFieldNumber = 1; + static const int kSequenceFieldNumber = 2; ::google::protobuf::uint64 sequence() const; void set_sequence(::google::protobuf::uint64 value); + // optional .zproto.Router router = 3; + bool has_router() const; + void clear_router(); + static const int kRouterFieldNumber = 3; + const ::zproto::Router& router() const; + ::zproto::Router* mutable_router(); + ::zproto::Router* release_router(); + void set_allocated_router(::zproto::Router* router); + // @@protoc_insertion_point(class_scope:zproto.SequenceRsp) private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::zproto::Router* router_; ::google::protobuf::uint64 sequence_; mutable int _cached_size_; friend void protobuf_InitDefaults_seqsvr_2eproto_impl(); @@ -1303,24 +1339,10 @@ class LoadMaxSeqsDataReq : public ::google::protobuf::Message /* @@protoc_insert // accessors ------------------------------------------------------- - // optional uint32 set_id = 1; - void clear_set_id(); - static const int kSetIdFieldNumber = 1; - ::google::protobuf::uint32 set_id() const; - void set_set_id(::google::protobuf::uint32 value); - - // optional uint32 alloc_id = 2; - void clear_alloc_id(); - static const int kAllocIdFieldNumber = 2; - ::google::protobuf::uint32 alloc_id() const; - void set_alloc_id(::google::protobuf::uint32 value); - // @@protoc_insertion_point(class_scope:zproto.LoadMaxSeqsDataReq) private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 set_id_; - ::google::protobuf::uint32 alloc_id_; mutable int _cached_size_; friend void protobuf_InitDefaults_seqsvr_2eproto_impl(); friend void protobuf_AddDesc_seqsvr_2eproto_impl(); @@ -1453,18 +1475,6 @@ class SaveMaxSeqReq : public ::google::protobuf::Message /* @@protoc_insertion_p // accessors ------------------------------------------------------- - // optional uint32 set_id = 1; - void clear_set_id(); - static const int kSetIdFieldNumber = 1; - ::google::protobuf::uint32 set_id() const; - void set_set_id(::google::protobuf::uint32 value); - - // optional uint32 alloc_id = 2; - void clear_alloc_id(); - static const int kAllocIdFieldNumber = 2; - ::google::protobuf::uint32 alloc_id() const; - void set_alloc_id(::google::protobuf::uint32 value); - // optional uint32 section_id = 3; void clear_section_id(); static const int kSectionIdFieldNumber = 3; @@ -1481,8 +1491,6 @@ class SaveMaxSeqReq : public ::google::protobuf::Message /* @@protoc_insertion_p private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 set_id_; - ::google::protobuf::uint32 alloc_id_; ::google::protobuf::uint64 max_seq_; ::google::protobuf::uint32 section_id_; mutable int _cached_size_; @@ -1672,7 +1680,51 @@ inline const Range* Range::internal_default_instance() { // AllocSvrEntry -// optional .zproto.IpPort addr = 1; +// optional string alloc_name = 1; +inline void AllocSvrEntry::clear_alloc_name() { + alloc_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& AllocSvrEntry::alloc_name() const { + // @@protoc_insertion_point(field_get:zproto.AllocSvrEntry.alloc_name) + return alloc_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void AllocSvrEntry::set_alloc_name(const ::std::string& value) { + + alloc_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:zproto.AllocSvrEntry.alloc_name) +} +inline void AllocSvrEntry::set_alloc_name(const char* value) { + + alloc_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:zproto.AllocSvrEntry.alloc_name) +} +inline void AllocSvrEntry::set_alloc_name(const char* value, size_t size) { + + alloc_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:zproto.AllocSvrEntry.alloc_name) +} +inline ::std::string* AllocSvrEntry::mutable_alloc_name() { + + // @@protoc_insertion_point(field_mutable:zproto.AllocSvrEntry.alloc_name) + return alloc_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* AllocSvrEntry::release_alloc_name() { + // @@protoc_insertion_point(field_release:zproto.AllocSvrEntry.alloc_name) + + return alloc_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void AllocSvrEntry::set_allocated_alloc_name(::std::string* alloc_name) { + if (alloc_name != NULL) { + + } else { + + } + alloc_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), alloc_name); + // @@protoc_insertion_point(field_set_allocated:zproto.AllocSvrEntry.alloc_name) +} + +// optional .zproto.IpPort addr = 2; inline bool AllocSvrEntry::has_addr() const { return this != internal_default_instance() && addr_ != NULL; } @@ -1711,7 +1763,7 @@ inline void AllocSvrEntry::set_allocated_addr(::zproto::IpPort* addr) { // @@protoc_insertion_point(field_set_allocated:zproto.AllocSvrEntry.addr) } -// repeated .zproto.Range ranges = 2; +// repeated .zproto.Range ranges = 3; inline int AllocSvrEntry::ranges_size() const { return ranges_.size(); } @@ -1748,7 +1800,51 @@ inline const AllocSvrEntry* AllocSvrEntry::internal_default_instance() { // SetEntry -// repeated .zproto.AllocSvrEntry allocs = 1; +// optional string set_name = 1; +inline void SetEntry::clear_set_name() { + set_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline const ::std::string& SetEntry::set_name() const { + // @@protoc_insertion_point(field_get:zproto.SetEntry.set_name) + return set_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void SetEntry::set_set_name(const ::std::string& value) { + + set_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:zproto.SetEntry.set_name) +} +inline void SetEntry::set_set_name(const char* value) { + + set_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:zproto.SetEntry.set_name) +} +inline void SetEntry::set_set_name(const char* value, size_t size) { + + set_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size)); + // @@protoc_insertion_point(field_set_pointer:zproto.SetEntry.set_name) +} +inline ::std::string* SetEntry::mutable_set_name() { + + // @@protoc_insertion_point(field_mutable:zproto.SetEntry.set_name) + return set_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* SetEntry::release_set_name() { + // @@protoc_insertion_point(field_release:zproto.SetEntry.set_name) + + return set_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void SetEntry::set_allocated_set_name(::std::string* set_name) { + if (set_name != NULL) { + + } else { + + } + set_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), set_name); + // @@protoc_insertion_point(field_set_allocated:zproto.SetEntry.set_name) +} + +// repeated .zproto.AllocSvrEntry allocs = 2; inline int SetEntry::allocs_size() const { return allocs_.size(); } @@ -1778,7 +1874,7 @@ SetEntry::allocs() const { return allocs_; } -// optional .zproto.Range range = 2; +// optional .zproto.Range range = 3; inline bool SetEntry::has_range() const { return this != internal_default_instance() && range_ != NULL; } @@ -1838,51 +1934,7 @@ inline void Router::set_version(::google::protobuf::uint32 value) { // @@protoc_insertion_point(field_set:zproto.Router.version) } -// optional string name = 2; -inline void Router::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Router::name() const { - // @@protoc_insertion_point(field_get:zproto.Router.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Router::set_name(const ::std::string& value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:zproto.Router.name) -} -inline void Router::set_name(const char* value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:zproto.Router.name) -} -inline void Router::set_name(const char* value, size_t size) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:zproto.Router.name) -} -inline ::std::string* Router::mutable_name() { - - // @@protoc_insertion_point(field_mutable:zproto.Router.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Router::release_name() { - // @@protoc_insertion_point(field_release:zproto.Router.name) - - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Router::set_allocated_name(::std::string* name) { - if (name != NULL) { - - } else { - - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:zproto.Router.name) -} - -// repeated .zproto.SetEntry sets = 3; +// repeated .zproto.SetEntry sets = 2; inline int Router::sets_size() const { return sets_.size(); } @@ -2039,6 +2091,20 @@ inline void FetchNextSequenceReq::set_id(::google::protobuf::uint32 value) { // @@protoc_insertion_point(field_set:zproto.FetchNextSequenceReq.id) } +// optional uint32 version = 2; +inline void FetchNextSequenceReq::clear_version() { + version_ = 0u; +} +inline ::google::protobuf::uint32 FetchNextSequenceReq::version() const { + // @@protoc_insertion_point(field_get:zproto.FetchNextSequenceReq.version) + return version_; +} +inline void FetchNextSequenceReq::set_version(::google::protobuf::uint32 value) { + + version_ = value; + // @@protoc_insertion_point(field_set:zproto.FetchNextSequenceReq.version) +} + inline const FetchNextSequenceReq* FetchNextSequenceReq::internal_default_instance() { return &FetchNextSequenceReq_default_instance_.get(); } @@ -2060,6 +2126,20 @@ inline void GetCurrentSequenceReq::set_id(::google::protobuf::uint32 value) { // @@protoc_insertion_point(field_set:zproto.GetCurrentSequenceReq.id) } +// optional uint32 version = 2; +inline void GetCurrentSequenceReq::clear_version() { + version_ = 0u; +} +inline ::google::protobuf::uint32 GetCurrentSequenceReq::version() const { + // @@protoc_insertion_point(field_get:zproto.GetCurrentSequenceReq.version) + return version_; +} +inline void GetCurrentSequenceReq::set_version(::google::protobuf::uint32 value) { + + version_ = value; + // @@protoc_insertion_point(field_set:zproto.GetCurrentSequenceReq.version) +} + inline const GetCurrentSequenceReq* GetCurrentSequenceReq::internal_default_instance() { return &GetCurrentSequenceReq_default_instance_.get(); } @@ -2067,7 +2147,7 @@ inline const GetCurrentSequenceReq* GetCurrentSequenceReq::internal_default_inst // SequenceRsp -// optional uint64 sequence = 1; +// optional uint64 sequence = 2; inline void SequenceRsp::clear_sequence() { sequence_ = GOOGLE_ULONGLONG(0); } @@ -2081,6 +2161,45 @@ inline void SequenceRsp::set_sequence(::google::protobuf::uint64 value) { // @@protoc_insertion_point(field_set:zproto.SequenceRsp.sequence) } +// optional .zproto.Router router = 3; +inline bool SequenceRsp::has_router() const { + return this != internal_default_instance() && router_ != NULL; +} +inline void SequenceRsp::clear_router() { + if (GetArenaNoVirtual() == NULL && router_ != NULL) delete router_; + router_ = NULL; +} +inline const ::zproto::Router& SequenceRsp::router() const { + // @@protoc_insertion_point(field_get:zproto.SequenceRsp.router) + return router_ != NULL ? *router_ + : *::zproto::Router::internal_default_instance(); +} +inline ::zproto::Router* SequenceRsp::mutable_router() { + + if (router_ == NULL) { + router_ = new ::zproto::Router; + } + // @@protoc_insertion_point(field_mutable:zproto.SequenceRsp.router) + return router_; +} +inline ::zproto::Router* SequenceRsp::release_router() { + // @@protoc_insertion_point(field_release:zproto.SequenceRsp.router) + + ::zproto::Router* temp = router_; + router_ = NULL; + return temp; +} +inline void SequenceRsp::set_allocated_router(::zproto::Router* router) { + delete router_; + router_ = router; + if (router) { + + } else { + + } + // @@protoc_insertion_point(field_set_allocated:zproto.SequenceRsp.router) +} + inline const SequenceRsp* SequenceRsp::internal_default_instance() { return &SequenceRsp_default_instance_.get(); } @@ -2234,34 +2353,6 @@ inline const SequenceListRsp* SequenceListRsp::internal_default_instance() { // LoadMaxSeqsDataReq -// optional uint32 set_id = 1; -inline void LoadMaxSeqsDataReq::clear_set_id() { - set_id_ = 0u; -} -inline ::google::protobuf::uint32 LoadMaxSeqsDataReq::set_id() const { - // @@protoc_insertion_point(field_get:zproto.LoadMaxSeqsDataReq.set_id) - return set_id_; -} -inline void LoadMaxSeqsDataReq::set_set_id(::google::protobuf::uint32 value) { - - set_id_ = value; - // @@protoc_insertion_point(field_set:zproto.LoadMaxSeqsDataReq.set_id) -} - -// optional uint32 alloc_id = 2; -inline void LoadMaxSeqsDataReq::clear_alloc_id() { - alloc_id_ = 0u; -} -inline ::google::protobuf::uint32 LoadMaxSeqsDataReq::alloc_id() const { - // @@protoc_insertion_point(field_get:zproto.LoadMaxSeqsDataReq.alloc_id) - return alloc_id_; -} -inline void LoadMaxSeqsDataReq::set_alloc_id(::google::protobuf::uint32 value) { - - alloc_id_ = value; - // @@protoc_insertion_point(field_set:zproto.LoadMaxSeqsDataReq.alloc_id) -} - inline const LoadMaxSeqsDataReq* LoadMaxSeqsDataReq::internal_default_instance() { return &LoadMaxSeqsDataReq_default_instance_.get(); } @@ -2320,34 +2411,6 @@ inline const LoadMaxSeqsDataRsp* LoadMaxSeqsDataRsp::internal_default_instance() // SaveMaxSeqReq -// optional uint32 set_id = 1; -inline void SaveMaxSeqReq::clear_set_id() { - set_id_ = 0u; -} -inline ::google::protobuf::uint32 SaveMaxSeqReq::set_id() const { - // @@protoc_insertion_point(field_get:zproto.SaveMaxSeqReq.set_id) - return set_id_; -} -inline void SaveMaxSeqReq::set_set_id(::google::protobuf::uint32 value) { - - set_id_ = value; - // @@protoc_insertion_point(field_set:zproto.SaveMaxSeqReq.set_id) -} - -// optional uint32 alloc_id = 2; -inline void SaveMaxSeqReq::clear_alloc_id() { - alloc_id_ = 0u; -} -inline ::google::protobuf::uint32 SaveMaxSeqReq::alloc_id() const { - // @@protoc_insertion_point(field_get:zproto.SaveMaxSeqReq.alloc_id) - return alloc_id_; -} -inline void SaveMaxSeqReq::set_alloc_id(::google::protobuf::uint32 value) { - - alloc_id_ = value; - // @@protoc_insertion_point(field_set:zproto.SaveMaxSeqReq.alloc_id) -} - // optional uint32 section_id = 3; inline void SaveMaxSeqReq::clear_section_id() { section_id_ = 0u; diff --git a/seqsvr/proto/proto/seqsvr.proto b/seqsvr/proto/proto/seqsvr.proto index a01406d..3e99db4 100644 --- a/seqsvr/proto/proto/seqsvr.proto +++ b/seqsvr/proto/proto/seqsvr.proto @@ -36,13 +36,15 @@ message Range { } message AllocSvrEntry { - IpPort addr = 1; - repeated Range ranges = 2; + string alloc_name = 1; + IpPort addr = 2; + repeated Range ranges = 3; } message SetEntry { - repeated AllocSvrEntry allocs = 1; // set集合 - Range range = 2; // 号段范围 + string set_name = 1; + repeated AllocSvrEntry allocs = 2; // set集合 + Range range = 3; // 号段范围 } message Router { @@ -74,17 +76,25 @@ message GetRouteTableRsp { // GetNextSequenceReq -> SequenceRsp message FetchNextSequenceReq { uint32 id = 1; + uint32 version = 2; // 当前客户端版本号 } // 查询当前Seq // GetCurrentSequenceReq -> SequenceRsp message GetCurrentSequenceReq { uint32 id = 1; + uint32 version = 2; // 当前客户端版本号 } // 返回 message SequenceRsp { - uint64 sequence = 1; + // 1. 无法提供服务 + // 2. id不存在,仅返回路由表 + // 3. id存在,返回sequence,路由表未更新 + // 4. id存在,返回sequence,路由表需要更新 + // int32 result = 1; + uint64 sequence = 2; // 可能未设置 + Router router = 3; // 如果版本号 } // FetchNextSequenceListReq -> SequenceListRsp @@ -111,8 +121,8 @@ message SequenceListRsp { // 加载max_seqs数据 // LoadMaxSeqsDataReq -> LoadMaxSeqsDataRsp message LoadMaxSeqsDataReq { - uint32 set_id = 1; - uint32 alloc_id = 2; + // uint32 set_id = 1; + // uint32 alloc_id = 2; } // LoadMaxSeqsDataRsp @@ -123,8 +133,8 @@ message LoadMaxSeqsDataRsp { // 加载max_seqs数据 // SaveMaxSeqReq -> SaveMaxSeqRsp message SaveMaxSeqReq { - uint32 set_id = 1; - uint32 alloc_id = 2; + // uint32 set_id = 1; + // uint32 alloc_id = 2; uint32 section_id = 3; uint64 max_seq = 4; } diff --git a/seqsvr/storesvr/store_server.cc b/seqsvr/storesvr/store_server.cc index f0931aa..b05f20d 100644 --- a/seqsvr/storesvr/store_server.cc +++ b/seqsvr/storesvr/store_server.cc @@ -33,7 +33,7 @@ StoreServer::StoreServer() { bool StoreServer::Initialize() { auto store_instance = StoreSvrManager::GetInstance(); - store_instance->Initialize(store_config_.set_id, store_config_.store_path); + store_instance->Initialize(store_config_.set_name, store_config_.store_path); RegisterService("store_server", "rpc_server", "zrpc"); BaseServer::Initialize(); diff --git a/seqsvr/storesvr/store_server.h b/seqsvr/storesvr/store_server.h index 68c8a12..f16b417 100644 --- a/seqsvr/storesvr/store_server.h +++ b/seqsvr/storesvr/store_server.h @@ -34,14 +34,14 @@ struct StoreConfig : public nebula::Configurable { v = Configurable::GetConfigValue(conf, "store_path"); if (v.isString()) store_path = v.asString(); - v = Configurable::GetConfigValue(conf, "set_id"); - if (v.isInt()) set_id = static_cast(v.asInt()); + v = Configurable::GetConfigValue(conf, "set_name"); + if (v.isString()) set_name = v.asString(); return true; } std::string store_path; - int set_id {0}; + std::string set_name; }; class StoreServer : public nebula::BaseServer { diff --git a/seqsvr/storesvr/store_service_impl.cc b/seqsvr/storesvr/store_service_impl.cc index e843b50..01538b7 100644 --- a/seqsvr/storesvr/store_service_impl.cc +++ b/seqsvr/storesvr/store_service_impl.cc @@ -26,14 +26,12 @@ int StoreServiceImpl::LoadMaxSeqsData(const zproto::LoadMaxSeqsDataReq& request, zproto::LoadMaxSeqsDataRsp* response) { auto max_seqs = response->mutable_max_seqs(); - StoreSvrManager::GetInstance()->GetSectionsData(request.set_id(), request.alloc_id(), 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.set_id(), - request.alloc_id(), - request.section_id(), + uint64_t last_max_seq = StoreSvrManager::GetInstance()->SetSectionsData(request.section_id(), request.max_seq()); response->set_last_max_seq(last_max_seq); return 0; diff --git a/seqsvr/storesvr/storesvr_manager.cc b/seqsvr/storesvr/storesvr_manager.cc index 4130555..825800c 100644 --- a/seqsvr/storesvr/storesvr_manager.cc +++ b/seqsvr/storesvr/storesvr_manager.cc @@ -34,14 +34,14 @@ std::shared_ptr StoreSvrManager::GetInstance() { return g_storesvr_manager.try_get(); } -bool StoreSvrManager::Initialize(uint32_t set_id, const std::string& filepath) { +bool StoreSvrManager::Initialize(const std::string& set_name, const std::string& filepath) { boost::filesystem::path f2(filepath); if (!boost::filesystem::exists(f2)) { LOG(ERROR) << "Initialize - store db's filepath not exist!! " << filepath; return false; } - set_id_ = set_id; + // set_id_ = set_id; seq_file_path_ = filepath + "/seqdb.dat"; route_table_file_path_ = filepath + "/router.dat"; @@ -110,21 +110,22 @@ StoreSvrManager::~StoreSvrManager() { folly::closeNoInt(section_fd_); } -std::string StoreSvrManager::GetSectionsData(uint32_t set_id, uint32_t alloc_id) { +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(uint32_t set_id, uint32_t alloc_id, std::string* data) { +bool StoreSvrManager::GetSectionsData(std::string* data) { data->assign((char*)mapping_mem_.data(), mapping_mem_.size()*sizeof(uint64_t)); return true; } -uint64_t StoreSvrManager::SetSectionsData(uint32_t set_id, uint32_t alloc_id, uint32_t section_id, uint64_t max_seq) { +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; + // TODO(@benqi): 1. msync, 2. 是否要锁? if (rv > mapping_mem_[section_id]) { mapping_mem_[section_id] = rv; } else { @@ -136,7 +137,7 @@ uint64_t StoreSvrManager::SetSectionsData(uint32_t set_id, uint32_t alloc_id, ui bool StoreSvrManager::SaveCacheRouter(const zproto::Router& router) { std::string data; - if (!cache_router_.SerializeToString(&data)) { + if (!router.SerializeToString(&data)) { LOG(ERROR) << "SaveCacheRouter - cache_router_ serialize error!!!!"; return false; } diff --git a/seqsvr/storesvr/storesvr_manager.h b/seqsvr/storesvr/storesvr_manager.h index 5b8dc2b..b0aaf80 100644 --- a/seqsvr/storesvr/storesvr_manager.h +++ b/seqsvr/storesvr/storesvr_manager.h @@ -31,12 +31,12 @@ class StoreSvrManager { static std::shared_ptr GetInstance(); - bool Initialize(uint32_t set_id, const std::string& filepath); + bool Initialize(const std::string& set_name, const std::string& filepath); - std::string GetSectionsData(uint32_t set_id, uint32_t alloc_id); - bool GetSectionsData(uint32_t set_id, uint32_t alloc_id, std::string* data); + std::string GetSectionsData(); + bool GetSectionsData(std::string* data); - uint64_t SetSectionsData(uint32_t set_id, uint32_t alloc_id, uint32_t section_id, uint64_t max_seq); + uint64_t SetSectionsData(uint32_t section_id, uint64_t max_seq); zproto::Router& GetCacheRouter() { return cache_router_; @@ -51,9 +51,7 @@ class StoreSvrManager { int section_fd_ {-1}; folly::MemoryMapping* section_max_seqs_mapping_ {nullptr}; folly::Range mapping_mem_; - - uint32_t set_id_{1}; - + bool inited_ = false; std::string seq_file_path_; std::string route_table_file_path_; diff --git a/seqsvr/storesvr/zrpc_store_dispatcher.cc b/seqsvr/storesvr/zrpc_store_dispatcher.cc index ced79a7..1af4526 100644 --- a/seqsvr/storesvr/zrpc_store_dispatcher.cc +++ b/seqsvr/storesvr/zrpc_store_dispatcher.cc @@ -33,6 +33,9 @@ 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) {