Skip to content

Commit

Permalink
fix gateway not broadcast the latest status when updated
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Dec 12, 2024
1 parent 1faafa8 commit 28c2e38
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GatewayNodeInfo

// get the node information by nodeID
virtual ppc::protocol::INodeInfo::Ptr nodeInfo(bcos::bytes const& nodeID) const = 0;
virtual bool tryAddNodeInfo(ppc::protocol::INodeInfo::Ptr const& nodeInfo) = 0;
virtual bool tryAddNodeInfo(ppc::protocol::INodeInfo::Ptr const& nodeInfo, bool& updated) = 0;
virtual void removeNodeInfo(bcos::bytes const& nodeID) = 0;

virtual std::vector<std::shared_ptr<ppc::front::IFrontClient>> chooseRouteByComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ void GatewayNodeInfoImpl::updateNodeList()
}

// Note: this is wrappered with lock
bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info)
bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info, bool& updated)
{
updated = false;
auto nodeID = info->nodeID().toBytes();
auto existedNodeInfo = nodeInfo(nodeID);
// the node info has not been updated
Expand All @@ -101,6 +102,7 @@ bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info)
{
bcos::WriteGuard l(x_nodeList);
existedNodeInfo->setMeta(meta);
updated = true;
GATEWAY_LOG(INFO) << LOG_DESC("tryAddNodeInfo, update the meta, updated nodeInfo")
<< printNodeInfo(existedNodeInfo);
}
Expand All @@ -111,6 +113,7 @@ bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info)
bcos::WriteGuard l(x_nodeList);
existedNodeInfo->setComponents(
std::set<std::string>(components.begin(), components.end()));
updated = true;
GATEWAY_LOG(INFO) << LOG_DESC("tryAddNodeInfo, update the components, updated nodeInfo")
<< printNodeInfo(existedNodeInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GatewayNodeInfoImpl : public GatewayNodeInfo
void encode(bcos::bytes& data) const override;
void decode(bcos::bytesConstRef data) override;

bool tryAddNodeInfo(ppc::protocol::INodeInfo::Ptr const& nodeInfo) override;
bool tryAddNodeInfo(ppc::protocol::INodeInfo::Ptr const& nodeInfo, bool& updated) override;
void removeNodeInfo(bcos::bytes const& nodeID) override;

std::vector<std::shared_ptr<ppc::front::IFrontClient>> chooseRouteByComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ using namespace ppc::gateway;
bool LocalRouter::registerNodeInfo(ppc::protocol::INodeInfo::Ptr nodeInfo,
std::function<void()> onUnHealthHandler, bool removeHandlerOnUnhealth)
{
LOCAL_ROUTER_LOG(INFO) << LOG_DESC("registerNodeInfo") << printNodeInfo(nodeInfo);
auto ret = m_routerInfo->tryAddNodeInfo(nodeInfo);
LOCAL_ROUTER_LOG(DEBUG) << LOG_DESC("registerNodeInfo") << printNodeInfo(nodeInfo);
bool updated = false;
auto ret = m_routerInfo->tryAddNodeInfo(nodeInfo, updated);
if (ret)
{
// only create the frontClient when update
nodeInfo->setFront(m_frontBuilder->buildClient(
nodeInfo->endPoint(), onUnHealthHandler, removeHandlerOnUnhealth));
LOCAL_ROUTER_LOG(INFO) << LOG_DESC("registerNodeInfo: update the node")
<< printNodeInfo(nodeInfo);
}
// update the status if inserted or updated
if (ret || updated)
{
increaseSeq();
}
return ret;
Expand Down

0 comments on commit 28c2e38

Please sign in to comment.