use more rational node timeout, 60s.
| | |
| | | } |
| | | }; |
| | | |
| | | auto center_ptr = std::make_shared<Synced<NodeCenter>>("#bhome_center", gc, 6s, 6s * 2); |
| | | auto nsec = seconds(NodeTimeoutSec()); |
| | | auto center_ptr = std::make_shared<Synced<NodeCenter>>("#bhome_center", gc, nsec, nsec * 3); // *3 to allow other clients to finish sending msgs. |
| | | AddCenter(center_ptr); |
| | | |
| | | for (auto &kv : Centers()) { |
| | |
| | | { |
| | | ec = LastErrorStore().ec_; |
| | | msg = LastErrorStore().msg_; |
| | | } |
| | | } |
| | | |
| | | int NodeTimeoutSec() { return 60; } |
| | |
| | | bool BHNodeInit(const int64_t request, int64_t &reply); |
| | | void BHCenterHandleInit(std::function<int64_t(const int64_t)> const &onReq); |
| | | |
| | | // node mq is avail with in timeout; after that may get killed. |
| | | int NodeTimeoutSec(); |
| | | |
| | | #endif // end of include guard: DEFS_KP8LKGD0 |
| | |
| | | |
| | | private: |
| | | static TimePoint Now() { return TimedMsg::Clock::now(); } |
| | | static TimePoint DefaultExpire() { return Now() + std::chrono::seconds(60); } |
| | | static TimePoint DefaultExpire() { return Now() + std::chrono::seconds(NodeTimeoutSec()); } |
| | | void AppendData(const MQInfo &mq, const Data data, const TimePoint &expire, OnMsgEvent onExpire); |
| | | |
| | | typedef std::deque<TimedMsg> Array; |
| | |
| | | { |
| | | class Impl |
| | | { |
| | | typedef std::unordered_map<Topic, Address> Records; |
| | | struct TimedRec { |
| | | Address addr_; |
| | | int64_t timestamp_; |
| | | }; |
| | | typedef std::unordered_map<Topic, TimedRec> Records; |
| | | Records records_; |
| | | |
| | | public: |
| | |
| | | { |
| | | auto pos = records_.find(topic); |
| | | if (pos != records_.end()) { |
| | | addr = pos->second; |
| | | return true; |
| | | } else { |
| | | return false; |
| | | if (NowSec() - pos->second.timestamp_ < NodeTimeoutSec() / 2) { |
| | | addr = pos->second.addr_; |
| | | return true; |
| | | } else { |
| | | LOG_TRACE() << "topic dest cache timeout."; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | bool Store(const Topic &topic, const Address &addr) |
| | | { |
| | | records_[topic] = addr; |
| | | records_[topic] = {addr, NowSec()}; |
| | | return true; |
| | | } |
| | | }; |