Skip to content

Commit fcab9b4

Browse files
authored
fix gateway not broadcast the latest status when updated (#124)
1 parent 1faafa8 commit fcab9b4

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class GatewayNodeInfo
4242

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

4848
virtual std::vector<std::shared_ptr<ppc::front::IFrontClient>> chooseRouteByComponent(

cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ void GatewayNodeInfoImpl::updateNodeList()
8888
}
8989

9090
// Note: this is wrappered with lock
91-
bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info)
91+
bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info, bool& updated)
9292
{
93+
updated = false;
9394
auto nodeID = info->nodeID().toBytes();
9495
auto existedNodeInfo = nodeInfo(nodeID);
9596
// the node info has not been updated
@@ -101,6 +102,7 @@ bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info)
101102
{
102103
bcos::WriteGuard l(x_nodeList);
103104
existedNodeInfo->setMeta(meta);
105+
updated = true;
104106
GATEWAY_LOG(INFO) << LOG_DESC("tryAddNodeInfo, update the meta, updated nodeInfo")
105107
<< printNodeInfo(existedNodeInfo);
106108
}
@@ -111,6 +113,7 @@ bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info)
111113
bcos::WriteGuard l(x_nodeList);
112114
existedNodeInfo->setComponents(
113115
std::set<std::string>(components.begin(), components.end()));
116+
updated = true;
114117
GATEWAY_LOG(INFO) << LOG_DESC("tryAddNodeInfo, update the components, updated nodeInfo")
115118
<< printNodeInfo(existedNodeInfo);
116119
}

cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GatewayNodeInfoImpl : public GatewayNodeInfo
5656
void encode(bcos::bytes& data) const override;
5757
void decode(bcos::bytesConstRef data) override;
5858

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

6262
std::vector<std::shared_ptr<ppc::front::IFrontClient>> chooseRouteByComponent(

cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ using namespace ppc::gateway;
2929
bool LocalRouter::registerNodeInfo(ppc::protocol::INodeInfo::Ptr nodeInfo,
3030
std::function<void()> onUnHealthHandler, bool removeHandlerOnUnhealth)
3131
{
32-
LOCAL_ROUTER_LOG(INFO) << LOG_DESC("registerNodeInfo") << printNodeInfo(nodeInfo);
33-
auto ret = m_routerInfo->tryAddNodeInfo(nodeInfo);
32+
LOCAL_ROUTER_LOG(DEBUG) << LOG_DESC("registerNodeInfo") << printNodeInfo(nodeInfo);
33+
bool updated = false;
34+
auto ret = m_routerInfo->tryAddNodeInfo(nodeInfo, updated);
3435
if (ret)
3536
{
3637
// only create the frontClient when update
3738
nodeInfo->setFront(m_frontBuilder->buildClient(
3839
nodeInfo->endPoint(), onUnHealthHandler, removeHandlerOnUnhealth));
3940
LOCAL_ROUTER_LOG(INFO) << LOG_DESC("registerNodeInfo: update the node")
4041
<< printNodeInfo(nodeInfo);
42+
}
43+
// update the status if inserted or updated
44+
if (ret || updated)
45+
{
4146
increaseSeq();
4247
}
4348
return ret;

0 commit comments

Comments
 (0)