forked from TrueCloudLab/frostfs-node
Dmitrii Stepanov
888f966eb4
Different DBs can be rebuild concurrently. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
26 lines
465 B
Go
26 lines
465 B
Go
package engine
|
|
|
|
import "context"
|
|
|
|
type rebuildLimiter struct {
|
|
semaphore chan struct{}
|
|
}
|
|
|
|
func newRebuildLimiter(workersCount uint32) *rebuildLimiter {
|
|
return &rebuildLimiter{
|
|
semaphore: make(chan struct{}, workersCount),
|
|
}
|
|
}
|
|
|
|
func (l *rebuildLimiter) AcquireWorkSlot(ctx context.Context) error {
|
|
select {
|
|
case l.semaphore <- struct{}{}:
|
|
return nil
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
}
|
|
}
|
|
|
|
func (l *rebuildLimiter) ReleaseWorkSlot() {
|
|
<-l.semaphore
|
|
}
|