From 0f5dd2fbd296f433e0296531b6a40deb7fc804f2 Mon Sep 17 00:00:00 2001 From: luorijun Date: Mon, 2 Mar 2026 14:18:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E9=87=8F=E6=9B=B4=E6=96=B0=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- gateway/gateway.go | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eaa9272..5ed3184 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ ## TODO -检查连接被提前关闭的问题 +数据通道池化 + +协程池化 访问失败的也返回访问记录 -解决节点断开立即重连会导致 status 覆盖的问题 - -实现一个机制使更新数据的后项能够覆盖前项 +解决节点断开立即重连会导致 status 覆盖的问题,维护一个修改表,每次提交后清空,每个节点的修改在同一阶段内只有一次 节点每次发送心跳后提供或计算 loss 和 rtt 信息,并对比 host 和 status,将需要更新的数据提交到更新队列 diff --git a/gateway/gateway.go b/gateway/gateway.go index e291634..5baf26c 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -190,12 +190,23 @@ func startWeb(ctx context.Context) error { func startTask(ctx context.Context) error { + // 维护一个修改表,每次提交后清空,每个节点的修改在同一阶段内只有一次 var lock = sync.Mutex{} var updates = make([]*core.Edge, 0) + var updatesMap = make(map[int32]*core.Edge) go func() { for data := range app.EdgeUpdates { lock.Lock() - updates = append(updates, data) + if update, ok := updatesMap[data.Id]; ok { + if data.Status != update.Status { + // 如果状态发生变化,则更新 + updatesMap[data.Id] = data + updates = append(updates, data) + } + } else { + updatesMap[data.Id] = data + updates = append(updates, data) + } lock.Unlock() } }()