forked from TrueCloudLab/frostfs-sdk-go
[#300] pool: Move 'healthCheck' to separate file
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
b083bf8546
commit
d77a8742bc
2 changed files with 47 additions and 41 deletions
47
pool/healthcheck.go
Normal file
47
pool/healthcheck.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package pool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type healthCheck struct {
|
||||||
|
cancel context.CancelFunc
|
||||||
|
closedCh chan struct{}
|
||||||
|
|
||||||
|
clientRebalanceInterval time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func newHealthCheck(clientRebalanceInterval time.Duration) *healthCheck {
|
||||||
|
var h healthCheck
|
||||||
|
h.clientRebalanceInterval = clientRebalanceInterval
|
||||||
|
h.closedCh = make(chan struct{})
|
||||||
|
return &h
|
||||||
|
}
|
||||||
|
|
||||||
|
// startRebalance runs loop to monitor connection healthy status.
|
||||||
|
func (h *healthCheck) startRebalance(ctx context.Context, callback func(ctx context.Context)) {
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
h.cancel = cancel
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(h.clientRebalanceInterval)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
close(h.closedCh)
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
callback(ctx)
|
||||||
|
ticker.Reset(h.clientRebalanceInterval)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *healthCheck) stopRebalance() {
|
||||||
|
h.cancel()
|
||||||
|
<-h.closedCh
|
||||||
|
}
|
41
pool/pool.go
41
pool/pool.go
|
@ -2026,20 +2026,6 @@ type connectionManager struct {
|
||||||
healthChecker *healthCheck
|
healthChecker *healthCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
type healthCheck struct {
|
|
||||||
cancel context.CancelFunc
|
|
||||||
closedCh chan struct{}
|
|
||||||
|
|
||||||
clientRebalanceInterval time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func newHealthCheck(clientRebalanceInterval time.Duration) *healthCheck {
|
|
||||||
var h healthCheck
|
|
||||||
h.clientRebalanceInterval = clientRebalanceInterval
|
|
||||||
h.closedCh = make(chan struct{})
|
|
||||||
return &h
|
|
||||||
}
|
|
||||||
|
|
||||||
type innerPool struct {
|
type innerPool struct {
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
sampler *sampler
|
sampler *sampler
|
||||||
|
@ -2289,33 +2275,6 @@ func adjustNodeParams(nodeParams []NodeParam) ([]*nodesParam, error) {
|
||||||
return nodesParams, nil
|
return nodesParams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// startRebalance runs loop to monitor connection healthy status.
|
|
||||||
func (h *healthCheck) startRebalance(ctx context.Context, callback func(ctx context.Context)) {
|
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
h.cancel = cancel
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
ticker := time.NewTicker(h.clientRebalanceInterval)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
close(h.closedCh)
|
|
||||||
return
|
|
||||||
case <-ticker.C:
|
|
||||||
callback(ctx)
|
|
||||||
ticker.Reset(h.clientRebalanceInterval)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *healthCheck) stopRebalance() {
|
|
||||||
h.cancel()
|
|
||||||
<-h.closedCh
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cm *connectionManager) updateNodesHealth(ctx context.Context, buffers [][]float64) {
|
func (cm *connectionManager) updateNodesHealth(ctx context.Context, buffers [][]float64) {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
for i, inner := range cm.innerPools {
|
for i, inner := range cm.innerPools {
|
||||||
|
|
Loading…
Add table
Reference in a new issue