This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package worker | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/tidb-lightning/lightning/metric" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////// | ||
|
||
type RestoreWorkerPool struct { | ||
limit int | ||
workers chan *RestoreWorker | ||
name string | ||
} | ||
|
||
type RestoreWorker struct { | ||
ID int64 | ||
} | ||
|
||
func NewRestoreWorkerPool(ctx context.Context, limit int, name string) *RestoreWorkerPool { | ||
workers := make(chan *RestoreWorker, limit) | ||
for i := 0; i < limit; i++ { | ||
workers <- &RestoreWorker{ID: int64(i + 1)} | ||
} | ||
|
||
metric.IdleWorkersGauge.WithLabelValues(name).Set(float64(limit)) | ||
return &RestoreWorkerPool{ | ||
limit: limit, | ||
workers: workers, | ||
name: name, | ||
} | ||
} | ||
|
||
func (pool *RestoreWorkerPool) Apply() *RestoreWorker { | ||
worker := <-pool.workers | ||
metric.IdleWorkersGauge.WithLabelValues(pool.name).Set(float64(len(pool.workers))) | ||
return worker | ||
} | ||
func (pool *RestoreWorkerPool) Recycle(worker *RestoreWorker) { | ||
pool.workers <- worker | ||
metric.IdleWorkersGauge.WithLabelValues(pool.name).Set(float64(len(pool.workers))) | ||
} | ||
|
||
//////////////////////////////////////////////////////////////// |