From 28c2e381d08eb6c389ccc0b18dc7ed612e12fa33 Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Fri, 13 Dec 2024 00:51:06 +0800 Subject: [PATCH] fix gateway not broadcast the latest status when updated --- .../ppc-gateway/gateway/router/GatewayNodeInfo.h | 2 +- .../ppc-gateway/gateway/router/GatewayNodeInfoImpl.cpp | 5 ++++- .../ppc-gateway/gateway/router/GatewayNodeInfoImpl.h | 2 +- .../ppc-gateway/gateway/router/LocalRouter.cpp | 9 +++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfo.h b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfo.h index e12fe0d6..825a476d 100644 --- a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfo.h +++ b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfo.h @@ -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> chooseRouteByComponent( diff --git a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.cpp b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.cpp index c23a695b..c6bc0d95 100644 --- a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.cpp +++ b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.cpp @@ -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 @@ -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); } @@ -111,6 +113,7 @@ bool GatewayNodeInfoImpl::tryAddNodeInfo(INodeInfo::Ptr const& info) bcos::WriteGuard l(x_nodeList); existedNodeInfo->setComponents( std::set(components.begin(), components.end())); + updated = true; GATEWAY_LOG(INFO) << LOG_DESC("tryAddNodeInfo, update the components, updated nodeInfo") << printNodeInfo(existedNodeInfo); } diff --git a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.h b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.h index aeab2c1d..1f32c233 100644 --- a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.h +++ b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/GatewayNodeInfoImpl.h @@ -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> chooseRouteByComponent( diff --git a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp index 5ada018c..9e09e4b2 100644 --- a/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp +++ b/cpp/wedpr-transport/ppc-gateway/ppc-gateway/gateway/router/LocalRouter.cpp @@ -29,8 +29,9 @@ using namespace ppc::gateway; bool LocalRouter::registerNodeInfo(ppc::protocol::INodeInfo::Ptr nodeInfo, std::function 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 @@ -38,6 +39,10 @@ bool LocalRouter::registerNodeInfo(ppc::protocol::INodeInfo::Ptr nodeInfo, 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;