mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-15 17:16:07 +00:00
Node-backed client and inbound edits no longer hard-fail when the backing node is offline or disabled. Edits commit to the panel DB immediately and reconcile to the node when it reconnects (eventual consistency); the panel is the single source of truth for desired config. - Add Node.ConfigDirty/ConfigDirtyAt; mark a node dirty when an edit commits without reaching it (cleared via CAS on ConfigDirtyAt after a full reconcile). - nodePushPlan() reads node state fresh from the DB, skips the push for offline/disabled nodes (no 10s hang), and treats push failures as non-fatal across every mutation path (client add/update/del + bulk + attach/detach; inbound add/update/del/toggle/resetTraffic). - ReconcileNode() pushes the panel's desired config to a node on reconnect (refreshing the remote tag cache first) and prunes node-side orphans; runs before the traffic pull in the node sync job. - While a node is dirty the traffic pull applies only up/down deltas and node-initiated disables, never overwriting desired config from a stale node snapshot. - Surface a non-blocking 'saved; will sync on reconnect' warning to the UI. Validated with a two-panel Docker E2E: client delete/update, attach/detach, and inbound add/delete all reconcile correctly offline -> reconnect.
This commit is contained in:
@@ -480,6 +480,50 @@ func (s *NodeService) UpdateHeartbeat(id int, p HeartbeatPatch) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NodeService) MarkNodeDirty(id int) error {
|
||||
if id <= 0 {
|
||||
return nil
|
||||
}
|
||||
return database.GetDB().Model(model.Node{}).
|
||||
Where("id = ?", id).
|
||||
Updates(map[string]any{
|
||||
"config_dirty": true,
|
||||
"config_dirty_at": time.Now().UnixMilli(),
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (s *NodeService) ClearNodeDirty(id int, dirtyAt int64) error {
|
||||
if id <= 0 {
|
||||
return nil
|
||||
}
|
||||
return database.GetDB().Model(model.Node{}).
|
||||
Where("id = ? AND config_dirty_at = ?", id, dirtyAt).
|
||||
Update("config_dirty", false).Error
|
||||
}
|
||||
|
||||
func (s *NodeService) NodeSyncState(id int) (enabled bool, status string, dirty bool, dirtyAt int64, err error) {
|
||||
if id <= 0 {
|
||||
return false, "", false, 0, errors.New("invalid node id")
|
||||
}
|
||||
var row model.Node
|
||||
err = database.GetDB().Model(model.Node{}).
|
||||
Select("enable", "status", "config_dirty", "config_dirty_at").
|
||||
Where("id = ?", id).
|
||||
First(&row).Error
|
||||
if err != nil {
|
||||
return false, "", false, 0, err
|
||||
}
|
||||
return row.Enable, row.Status, row.ConfigDirty, row.ConfigDirtyAt, nil
|
||||
}
|
||||
|
||||
func (s *NodeService) IsNodePending(id int) bool {
|
||||
enabled, status, dirty, _, err := s.NodeSyncState(id)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return !enabled || status != "online" || dirty
|
||||
}
|
||||
|
||||
func nodeMetricKey(id int, metric string) string {
|
||||
return "node:" + strconv.Itoa(id) + ":" + metric
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user