修复更新节点时并发导致的分配失败问题
This commit is contained in:
@@ -20,7 +20,7 @@ func FindCitiesWithEdgesCount(tx *gorm.DB) ([]model.City, error) {
|
||||
model.City
|
||||
EdgesCount int `gorm:"column:edges_count"`
|
||||
}
|
||||
err := tx.Debug().
|
||||
err := tx.
|
||||
Select("cityhash.*, COUNT(edge.id) AS edges_count").
|
||||
Joins("LEFT JOIN edge ON edge.city_id = cityhash.id").
|
||||
Where("cityhash.label IS NOT NULL").
|
||||
|
||||
@@ -94,6 +94,14 @@ func Update(args ...UpdateArgs) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询城市 %s 可用节点失败:%w", city.Name, err)
|
||||
}
|
||||
if len(edges) < count {
|
||||
slog.Debug("城市节点不足,将循环使用节点", "城市", city.Name, "节点数", city.EdgesCount, "网关数", count)
|
||||
edges, err = SliceActiveEdgesByCity(tx, city.Id, 0, count)
|
||||
if err != nil {
|
||||
return fmt.Errorf("查询城市 %s 可用节点失败:%w", city.Name, err)
|
||||
}
|
||||
offset = 0
|
||||
}
|
||||
|
||||
// 更新网关配置
|
||||
var configs2Create []model.Config
|
||||
|
||||
15
cmd/tmp.go
15
cmd/tmp.go
@@ -1,15 +0,0 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
//slog.Debug("初始化环境变量")
|
||||
//err := godotenv.Load()
|
||||
//if err != nil {
|
||||
// slog.Error(fmt.Errorf("初始化变量失败:%w", err).Error())
|
||||
//}
|
||||
//
|
||||
//model.Init()
|
||||
//clients.InitRedis()
|
||||
//
|
||||
//cities, _ := actions.FindCitiesWithEdgesCount(model.DB)
|
||||
//fmt.Printf("%v\n", cities)
|
||||
}
|
||||
Reference in New Issue
Block a user