增量更新节点状态

This commit is contained in:
2026-03-02 14:18:11 +08:00
parent f45ab3e89c
commit 0f5dd2fbd2
2 changed files with 16 additions and 5 deletions

View File

@@ -1,12 +1,12 @@
## TODO
检查连接被提前关闭的问题
数据通道池化
协程池化
访问失败的也返回访问记录
解决节点断开立即重连会导致 status 覆盖的问题
实现一个机制使更新数据的后项能够覆盖前项
解决节点断开立即重连会导致 status 覆盖的问题,维护一个修改表,每次提交后清空,每个节点的修改在同一阶段内只有一次
节点每次发送心跳后提供或计算 loss 和 rtt 信息,并对比 host 和 status将需要更新的数据提交到更新队列

View File

@@ -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()
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()
}
}()