mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 16:04:50 +03:00
fix(nodes): isolate traffic sync and report client apply outcomes (#7308)
Isolate traffic synchronization with bounded round-robin per-node workers, independent maintenance and publication, cancellation and ordered shutdown drain. Recheck online eligibility inside the serialized writer before merging snapshots and retain the latest valid speed sample per node, with expiry and explicit empty publication.
Report direct per-node applied/pending/failed outcomes without changing local-save success semantics. Propagate downstream pending separately from direct ACKs so acknowledged batch items do not abort subsequent work. Integrate live admission into the existing #7314 ordered dispatcher with separate four-second queue and batch budgets, retaining monotonic dirty generations, exclusive full-delete/reconcile turns, durable deletion outbox, generation-matched settlement, cross-node recreation safeguards and targeted fingerprint invalidation. Preserve legacy peer compatibility and update generated API documentation.
Validation: all 12 CI jobs and Docs CI passed on reviewed head d13850474f (runs 46871519847 and 46871519831). PostgreSQL logs confirm eight ordering regressions, including saturation, lost ACK, cross-node recreation and bulk recovery. Author reports make verify, focused SQLite/PostgreSQL race tests, four mixed-version node E2E pairings and Xray E2E. No independent production-scale latency measurement or universal HTTP timeout guarantee.
Residual follow-ups: possible conservative false-pending result when a final full delete settles an intermediate superseded intent on the same node; add per-logical-operation settlement regression. Verify shutdown drain under a blocked writer/maintenance worker. These static-review concerns remain open for follow-up, not demonstrated data loss or a new deadlock.
Refs #7293
This commit is contained in:
@@ -51,7 +51,7 @@ func sameNodeClientDelete(db *gorm.DB, row model.NodePendingClientDelete) *gorm.
|
||||
|
||||
// applyNodeClientDelete runs under the node-wide turn. Later attached clients
|
||||
// push after this turn or are restored by the dirty generation on reconcile.
|
||||
func applyNodeClientDelete(ctx context.Context, rt runtime.Runtime, row model.NodePendingClientDelete) error {
|
||||
func applyNodeClientDelete(ctx context.Context, rt runtime.Runtime, row model.NodePendingClientDelete) (runtime.ClientApplyResult, bool, error) {
|
||||
db := database.GetDB().WithContext(ctx)
|
||||
var target struct {
|
||||
Desired bool
|
||||
@@ -63,16 +63,19 @@ func applyNodeClientDelete(ctx context.Context, rt runtime.Runtime, row model.No
|
||||
Joins("LEFT JOIN clients ON clients.email = node_pending_client_deletes.email").
|
||||
Limit(1).Scan(&target)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
return result.Error
|
||||
return runtime.ClientApplyResult{}, false, result.Error
|
||||
}
|
||||
// Only a desired attachment on this node supersedes its pending delete.
|
||||
// Recreating the email elsewhere must not leave the old node record behind.
|
||||
var applied runtime.ClientApplyResult
|
||||
if !target.Desired {
|
||||
if err := rt.DeleteClient(ctx, row.Email); err != nil {
|
||||
return err
|
||||
var err error
|
||||
applied, err = rt.DeleteClient(ctx, row.Email)
|
||||
if err != nil {
|
||||
return applied, false, err
|
||||
}
|
||||
}
|
||||
return sameNodeClientDelete(db, row).Delete(&model.NodePendingClientDelete{}).Error
|
||||
return applied, !target.Desired, sameNodeClientDelete(db, row).Delete(&model.NodePendingClientDelete{}).Error
|
||||
}
|
||||
|
||||
const nodeClientDeletePage = 200
|
||||
@@ -93,7 +96,7 @@ func deliverNodeClientDeletes(ctx context.Context, nodeID int, rt runtime.Runtim
|
||||
defer cancel()
|
||||
var firstErr error
|
||||
for _, row := range rows {
|
||||
if err := applyNodeClientDelete(sendCtx, rt, row); err != nil {
|
||||
if _, _, err := applyNodeClientDelete(sendCtx, rt, row); err != nil {
|
||||
if firstErr == nil {
|
||||
firstErr = err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user