mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
Support failover in cluster (experimental)
This commit is contained in:
36
cluster/core/cron.go
Normal file
36
cluster/core/cron.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/hdt3213/godis/cluster/raft"
|
||||
)
|
||||
|
||||
func (cluster *Cluster) clusterCron() {
|
||||
if cluster.config.noCron {
|
||||
return
|
||||
}
|
||||
ticker := time.NewTicker(time.Second)
|
||||
var running int32
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if cluster.raftNode.State() == raft.Leader {
|
||||
if atomic.CompareAndSwapInt32(&running, 0, 1) {
|
||||
// Disable parallelism
|
||||
go func() {
|
||||
cluster.doFailoverCheck()
|
||||
cluster.doRebalance()
|
||||
atomic.StoreInt32(&running, 0)
|
||||
}()
|
||||
}
|
||||
} else {
|
||||
cluster.sendHearbeat()
|
||||
}
|
||||
case <-cluster.closeChan:
|
||||
ticker.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user