Skip to content

Commit cc9af8d

Browse files
Revert "Restart zero worker if there is still work to do (go-gitea#18658)"
This reverts commit df44017.
1 parent 03f671a commit cc9af8d

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

modules/queue/workerpool.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ func (p *WorkerPool) hasNoWorkerScaling() bool {
115115
return p.numberOfWorkers == 0 && (p.boostTimeout == 0 || p.boostWorkers == 0 || p.maxNumberOfWorkers == 0)
116116
}
117117

118-
// zeroBoost will add a temporary boost worker for a no worker queue
119-
// p.lock must be locked at the start of this function BUT it will be unlocked by the end of this function
120-
// (This is because addWorkers has to be called whilst unlocked)
121118
func (p *WorkerPool) zeroBoost() {
122119
ctx, cancel := context.WithTimeout(p.baseCtx, p.boostTimeout)
123120
mq := GetManager().GetManagedQueue(p.qid)
@@ -319,17 +316,6 @@ func (p *WorkerPool) addWorkers(ctx context.Context, cancel context.CancelFunc,
319316
}
320317
p.pause()
321318
}
322-
select {
323-
case <-p.baseCtx.Done():
324-
// this worker queue is shut-down don't reboost
325-
default:
326-
if p.numberOfWorkers == 0 && atomic.LoadInt64(&p.numInQueue) > 0 {
327-
// OK there are no workers but... there's still work to be done -> Reboost
328-
p.zeroBoost()
329-
// p.lock will be unlocked by zeroBoost
330-
return
331-
}
332-
}
333319
p.lock.Unlock()
334320
}()
335321
}

services/mirror/mirror.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
5959

6060
handler := func(idx int, bean interface{}, limit int) error {
6161
var item SyncRequest
62-
var repo *repo_model.Repository
6362
if m, ok := bean.(*repo_model.Mirror); ok {
6463
if m.Repo == nil {
6564
log.Error("Disconnected mirror found: %d", m.ID)
6665
return nil
6766
}
68-
repo = m.Repo
6967
item = SyncRequest{
7068
Type: PullMirrorType,
7169
RepoID: m.RepoID,
@@ -75,7 +73,6 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
7573
log.Error("Disconnected push-mirror found: %d", m.ID)
7674
return nil
7775
}
78-
repo = m.Repo
7976
item = SyncRequest{
8077
Type: PushMirrorType,
8178
RepoID: m.RepoID,
@@ -92,16 +89,17 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
9289
default:
9390
}
9491

92+
// Check if this request is already in the queue
93+
has, err := mirrorQueue.Has(&item)
94+
if err != nil {
95+
return err
96+
}
97+
if has {
98+
return nil
99+
}
100+
95101
// Push to the Queue
96102
if err := mirrorQueue.Push(&item); err != nil {
97-
if err == queue.ErrAlreadyInQueue {
98-
if item.Type == PushMirrorType {
99-
log.Trace("PushMirrors for %-v already queued for sync", repo)
100-
} else {
101-
log.Trace("PullMirrors for %-v already queued for sync", repo)
102-
}
103-
return nil
104-
}
105103
return err
106104
}
107105

@@ -112,29 +110,23 @@ func Update(ctx context.Context, pullLimit, pushLimit int) error {
112110
return nil
113111
}
114112

115-
pullMirrorsRequested := 0
116113
if pullLimit != 0 {
117-
requested = 0
118114
if err := repo_model.MirrorsIterate(func(idx int, bean interface{}) error {
119115
return handler(idx, bean, pullLimit)
120116
}); err != nil && err != errLimit {
121117
log.Error("MirrorsIterate: %v", err)
122118
return err
123119
}
124-
pullMirrorsRequested, requested = requested, 0
125120
}
126-
pushMirrorsRequested := 0
127121
if pushLimit != 0 {
128-
requested = 0
129122
if err := repo_model.PushMirrorsIterate(func(idx int, bean interface{}) error {
130123
return handler(idx, bean, pushLimit)
131124
}); err != nil && err != errLimit {
132125
log.Error("PushMirrorsIterate: %v", err)
133126
return err
134127
}
135-
pushMirrorsRequested, requested = requested, 0
136128
}
137-
log.Trace("Finished: Update: %d pull mirrors and %d push mirrors queued", pullMirrorsRequested, pushMirrorsRequested)
129+
log.Trace("Finished: Update")
138130
return nil
139131
}
140132

0 commit comments

Comments
 (0)