lichao
2021-05-18 ccf72bb0b8aa9c421bb2964acca2dcd868d10a94
use more rational node timeout, 60s.
5个文件已修改
31 ■■■■ 已修改文件
box/center.cpp 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/defs.cpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/defs.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/sendq.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/topic_node.h 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
box/center.cpp
@@ -822,7 +822,8 @@
        }
    };
    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()) {
src/defs.cpp
@@ -187,4 +187,6 @@
{
    ec = LastErrorStore().ec_;
    msg = LastErrorStore().msg_;
}
}
int NodeTimeoutSec() { return 60; }
src/defs.h
@@ -66,4 +66,7 @@
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
src/sendq.h
@@ -89,7 +89,7 @@
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;
src/topic_node.h
@@ -86,7 +86,11 @@
    {
        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:
@@ -94,15 +98,18 @@
            {
                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;
            }
        };